From 7bda40f656c4459b74cf13ae910f310e1da0dfa6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 30 Mar 2017 16:00:27 -0400 Subject: [PATCH] Common functions read and write mute and solo in Wave and Note --- src/NoteTrack.cpp | 7 +++---- src/Track.cpp | 27 +++++++++++++++++++++++++++ src/Track.h | 13 +++++++++++++ src/WaveTrack.cpp | 11 +++-------- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/NoteTrack.cpp b/src/NoteTrack.cpp index 234975a24..914a8f6c5 100644 --- a/src/NoteTrack.cpp +++ b/src/NoteTrack.cpp @@ -758,6 +758,8 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs) double dblValue; if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(strValue)) mName = strValue; + else if (this->NoteTrackBase::HandleXMLAttribute(attr, value)) + {} else if (!wxStrcmp(attr, wxT("offset")) && XMLValueChecker::IsGoodString(strValue) && Internat::CompatibleToDouble(strValue, &dblValue)) @@ -831,10 +833,7 @@ void NoteTrack::WriteXML(XMLWriter &xmlFile) const saveme->mSeq->write(data, true); xmlFile.StartTag(wxT("notetrack")); xmlFile.WriteAttr(wxT("name"), saveme->mName); -#ifdef EXPERIMENTAL_MIDI_OUT - xmlFile.WriteAttr(wxT("mute"), mMute); - xmlFile.WriteAttr(wxT("solo"), mSolo); -#endif + this->NoteTrackBase::WriteXMLAttributes(xmlFile); xmlFile.WriteAttr(wxT("offset"), saveme->GetOffset()); xmlFile.WriteAttr(wxT("visiblechannels"), saveme->mVisibleChannels); xmlFile.WriteAttr(wxT("height"), saveme->GetActualHeight()); diff --git a/src/Track.cpp b/src/Track.cpp index 166b2393b..9004253a8 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -341,6 +341,33 @@ void PlayableTrack::Merge( const Track &orig ) AudioTrack::Merge( *pOrig ); } +// Serialize, not with tags of its own, but as attributes within a tag. +void PlayableTrack::WriteXMLAttributes(XMLWriter &xmlFile) const +{ + xmlFile.WriteAttr(wxT("mute"), mMute); + xmlFile.WriteAttr(wxT("solo"), mSolo); + AudioTrack::WriteXMLAttributes(xmlFile); +} + +// Return true iff the attribute is recognized. +bool PlayableTrack::HandleXMLAttribute(const wxChar *attr, const wxChar *value) +{ + const wxString strValue{ value }; + long nValue; + if (!wxStrcmp(attr, wxT("mute")) && + XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { + mMute = (nValue != 0); + return true; + } + else if (!wxStrcmp(attr, wxT("solo")) && + XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) { + mSolo = (nValue != 0); + return true; + } + + return AudioTrack::HandleXMLAttribute(attr, value); +} + // TrackListIterator TrackListIterator::TrackListIterator(TrackList * val) : l(val) diff --git a/src/Track.h b/src/Track.h index 39a994168..2b74e076d 100644 --- a/src/Track.h +++ b/src/Track.h @@ -251,6 +251,13 @@ public: AudioTrack(const std::shared_ptr &projDirManager) : Track{ projDirManager } {} AudioTrack(const Track &orig) : Track{ orig } {} + + // Serialize, not with tags of its own, but as attributes within a tag. + void WriteXMLAttributes(XMLWriter &xmlFile) const {} + + // Return true iff the attribute is recognized. + bool HandleXMLAttribute(const wxChar * /*attr*/, const wxChar * /*value*/) + { return false; } }; class PlayableTrack /* not final */ : public AudioTrack @@ -268,6 +275,12 @@ public: void Init( const PlayableTrack &init ); void Merge( const Track &init ) override; + // Serialize, not with tags of its own, but as attributes within a tag. + void WriteXMLAttributes(XMLWriter &xmlFile) const; + + // Return true iff the attribute is recognized. + bool HandleXMLAttribute(const wxChar *attr, const wxChar *value); + protected: bool mMute { false }; bool mSolo { false }; diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 6c2fed45f..93c641a5a 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -1685,12 +1685,8 @@ bool WaveTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs) // track is created. mLegacyProjectFileOffset = dblValue; } - else if (!wxStrcmp(attr, wxT("mute")) && - XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) - mMute = (nValue != 0); - else if (!wxStrcmp(attr, wxT("solo")) && - XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) - mSolo = (nValue != 0); + else if (this->PlayableTrack::HandleXMLAttribute(attr, value)) + {} else if (!wxStrcmp(attr, wxT("height")) && XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) mHeight = nValue; @@ -1789,8 +1785,7 @@ void WaveTrack::WriteXML(XMLWriter &xmlFile) const xmlFile.WriteAttr(wxT("name"), mName); xmlFile.WriteAttr(wxT("channel"), mChannel); xmlFile.WriteAttr(wxT("linked"), mLinked); - xmlFile.WriteAttr(wxT("mute"), mMute); - xmlFile.WriteAttr(wxT("solo"), mSolo); + this->PlayableTrack::WriteXMLAttributes(xmlFile); #ifdef EXPERIMENTAL_OUTPUT_DISPLAY int height; if(MONO_PAN)