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

VST preset preview #5441

Merged
merged 6 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -230,6 +234,9 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
return "instrumenttrack";
}

// get the name of the instrument in the saved data
QString getSavedInstrumentName(const QDomElement & thisElement) const;


protected slots:
void updateBaseNote();
Expand Down
28 changes: 21 additions & 7 deletions plugins/vestige/vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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 )
{
Expand Down
16 changes: 3 additions & 13 deletions src/core/PresetPreviewPlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 37 additions & 14 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,11 @@ void InstrumentTrack::saveTrackSpecificSettings( QDomDocument& doc, QDomElement

void InstrumentTrack::loadTrackSpecificSettings( const QDomElement & thisElement )
{
silenceAllNotes( true );
// 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();

Expand Down Expand Up @@ -815,33 +819,39 @@ 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();
if (reuseInstrument)
{
m_instrument->restoreState(node.firstChildElement());
}
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();
}
Expand All @@ -863,6 +873,19 @@ void InstrumentTrack::setPreviewMode( const bool value )



QString InstrumentTrack::getSavedInstrumentName(const QDomElement &thisElement) const
{
QDomElement elem = thisElement.firstChildElement("instrument");
if (!elem.isNull())
{
return elem.attribute("name");
}
return "";
}




Instrument * InstrumentTrack::loadInstrument(const QString & _plugin_name,
const Plugin::Descriptor::SubPluginFeatures::Key *key, bool keyFromDnd)
{
Expand Down