summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-10-30 17:37:50 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2018-10-30 17:37:50 +0100
commit75b19928e264ed5a58077498fd61f71e99dc400d (patch)
treed03c7d8239074566b8b30c95c8b02772bf875da7
parentdfe71a21e5a190e5228964265c62416779454bec (diff)
Add interface to set midnam data from the outside
-rw-r--r--plugin.h3
-rw-r--r--pluginlv2.cc55
-rw-r--r--pluginlv2.h13
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<std::pair<int, std::string>>& 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 <iostream>
#include <sstream>
#include <assert.h>
@@ -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<std::pair<int, std::string>>& 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)
"<MIDINameDocument>\n"
" <Author/>\n"
" <MasterDeviceNames>\n"
- " <Manufacturer>The Drum Gizmo Foundation</Manufacturer>\n"
- " <Model>Drumgizmo:" << ((const void *) instance) << "</Model>\n"; //<< needs to match MidnamModel()
+ " <Manufacturer>" << plugin_lv2->getVendorString() << "</Manufacturer>\n"
+ " <Model>" << plugin_lv2->getProductString() << ":" << ((const void *) instance) << "</Model>\n"; //<< needs to match MidnamModel()
ss << " <CustomDeviceMode Name=\"Default\">\n";
ss << " <ChannelNameSetAssignments>\n";
@@ -523,11 +538,17 @@ char* PluginLV2::MidnamFile (LV2_Handle instance)
" </PatchBank>\n"
" </ChannelNameSet>\n"
" <NoteNameList Name=\"Notes\">\n";
-
- // XXX TODO ask plugin_lv2, iterate over mapped samples
- ss << " <Note Number=\"36\" Name=\"KickDrum\"/>\n";
- ss << " <Note Number=\"38\" Name=\"Snare\"/>\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 << " <Note Number=\"" << m.first << "\" Name=\""<< m.second << "\"/>\n";
+ }
ss <<
" </NoteNameList>\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 <plugin.h>
+#include <array>
+
#include <lv2/lv2plug.in/ns/lv2core/lv2.h>
#include <lv2/lv2plug.in/ns/ext/urid/urid.h>
#include <lv2/lv2plug.in/ns/ext/state/state.h>
@@ -36,13 +38,13 @@
#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
#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<std::pair<int, std::string>>& 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<std::pair<int, std::string>, 127> midnamData;
+ volatile bool midnam_changed{false};
bool active{false};