From 1fa918b90af39c16d4bf83781fdfd4dd20464031 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 5 Dec 2013 09:25:30 +0000 Subject: [PATCH] More DISTRHO work, fixup some LV2 stuff --- .../nekobi/DistrhoPluginNekobi.hpp | 3 - .../carla_native/nekobi/DistrhoUINekobi.hpp | 1 - .../modules/distrho/src/DistrhoPluginLV2.cpp | 63 ++++++++----------- .../distrho/src/DistrhoPluginLV2export.cpp | 2 +- source/modules/distrho/src/DistrhoUILV2.cpp | 18 ++---- 5 files changed, 31 insertions(+), 56 deletions(-) diff --git a/source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp b/source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp index 841848ab7..73f21b7a1 100644 --- a/source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp +++ b/source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp @@ -48,9 +48,6 @@ public: DistrhoPluginNekobi(); ~DistrhoPluginNekobi() override; - void d_initStateKey(uint32_t, d_string&) override {} - void d_setState(const char*, const char*) override {} - protected: // ------------------------------------------------------------------- // Information diff --git a/source/modules/carla_native/nekobi/DistrhoUINekobi.hpp b/source/modules/carla_native/nekobi/DistrhoUINekobi.hpp index b17881c8a..edf83f697 100644 --- a/source/modules/carla_native/nekobi/DistrhoUINekobi.hpp +++ b/source/modules/carla_native/nekobi/DistrhoUINekobi.hpp @@ -65,7 +65,6 @@ protected: // DSP Callbacks void d_parameterChanged(uint32_t index, float value) override; - void d_stateChanged(const char*, const char*) override {} // ------------------------------------------------------------------- // UI Callbacks diff --git a/source/modules/distrho/src/DistrhoPluginLV2.cpp b/source/modules/distrho/src/DistrhoPluginLV2.cpp index b7dcdbbdc..bcdab9669 100644 --- a/source/modules/distrho/src/DistrhoPluginLV2.cpp +++ b/source/modules/distrho/src/DistrhoPluginLV2.cpp @@ -369,57 +369,44 @@ public: // ------------------------------------------------------------------- #if DISTRHO_PLUGIN_WANT_STATE - LV2_State_Status lv2_save(LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* /*features*/) + LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle, const uint32_t flags) { - flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE; + //flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE; for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it) { const d_string& key = it->first; const d_string& value = it->second; - store(handle, fUridMap->map(fUridMap->handle, (const char*)key), (const char*)value, value.length(), fURIDs.atomString, flags); + store(handle, fUridMap->map(fUridMap->handle, (const char*)key), (const char*)value, value.length()+1, fURIDs.atomString, flags); } return LV2_STATE_SUCCESS; } - LV2_State_Status lv2_restore(LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* /*features*/) + LV2_State_Status lv2_restore(const LV2_State_Retrieve_Function retrieve, const LV2_State_Handle handle) { - size_t size = 0; - uint32_t type = 0; + size_t size = 0; + uint32_t type = 0; + uint32_t flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE; - flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE; - - d_stderr2("lv2_restore called"); - - //for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i) + for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i) { - //const d_string& key = fPlugin.getStateKey(i); - const d_string key("yKey1"); + const d_string& key = fPlugin.getStateKey(i); const void* data = retrieve(handle, fUridMap->map(fUridMap->handle, (const char*)key), &size, &type, &flags); - if (size == 0 || data == nullptr) - { - d_stderr2("lv2_restore err 1"); - return LV2_STATE_SUCCESS;//continue; - } + if (size == 0) + continue; + if (data == nullptr) + continue; if (type != fURIDs.atomString) - { - d_stderr2("lv2_restore err 2"); - return LV2_STATE_SUCCESS;//continue; - } + continue; const char* const value((const char*)data); if (std::strlen(value) != size) - { - d_stderr2("lv2_restore err 3"); - return LV2_STATE_SUCCESS;//continue; - } - - d_stderr2("Got request of state restore, key: \"%s\", value: \"%s\"", (const char*)key, (const char*)value); + continue; setState(key, value); } @@ -431,7 +418,7 @@ public: LV2_Worker_Status lv2_work(const void* const data) { - const char* const stateKey((const char*)data + 1); + const char* const stateKey((const char*)data); const char* const stateValue(stateKey+std::strlen(stateKey)+1); setState(stateKey, stateValue); @@ -496,16 +483,16 @@ private: #if DISTRHO_PLUGIN_WANT_STATE StringMap fStateMap; - void setState(const char* const newKey, const char* const newValue) + void setState(const char* const key, const char* const newValue) { - fPlugin.setState(newKey, newValue); + fPlugin.setState(key, newValue); // check if key already exists for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it) { - const d_string& key = it->first; + const d_string& d_key = it->first; - if (key == newKey) + if (d_key == key) { it->second = newValue; return; @@ -513,7 +500,7 @@ private: } // add a new one then - d_string d_key(newKey); + d_string d_key(key); fStateMap[d_key] = newValue; } #endif @@ -653,14 +640,14 @@ static void lv2_select_program(LV2_Handle instance, uint32_t bank, uint32_t prog // ----------------------------------------------------------------------- #if DISTRHO_PLUGIN_WANT_STATE -static LV2_State_Status lv2_save(LV2_Handle instance, LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features) +static LV2_State_Status lv2_save(LV2_Handle instance, LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const*) { - return instancePtr->lv2_save(store, handle, flags, features); + return instancePtr->lv2_save(store, handle, flags); } -static LV2_State_Status lv2_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features) +static LV2_State_Status lv2_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t, const LV2_Feature* const*) { - return instancePtr->lv2_restore(retrieve, handle, flags, features); + return instancePtr->lv2_restore(retrieve, handle); } LV2_Worker_Status lv2_work(LV2_Handle instance, LV2_Worker_Respond_Function, LV2_Worker_Respond_Handle, uint32_t, const void* data) diff --git a/source/modules/distrho/src/DistrhoPluginLV2export.cpp b/source/modules/distrho/src/DistrhoPluginLV2export.cpp index c4bb88093..5240c63d0 100644 --- a/source/modules/distrho/src/DistrhoPluginLV2export.cpp +++ b/source/modules/distrho/src/DistrhoPluginLV2export.cpp @@ -136,7 +136,7 @@ void lv2_generate_ttl(const char* const basename) pluginString += "\n"; // extensionData - pluginString += " lv2:extensionData <" LV2_OPTIONS__interface "> "; + pluginString += " lv2:extensionData <" LV2_STATE__interface "> "; #if DISTRHO_PLUGIN_WANT_STATE pluginString += ",\n <" LV2_OPTIONS__interface "> "; pluginString += ",\n <" LV2_WORKER__interface "> "; diff --git a/source/modules/distrho/src/DistrhoUILV2.cpp b/source/modules/distrho/src/DistrhoUILV2.cpp index d89fe1227..138ed4eb5 100644 --- a/source/modules/distrho/src/DistrhoUILV2.cpp +++ b/source/modules/distrho/src/DistrhoUILV2.cpp @@ -111,21 +111,13 @@ protected: // join key and value std::string tmpStr; - tmpStr += key; - tmpStr += "\xff"; - tmpStr += value; + tmpStr += std::string(key); + tmpStr += std::string("\0", 1); + tmpStr += std::string(value); - // get size + // get msg size const size_t msgSize(tmpStr.size()+1); - // convert into char[] - char msg[msgSize]; - std::memcpy(msg, tmpStr.c_str(), msgSize-1); - - // set proper null chars - msg[std::strlen(key)] = '\0'; - msg[msgSize] = '\0'; - // reserve atom space const size_t atomSize(lv2_atom_pad_size(sizeof(LV2_Atom) + msgSize)); char atomBuf[atomSize]; @@ -137,7 +129,7 @@ protected: atom->type = fUridMap->map(fUridMap->handle, "urn:distrho:keyValueState"); // set atom data - std::memcpy(atomBuf + sizeof(LV2_Atom), msg, msgSize); + std::memcpy(atomBuf + sizeof(LV2_Atom), tmpStr.data(), msgSize-1); // send to DSP side fWriteFunction(fController, eventInPortIndex, atomSize, fUridMap->map(fUridMap->handle, LV2_ATOM__eventTransfer), atom);