mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 16:40:07 +02:00
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:
parent
2b2d13d5be
commit
98f322d685
@ -2390,8 +2390,8 @@ bool LabelTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
const wxString strValue = value;
|
const wxString strValue = value;
|
||||||
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
|
if (this->Track::HandleCommonXMLAttribute(attr, strValue))
|
||||||
mName = strValue;
|
;
|
||||||
else if (!wxStrcmp(attr, wxT("numlabels")) &&
|
else if (!wxStrcmp(attr, wxT("numlabels")) &&
|
||||||
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
|
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue))
|
||||||
{
|
{
|
||||||
@ -2403,15 +2403,6 @@ bool LabelTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
mLabels.clear();
|
mLabels.clear();
|
||||||
mLabels.reserve(nValue);
|
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;
|
return true;
|
||||||
@ -2434,11 +2425,8 @@ void LabelTrack::WriteXML(XMLWriter &xmlFile) const
|
|||||||
int len = mLabels.size();
|
int len = mLabels.size();
|
||||||
|
|
||||||
xmlFile.StartTag(wxT("labeltrack"));
|
xmlFile.StartTag(wxT("labeltrack"));
|
||||||
xmlFile.WriteAttr(wxT("name"), mName);
|
this->Track::WriteCommonXMLAttributes( xmlFile );
|
||||||
xmlFile.WriteAttr(wxT("numlabels"), len);
|
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) {
|
for (auto &labelStruct: mLabels) {
|
||||||
xmlFile.StartTag(wxT("label"));
|
xmlFile.StartTag(wxT("label"));
|
||||||
|
@ -873,8 +873,8 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
const wxString strValue = value;
|
const wxString strValue = value;
|
||||||
long nValue;
|
long nValue;
|
||||||
double dblValue;
|
double dblValue;
|
||||||
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
|
if (this->Track::HandleCommonXMLAttribute(attr, strValue))
|
||||||
mName = strValue;
|
;
|
||||||
else if (this->NoteTrackBase::HandleXMLAttribute(attr, value))
|
else if (this->NoteTrackBase::HandleXMLAttribute(attr, value))
|
||||||
{}
|
{}
|
||||||
else if (!wxStrcmp(attr, wxT("offset")) &&
|
else if (!wxStrcmp(attr, wxT("offset")) &&
|
||||||
@ -888,15 +888,6 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
return false;
|
return false;
|
||||||
mVisibleChannels = nValue;
|
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
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
else if (!wxStrcmp(attr, wxT("velocity")) &&
|
else if (!wxStrcmp(attr, wxT("velocity")) &&
|
||||||
XMLValueChecker::IsGoodString(strValue) &&
|
XMLValueChecker::IsGoodString(strValue) &&
|
||||||
@ -939,13 +930,10 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile) const
|
|||||||
}
|
}
|
||||||
saveme->GetSeq().write(data, true);
|
saveme->GetSeq().write(data, true);
|
||||||
xmlFile.StartTag(wxT("notetrack"));
|
xmlFile.StartTag(wxT("notetrack"));
|
||||||
xmlFile.WriteAttr(wxT("name"), saveme->mName);
|
saveme->Track::WriteCommonXMLAttributes( xmlFile );
|
||||||
this->NoteTrackBase::WriteXMLAttributes(xmlFile);
|
this->NoteTrackBase::WriteXMLAttributes(xmlFile);
|
||||||
xmlFile.WriteAttr(wxT("offset"), saveme->GetOffset());
|
xmlFile.WriteAttr(wxT("offset"), saveme->GetOffset());
|
||||||
xmlFile.WriteAttr(wxT("visiblechannels"), saveme->mVisibleChannels);
|
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
|
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||||
xmlFile.WriteAttr(wxT("velocity"), (double) saveme->mVelocity);
|
xmlFile.WriteAttr(wxT("velocity"), (double) saveme->mVelocity);
|
||||||
|
@ -498,8 +498,7 @@ void ProjectFileIO::WriteXML(
|
|||||||
xmlFile.WriteAttr(wxT("offset"), offset, 8);
|
xmlFile.WriteAttr(wxT("offset"), offset, 8);
|
||||||
xmlFile.WriteAttr(wxT("mute"), pWaveTrack->GetMute());
|
xmlFile.WriteAttr(wxT("mute"), pWaveTrack->GetMute());
|
||||||
xmlFile.WriteAttr(wxT("solo"), pWaveTrack->GetSolo());
|
xmlFile.WriteAttr(wxT("solo"), pWaveTrack->GetSolo());
|
||||||
xmlFile.WriteAttr(wxT("height"), pWaveTrack->GetActualHeight());
|
pWaveTrack->Track::WriteCommonXMLAttributes( xmlFile, false );
|
||||||
xmlFile.WriteAttr(wxT("minimized"), pWaveTrack->GetMinimized());
|
|
||||||
|
|
||||||
// Don't store "rate" tag because the importer can figure that out.
|
// Don't store "rate" tag because the importer can figure that out.
|
||||||
// xmlFile.WriteAttr(wxT("rate"), pWaveTrack->GetRate());
|
// xmlFile.WriteAttr(wxT("rate"), pWaveTrack->GetRate());
|
||||||
|
@ -204,14 +204,8 @@ bool TimeTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
const wxString strValue = value;
|
const wxString strValue = value;
|
||||||
if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
|
if (this->Track::HandleCommonXMLAttribute(attr, 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);
|
|
||||||
else if (!wxStrcmp(attr, wxT("rangelower")))
|
else if (!wxStrcmp(attr, wxT("rangelower")))
|
||||||
{
|
{
|
||||||
SetRangeLower( Internat::CompatibleToDouble(value) );
|
SetRangeLower( Internat::CompatibleToDouble(value) );
|
||||||
@ -266,12 +260,10 @@ void TimeTrack::WriteXML(XMLWriter &xmlFile) const
|
|||||||
// may throw
|
// may throw
|
||||||
{
|
{
|
||||||
xmlFile.StartTag(wxT("timetrack"));
|
xmlFile.StartTag(wxT("timetrack"));
|
||||||
|
this->Track::WriteCommonXMLAttributes( xmlFile );
|
||||||
|
|
||||||
xmlFile.WriteAttr(wxT("name"), mName);
|
|
||||||
//xmlFile.WriteAttr(wxT("channel"), mChannel);
|
//xmlFile.WriteAttr(wxT("channel"), mChannel);
|
||||||
//xmlFile.WriteAttr(wxT("offset"), mOffset, 8);
|
//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("rangelower"), GetRangeLower(), 12);
|
||||||
xmlFile.WriteAttr(wxT("rangeupper"), GetRangeUpper(), 12);
|
xmlFile.WriteAttr(wxT("rangeupper"), GetRangeUpper(), 12);
|
||||||
xmlFile.WriteAttr(wxT("displaylog"), GetDisplayLog());
|
xmlFile.WriteAttr(wxT("displaylog"), GetDisplayLog());
|
||||||
|
@ -1279,6 +1279,46 @@ std::shared_ptr<const Track> Track::SubstituteOriginalTrack() const
|
|||||||
return SharedPointer();
|
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
|
bool TrackList::HasPendingTracks() const
|
||||||
{
|
{
|
||||||
if ( !mPendingUpdates.empty() )
|
if ( !mPendingUpdates.empty() )
|
||||||
|
@ -741,6 +741,13 @@ public:
|
|||||||
bool IsLeader() const;
|
bool IsLeader() const;
|
||||||
bool IsSelectedLeader() 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:
|
protected:
|
||||||
std::shared_ptr<Track> DoFindTrack() override;
|
std::shared_ptr<Track> DoFindTrack() override;
|
||||||
|
|
||||||
|
@ -1717,15 +1717,8 @@ bool WaveTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
}
|
}
|
||||||
else if (this->PlayableTrack::HandleXMLAttribute(attr, value))
|
else if (this->PlayableTrack::HandleXMLAttribute(attr, value))
|
||||||
{}
|
{}
|
||||||
else if (!wxStrcmp(attr, wxT("height")) &&
|
else if (this->Track::HandleCommonXMLAttribute(attr, strValue))
|
||||||
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 (!wxStrcmp(attr, wxT("gain")) &&
|
else if (!wxStrcmp(attr, wxT("gain")) &&
|
||||||
XMLValueChecker::IsGoodString(strValue) &&
|
XMLValueChecker::IsGoodString(strValue) &&
|
||||||
Internat::CompatibleToDouble(strValue, &dblValue))
|
Internat::CompatibleToDouble(strValue, &dblValue))
|
||||||
@ -1735,8 +1728,6 @@ bool WaveTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
Internat::CompatibleToDouble(strValue, &dblValue) &&
|
Internat::CompatibleToDouble(strValue, &dblValue) &&
|
||||||
(dblValue >= -1.0) && (dblValue <= 1.0))
|
(dblValue >= -1.0) && (dblValue <= 1.0))
|
||||||
mPan = dblValue;
|
mPan = dblValue;
|
||||||
else if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue))
|
|
||||||
mName = strValue;
|
|
||||||
else if (!wxStrcmp(attr, wxT("channel")))
|
else if (!wxStrcmp(attr, wxT("channel")))
|
||||||
{
|
{
|
||||||
if (!XMLValueChecker::IsGoodInt(strValue) || !strValue.ToLong(&nValue) ||
|
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("autosaveid"), mAutoSaveIdent);
|
||||||
}
|
}
|
||||||
xmlFile.WriteAttr(wxT("name"), mName);
|
this->Track::WriteCommonXMLAttributes( xmlFile );
|
||||||
xmlFile.WriteAttr(wxT("channel"), mChannel);
|
xmlFile.WriteAttr(wxT("channel"), mChannel);
|
||||||
xmlFile.WriteAttr(wxT("linked"), mLinked);
|
xmlFile.WriteAttr(wxT("linked"), mLinked);
|
||||||
this->PlayableTrack::WriteXMLAttributes(xmlFile);
|
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("rate"), mRate);
|
||||||
xmlFile.WriteAttr(wxT("gain"), (double)mGain);
|
xmlFile.WriteAttr(wxT("gain"), (double)mGain);
|
||||||
xmlFile.WriteAttr(wxT("pan"), (double)mPan);
|
xmlFile.WriteAttr(wxT("pan"), (double)mPan);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user