From 9965e8275aa8efea54bf9f037dfec21e18255d72 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 3 Jan 2015 21:09:50 +0000 Subject: [PATCH] Optimize data saving for bridges; Keep last loaded state --- source/backend/CarlaPlugin.hpp | 4 ++-- source/backend/engine/CarlaEngine.cpp | 12 ++++++++-- source/backend/plugin/CarlaPlugin.cpp | 6 +++-- source/backend/plugin/CarlaPluginBridge.cpp | 26 ++++++++++++++++----- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index a93f0dbe6..57d575415 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -388,11 +388,11 @@ public: /*! * Get the plugin's save state. - * The plugin will automatically call prepareForSave() as needed. + * The plugin will automatically call prepareForSave() if requested. * * @see loadStateSave() */ - const CarlaStateSave& getStateSave(); + const CarlaStateSave& getStateSave(const bool callPrepareForSave = true); /*! * Get the plugin's save state. diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 39ea8903d..530f401c1 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1519,6 +1519,15 @@ void CarlaEngine::setPluginPeaks(const uint pluginId, float const inPeaks[2], fl void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const { + // send initial prepareForSave first, giving time for bridges to act + for (uint i=0; i < pData->curPluginCount; ++i) + { + CarlaPlugin* const plugin(pData->plugins[i].plugin); + + if (plugin != nullptr && plugin->isEnabled()) + plugin->prepareForSave(); + } + outStream << "\n"; outStream << "\n"; outStream << "\n"; @@ -1528,7 +1537,6 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const MemoryOutputStream outSettings(1024); - // save appropriate engine settings outSettings << " \n"; @@ -1578,7 +1586,7 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const outPlugin << " \n"; outPlugin << " \n"; - outPlugin << plugin->getStateSave().toString(); + outPlugin << plugin->getStateSave(false).toString(); outPlugin << " \n"; outStream << outPlugin; } diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index ab1b74cf0..96d8a50c8 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -476,10 +476,12 @@ void CarlaPlugin::randomizeParameters() noexcept } } -const CarlaStateSave& CarlaPlugin::getStateSave() +const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave) { + if (callPrepareForSave) + prepareForSave(); + pData->stateSave.clear(); - prepareForSave(); const PluginType pluginType(getType()); diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 3356c90bd..28254cb57 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -739,7 +739,7 @@ public: fPluginType(ptype), fInitiated(false), fInitError(false), - fSaved(false), + fSaved(true), fTimedOut(false), fTimedError(false), fLastPongCounter(-1), @@ -841,10 +841,15 @@ public: // ------------------------------------------------------------------- // Information (current data) + // TODO - missing getCustomData + std::size_t getChunkData(void** const dataPtr) noexcept override { CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0); CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); + + waitForSaved(); + CARLA_SAFE_ASSERT_RETURN(fInfo.chunk.size() > 0, 0); *dataPtr = fInfo.chunk.data(); @@ -910,7 +915,7 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() override + void prepareForSave() noexcept override { fSaved = false; @@ -920,8 +925,14 @@ public: fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientPrepareForSave); fShmNonRtClientControl.commitWrite(); } + } - carla_stdout("CarlaPluginBridge::prepareForSave() - sent, now waiting..."); + void waitForSaved() + { + if (fSaved) + return; + + carla_stdout("CarlaPluginBridge::waitForSaved() - now waiting..."); for (int i=0; i < 300; ++i) { @@ -930,13 +941,12 @@ public: carla_msleep(20); pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); pData->engine->idle(); - idle(); } if (! fSaved) - carla_stderr("CarlaPluginBridge::prepareForSave() - Timeout while requesting save state"); + carla_stderr("CarlaPluginBridge::waitForSaved() - Timeout while requesting save state"); else - carla_stdout("CarlaPluginBridge::prepareForSave() - success!"); + carla_stdout("CarlaPluginBridge::waitForSaved() - success!"); } // ------------------------------------------------------------------- @@ -1118,6 +1128,10 @@ public: fShmNonRtClientControl.writeCustomData(filePath.toRawUTF8(), ulength); fShmNonRtClientControl.commitWrite(); } + + // save data internally as well + fInfo.chunk.resize(dataSize); + std::memcpy(fInfo.chunk.data(), data, dataSize); } // -------------------------------------------------------------------