Do not save MIDI connections in presets (#7445)

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.
This commit is contained in:
Michael Gregorius
2024-08-20 19:50:39 +02:00
committed by GitHub
parent 5e697f01c8
commit 88ee83bb4a
12 changed files with 58 additions and 47 deletions

View File

@@ -50,8 +50,7 @@ public:
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:

View File

@@ -133,8 +133,7 @@ public:
// 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;

View File

@@ -57,8 +57,7 @@ public:
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);

View File

@@ -54,8 +54,7 @@ public:
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()

View File

@@ -107,19 +107,17 @@ public:
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 );
@@ -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;
@@ -222,8 +224,6 @@ private:
BoolModel m_soloModel;
bool m_mutedBeforeSolo;
bool m_simpleSerializingMode;
clipVector m_clips;
QMutex m_processingLock;

View File

@@ -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 );
@@ -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-
@@ -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" );
}
@@ -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;
}
@@ -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
@@ -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() )
{
@@ -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() )
@@ -279,7 +272,7 @@ void Track::loadSettings( const QDomElement & element )
}
node = node.nextSibling();
}
m_simpleSerializingMode = false;
return;
}
@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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)
{
}

View File

@@ -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" );
@@ -860,7 +860,7 @@ 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())
{
@@ -868,7 +868,11 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement
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);
}
@@ -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);

View File

@@ -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] ==

View File

@@ -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