implement VST midi-output
authorRobin Gareus <robin@gareus.org>
Sun, 2 Mar 2014 20:12:25 +0000 (21:12 +0100)
committerRobin Gareus <robin@gareus.org>
Sun, 2 Mar 2014 20:18:52 +0000 (21:18 +0100)
libs/ardour/ardour/vst_plugin.h
libs/ardour/session_vst.cc
libs/ardour/vst_plugin.cc

index 942f7192db196bb2863534ea3b564092c9bc0fcb..3450e2a480d22fc0b938590380574feb459865fe 100644 (file)
@@ -73,6 +73,7 @@ public:
        
        AEffect * plugin () const { return _plugin; }
        VSTState * state () const { return _state; }
+       MidiBuffer * midi_buffer () const { return _midi_out_buf; }
 
        int set_state (XMLNode const &, int);
 
@@ -94,6 +95,8 @@ protected:
        VSTHandle* _handle;
        VSTState*  _state;
        AEffect*   _plugin;
+
+       MidiBuffer* _midi_out_buf;
 };
 
 }
index b279f520157187030d85f026062337720fe2b4c9..845293de7caf084c2284b16111cb67736173438f 100644 (file)
@@ -49,6 +49,8 @@ int Session::vst_current_loading_id = 0;
 const char* Session::vst_can_do_strings[] = {
        X_("supplyIdle"),
        X_("sendVstTimeInfo"),
+       X_("sendVstEvents"),
+       X_("sendVstMidiEvent"),
        X_("supportShell"),
        X_("shellCategory")
 };
@@ -256,6 +258,15 @@ intptr_t Session::vst_callback (
        case audioMasterProcessEvents:
                SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
                // VstEvents* in <ptr>
+               if (plug->midi_buffer()) {
+                       VstEvents* v = (VstEvents*)ptr;
+                       for (int n = 0 ; n < v->numEvents; ++n) {
+                               VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
+                               if (vme->type == kVstMidiType) {
+                                       plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData);
+                               }
+                       }
+               }
                return 0;
 
        case audioMasterSetTime:
index 23383496bf2e5210fec89bb18807518942864c56..3ea103a7b79b70b81390761d0b115daf63439607 100644 (file)
@@ -552,6 +552,7 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
        ChanCount bufs_count;
        bufs_count.set(DataType::AUDIO, 1);
        bufs_count.set(DataType::MIDI, 1);
+       _midi_out_buf = 0;
 
        BufferSet& silent_bufs  = _session.get_silent_buffers(bufs_count);
        BufferSet& scratch_bufs = _session.get_scratch_buffers(bufs_count);
@@ -590,12 +591,28 @@ VSTPlugin::connect_and_run (BufferSet& bufs,
        }
 
        if (bufs.count().n_midi() > 0) {
-               VstEvents* v = bufs.get_vst_midi (0);
-               _plugin->dispatcher (_plugin, effProcessEvents, 0, 0, v, 0);
+               VstEvents* v = 0;
+               bool valid = false;
+               const uint32_t buf_index_in = in_map.get(DataType::MIDI, 0, &valid);
+               if (valid) {
+                       v = bufs.get_vst_midi (0);
+               }
+               valid = false;
+               const uint32_t buf_index_out = out_map.get(DataType::MIDI, 0, &valid);
+               if (valid) {
+                       _midi_out_buf = &bufs.get_midi(buf_index_out);
+                       _midi_out_buf->silence(0, 0);
+               } else {
+                       _midi_out_buf = 0;
+               }
+               if (v) {
+                       _plugin->dispatcher (_plugin, effProcessEvents, 0, 0, v, 0);
+               }
        }
 
        /* we already know it can support processReplacing */
        _plugin->processReplacing (_plugin, &ins[0], &outs[0], nframes);
+       _midi_out_buf = 0;
 
        return 0;
 }