Skip to content

Commit

Permalink
Do not save MIDI connections in presets (#7445)
Browse files Browse the repository at this point in the history
Ensure that no MIDI information (connected inputs, outputs, etc.) is
stored in presets. This main fix can be found in
`InstrumentTrack::saveTrackSpecificSettings` where the state of the
MIDI ports are now only saved if we are not in preset mode.

The remaining changes are concered with a refactoring of the code
that's related to saving and loading presets.

The refactoring mainly revolves around the removal of the member
`m_simpleSerializingMode` and the method `setSimpleSerializing` in
`Track`.

This is accomplished by introducing two new methods `saveTrack` and
`loadTrack`. These methods have a similar interface to `saveSettings`
and `loadSettings` but they additionally contain a boolean which
indicates if a preset is saved/loaded or a whole track. Both new
methods contain the previous code of `saveSettings` and `loadSettings`.
The latter two now only delegate to the new methods assuming that the
full track is to be stored/loaded if called via the overridden methods
`saveSettings` and `loadSettings`.

The methods `savePreset` and `loadPreset` are added as well. They call
`saveTrack` and `loadTrack` with the preset boolean set to `true`.
These methods are now used by all places in the code where presets are
saved or loaded which makes the code more readable. Clients also do not
need to know any implementation details of `Track`, e.g. like having to
call `setSimpleSerializing`.

Adjust `saveTrackSpecificSettings` so that it also passes information
of whether a preset or a whole track is stored. This leads to changes
in the interfaces of `AutomationTrack`, `InstrumentTrack`,
`PatternTrack` and `SampleTrack`. Only the implementation of
`InstrumentTrack` uses the new information though.
  • Loading branch information
michaelgregorius committed Aug 20, 2024
1 parent 5e697f0 commit 88ee83b
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 47 deletions.
3 changes: 1 addition & 2 deletions include/AutomationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class AutomationTrack : public Track
gui::TrackView * createView( gui::TrackContainerView* ) override;
Clip* createClip(const TimePos & pos) override;

void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override;
void loadTrackSpecificSettings( const QDomElement & _this ) override;

private:
Expand Down
3 changes: 1 addition & 2 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor


// called by track
void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override;
void loadTrackSpecificSettings( const QDomElement & _this ) override;

using Track::setJournalling;
Expand Down
3 changes: 1 addition & 2 deletions include/PatternTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class LMMS_EXPORT PatternTrack : public Track
gui::TrackView * createView( gui::TrackContainerView* tcv ) override;
Clip* createClip(const TimePos & pos) override;

void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override;
void loadTrackSpecificSettings( const QDomElement & _this ) override;

static PatternTrack* findPatternTrack(int pattern_num);
Expand Down
3 changes: 1 addition & 2 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class SampleTrack : public Track
Clip* createClip(const TimePos & pos) override;


void saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _parent ) override;
void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override;
void loadTrackSpecificSettings( const QDomElement & _this ) override;

inline IntModel * mixerChannelModel()
Expand Down
18 changes: 9 additions & 9 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,17 @@ class LMMS_EXPORT Track : public Model, public JournallingObject
virtual gui::TrackView * createView( gui::TrackContainerView * view ) = 0;
virtual Clip * createClip( const TimePos & pos ) = 0;

virtual void saveTrackSpecificSettings( QDomDocument & doc,
QDomElement & parent ) = 0;
virtual void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) = 0;
virtual void loadTrackSpecificSettings( const QDomElement & element ) = 0;

// Saving and loading of presets which do not necessarily contain all the track information
void savePreset(QDomDocument & doc, QDomElement & element);
void loadPreset(const QDomElement & element);

// Saving and loading of full tracks
void saveSettings( QDomDocument & doc, QDomElement & element ) override;
void loadSettings( const QDomElement & element ) override;

void setSimpleSerializing()
{
m_simpleSerializingMode = true;
}

