diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index 787c130c2..888e9e59a 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -401,8 +401,17 @@ public: /*! * Tell the plugin to prepare for save. + * @param temporary Wherever we are saving into a temporary location + * (for duplication, renaming or similar) */ - virtual void prepareForSave(); + virtual void prepareForSave(bool temporary); + + /*! + * Call LV2 restore. + * @param temporary Wherever we are saving into a temporary location + * (for duplication, renaming or similar) + */ + virtual void restoreLV2State(bool temporary) noexcept; /*! * Reset all possible parameters. @@ -981,13 +990,6 @@ protected: // ------------------------------------------------------------------- // Internal helper functions -public: - // FIXME: remove public exception on 2.1 release - /*! - * Call LV2 restore. - */ - virtual void restoreLV2State() noexcept; - protected: /*! * Allow engine to signal that plugin will be deleted soon. diff --git a/source/backend/CarlaStandalone.cpp b/source/backend/CarlaStandalone.cpp index 3e6a42caa..99ea70f74 100644 --- a/source/backend/CarlaStandalone.cpp +++ b/source/backend/CarlaStandalone.cpp @@ -2121,7 +2121,7 @@ void carla_prepare_for_save(CarlaHostHandle handle, uint pluginId) CARLA_SAFE_ASSERT_RETURN(handle->engine != nullptr,); if (const CarlaPluginPtr plugin = handle->engine->getPlugin(pluginId)) - plugin->prepareForSave(); + plugin->prepareForSave(false); } void carla_reset_parameters(CarlaHostHandle handle, uint pluginId) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index da75fc38b..befb5ea1c 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -694,7 +694,8 @@ bool CarlaEngine::addPlugin(const BinaryType btype, "http://sfztools.github.io/sfizz:sfzfile", filename, false); - plugin->restoreLV2State(); + + plugin->restoreLV2State(true); } #endif @@ -2214,7 +2215,7 @@ void CarlaEngine::saveProjectInternal(water::MemoryOutputStream& outStream) cons if (plugin->getHints() & PLUGIN_IS_BRIDGE) plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "false", false); #endif - plugin->prepareForSave(); + plugin->prepareForSave(false); } } } @@ -2774,7 +2775,7 @@ bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc, const bool alw lsState << "0 0 0 0 1 0 GIG\n"; plugin->setCustomData(LV2_ATOM__String, "http://linuxsampler.org/schema#state-string", lsState.toRawUTF8(), true); - plugin->restoreLV2State(); + plugin->restoreLV2State(true); plugin->setDryWet(stateSave.dryWet, true, true); plugin->setVolume(stateSave.volume, true, true); @@ -2827,7 +2828,7 @@ bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc, const bool alw stateSave.binary, false); - plugin->restoreLV2State(); + plugin->restoreLV2State(true); plugin->setDryWet(stateSave.dryWet, true, true); plugin->setVolume(stateSave.volume, true, true); diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index 7a133b914..c3c6e0e4d 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -990,7 +990,7 @@ public: return; } - plugin->prepareForSave(); + plugin->prepareForSave(false); for (uint32_t i=0, count=plugin->getCustomDataCount(); iisEnabled()) - plugin->restoreLV2State(); + plugin->restoreLV2State(false); break; case kPluginBridgeNonRtClientShowUI: diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index a80acc458..27bf381f9 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -2255,7 +2255,7 @@ bool CarlaEngineNativeUI::msgReceived(const char* const msg) noexcept CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(pluginId), true); if (const CarlaPluginPtr plugin = fEngine->getPlugin(pluginId)) - plugin->prepareForSave(); + plugin->prepareForSave(false); } else if (std::strcmp(msg, "reset_parameters") == 0) { diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 6f4e78afd..0168e9b0a 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -439,7 +439,7 @@ void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noe // ------------------------------------------------------------------- // Set data (state) -void CarlaPlugin::prepareForSave() +void CarlaPlugin::prepareForSave(bool) { } @@ -508,7 +508,10 @@ void CarlaPlugin::randomizeParameters() noexcept const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave) { if (callPrepareForSave) - prepareForSave(); + { + pData->stateSave.temporary = true; + prepareForSave(true); + } pData->stateSave.clear(); @@ -902,7 +905,7 @@ void CarlaPlugin::loadStateSave(const CarlaStateSave& stateSave) if (std::strcmp(customData.type, CUSTOM_DATA_TYPE_PROPERTY) == 0) continue; - restoreLV2State(); + restoreLV2State(stateSave.temporary); break; } } @@ -2564,9 +2567,9 @@ void CarlaPlugin::setPatchbayNodeId(const uint32_t nodeId) noexcept // ------------------------------------------------------------------- -void CarlaPlugin::restoreLV2State() noexcept +void CarlaPlugin::restoreLV2State(const bool temporary) noexcept { - carla_stderr2("Warning: restoreLV2State() called for non-implemented type"); + carla_stderr2("Warning: restoreLV2State(%s) called for non-implemented type", bool2str(temporary)); } void CarlaPlugin::prepareForDeletion() noexcept diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 7603be463..c80f9d358 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -606,7 +606,7 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() noexcept override + void prepareForSave(bool) noexcept override { fSaved = false; @@ -1946,7 +1946,7 @@ public: // ------------------------------------------------------------------- // Internal helper functions - void restoreLV2State() noexcept override + void restoreLV2State(bool) noexcept override { const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex); diff --git a/source/backend/plugin/CarlaPluginFluidSynth.cpp b/source/backend/plugin/CarlaPluginFluidSynth.cpp index c736a8a4d..d0e9f2a34 100644 --- a/source/backend/plugin/CarlaPluginFluidSynth.cpp +++ b/source/backend/plugin/CarlaPluginFluidSynth.cpp @@ -378,13 +378,14 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() override + void prepareForSave(bool) override { char strBuf[STR_MAX+1]; - std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i", fCurMidiProgs[0], fCurMidiProgs[1], fCurMidiProgs[2], fCurMidiProgs[3], - fCurMidiProgs[4], fCurMidiProgs[5], fCurMidiProgs[6], fCurMidiProgs[7], - fCurMidiProgs[8], fCurMidiProgs[9], fCurMidiProgs[10], fCurMidiProgs[11], - fCurMidiProgs[12], fCurMidiProgs[13], fCurMidiProgs[14], fCurMidiProgs[15]); + std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i", + fCurMidiProgs[0], fCurMidiProgs[1], fCurMidiProgs[2], fCurMidiProgs[3], + fCurMidiProgs[4], fCurMidiProgs[5], fCurMidiProgs[6], fCurMidiProgs[7], + fCurMidiProgs[8], fCurMidiProgs[9], fCurMidiProgs[10], fCurMidiProgs[11], + fCurMidiProgs[12], fCurMidiProgs[13], fCurMidiProgs[14], fCurMidiProgs[15]); CarlaPlugin::setCustomData(CUSTOM_DATA_TYPE_STRING, "midiPrograms", strBuf, false); } diff --git a/source/backend/plugin/CarlaPluginJack.cpp b/source/backend/plugin/CarlaPluginJack.cpp index 4384bd5ad..435ba89e8 100644 --- a/source/backend/plugin/CarlaPluginJack.cpp +++ b/source/backend/plugin/CarlaPluginJack.cpp @@ -676,7 +676,7 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() noexcept override + void prepareForSave(bool) noexcept override { #ifdef HAVE_LIBLO if (fInfo.setupLabel.length() == 6) diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index ff8684627..dbe91554e 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -1321,20 +1321,24 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() override + void prepareForSave(const bool temporary) override { CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fExt.state != nullptr && fExt.state->save != nullptr) { - const File tmpDir(handleStateMapToAbsolutePath(false, false, true, ".")); - - if (tmpDir.exists()) + // move temporary stuff to main state dir on full save + if (! temporary) { - const File stateDir(handleStateMapToAbsolutePath(true, false, false, ".")); + const File tmpDir(handleStateMapToAbsolutePath(false, false, true, ".")); - if (stateDir.isNotNull()) - tmpDir.moveFileTo(stateDir); + if (tmpDir.exists()) + { + const File stateDir(handleStateMapToAbsolutePath(true, false, false, ".")); + + if (stateDir.isNotNull()) + tmpDir.moveFileTo(stateDir); + } } fExt.state->save(fHandle, carla_lv2_state_store, this, LV2_STATE_IS_POD, fStateFeatures); @@ -1349,8 +1353,27 @@ public: void setName(const char* const newName) override { + const File tmpDir1(handleStateMapToAbsolutePath(false, false, true, ".")); + CarlaPlugin::setName(newName); + if (tmpDir1.exists()) + { + const File tmpDir2(handleStateMapToAbsolutePath(false, false, true, ".")); + + carla_stdout("dir1 %s, dir2 %s", + tmpDir1.getFullPathName().toRawUTF8(), + tmpDir2.getFullPathName().toRawUTF8()); + + if (tmpDir2.isNotNull()) + { + if (tmpDir2.exists()) + tmpDir2.deleteRecursively(); + + tmpDir1.moveFileTo(tmpDir2); + } + } + if (fLv2Options.windowTitle != nullptr && pData->uiTitle.isEmpty()) setWindowTitle(nullptr); } @@ -4840,15 +4863,18 @@ public: // ------------------------------------------------------------------- // Internal helper functions - void restoreLV2State() noexcept override + void restoreLV2State(const bool temporary) noexcept override { if (fExt.state == nullptr || fExt.state->restore == nullptr) return; - const File tmpDir(handleStateMapToAbsolutePath(false, false, true, ".")); + if (! temporary) + { + const File tmpDir(handleStateMapToAbsolutePath(false, false, true, ".")); - if (tmpDir.exists()) - tmpDir.deleteRecursively(); + if (tmpDir.exists()) + tmpDir.deleteRecursively(); + } LV2_State_Status status = LV2_STATE_ERR_UNKNOWN; @@ -4856,13 +4882,21 @@ public: const ScopedSingleProcessLocker spl(this, !fHasThreadSafeRestore); try { - status = fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, LV2_STATE_IS_POD, fStateFeatures); + status = fExt.state->restore(fHandle, + carla_lv2_state_retrieve, + this, + LV2_STATE_IS_POD, + temporary ? fFeatures : fStateFeatures); } catch(...) {} if (fHandle2 != nullptr) { try { - fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, LV2_STATE_IS_POD, fStateFeatures); + fExt.state->restore(fHandle, + carla_lv2_state_retrieve, + this, + LV2_STATE_IS_POD, + temporary ? fFeatures : fStateFeatures); } catch(...) {} } } diff --git a/source/backend/plugin/CarlaPluginNative.cpp b/source/backend/plugin/CarlaPluginNative.cpp index a94c1e8b9..92593f1c4 100644 --- a/source/backend/plugin/CarlaPluginNative.cpp +++ b/source/backend/plugin/CarlaPluginNative.cpp @@ -658,7 +658,7 @@ public: // ------------------------------------------------------------------- // Set data (state) - void prepareForSave() override + void prepareForSave(bool) override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); diff --git a/source/utils/CarlaStateUtils.cpp b/source/utils/CarlaStateUtils.cpp index b3b73675b..e0ad2c239 100644 --- a/source/utils/CarlaStateUtils.cpp +++ b/source/utils/CarlaStateUtils.cpp @@ -192,6 +192,7 @@ CarlaStateSave::CarlaStateSave() noexcept binary(nullptr), uniqueId(0), options(0x0), + temporary(false), #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH active(false), dryWet(1.0f), diff --git a/source/utils/CarlaStateUtils.hpp b/source/utils/CarlaStateUtils.hpp index e98ba660a..cbf22a110 100644 --- a/source/utils/CarlaStateUtils.hpp +++ b/source/utils/CarlaStateUtils.hpp @@ -73,6 +73,9 @@ struct CarlaStateSave { int64_t uniqueId; uint options; + // saved during clone, rename or similar + bool temporary; + #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH bool active; float dryWet;