From 75b19928e264ed5a58077498fd61f71e99dc400d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 30 Oct 2018 17:37:50 +0100 Subject: Add interface to set midnam data from the outside --- plugin.h | 3 +++ pluginlv2.cc | 55 +++++++++++++++++++++++++++++++++++++++---------------- pluginlv2.h | 13 ++++++++++--- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/plugin.h b/plugin.h index f541255..e1d8d69 100644 --- a/plugin.h +++ b/plugin.h @@ -120,6 +120,9 @@ public: virtual std::size_t getNumberOfAudioOutputs() = 0; + //! Call this method to set midnam data for midi input + virtual void setMidnamData(const std::vector>& midnam) {} + //! Get unique plugin id. virtual std::string getId() = 0; diff --git a/pluginlv2.cc b/pluginlv2.cc index fd0bfbf..46ef83b 100644 --- a/pluginlv2.cc +++ b/pluginlv2.cc @@ -26,7 +26,6 @@ */ #include "pluginlv2.h" -#include #include #include @@ -122,7 +121,7 @@ LV2_Handle PluginLV2::instantiate(const struct _LV2_Descriptor* descriptor, } #endif -#ifdef DISPLAY_INTERFACE +#ifdef MIDNAM_INTERFACE if(uri == LV2_MIDNAM__update) { plugin_lv2->midnam = (LV2_Midnam*)data; @@ -363,10 +362,11 @@ void PluginLV2::run(LV2_Handle instance, uint32_t sample_count) plugin_lv2->pos += sample_count; -#ifdef MIDNAME_INTERFACE - if (0) // XXX drumkit changed +#ifdef MIDNAM_INTERFACE + if(plugin_lv2->midnam_changed) { - plugin_lv2->midnam->update (plugin_lv2->midnam->handle); + plugin_lv2->midnam->update(plugin_lv2->midnam->handle); + plugin_lv2->midnam_changed = false; } #endif @@ -485,7 +485,22 @@ LV2_Inline_Display_Image_Surface* PluginLV2::inlineRender(LV2_Handle instance, return &plugin_lv2->surf; } -#ifdef MIDNAME_INTERFACE +void PluginLV2::setMidnamData(const std::vector>& midnam) +{ + auto idx = 0u; + for(const auto& m : midnam) + { + this->midnamData[idx] = m; + idx++; + } + for(;idx < this->midnamData.size(); ++idx) + { + this->midnamData[idx] = {-1, {}}; + } + midnam_changed = true; +} + +#ifdef MIDNAM_INTERFACE char* PluginLV2::MidnamFile (LV2_Handle instance) { PluginLV2* plugin_lv2 = (PluginLV2*)instance; @@ -496,8 +511,8 @@ char* PluginLV2::MidnamFile (LV2_Handle instance) "\n" " \n" " \n" - " The Drum Gizmo Foundation\n" - " Drumgizmo:" << ((const void *) instance) << "\n"; //<< needs to match MidnamModel() + " " << plugin_lv2->getVendorString() << "\n" + " " << plugin_lv2->getProductString() << ":" << ((const void *) instance) << "\n"; //<< needs to match MidnamModel() ss << " \n"; ss << " \n"; @@ -523,11 +538,17 @@ char* PluginLV2::MidnamFile (LV2_Handle instance) " \n" " \n" " \n"; - - // XXX TODO ask plugin_lv2, iterate over mapped samples - ss << " \n"; - ss << " \n"; - // XXX + // TODO: Fill in empty slots for the notes that are not in the map + // Does Ardour preserve the note names for the unspecified notes? + // ... and is this a bug?? + for(const auto& m : plugin_lv2->midnamData) + { + if(m.first == -1) + { + continue; + } + ss << " \n"; + } ss << " \n" @@ -537,10 +558,12 @@ char* PluginLV2::MidnamFile (LV2_Handle instance) return strdup (ss.str().c_str()); } -char* PluginLV2::MidnamModel (LV2_Handle instance) +char* PluginLV2::MidnamModel(LV2_Handle instance) { + PluginLV2* plugin_lv2 = (PluginLV2*)instance; char* rv = (char*) malloc (64 * sizeof (char)); - snprintf (rv, 64, "Drumgizmo:%p", (void*) instance); + snprintf(rv, 64, "%s:%p", + plugin_lv2->getProductString().data(), (void*) instance); rv[63] = 0; return rv; } @@ -566,7 +589,7 @@ const void* PluginLV2::extensionData(const char *uri) } #endif -#ifdef MIDNAME_INTERFACE +#ifdef MIDNAM_INTERFACE static const LV2_Midnam_Interface midnam = { MidnamFile, MidnamModel, MidnamFree }; if (!strcmp (uri, LV2_MIDNAM__interface)) { diff --git a/pluginlv2.h b/pluginlv2.h index 10f816e..43563cc 100644 --- a/pluginlv2.h +++ b/pluginlv2.h @@ -28,6 +28,8 @@ #include +#include + #include #include #include @@ -36,13 +38,13 @@ #include #define DISPLAY_INTERFACE -#define MIDNAME_INTERFACE +#define MIDNAM_INTERFACE #ifdef DISPLAY_INTERFACE #include "inline-display.h" #endif -#ifdef MIDNAME_INTERFACE +#ifdef MIDNAM_INTERFACE #include "midnam_lv2.h" #endif @@ -119,6 +121,8 @@ public: //! This must remain constant during the lifespan of the plugin instance. virtual std::size_t getNumberOfMidiOutputs() override = 0; + //! Call this method to set midnam data for midi input + virtual void setMidnamData(const std::vector>& midnam) override; //! Get unique plugin id. std::string getId() override = 0; @@ -261,12 +265,15 @@ private: uint32_t max_h); #endif -#ifdef MIDNAME_INTERFACE +#ifdef MIDNAM_INTERFACE LV2_Midnam* midnam{nullptr}; static char* MidnamFile (LV2_Handle instance); static char* MidnamModel (LV2_Handle instance); static void MidnamFree (char*); #endif + // TODO:: Make this list thread safe! + std::array, 127> midnamData; + volatile bool midnam_changed{false}; bool active{false}; -- cgit v1.2.3