DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 1ae94bf2216b02e99513f8a3ff7d39efe8152a9d
parent 4c59baa3140863353827038b1e5966d7c1166880
Author: falkTX <falktx@falktx.com>
Date:   Sun, 26 Sep 2021 16:19:30 +0100

VST3 cleanup, add state-set UI message

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdistrho/src/DistrhoPluginVST3.cpp | 146+++++++++----------------------------------------------------------------------
Mdistrho/src/DistrhoUIVST3.cpp | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 77 insertions(+), 148 deletions(-)

diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp @@ -17,6 +17,16 @@ #include "DistrhoPluginInternal.hpp" #include "../extra/ScopedPointer.hpp" +#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI +# undef DISTRHO_PLUGIN_HAS_UI +# define DISTRHO_PLUGIN_HAS_UI 0 +#endif + +#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI +# undef DISTRHO_PLUGIN_HAS_UI +# define DISTRHO_PLUGIN_HAS_UI 0 +#endif + #if DISTRHO_PLUGIN_HAS_UI # include "../extra/RingBuffer.hpp" #endif @@ -35,8 +45,10 @@ * - parameter enumeration as lists * - hide parameter outputs? * - hide program parameter? - * - state support + * - save and restore state * - save and restore current program + * - proper send of parameter, program and state changes to UI + * - send current state to UI on request * - midi cc parameter mapping * - full MIDI1 encode and decode * - decode version number (0x102030 -> 1.2.3) @@ -796,33 +808,6 @@ public: } // ---------------------------------------------------------------------------------------------------------------- - // v3_bstream interface calls (for state support) - - v3_result read(void* /*buffer*/, int32_t /*num_bytes*/, int32_t* /*bytes_read*/) - { - // TODO - return V3_NOT_IMPLEMENTED; - } - - v3_result write(void* /*buffer*/, int32_t /*num_bytes*/, int32_t* /*bytes_written*/) - { - // TODO - return V3_NOT_IMPLEMENTED; - } - - v3_result seek(int64_t /*pos*/, int32_t /*seek_mode*/, int64_t* /*result*/) - { - // TODO - return V3_NOT_IMPLEMENTED; - } - - v3_result tell(int64_t* /*pos*/) - { - // TODO - return V3_NOT_IMPLEMENTED; - } - - // ---------------------------------------------------------------------------------------------------------------- // v3_audio_processor interface calls v3_result setBusArrangements(v3_speaker_arrangement*, int32_t, v3_speaker_arrangement*, int32_t) @@ -1269,7 +1254,7 @@ public: DISTRHO_SAFE_ASSERT_RETURN(value >= 0.0 && value <= 1.0, V3_INVALID_ARG); // TESTING remove this - sendParameterChangeTest(rindex, value); + sendParameterChangeToUI(rindex, value); #if DISTRHO_PLUGIN_WANT_PROGRAMS if (rindex == 0) @@ -1491,7 +1476,7 @@ private: // ---------------------------------------------------------------------------------------------------------------- // helper functions called during message passing, can block - void sendParameterChangeTest(const v3_param_id rindex, const double value) + void sendParameterChangeToUI(const v3_param_id rindex, const double value) { d_stdout("will send message now"); DISTRHO_SAFE_ASSERT_RETURN(fConnectionToUI != nullptr,); @@ -2051,7 +2036,7 @@ struct dpf_edit_controller : v3_edit_controller_cpp { PluginVst3* const vst3 = controller->vst3; DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, nullptr); -#if 1 // DISTRHO_PLUGIN_HAS_UI +#if DISTRHO_PLUGIN_HAS_UI // we require a component connection DISTRHO_SAFE_ASSERT_RETURN(controller->connectionComp != nullptr, nullptr); DISTRHO_SAFE_ASSERT_RETURN(controller->connectionComp->other != nullptr, nullptr); @@ -2300,104 +2285,6 @@ struct dpf_audio_processor : v3_audio_processor_cpp { } }; -#if 0 -// -------------------------------------------------------------------------------------------------------------------- -// dpf_state_stream - -struct v3_bstream_cpp : v3_funknown { - v3_bstream stream; -}; - -struct dpf_state_stream : v3_bstream_cpp { - ScopedPointer<PluginVst3>& vst3; - - dpf_state_stream(ScopedPointer<PluginVst3>& v) - : vst3(v) - { - static const uint8_t* kSupportedInterfaces[] = { - v3_funknown_iid, - v3_bstream_iid - }; - - // ------------------------------------------------------------------------------------------------------------ - // v3_funknown - - query_interface = []V3_API(void* self, const v3_tuid iid, void** iface) -> v3_result - { - d_stdout("dpf_factory::query_interface => %p %s %p", self, tuid2str(iid), iface); - *iface = NULL; - DISTRHO_SAFE_ASSERT_RETURN(self != nullptr, V3_NO_INTERFACE); - - for (const uint8_t* interface_iid : kSupportedInterfaces) - { - if (v3_tuid_match(interface_iid, iid)) - { - *iface = self; - return V3_OK; - } - } - - return V3_NO_INTERFACE; - }; - - // there is only a single instance of this, so we don't have to care here - ref = []V3_API(void*) -> uint32_t { return 1; }; - unref = []V3_API(void*) -> uint32_t { return 0; }; - - // ------------------------------------------------------------------------------------------------------------ - // v3_bstream - - stream.read = []V3_API(void* self, void* buffer, int32_t num_bytes, int32_t* bytes_read) -> v3_result - { - d_stdout("dpf_state_stream::read => %p %p %i %p", self, buffer, num_bytes, bytes_read); - dpf_state_stream* const stream = *(dpf_state_stream**)self; - DISTRHO_SAFE_ASSERT_RETURN(stream != nullptr, V3_NOT_INITIALISED); - - PluginVst3* const vst3 = stream->vst3; - DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, V3_NOT_INITIALISED); - - return V3_NOT_IMPLEMENTED; - }; - - stream.write = []V3_API(void* self, void* buffer, int32_t num_bytes, int32_t* bytes_written) -> v3_result - { - d_stdout("dpf_state_stream::write => %p %p %i %p", self, buffer, num_bytes, bytes_written); - dpf_state_stream* const stream = *(dpf_state_stream**)self; - DISTRHO_SAFE_ASSERT_RETURN(stream != nullptr, V3_NOT_INITIALISED); - - PluginVst3* const vst3 = stream->vst3; - DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, V3_NOT_INITIALISED); - - return V3_NOT_IMPLEMENTED; - }; - - stream.seek = []V3_API(void* self, int64_t pos, int32_t seek_mode, int64_t* result) -> v3_result - { - d_stdout("dpf_state_stream::seek => %p %lu %i %p", self, pos, seek_mode, result); - dpf_state_stream* const stream = *(dpf_state_stream**)self; - DISTRHO_SAFE_ASSERT_RETURN(stream != nullptr, V3_NOT_INITIALISED); - - PluginVst3* const vst3 = stream->vst3; - DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, V3_NOT_INITIALISED); - - return V3_NOT_IMPLEMENTED; - }; - - stream.tell = []V3_API(void* self, int64_t* pos) -> v3_result - { - d_stdout("dpf_state_stream::tell => %p %p", self, pos); - dpf_state_stream* const stream = *(dpf_state_stream**)self; - DISTRHO_SAFE_ASSERT_RETURN(stream != nullptr, V3_NOT_INITIALISED); - - PluginVst3* const vst3 = stream->vst3; - DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, V3_NOT_INITIALISED); - - return V3_NOT_IMPLEMENTED; - }; - } -}; -#endif - // -------------------------------------------------------------------------------------------------------------------- // dpf_component @@ -2412,7 +2299,6 @@ struct dpf_component : v3_component_cpp { ScopedPointer<dpf_audio_processor> processor; ScopedPointer<dpf_dsp_connection_point> connection; // kConnectionPointComponent ScopedPointer<dpf_edit_controller> controller; - // ScopedPointer<dpf_state_stream> stream; ScopedPointer<PluginVst3> vst3; dpf_component(ScopedPointer<dpf_component>* const s) diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp @@ -14,12 +14,7 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "DistrhoUIInternal.hpp" - -#include <atomic> - -// TESTING awful idea dont reuse -#include "../extra/Thread.hpp" +#include "DistrhoPluginChecks.h" #if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI # undef DISTRHO_PLUGIN_HAS_UI @@ -34,9 +29,16 @@ // #undef DISTRHO_PLUGIN_HAS_UI // #define DISTRHO_PLUGIN_HAS_UI 1 -// #if DISTRHO_PLUGIN_HAS_UI -# include "DistrhoUIInternal.hpp" -// #endif +#if DISTRHO_PLUGIN_HAS_UI + +// -------------------------------------------------------------------------------------------------------------------- + +#include "DistrhoUIInternal.hpp" + +#include <atomic> + +// TESTING awful idea dont reuse +#include "../extra/Thread.hpp" #include "travesty/edit_controller.h" #include "travesty/message.h" @@ -48,12 +50,9 @@ /* TODO items: * - disable UI if non-embed UI build - * - parameter change listener - * - program change listener - * - program change sender - * - state change listener * - sample rate change listener - * - call component handler restart with params-changed flag when setting program? + * - proper send of parameter, program and state changes to UI + * - request current state of UI when created */ START_NAMESPACE_DISTRHO @@ -122,7 +121,7 @@ public: sendNoteCallback, setSizeCallback, nullptr, // TODO file request - nullptr, + nullptr, // bundlePath instancePointer, scaleFactor), fView(view), @@ -263,12 +262,52 @@ public: res = v3_cpp_obj(attrs)->get_float(attrs, "value", &value); DISTRHO_SAFE_ASSERT_INT_RETURN(res == V3_OK, res, res); - rindex -= fUI.getParameterOffset(); - DISTRHO_SAFE_ASSERT_RETURN(rindex >= 0, V3_INTERNAL_ERR); +#if DISTRHO_PLUGIN_WANT_PROGRAMS + if (rindex == 0) + { + DISTRHO_SAFE_ASSERT_RETURN(value >= 0.0, V3_INTERNAL_ERR); + + fUI.programLoaded(static_cast<uint32_t>(value + 0.5)); + } + else +#endif + { + rindex -= fUI.getParameterOffset(); + DISTRHO_SAFE_ASSERT_RETURN(rindex >= 0, V3_INTERNAL_ERR); + + fUI.parameterChanged(static_cast<uint32_t>(rindex), value); + } + + return V3_OK; + } + +#if DISTRHO_PLUGIN_WANT_STATE + if (std::strcmp(msgid, "state-set") == 0) + { + int16_t* key16; + int16_t* value16; + uint32_t keySize, valueSize; + v3_result res; + + res = v3_cpp_obj(attrs)->get_binary(attrs, "key", (const void**)&key16, &keySize); + DISTRHO_SAFE_ASSERT_INT_RETURN(res == V3_OK, res, res); + + res = v3_cpp_obj(attrs)->get_binary(attrs, "value", (const void**)&value16, &valueSize); + DISTRHO_SAFE_ASSERT_INT_RETURN(res == V3_OK, res, res); + + // do cheap inline conversion + char* const key = (char*)key16; + char* const value = (char*)value16; - fUI.parameterChanged(rindex, value); + for (uint32_t i=0; i<keySize/sizeof(int16_t); ++i) + key[i] = key16[i]; + for (uint32_t i=0; i<valueSize/sizeof(int16_t); ++i) + value[i] = value16[i]; + + fPlugin.stateChanged(key, value); return V3_OK; } +#endif d_stdout("UIVst3 received unknown msg '%s'", msgid); @@ -1257,3 +1296,7 @@ v3_plugin_view** dpf_plugin_view_create(void* const instancePointer, const doubl // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DISTRHO + +// -------------------------------------------------------------------------------------------------------------------- + +#endif // DISTRHO_PLUGIN_HAS_UI