Move writing and reading of common Track fields into functions...

... also now writing selected state of TimeTrack as for other tracks, fixing
an omission, with no harm to forward compatibility
This commit is contained in:
Paul Licameli 2018-11-20 14:37:19 -05:00
parent 2b2d13d5be
commit 98f322d685
7 changed files with 60 additions and 58 deletions

View File

@ -2390,8 +2390,8 @@ bool LabelTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
return true;
const wxString strValue = value;
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
mName = strValue;
if (this->Track::HandleCommonXMLAttribute(attr, strValue))
;
else if (!wxStrcmp(attr, wxT("numlabels")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
{
@ -2403,15 +2403,6 @@ bool LabelTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
mLabels.clear();
mLabels.reserve(nValue);
}
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
SetHeight(nValue);
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
SetMinimized(nValue != 0);
else if (!wxStrcmp(attr, wxT("isSelected")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
this->SetSelected(nValue != 0);
}
return true;
@ -2434,11 +2425,8 @@ void LabelTrack::WriteXML(XMLWriter &xmlFile) const
int len = mLabels.size();
xmlFile.StartTag(wxT("labeltrack"));
xmlFile.WriteAttr(wxT("name"), mName);
this->Track::WriteCommonXMLAttributes( xmlFile );
xmlFile.WriteAttr(wxT("numlabels"), len);
xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), this->GetMinimized());
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
for (auto &labelStruct: mLabels) {
xmlFile.StartTag(wxT("label"));

View File

@ -873,8 +873,8 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
const wxString strValue = value;
long nValue;
double dblValue;
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
mName = strValue;
if (this->Track::HandleCommonXMLAttribute(attr, strValue))
;
else if (this->NoteTrackBase::HandleXMLAttribute(attr, value))
{}
else if (!wxStrcmp(attr, wxT("offset")) &&
@ -888,15 +888,6 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
return false;
mVisibleChannels = nValue;
}
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
mHeight = nValue;
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
mMinimized = (nValue != 0);
else if (!wxStrcmp(attr, wxT("isSelected")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
this->SetSelected(nValue != 0);
#ifdef EXPERIMENTAL_MIDI_OUT
else if (!wxStrcmp(attr, wxT("velocity")) &&
XMLValueChecker::IsGoodString(strValue) &&
@ -939,13 +930,10 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile) const
}
saveme->GetSeq().write(data, true);
xmlFile.StartTag(wxT("notetrack"));
xmlFile.WriteAttr(wxT("name"), saveme->mName);
saveme->Track::WriteCommonXMLAttributes( xmlFile );
this->NoteTrackBase::WriteXMLAttributes(xmlFile);
xmlFile.WriteAttr(wxT("offset"), saveme->GetOffset());
xmlFile.WriteAttr(wxT("visiblechannels"), saveme->mVisibleChannels);
xmlFile.WriteAttr(wxT("height"), saveme->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), saveme->GetMinimized());
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
#ifdef EXPERIMENTAL_MIDI_OUT
xmlFile.WriteAttr(wxT("velocity"), (double) saveme->mVelocity);

View File

@ -498,8 +498,7 @@ void ProjectFileIO::WriteXML(
xmlFile.WriteAttr(wxT("offset"), offset, 8);
xmlFile.WriteAttr(wxT("mute"), pWaveTrack->GetMute());
xmlFile.WriteAttr(wxT("solo"), pWaveTrack->GetSolo());
xmlFile.WriteAttr(wxT("height"), pWaveTrack->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), pWaveTrack->GetMinimized());
pWaveTrack->Track::WriteCommonXMLAttributes( xmlFile, false );
// Don't store "rate" tag because the importer can figure that out.
// xmlFile.WriteAttr(wxT("rate"), pWaveTrack->GetRate());

View File

@ -204,14 +204,8 @@ bool TimeTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
break;
const wxString strValue = value;
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
mName = strValue;
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
mHeight = nValue;
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
mMinimized = (nValue != 0);
if (this->Track::HandleCommonXMLAttribute(attr, strValue))
;
else if (!wxStrcmp(attr, wxT("rangelower")))
{
SetRangeLower( Internat::CompatibleToDouble(value) );
@ -266,12 +260,10 @@ void TimeTrack::WriteXML(XMLWriter &xmlFile) const
// may throw
{
xmlFile.StartTag(wxT("timetrack"));
this->Track::WriteCommonXMLAttributes( xmlFile );
xmlFile.WriteAttr(wxT("name"), mName);
//xmlFile.WriteAttr(wxT("channel"), mChannel);
//xmlFile.WriteAttr(wxT("offset"), mOffset, 8);
xmlFile.WriteAttr(wxT("height"), GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), GetMinimized());
xmlFile.WriteAttr(wxT("rangelower"), GetRangeLower(), 12);
xmlFile.WriteAttr(wxT("rangeupper"), GetRangeUpper(), 12);
xmlFile.WriteAttr(wxT("displaylog"), GetDisplayLog());

View File

@ -1279,6 +1279,46 @@ std::shared_ptr<const Track> Track::SubstituteOriginalTrack() const
return SharedPointer();
}
// Serialize, not with tags of its own, but as attributes within a tag.
void Track::WriteCommonXMLAttributes(
XMLWriter &xmlFile, bool includeNameAndSelected) const
{
if (includeNameAndSelected) {
xmlFile.WriteAttr(wxT("name"), GetName());
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
}
xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), this->GetMinimized());
}
// Return true iff the attribute is recognized.
bool Track::HandleCommonXMLAttribute(const wxChar *attr, const wxChar *value)
{
long nValue = -1;
wxString strValue( value );
if (!wxStrcmp(attr, wxT("name")) &&
XMLValueChecker::IsGoodString(strValue)) {
SetName( strValue );
return true;
}
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) {
SetHeight(nValue);
return true;
}
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) {
SetMinimized(nValue != 0);
return true;
}
else if (!wxStrcmp(attr, wxT("isSelected")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) {
this->SetSelected(nValue != 0);
return true;
}
return false;
}
bool TrackList::HasPendingTracks() const
{
if ( !mPendingUpdates.empty() )

View File

@ -741,6 +741,13 @@ public:
bool IsLeader() const;
bool IsSelectedLeader() const;
// Serialize, not with tags of its own, but as attributes within a tag.
void WriteCommonXMLAttributes(
XMLWriter &xmlFile, bool includeNameAndSelected = true) const;
// Return true iff the attribute is recognized.
bool HandleCommonXMLAttribute(const wxChar *attr, const wxChar *value);
protected:
std::shared_ptr<Track> DoFindTrack() override;

View File

@ -1717,15 +1717,8 @@ bool WaveTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
}
else if (this->PlayableTrack::HandleXMLAttribute(attr, value))
{}
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
SetHeight(nValue);
else if (!wxStrcmp(attr, wxT("minimized")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
mMinimized = (nValue != 0);
else if (!wxStrcmp(attr, wxT("isSelected")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
this->SetSelected(nValue != 0);
else if (this->Track::HandleCommonXMLAttribute(attr, strValue))
;
else if (!wxStrcmp(attr, wxT("gain")) &&
XMLValueChecker::IsGoodString(strValue) &&
Internat::CompatibleToDouble(strValue, &dblValue))
@ -1735,8 +1728,6 @@ bool WaveTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
Internat::CompatibleToDouble(strValue, &dblValue) &&
(dblValue >= -1.0) && (dblValue <= 1.0))
mPan = dblValue;
else if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
mName = strValue;
else if (!wxStrcmp(attr, wxT("channel")))
{
if (!XMLValueChecker::IsGoodInt(strValue) || !strValue.ToLong(&nValue) ||
@ -1813,13 +1804,10 @@ void WaveTrack::WriteXML(XMLWriter &xmlFile) const
{
xmlFile.WriteAttr(wxT("autosaveid"), mAutoSaveIdent);
}
xmlFile.WriteAttr(wxT("name"), mName);
this->Track::WriteCommonXMLAttributes( xmlFile );
xmlFile.WriteAttr(wxT("channel"), mChannel);
xmlFile.WriteAttr(wxT("linked"), mLinked);
this->PlayableTrack::WriteXMLAttributes(xmlFile);
xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), this->GetMinimized());
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
xmlFile.WriteAttr(wxT("rate"), mRate);
xmlFile.WriteAttr(wxT("gain"), (double)mGain);
xmlFile.WriteAttr(wxT("pan"), (double)mPan);