From dc11088f8495112d99fdeb96a749c2e40ad7b200 Mon Sep 17 00:00:00 2001 From: akimaze Date: Mon, 6 Apr 2020 20:55:43 +0200 Subject: [PATCH 1/6] Enable vestige presets preview. --- src/core/PresetPreviewPlayHandle.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/core/PresetPreviewPlayHandle.cpp b/src/core/PresetPreviewPlayHandle.cpp index 11b145b222d..d7a0260ef55 100644 --- a/src/core/PresetPreviewPlayHandle.cpp +++ b/src/core/PresetPreviewPlayHandle.cpp @@ -156,19 +156,9 @@ PresetPreviewPlayHandle::PresetPreviewPlayHandle( const QString & _preset_file, dataFileCreated = true; } - // vestige previews are bug prone; fallback on 3xosc with volume of 0 - // without an instrument in preview track, it will segfault - if(dataFile->content().elementsByTagName( "vestige" ).length() == 0 ) - { - s_previewTC->previewInstrumentTrack()-> - loadTrackSpecificSettings( - dataFile->content().firstChild().toElement() ); - } - else - { - s_previewTC->previewInstrumentTrack()->loadInstrument("tripleoscillator"); - s_previewTC->previewInstrumentTrack()->setVolume( 0 ); - } + s_previewTC->previewInstrumentTrack()->loadTrackSpecificSettings( + dataFile->content().firstChild().toElement()); + if( dataFileCreated ) { delete dataFile; From a5c3a8098035747e9ad9e25c1f0f2c30feeb94db Mon Sep 17 00:00:00 2001 From: akimaze Date: Mon, 6 Apr 2020 20:55:52 +0200 Subject: [PATCH 2/6] Don't destroy vestige instrument on every preset change. --- include/InstrumentTrack.h | 2 ++ src/tracks/InstrumentTrack.cpp | 57 +++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index d72331e5284..3473ceb3156 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -230,6 +230,8 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor return "instrumenttrack"; } + QString getInstrumentName(const QDomElement & thisElement) const; + protected slots: void updateBaseNote(); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index ac2a7f45166..158f5c17a71 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -771,7 +771,8 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement ) { - silenceAllNotes( true ); + silenceAllNotes(!(m_previewMode && m_instrument && m_instrument->nodeName() == "vestige" + && getInstrumentName(thisElement) == "vestige")); lock(); @@ -815,33 +816,44 @@ void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement { m_audioPort.effects()->restoreState( node.toElement() ); } - else if( node.nodeName() == "instrument" ) + else if(node.nodeName() == "instrument") { typedef Plugin::Descriptor::SubPluginFeatures::Key PluginKey; - PluginKey key( node.toElement().elementsByTagName( "key" ).item( 0 ).toElement() ); - - delete m_instrument; - m_instrument = NULL; - m_instrument = Instrument::instantiate( - node.toElement().attribute( "name" ), this, &key); - m_instrument->restoreState( node.firstChildElement() ); + PluginKey key(node.toElement().elementsByTagName("key").item(0).toElement()); - emit instrumentChanged(); + // don't delete vestige instrument in preview mode because loading vst + // can take long time, so better try change settings without recreating + // everything (this speeds up the loading of subsequent presets from one plugin) + if (m_previewMode && m_instrument && m_instrument->nodeName() == "vestige" && + node.toElement().attribute("name") == "vestige") + { + m_instrument->restoreState(node.firstChildElement()); + emit instrumentChanged(); + } + else + { + delete m_instrument; + m_instrument = NULL; + m_instrument = Instrument::instantiate( + node.toElement().attribute("name"), this, &key); + m_instrument->restoreState(node.firstChildElement()); + emit instrumentChanged(); + } } // compat code - if node-name doesn't match any known // one, we assume that it is an instrument-plugin // which we'll try to load - else if( AutomationPattern::classNodeName() != node.nodeName() && + else if(AutomationPattern::classNodeName() != node.nodeName() && ControllerConnection::classNodeName() != node.nodeName() && - !node.toElement().hasAttribute( "id" ) ) + !node.toElement().hasAttribute( "id" )) { delete m_instrument; m_instrument = NULL; m_instrument = Instrument::instantiate( node.nodeName(), this, nullptr, true); - if( m_instrument->nodeName() == node.nodeName() ) + if (m_instrument->nodeName() == node.nodeName()) { - m_instrument->restoreState( node.toElement() ); + m_instrument->restoreState(node.toElement()); } emit instrumentChanged(); } @@ -863,6 +875,23 @@ void InstrumentTrack::setPreviewMode( const bool value ) +QString InstrumentTrack::getInstrumentName(const QDomElement &thisElement) const +{ + QDomNode node = thisElement.firstChild(); + while (!node.isNull()) + { + if (node.isElement() && node.nodeName() == "instrument") + { + return node.toElement().attribute("name"); + } + node = node.nextSibling(); + } + return ""; +} + + + + Instrument * InstrumentTrack::loadInstrument(const QString & _plugin_name, const Plugin::Descriptor::SubPluginFeatures::Key *key, bool keyFromDnd) { From b3be0050cf51d444aa5632b0998436e5e99cb733 Mon Sep 17 00:00:00 2001 From: akimaze Date: Mon, 6 Apr 2020 20:56:03 +0200 Subject: [PATCH 3/6] Don't reload VST dll plugin when it's not necessary. Always hide plugin UI in preview mode. --- include/InstrumentTrack.h | 4 ++++ plugins/vestige/vestige.cpp | 28 +++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 3473ceb3156..c318b54aab1 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -214,6 +214,10 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor void setPreviewMode( const bool ); + bool isPreviewMode() const + { + return m_previewMode; + } signals: void instrumentChanged(); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index fc61a248441..9efd3c97b4d 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -198,9 +198,15 @@ void vestigeInstrument::loadSettings( const QDomElement & _this ) { m_plugin->loadSettings( _this ); - if ( _this.attribute( "guivisible" ).toInt() ) { + if (instrumentTrack() != NULL && instrumentTrack()->isPreviewMode()) + { + m_plugin->hideUI(); + } + else if (_this.attribute( "guivisible" ).toInt()) + { m_plugin->showUI(); - } else { + } else + { m_plugin->hideUI(); } @@ -322,12 +328,17 @@ void vestigeInstrument::loadFile( const QString & _file ) { m_pluginMutex.lock(); const bool set_ch_name = ( m_plugin != NULL && - instrumentTrack()->name() == m_plugin->name() ) || - instrumentTrack()->name() == InstrumentTrack::tr( "Default preset" ) || - instrumentTrack()->name() == displayName(); + instrumentTrack()->name() == m_plugin->name() ) || + instrumentTrack()->name() == InstrumentTrack::tr( "Default preset" ) || + instrumentTrack()->name() == displayName(); m_pluginMutex.unlock(); + // if the same is loaded don't load again (for preview) + if (instrumentTrack() != NULL && instrumentTrack()->isPreviewMode() && + m_pluginDLL == SampleBuffer::tryToMakeRelative( _file )) + return; + if ( m_plugin != NULL ) { closePlugin(); @@ -354,8 +365,11 @@ void vestigeInstrument::loadFile( const QString & _file ) return; } - m_plugin->createUI(nullptr); - m_plugin->showUI(); + if ( !(instrumentTrack() != NULL && instrumentTrack()->isPreviewMode())) + { + m_plugin->createUI(nullptr); + m_plugin->showUI(); + } if( set_ch_name ) { From b42ed45340214ad400fee1adc8e7b72fbd5b6f84 Mon Sep 17 00:00:00 2001 From: akimaze Date: Sat, 25 Apr 2020 14:38:57 +0200 Subject: [PATCH 4/6] Don't remove other instruments in preview mode, don't send instrument change signal. --- src/tracks/InstrumentTrack.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 158f5c17a71..ef279bed100 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -771,8 +771,7 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement ) { - silenceAllNotes(!(m_previewMode && m_instrument && m_instrument->nodeName() == "vestige" - && getInstrumentName(thisElement) == "vestige")); + silenceAllNotes(!(m_previewMode && m_instrument && m_instrument->nodeName() == getInstrumentName(thisElement))); lock(); @@ -821,14 +820,10 @@ void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement typedef Plugin::Descriptor::SubPluginFeatures::Key PluginKey; PluginKey key(node.toElement().elementsByTagName("key").item(0).toElement()); - // don't delete vestige instrument in preview mode because loading vst - // can take long time, so better try change settings without recreating - // everything (this speeds up the loading of subsequent presets from one plugin) - if (m_previewMode && m_instrument && m_instrument->nodeName() == "vestige" && - node.toElement().attribute("name") == "vestige") + // don't delete instrument in preview mode if it's the same + if (m_previewMode && m_instrument && m_instrument->nodeName() == node.toElement().attribute("name")) { m_instrument->restoreState(node.firstChildElement()); - emit instrumentChanged(); } else { From 1345554f3efb2092a1734c472a67e9fec87a5411 Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Sat, 9 May 2020 11:36:05 +0900 Subject: [PATCH 5/6] Minor changes --- include/InstrumentTrack.h | 3 ++- src/tracks/InstrumentTrack.cpp | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index c318b54aab1..cf674b77031 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -234,7 +234,8 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor return "instrumenttrack"; } - QString getInstrumentName(const QDomElement & thisElement) const; + // get the name of the instrument in the saved data + QString getSavedInstrumentName(const QDomElement & thisElement) const; protected slots: diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index ef279bed100..bdcb7bf548a 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -771,7 +771,11 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement ) { - silenceAllNotes(!(m_previewMode && m_instrument && m_instrument->nodeName() == getInstrumentName(thisElement))); + // don't delete instrument in preview mode if it's the same + // we can't do this for other situations due to some issues with linked models + bool reuseInstrument = m_previewMode && m_instrument && m_instrument->nodeName() == getSavedInstrumentName(thisElement); + // remove the InstrumentPlayHandle if and only if we need to delete the instrument + silenceAllNotes(!reuseInstrument); lock(); @@ -820,8 +824,7 @@ void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement typedef Plugin::Descriptor::SubPluginFeatures::Key PluginKey; PluginKey key(node.toElement().elementsByTagName("key").item(0).toElement()); - // don't delete instrument in preview mode if it's the same - if (m_previewMode && m_instrument && m_instrument->nodeName() == node.toElement().attribute("name")) + if (reuseInstrument) { m_instrument->restoreState(node.firstChildElement()); } @@ -870,16 +873,12 @@ void InstrumentTrack::setPreviewMode( const bool value ) -QString InstrumentTrack::getInstrumentName(const QDomElement &thisElement) const +QString InstrumentTrack::getSavedInstrumentName(const QDomElement &thisElement) const { - QDomNode node = thisElement.firstChild(); - while (!node.isNull()) + QDomNode elem = thisElement.firstChildElement("instrument"); + if (!elem.isNull()) { - if (node.isElement() && node.nodeName() == "instrument") - { - return node.toElement().attribute("name"); - } - node = node.nextSibling(); + return elem.attribute("name"); } return ""; } From 94066db85d50c85726b2fe4df7e38d74a63310bb Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Sat, 9 May 2020 11:39:49 +0900 Subject: [PATCH 6/6] Add a change I missed --- src/tracks/InstrumentTrack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index bdcb7bf548a..967c1a65300 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -875,7 +875,7 @@ void InstrumentTrack::setPreviewMode( const bool value ) QString InstrumentTrack::getSavedInstrumentName(const QDomElement &thisElement) const { - QDomNode elem = thisElement.firstChildElement("instrument"); + QDomElement elem = thisElement.firstChildElement("instrument"); if (!elem.isNull()) { return elem.attribute("name");