[SCM] calf/master: + LV2: implementation of MIDI Input in Monosynth and Organ

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:37:00 UTC 2013


The following commit has been merged in the master branch:
commit ded705b30cd03e77896e09dabf9ed96ef2b2331c
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Tue Jan 15 22:44:40 2008 +0000

    + LV2: implementation of MIDI Input in Monosynth and Organ
    
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@104 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/giface.h b/src/calf/giface.h
index 0c6c1e8..63f37f6 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -161,7 +161,7 @@ struct giface_plugin_info
 {
     ladspa_info *info;
     int inputs, outputs, params;
-    bool rt_capable, midi_capable;
+    bool rt_capable, midi_in_capable;
     parameter_properties *param_props;
 };
 
diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index f89bf9a..ca25f84 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -3,6 +3,7 @@
 #include <string>
 #include <lv2.h>
 #include <calf/giface.h>
+#include <calf/lv2-midiport.h>
 
 namespace synth {
 
@@ -11,6 +12,7 @@ struct lv2_instance: public Module, public plugin_ctl_iface
 {
     bool set_srate;
     int srate_to_set;
+    LV2_MIDI *midi_data;
     lv2_instance()
     {
         for (int i=0; i < Module::in_count; i++)
@@ -19,6 +21,7 @@ struct lv2_instance: public Module, public plugin_ctl_iface
             Module::outs[i] = NULL;
         for (int i=0; i < Module::param_count; i++)
             Module::params[i] = NULL;
+        midi_data = NULL;
         set_srate = true;
         srate_to_set = 44100;
     }
@@ -87,6 +90,9 @@ struct lv2_wrapper
             int i = port - ins - outs;
             mod->params[i] = (float *)DataLocation;
         }
+        else if (Module::support_midi && port == ins + outs + params) {
+            mod->midi_data = (LV2_MIDI *)DataLocation;
+        }
     }
 
     static void cb_activate(LV2_Handle Instance) {
@@ -133,7 +139,36 @@ struct lv2_wrapper
             mod->set_srate = false;
         }
         mod->params_changed();
-        process_slice(mod, 0, SampleCount);
+        uint32_t offset = 0;
+        if (mod->midi_data)
+        {
+            struct MIDI_ITEM {
+                double timestamp;
+                uint32_t size;
+                unsigned char data[1];
+            };
+            unsigned char *data = (unsigned char *)mod->midi_data->data;
+            for (uint32_t i = 0; i < mod->midi_data->event_count; i++) {
+                MIDI_ITEM *item = (MIDI_ITEM *)data;
+                uint32_t ts = (int)item->timestamp;
+                if (ts > offset)
+                {
+                    process_slice(mod, offset, ts);
+                    offset = ts;
+                }
+                switch(item->data[0] >> 4)
+                {
+                case 8: mod->note_off(item->data[1], item->data[2]); break;
+                case 9: mod->note_on(item->data[1], item->data[2]); break;
+                case 10: mod->program_change(item->data[1]); break;
+                case 11: mod->control_change(item->data[1], item->data[2]); break;
+                case 14: mod->pitch_bend(item->data[1] + 128 * item->data[2] - 8192); break;
+                }
+                // printf("timestamp %f item size %d first byte %x\n", item->timestamp, item->size, item->data[0]);
+                data += 12 + item->size;
+            }
+        }
+        process_slice(mod, offset, SampleCount);
     }
     static void cb_cleanup(LV2_Handle Instance) {
         instance *const mod = (instance *)Instance;
diff --git a/src/makerdf.cpp b/src/makerdf.cpp
index 1e0d7eb..5bd788a 100644
--- a/src/makerdf.cpp
+++ b/src/makerdf.cpp
@@ -55,7 +55,7 @@ void make_rdf()
     printf("%s\n", rdf.c_str());
 }
 
-static void add_port(string &ports, const char *symbol, const char *name, const char *direction, int pidx)
+static void add_port(string &ports, const char *symbol, const char *name, const char *direction, int pidx, const char *type = "lv2:AudioPort")
 {
     stringstream ss;
     const char *ind = "        ";
@@ -64,7 +64,7 @@ static void add_port(string &ports, const char *symbol, const char *name, const
     if (ports != "") ports += " , ";
     ss << "[\n";
     if (direction) ss << ind << "a lv2:" << direction << "Port ;\n";
-    ss << ind << "a lv2:AudioPort ;\n";
+    ss << ind << "a " << type << " ;\n";
     ss << ind << "lv2:index " << pidx << " ;\n";
     ss << ind << "lv2:symbol \"" << symbol << "\" ;\n";
     ss << ind << "lv2:name \"" << name << "\" ;\n";
@@ -111,6 +111,7 @@ void make_ttl()
         "@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .\n"
         "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
         "@prefix doap: <http://usefulinc.com/ns/doap#> .\n"
+        "@prefix midiext: <http://ll-plugins.nongnu.org/lv2/ext/MidiPort> .\n"
         "@prefix guiext: <http://ll-plugins.nongnu.org/lv2/ext/gui#> .\n"
         "\n"
     ;
@@ -173,6 +174,8 @@ void make_ttl()
             add_port(ports, out_names[i], out_names[i], "Output", pn++);
         for (int i = 0; i < pi.params; i++)
             add_ctl_port(ports, pi.param_props[i], pn++);
+        if (pi.midi_in_capable)
+            add_port(ports, "midi_in", "MIDI", "Input", pn++, "<http://ll-plugins.nongnu.org/lv2/ext/MidiPort>");
         if (!ports.empty())
             ttl += "    lv2:port " + ports + "\n";
         ttl += ".\n\n";
diff --git a/src/modules.cpp b/src/modules.cpp
index d2d2098..9f21b77 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -240,7 +240,7 @@ giface_plugin_info create_plugin_info(ladspa_info &info)
     pi.outputs = Module::out_count;
     pi.params = Module::param_count;
     pi.rt_capable = Module::rt_capable;
-    pi.midi_capable = Module::support_midi;
+    pi.midi_in_capable = Module::support_midi;
     pi.param_props = Module::param_props;
     return pi;
 }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list