From 1e6a902dd32e9bf4dbf57e17913bdd67acecfaad Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Wed, 17 Jan 2024 16:53:32 +0100 Subject: [PATCH] Fix most of the track cloning for MIDI ports (#7066) Fixes most of the problem that the MIDI port information is not cloned when a track is cloned. The bug was caused because cloning is implemented via serialization and deserialization of the Track. The previous code only serialized the MIDI port if `Engine::getSong()->isSavingProject()` is true. However, when we are cloning the statement will be `false` because we are not saving the song. Therefore the MIDI port's state was not saved and the clone was initialized with the default values. The fix is to serialize the MIDI port in the following cases: * We are not in song saving mode, i.e. we are in the state that this issue is about, e.g. cloning. * We save a song and the MIDI connections are not discarded. Using boolean algebra these conditions can be simplified as seen in the changed statement. --- src/tracks/InstrumentTrack.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 4b00e0d79..cdd360e70 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -859,9 +859,11 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement m_noteStacking.saveState( doc, thisElement ); m_arpeggio.saveState( doc, thisElement ); - // Don't save midi port info if the user chose to. - if (Engine::getSong()->isSavingProject() - && !Engine::getSong()->getSaveOptions().discardMIDIConnections.value()) + // 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. + if (!Engine::getSong()->isSavingProject() || + !Engine::getSong()->getSaveOptions().discardMIDIConnections.value()) { // Don't save auto assigned midi device connection bool hasAuto = m_hasAutoMidiDev;