// -- for usage by Clip only ---------------
Clip * addClip( Clip * clip );
void removeClip( Clip * clip );
Expand Down Expand Up @@ -209,6 +207,10 @@ public slots:

void toggleSolo();

private:
void saveTrack(QDomDocument& doc, QDomElement& element, bool presetMode);
void loadTrack(const QDomElement& element, bool presetMode);

private:
TrackContainer* m_trackContainer;
Type m_type;
Expand All @@ -222,8 +224,6 @@ public slots:
BoolModel m_soloModel;
bool m_mutedBeforeSolo;

bool m_simpleSerializingMode;

clipVector m_clips;

QMutex m_processingLock;
Expand Down
47 changes: 31 additions & 16 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Track::Track( Type type, TrackContainer * tc ) :
m_name(), /*!< The track's name */
m_mutedModel( false, this, tr( "Mute" ) ), /*!< For controlling track muting */
m_soloModel( false, this, tr( "Solo" ) ), /*!< For controlling track soloing */
m_simpleSerializingMode( false ),
m_clips() /*!< The clips (segments) */
{
m_trackContainer->addTrack( this );
Expand Down Expand Up @@ -174,10 +173,6 @@ Track* Track::clone()
}






/*! \brief Save this track's settings to file
*
* We save the track type and its muted state and solo state, then append the track-
Expand All @@ -186,12 +181,13 @@ Track* Track::clone()
*
* \param doc The QDomDocument to use to save
* \param element The The QDomElement to save into
* \param presetMode Describes whether to save the track as a preset or not.
* \todo Does this accurately describe the parameters? I think not!?
* \todo Save the track height
*/
void Track::saveSettings( QDomDocument & doc, QDomElement & element )
void Track::saveTrack(QDomDocument& doc, QDomElement& element, bool presetMode)
{
if( !m_simpleSerializingMode )
if (!presetMode)
{
element.setTagName( "track" );
}
Expand All @@ -215,11 +211,10 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element )
QDomElement tsDe = doc.createElement( nodeName() );
// let actual track (InstrumentTrack, PatternTrack, SampleTrack etc.) save its settings
element.appendChild( tsDe );
saveTrackSpecificSettings( doc, tsDe );
saveTrackSpecificSettings(doc, tsDe, presetMode);

if( m_simpleSerializingMode )
if (presetMode)
{
m_simpleSerializingMode = false;
return;
}

Expand All @@ -230,9 +225,6 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element )
}
}




/*! \brief Load the settings from a file
*
* We load the track's type and muted state and solo state, then clear out our
Expand All @@ -243,9 +235,10 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element )
* one at a time.
*
* \param element the QDomElement to load track settings from
* \param presetMode Indicates if a preset or a full track is loaded
* \todo Load the track height.
*/
void Track::loadSettings( const QDomElement & element )
void Track::loadTrack(const QDomElement& element, bool presetMode)
{
if( static_cast<Type>(element.attribute( "type" ).toInt()) != type() )
{
Expand All @@ -267,7 +260,7 @@ void Track::loadSettings( const QDomElement & element )
setColor(QColor{element.attribute("color")});
}

if( m_simpleSerializingMode )
if (presetMode)
{
QDomNode node = element.firstChild();
while( !node.isNull() )
Expand All @@ -279,7 +272,7 @@ void Track::loadSettings( const QDomElement & element )
}
node = node.nextSibling();
}
m_simpleSerializingMode = false;

return;
}

Expand Down Expand Up @@ -316,6 +309,28 @@ void Track::loadSettings( const QDomElement & element )
}
}

void Track::savePreset(QDomDocument & doc, QDomElement & element)
{
saveTrack(doc, element, true);
}

void Track::loadPreset(const QDomElement & element)
{
loadTrack(element, true);
}

void Track::saveSettings(QDomDocument& doc, QDomElement& element)
{
// Assume that everything should be saved if we are called through SerializingObject::saveSettings
saveTrack(doc, element, false);
}

