Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not save MIDI connections in presets #7445

9 changes: 3 additions & 6 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ public slots:

protected:
bool isPresetMode() const { return m_presetMode; }
void setPresetMode(bool presetMode = true)
{
m_presetMode = presetMode;
}

protected:
bool m_presetMode = false;

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

bool m_presetMode = false;

clipVector m_clips;

QMutex m_processingLock;
Expand Down
4 changes: 2 additions & 2 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void Track::saveSettings( QDomDocument & doc, QDomElement & element )

if (isPresetMode())
{
setPresetMode(false);
// No need to unset preset mode here as this will done by the guard in InstrumentTrack::savePreset
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ void Track::loadSettings( const QDomElement & element )
node = node.nextSibling();
}

setPresetMode(false);
// No need to unset preset mode here as this will done by the guard in InstrumentTrack::loadPreset
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand Down
34 changes: 32 additions & 2 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,45 @@ void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement
unlock();
}

/**
* @brief RAII "guard" used to safely change and reset booleans even during exceptions
*
* Needed to safely reset m_presetMode in savePreset and loadPreset. For this reason
* only defined locally because at least the pattern used by these methods should not
* spread outside.
*/
class BoolGuard
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved
{
public:
BoolGuard(bool& member, bool temporaryValue) :
m_member(member),
m_oldValue(member)
{
m_member = temporaryValue;
}

~BoolGuard()
{
m_member = m_oldValue;
}

BoolGuard(const BoolGuard&) = delete;
BoolGuard& operator=(const BoolGuard&) = delete;
michaelgregorius marked this conversation as resolved.
Show resolved Hide resolved

private:
bool & m_member;
bool const m_oldValue;
};

void InstrumentTrack::savePreset(QDomDocument & doc, QDomElement & element)
{
setPresetMode();
BoolGuard guard(m_presetMode, true);
saveSettings(doc, element);
}

void InstrumentTrack::loadPreset(const QDomElement & element)
{
setPresetMode();
BoolGuard guard(m_presetMode, true);
loadSettings(element);
}

Expand Down
Loading