Allow to send MIDI data directly to a plugin
authorRobin Gareus <robin@gareus.org>
Sat, 9 Sep 2017 00:23:13 +0000 (02:23 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 9 Sep 2017 01:08:46 +0000 (03:08 +0200)
libs/ardour/ardour/plugin.h
libs/ardour/ardour/plugin_insert.h
libs/ardour/plugin.cc
libs/ardour/plugin_insert.cc

index 419e33e5fa0d911b7ed1ce4d1166293cd70dd0de..52fbc71c68e75e6c14d3ea1165a854b2d1b83d2e 100644 (file)
@@ -33,6 +33,7 @@
 #include "ardour/cycles.h"
 #include "ardour/latent.h"
 #include "ardour/libardour_visibility.h"
+#include "ardour/midi_ring_buffer.h"
 #include "ardour/midi_state_tracker.h"
 #include "ardour/parameter_descriptor.h"
 #include "ardour/types.h"
@@ -159,6 +160,8 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
                return boost::shared_ptr<ScalePoints>();
        }
 
+       bool write_immediate_event (size_t size, const uint8_t* buf);
+
        void realtime_handle_transport_stopped ();
        void realtime_locate ();
        void monitoring_changed ();
@@ -379,6 +382,8 @@ private:
 
        PBD::ScopedConnection _preset_connection;
 
+       MidiRingBuffer<framepos_t> _immediate_events;
+
        void resolve_midi ();
 };
 
index f212528082d488c6b477aa119f9ad8ff45f7df26..a40cdc1bea218718073c2c6ec6243eb0b2c2d1e5 100644 (file)
@@ -77,6 +77,8 @@ class LIBARDOUR_API PluginInsert : public Processor
        bool reset_parameters_to_default ();
        bool can_reset_all_parameters ();
 
+       bool write_immediate_event (size_t size, const uint8_t* buf);
+
        int set_block_size (pframes_t nframes);
 
        ChanMapping input_map (uint32_t num) const {
index 7c312011be554b684f583324f9f6e5dc2316b020..64f00cf1c4768504335452b6d5c9178fe38c2cda 100644 (file)
@@ -101,6 +101,7 @@ Plugin::Plugin (AudioEngine& e, Session& s)
        , _have_presets (false)
        , _have_pending_stop_events (false)
        , _parameter_changed_since_last_preset (false)
+       , _immediate_events(6096) // FIXME: size?
 {
        _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
 }
@@ -116,6 +117,7 @@ Plugin::Plugin (const Plugin& other)
        , _have_presets (false)
        , _have_pending_stop_events (false)
        , _parameter_changed_since_last_preset (false)
+       , _immediate_events(6096) // FIXME: size?
 {
        _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
 }
@@ -345,16 +347,28 @@ Plugin::preset_by_uri (const string& uri)
        }
 }
 
+bool
+Plugin::write_immediate_event (size_t size, const uint8_t* buf)
+{
+       if (!Evoral::midi_event_is_valid (buf, size)) {
+               return false;
+       }
+       return (_immediate_events.write (0, Evoral::MIDI_EVENT, size, buf) == size);
+}
+
 int
 Plugin::connect_and_run (BufferSet& bufs,
                framepos_t /*start*/, framepos_t /*end*/, double /*speed*/,
                ChanMapping /*in_map*/, ChanMapping /*out_map*/,
-               pframes_t /* nframes */, framecnt_t /*offset*/)
+               pframes_t nframes, framecnt_t /*offset*/)
 {
        if (bufs.count().n_midi() > 0) {
 
-               /* Track notes that we are sending to the plugin */
+               if (_immediate_events.read_space() && nframes > 0) {
+                       _immediate_events.read (bufs.get_midi (0), 0, 1, nframes - 1, true);
+               }
 
+               /* Track notes that we are sending to the plugin */
                const MidiBuffer& b = bufs.get_midi (0);
 
                _tracker.track (b.begin(), b.end());
index 2afd18d19972fab07fc97b924b5062ecbfc559a3..ce05d6c298fc536b5da25eb9d86ab9c0f198c0b5 100644 (file)
@@ -705,6 +705,18 @@ PluginInsert::bypassable_changed ()
        BypassableChanged ();
 }
 
+bool
+PluginInsert::write_immediate_event (size_t size, const uint8_t* buf)
+{
+       bool rv = true;
+       for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
+               if (!(*i)->write_immediate_event (size, buf)) {
+                       rv = false;
+               }
+       }
+       return rv;
+}
+
 void
 PluginInsert::preset_load_set_value (uint32_t p, float v)
 {