Signed-off-by: falkTX <falktx@falktx.com>tags/v2.2.0-RC1
@@ -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. | |||
@@ -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) | |||
@@ -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); | |||
@@ -990,7 +990,7 @@ public: | |||
return; | |||
} | |||
plugin->prepareForSave(); | |||
plugin->prepareForSave(false); | |||
for (uint32_t i=0, count=plugin->getCustomDataCount(); i<count; ++i) | |||
{ | |||
@@ -1064,7 +1064,7 @@ public: | |||
case kPluginBridgeNonRtClientRestoreLV2State: | |||
if (plugin->isEnabled()) | |||
plugin->restoreLV2State(); | |||
plugin->restoreLV2State(false); | |||
break; | |||
case kPluginBridgeNonRtClientShowUI: | |||
@@ -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) | |||
{ | |||
@@ -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 | |||
@@ -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); | |||
@@ -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); | |||
} | |||
@@ -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) | |||
@@ -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(...) {} | |||
} | |||
} | |||
@@ -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,); | |||
@@ -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), | |||
@@ -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; | |||