From efbd23eb89d1ff975e27c04aede79fd13a53c614 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 7 Feb 2014 09:40:12 +0000 Subject: [PATCH] LV2 state and programs; Misc fixes --- source/Makefile.mk | 2 +- source/backend/plugin/BridgePlugin.cpp | 3 +- source/backend/plugin/CarlaPlugin.cpp | 40 +++---- source/backend/plugin/DssiPlugin.cpp | 19 ++- source/backend/plugin/JucePlugin.cpp | 4 +- source/backend/plugin/Lv2Plugin.cpp | 154 +++++++++++-------------- source/utils/CarlaLv2Utils.hpp | 4 +- 7 files changed, 107 insertions(+), 119 deletions(-) diff --git a/source/Makefile.mk b/source/Makefile.mk index a1aa50b45..5b1ec016e 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -53,7 +53,7 @@ endif # Common build and link flags BASE_FLAGS = -Wall -Wextra -pipe -DREAL_BUILD -BASE_OPTS = -O3 -ffast-math -mtune=generic -msse -msse2 -mfpmath=sse -fdata-sections -ffunction-sections +BASE_OPTS = -O2 -ffast-math -mtune=generic -msse -msse2 -mfpmath=sse -fdata-sections -ffunction-sections LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections ifeq ($(TESTBUILD),true) diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index ad5c0c125..50429a797 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -568,8 +568,7 @@ public: { osc_send_show(pData->osc.data); - if (pData->engine->getOptions().frontendWinId != 0) - pData->transientTryCounter = 1; + pData->tryTransient(); } else { diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 12611a089..1caead1cc 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -732,6 +732,12 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true); } + // --------------------------------------------------------------- + // Part 5x - set lv2 state + + if (getType() == PLUGIN_LV2) + setCustomData(CUSTOM_DATA_TYPE_STRING, "CarlaLoadLv2StateNow", "true", true); + // --------------------------------------------------------------- // Part 6 - set chunk @@ -1141,25 +1147,18 @@ void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, con void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) { - CARLA_ASSERT(type != nullptr); - CARLA_ASSERT(key != nullptr); - CARLA_ASSERT(value != nullptr); + CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(value != nullptr,); #ifdef BUILD_BRIDGE - if (! gIsLoadingProject) - { - CARLA_ASSERT(! sendGui); // this should never happen + if (! gIsLoadingProject) { + CARLA_SAFE_ASSERT_RETURN(! sendGui,); // this should never happen } +#else + // unused + (void)sendGui; #endif - if (type == nullptr) - return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is null", type, key, value, bool2str(sendGui)); - - if (key == nullptr) - return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui)); - - if (value == nullptr) - return carla_stderr2("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui)); - bool saveData = true; if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0) @@ -1179,14 +1178,9 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c { CustomData& cData(it.getValue()); - CARLA_ASSERT(cData.type != nullptr); - CARLA_ASSERT(cData.key != nullptr); - CARLA_ASSERT(cData.value != nullptr); - - if (cData.type == nullptr) - return; - if (cData.key == nullptr) - return; + CARLA_SAFE_ASSERT_RETURN(cData.type != nullptr,); + CARLA_SAFE_ASSERT_RETURN(cData.key != nullptr,); + CARLA_SAFE_ASSERT_RETURN(cData.value != nullptr,); if (std::strcmp(cData.key, key) == 0) { diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 4041bcf0b..e852bee75 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -305,10 +305,16 @@ public: if (fDssiDescriptor->configure != nullptr) { - fDssiDescriptor->configure(fHandle, key, value); + try { + fDssiDescriptor->configure(fHandle, key, value); + } catch(...) {} if (fHandle2 != nullptr) - fDssiDescriptor->configure(fHandle2, key, value); + { + try { + fDssiDescriptor->configure(fHandle2, key, value); + } catch(...) {} + } } if (sendGui && pData->osc.data.target != nullptr) @@ -338,7 +344,10 @@ public: CARLA_SAFE_ASSERT_RETURN(chunk.size() > 0,); const ScopedSingleProcessLocker spl(this, true); - fDssiDescriptor->set_custom_data(fHandle, chunk.data(), static_cast(chunk.size())); + + try { + fDssiDescriptor->set_custom_data(fHandle, chunk.data(), static_cast(chunk.size())); + } catch(...) {} } void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override @@ -350,8 +359,8 @@ public: if (index >= 0) { - const uint32_t bank = pData->midiprog.data[index].bank; - const uint32_t program = pData->midiprog.data[index].program; + const uint32_t bank(pData->midiprog.data[index].bank); + const uint32_t program(pData->midiprog.data[index].program); const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); diff --git a/source/backend/plugin/JucePlugin.cpp b/source/backend/plugin/JucePlugin.cpp index 736a5b556..5df616c8c 100644 --- a/source/backend/plugin/JucePlugin.cpp +++ b/source/backend/plugin/JucePlugin.cpp @@ -25,8 +25,6 @@ #include "juce_audio_processors.h" -// TODO - use setPlayConfigDetails - using namespace juce; CARLA_BACKEND_START_NAMESPACE @@ -493,6 +491,8 @@ public: if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0)) pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; + fInstance->setPlayConfigDetails(static_cast(aIns), static_cast(aOuts), pData->engine->getSampleRate(), static_cast(pData->engine->getBufferSize())); + bufferSizeChanged(pData->engine->getBufferSize()); //reloadPrograms(true); diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index fc90f157a..acdeabcb6 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -951,40 +951,37 @@ public: CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback); } -#if 0 void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - CARLA_ASSERT(type != nullptr); - CARLA_ASSERT(key != nullptr); - CARLA_ASSERT(value != nullptr); + CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); + CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(value != nullptr,); carla_debug("Lv2Plugin::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui)); - if (type == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is invalid", type, key, value, bool2str(sendGui)); - - if (key == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui)); - - if (value == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui)); - - CarlaPlugin::setCustomData(type, key, value, sendGui); - - // FIXME - we should only call this once, after all data is stored - - if (fExt.state != nullptr) + // we should only call state restore once + // so inject this in CarlaPlugin::loadSaveState + if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) == 0 && std::strcmp(key, "CarlaLoadLv2StateNow") == 0 && std::strcmp(value, "true") == 0) { - LV2_State_Status status; + if (fExt.state == nullptr) + return; + + LV2_State_Status status = LV2_STATE_ERR_UNKNOWN; { const ScopedSingleProcessLocker spl(this, true); - status = fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); + try { + status = fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); + } catch(...) {} if (fHandle2 != nullptr) - fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); + { + try { + fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); + } catch(...) {} + } } switch (status) @@ -1008,32 +1005,20 @@ public: carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - error, missing property", type, key, bool2str(sendGui)); break; } + return; } - if (sendGui) - { - //CustomData cdata; - //cdata.type = type; - //cdata.key = key; - //cdata.value = value; - //uiTransferCustomData(&cdata); - } + CarlaPlugin::setCustomData(type, key, value, sendGui); } - void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(index >= -1 && index < static_cast(fRdfDescriptor->PresetCount)); - CARLA_ASSERT(sendGui || sendOsc || sendCallback); // never call this from RT - - if (index < -1) - index = -1; - else if (index > static_cast(fRdfDescriptor->PresetCount)) - return; + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); + CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->prog.count),); if (index >= 0 && index < static_cast(fRdfDescriptor->PresetCount)) { - if (const LilvState* state = gLv2World.getState(fRdfDescriptor->Presets[index].URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) + if (const LilvState* state = Lv2WorldClass::getInstance().getState(fRdfDescriptor->Presets[index].URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) { const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); @@ -1047,16 +1032,10 @@ public: CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback); } - void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - CARLA_ASSERT(index >= -1 && index < static_cast(pData->midiprog.count)); - - if (index < -1) - index = -1; - else if (index > static_cast(pData->midiprog.count)) - return; + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); + CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); if (index >= 0 && fExt.programs != nullptr && fExt.programs->select_program != nullptr) { @@ -1065,15 +1044,20 @@ public: const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); - fExt.programs->select_program(fHandle, bank, program); + try { + fExt.programs->select_program(fHandle, bank, program); + } catch(...) {} if (fHandle2 != nullptr) - fExt.programs->select_program(fHandle2, bank, program); + { + try { + fExt.programs->select_program(fHandle2, bank, program); + } catch(...) {} + } } CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback); } -#endif // ------------------------------------------------------------------- // Set ui stuff @@ -2117,25 +2101,24 @@ public: carla_debug("Lv2Plugin::reload() - end"); } -#if 0 - void reloadPrograms(const bool init) override + void reloadPrograms(const bool doInit) override { - carla_debug("DssiPlugin::reloadPrograms(%s)", bool2str(init)); - uint32_t i, oldCount = pData->midiprog.count; - const int32_t current = pData->midiprog.current; + carla_debug("DssiPlugin::reloadPrograms(%s)", bool2str(doInit)); + const uint32_t oldCount = pData->midiprog.count; + const int32_t current = pData->midiprog.current; // special LV2 programs handling - if (init) + if (doInit) { pData->prog.clear(); - const uint32_t count(fRdfDescriptor->PresetCount); + const uint32_t presetCount(fRdfDescriptor->PresetCount); - if (count > 0) + if (presetCount > 0) { - pData->prog.createNew(count); + pData->prog.createNew(presetCount); - for (i=0; i < count; ++i) + for (uint32_t i=0; i < presetCount; ++i) pData->prog.names[i] = carla_strdup(fRdfDescriptor->Presets[i].Label); } } @@ -2144,23 +2127,23 @@ public: pData->midiprog.clear(); // Query new programs - uint32_t count = 0; + uint32_t newCount = 0; if (fExt.programs != nullptr && fExt.programs->get_program != nullptr && fExt.programs->select_program != nullptr) { - while (fExt.programs->get_program(fHandle, count)) - ++count; + for (; fExt.programs->get_program(fHandle, newCount);) + ++newCount; } - if (count > 0) + if (newCount > 0) { - pData->midiprog.createNew(count); + pData->midiprog.createNew(newCount); // Update data - for (i=0; i < count; ++i) + for (uint32_t i=0; i < newCount; ++i) { const LV2_Program_Descriptor* const pdesc(fExt.programs->get_program(fHandle, i)); - CARLA_ASSERT(pdesc != nullptr); - CARLA_ASSERT(pdesc->name != nullptr); + CARLA_SAFE_ASSERT_CONTINUE(pdesc != nullptr); + CARLA_SAFE_ASSERT(pdesc->name != nullptr); pData->midiprog.data[i].bank = pdesc->bank; pData->midiprog.data[i].program = pdesc->program; @@ -2172,23 +2155,23 @@ public: // Update OSC Names if (pData->engine->isOscControlRegistered()) { - pData->engine->osc_send_control_set_midi_program_count(fId, count); + pData->engine->oscSend_control_set_midi_program_count(pData->id, newCount); - for (i=0; i < count; ++i) - pData->engine->osc_send_control_set_midi_program_data(fId, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name); + for (uint32_t i=0; i < newCount; ++i) + pData->engine->oscSend_control_set_midi_program_data(pData->id, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name); } #endif - if (init) + if (doInit) { - if (count > 0) + if (newCount > 0) { setMidiProgram(0, false, false, false); } else { // load default state - if (const LilvState* state = gLv2World.getState(fDescriptor->URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) + if (const LilvState* state = Lv2WorldClass::getInstance().getState(fDescriptor->URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) { lilv_state_restore(state, fExt.state, fHandle, carla_lilv_set_port_value, this, 0, fFeatures); @@ -2202,25 +2185,25 @@ public: // Check if current program is invalid bool programChanged = false; - if (count == oldCount+1) + if (newCount == oldCount+1) { // one midi program added, probably created by user - pData->midiprog.current = oldCount; + pData->midiprog.current = static_cast(oldCount); programChanged = true; } - else if (current < 0 && count > 0) + else if (current < 0 && newCount > 0) { // programs exist now, but not before pData->midiprog.current = 0; programChanged = true; } - else if (current >= 0 && count == 0) + else if (current >= 0 && newCount == 0) { // programs existed before, but not anymore pData->midiprog.current = -1; programChanged = true; } - else if (current >= static_cast(count)) + else if (current >= static_cast(newCount)) { // current midi program > count pData->midiprog.current = 0; @@ -2235,10 +2218,9 @@ public: if (programChanged) setMidiProgram(pData->midiprog.current, true, true, true); - pData->engine->callback(CALLBACK_RELOAD_PROGRAMS, fId, 0, 0, 0.0f, nullptr); + pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr); } } -#endif // ------------------------------------------------------------------- // Plugin processing @@ -3644,6 +3626,7 @@ public: { CARLA_SAFE_ASSERT_RETURN(uiId < fRdfDescriptor->UICount, false); +#ifndef LV2_UIS_ONLY_INPROCESS const LV2_RDF_UI* const rdfUi(&fRdfDescriptor->UIs[uiId]); if (std::strstr(rdfUi->URI, "http://calf.sourceforge.net/plugins/gui/") != nullptr) @@ -3658,6 +3641,9 @@ public: } return true; +#else + return false; +#endif } bool isUiResizable() const noexcept diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index f09c1f037..344a61f60 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -402,7 +402,7 @@ public: // Create new RDF object (using lilv) static inline -const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool /*fillPresets*/) +const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool fillPresets) { CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0', nullptr); @@ -1019,7 +1019,7 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool /*fillPreset } } -#if 0 +#if 1 // ------------------------------------------------------------------- // Set Plugin Presets