Forward midi feedback from LV2 plugins and allow to chain LV2 midi plugins.

This commit is contained in:
Robin Gareus 2013-05-19 17:19:01 +02:00
parent 1acf8bdc67
commit db39613238
3 changed files with 44 additions and 2 deletions

View File

@ -122,6 +122,9 @@ public:
/** Flush modified LV2 event output buffers back to Ardour buffers */
void flush_lv2_midi(bool input, size_t i);
/** Forward plugin MIDI output to to Ardour buffers */
void forward_lv2_midi(LV2_Evbuf*, size_t, bool purge_ardour_buffer = true);
#endif
#if defined VST_SUPPORT || defined LXVST_SUPPORT

View File

@ -265,6 +265,25 @@ BufferSet::get_lv2_midi(bool input, size_t i, bool old_api)
return evbuf;
}
void
BufferSet::forward_lv2_midi(LV2_Evbuf* buf, size_t i, bool purge_ardour_buffer)
{
MidiBuffer& mbuf = get_midi(i);
if (purge_ardour_buffer) {
mbuf.silence(0, 0);
}
for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(buf);
lv2_evbuf_is_valid(i);
i = lv2_evbuf_next(i)) {
uint32_t frames, subframes, type, size;
uint8_t* data;
lv2_evbuf_get(i, &frames, &subframes, &type, &size, &data);
if (type == LV2Plugin::urids.midi_MidiEvent) {
mbuf.push_back(frames, size, data);
}
}
}
void
BufferSet::flush_lv2_midi(bool input, size_t i)
{

View File

@ -1640,8 +1640,28 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
PortFlags flags = _port_flags[port_index];
bool valid = false;
// Flush MIDI (write back to Ardour MIDI buffers)
if ((flags & PORT_OUTPUT) && (flags & (PORT_EVENT|PORT_SEQUENCE))) {
/* TODO ask drobilla about comment
* "Make Ardour event buffers generic so plugins can communicate"
* in libs/ardour/buffer_set.cc:310
*
* ideally the user could choose which of the following two modes
* to use (e.g. instrument/effect chains MIDI OUT vs MIDI TRHU).
*
* This implementation follows the discussion on IRC Mar 16 2013 16:47 UTC
* 16:51 < drobilla> rgareus: [..] i.e always replace with MIDI output [of LV2 plugin] if it's there
* 16:52 < drobilla> rgareus: That would probably be good enough [..] to make users not complain
* for quite a while at least ;)
*/
// copy output of LV2 plugin's MIDI port to Ardour MIDI buffers -- MIDI OUT
if ((flags & PORT_OUTPUT) && (flags & (PORT_EVENT|PORT_SEQUENCE|PORT_MIDI))) {
const uint32_t buf_index = out_map.get(
DataType::MIDI, midi_out_index++, &valid);
if (valid) {
bufs.forward_lv2_midi(_ev_buffers[port_index], buf_index);
}
}
// Flush MIDI (write back to Ardour MIDI buffers) -- MIDI THRU
else if ((flags & PORT_OUTPUT) && (flags & (PORT_EVENT|PORT_SEQUENCE))) {
const uint32_t buf_index = out_map.get(
DataType::MIDI, midi_out_index++, &valid);
if (valid) {