Browse Source

If loading project, only enable plugins after restoring its state

Fixes #402
tags/1.9.7
falkTX 7 years ago
parent
commit
0c6c8ac6e3
3 changed files with 46 additions and 11 deletions
  1. +1
    -0
      source/backend/CarlaPlugin.hpp
  2. +28
    -6
      source/backend/engine/CarlaEngine.cpp
  3. +17
    -5
      source/backend/plugin/CarlaPlugin.cpp

+ 1
- 0
source/backend/CarlaPlugin.hpp View File

@@ -929,6 +929,7 @@ protected:

private:
CarlaPlugin* const fPlugin;
bool fWasEnabled;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)


+ 28
- 6
source/backend/engine/CarlaEngine.cpp View File

@@ -693,6 +693,8 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype,
#ifndef BUILD_BRIDGE
if (oldPlugin != nullptr)
{
CARLA_SAFE_ASSERT(! pData->loadingProject);

const ScopedThreadStopper sts(this);

if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
@@ -714,10 +716,11 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype,

callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, nullptr);
}
else
else if (! pData->loadingProject)
#endif
{
plugin->setActive(true, true, false);
plugin->setEnabled(true);

++pData->curPluginCount;
callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
@@ -960,10 +963,6 @@ bool CarlaEngine::switchPlugins(const uint idA, const uint idB) noexcept
oscSend_control_switch_plugins(idA, idB);
*/


if (isRunning() && ! pData->aboutToClose)
pData->thread.startThread();

return true;
}
#endif
@@ -2145,7 +2144,9 @@ bool CarlaEngine::loadProjectInternal(juce::XmlDocument& xmlDoc)
if (addPlugin(getBinaryTypeFromFile(stateSave.binary), ptype, stateSave.binary,
stateSave.name, stateSave.label, stateSave.uniqueId, extraStuff, stateSave.options))
{
if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
const uint pluginId = pData->curPluginCount;

if (CarlaPlugin* const plugin = getPluginUnchecked(pluginId))
{
callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);

@@ -2158,12 +2159,33 @@ bool CarlaEngine::loadProjectInternal(juce::XmlDocument& xmlDoc)
plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "false", false);
#endif
plugin->loadStateSave(stateSave);

/* NOTE: The following code is the same as the end of addPlugin().
* When project is loading we do not enable the plugin right away,
* as we want to load state first.
*/
#ifdef BUILD_BRIDGE
plugin->setActive(true, true, false);
#endif
plugin->setEnabled(true);

++pData->curPluginCount;
callback(ENGINE_CALLBACK_PLUGIN_ADDED, pluginId, 0, 0, 0.0f, plugin->getName());

#ifndef BUILD_BRIDGE
if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
pData->graph.addPlugin(plugin);
#endif
}
else
{
carla_stderr2("Failed to get new plugin, state will not be restored correctly\n");
}
}
else
{
carla_stderr2("Failed to load a plugin, error was:\n%s", getLastError());
}
}

if (isPreset)


+ 17
- 5
source/backend/plugin/CarlaPlugin.cpp View File

@@ -961,6 +961,10 @@ void CarlaPlugin::setEnabled(const bool yesNo) noexcept

pData->masterMutex.lock();
pData->enabled = yesNo;

if (yesNo && ! pData->client->isActive())
pData->client->activate();

pData->masterMutex.unlock();
}

@@ -2018,7 +2022,8 @@ void CarlaPlugin::setPatchbayNodeId(const uint32_t nodeId) noexcept
// Scoped Disabler

CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
: fPlugin(plugin)
: fPlugin(plugin),
fWasEnabled(false)
{
CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,);
CARLA_SAFE_ASSERT_RETURN(plugin->pData != nullptr,);
@@ -2028,10 +2033,13 @@ CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept
plugin->pData->masterMutex.lock();

if (plugin->pData->enabled)
{
fWasEnabled = true;
plugin->pData->enabled = false;

if (plugin->pData->client->isActive())
plugin->pData->client->deactivate();
if (plugin->pData->client->isActive())
plugin->pData->client->deactivate();
}
}

CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
@@ -2041,8 +2049,12 @@ CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept
CARLA_SAFE_ASSERT_RETURN(fPlugin->pData->client != nullptr,);
carla_debug("CarlaPlugin::~ScopedDisabler()");

fPlugin->pData->enabled = true;
fPlugin->pData->client->activate();
if (fWasEnabled)
{
fPlugin->pData->enabled = true;
fPlugin->pData->client->activate();
}

fPlugin->pData->masterMutex.unlock();
}



Loading…
Cancel
Save