void Track::loadSettings(const QDomElement& element)
{
// Assume that everything should be loaded if we are called through SerializingObject::loadSettings
loadTrack(element, false);
}




Expand Down
4 changes: 2 additions & 2 deletions src/gui/editors/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ void TrackContainerView::dropEvent( QDropEvent * _de )
{
DataFile dataFile( value );
auto it = dynamic_cast<InstrumentTrack*>(Track::create(Track::Type::Instrument, m_tc));
it->setSimpleSerializing();
it->loadSettings( dataFile.content().toElement() );
it->loadPreset(dataFile.content().toElement());

//it->toggledInstrumentTrackButton( true );
_de->accept();
}
Expand Down
3 changes: 1 addition & 2 deletions src/gui/instrument/InstrumentTrackWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ void InstrumentTrackWindow::saveSettingsBtnClicked()
DataFile dataFile(DataFile::Type::InstrumentTrackSettings);
QDomElement& content(dataFile.content());

m_track->setSimpleSerializing();
m_track->saveSettings(dataFile, content);
m_track->savePreset(dataFile, content);
//We don't want to save muted & solo settings when we're saving a preset
content.setAttribute("muted", 0);
content.setAttribute("solo", 0);
Expand Down
3 changes: 1 addition & 2 deletions src/tracks/AutomationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ Clip* AutomationTrack::createClip(const TimePos & pos)



void AutomationTrack::saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _this )
void AutomationTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode)
{
}

Expand Down
13 changes: 8 additions & 5 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ gui::TrackView* InstrumentTrack::createView( gui::TrackContainerView* tcv )



void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement & thisElement )
void InstrumentTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& thisElement, bool presetMode)
{
m_volumeModel.saveSettings( doc, thisElement, "vol" );
m_panningModel.saveSettings( doc, thisElement, "pan" );
Expand Down Expand Up @@ -860,15 +860,19 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement

// Save the midi port info if we are not in song saving mode, e.g. in
// track cloning mode or if we are in song saving mode and the user
// has chosen to discard the MIDI connections.
// has chosen not to discard the MIDI connections.
if (!Engine::getSong()->isSavingProject() ||
!Engine::getSong()->getSaveOptions().discardMIDIConnections.value())
{
// Don't save auto assigned midi device connection
bool hasAuto = m_hasAutoMidiDev;
autoAssignMidiDevice(false);

m_midiPort.saveState( doc, thisElement );
// Only save the MIDI port information if we are not saving a preset.
if (!presetMode)
{
m_midiPort.saveState(doc, thisElement);
}

autoAssignMidiDevice(hasAuto);
}
Expand Down Expand Up @@ -1007,14 +1011,13 @@ void InstrumentTrack::replaceInstrument(DataFile dataFile)
int mixerChannel = mixerChannelModel()->value();

InstrumentTrack::removeMidiPortNode(dataFile);
setSimpleSerializing();

//Replacing an instrument shouldn't change the solo/mute state.
bool oldMute = isMuted();
bool oldSolo = isSolo();
bool oldMutedBeforeSolo = isMutedBeforeSolo();

loadSettings(dataFile.content().toElement());
loadPreset(dataFile.content().toElement());

setMuted(oldMute);
setSolo(oldSolo);
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/PatternTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Clip* PatternTrack::createClip(const TimePos & pos)



void PatternTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this)
void PatternTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _this, bool presetMode)
{
// _this.setAttribute( "icon", m_trackLabel->pixmapFile() );
/* _this.setAttribute( "current", s_infoMap[this] ==
Expand Down
3 changes: 1 addition & 2 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ Clip * SampleTrack::createClip(const TimePos & pos)



void SampleTrack::saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _this )
void SampleTrack::saveTrackSpecificSettings(QDomDocument& _doc, QDomElement& _this, bool presetMode)
{
m_audioPort.effects()->saveState( _doc, _this );
#if 0
Expand Down

0 comments on commit 88ee83b

Please sign in to comment.