From 6eec851cda92e1030173dbfd613c44883ced6816 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 9 Apr 2007 01:01:50 +0000 Subject: MIDI patching. wooo! git-svn-id: http://svn.drobilla.net/lad/ingen@429 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/LV2Node.cpp | 13 +++++++++---- src/libs/engine/MidiBuffer.cpp | 20 ++++++++++++++++++-- src/libs/engine/MidiBuffer.h | 23 ++++++----------------- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'src/libs') diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp index 4ea29d1f..459d3c78 100644 --- a/src/libs/engine/LV2Node.cpp +++ b/src/libs/engine/LV2Node.cpp @@ -93,7 +93,9 @@ LV2Node::instantiate() SLV2PortClass port_class = slv2_port_get_class(_lv2_plugin, id); - if (port_class == SLV2_AUDIO_INPUT || port_class == SLV2_AUDIO_OUTPUT) + // FIXME: MIDI buffer size? + if (port_class == SLV2_AUDIO_INPUT || port_class == SLV2_AUDIO_OUTPUT + || port_class == SLV2_MIDI_INPUT || port_class == SLV2_MIDI_OUTPUT) port_buffer_size = _buffer_size; else port_buffer_size = 1; @@ -184,10 +186,13 @@ LV2Node::set_port_buffer(size_t voice, size_t port_num, Buffer* buf) { assert(voice < _poly); - if (buf->type() == DataType::FLOAT) + if (buf->type() == DataType::FLOAT) { slv2_instance_connect_port(_instances[voice], port_num, ((AudioBuffer*)buf)->data()); - else if (buf->type() == DataType::MIDI) - slv2_instance_connect_port(_instances[voice], port_num, ((MidiBuffer*)buf)->data()->midi); + } else if (buf->type() == DataType::MIDI) { + cerr << "Connecting " << path() << ":" << port_num << " -> " << + ((MidiBuffer*)buf)->data() << endl; + slv2_instance_connect_port(_instances[voice], port_num, ((MidiBuffer*)buf)->data()); + } } diff --git a/src/libs/engine/MidiBuffer.cpp b/src/libs/engine/MidiBuffer.cpp index 3dcb7b4c..9842b28c 100644 --- a/src/libs/engine/MidiBuffer.cpp +++ b/src/libs/engine/MidiBuffer.cpp @@ -15,13 +15,29 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -//#include +#include #include "MidiBuffer.h" using namespace std; namespace Ingen { +MidiBuffer::MidiBuffer(size_t capacity) + : Buffer(DataType(DataType::MIDI), capacity) + , _buf(lv2midi_new((uint32_t)capacity)) + , _joined_buf(NULL) +{ + _local_state.midi = _buf; + _state = &_local_state; + assert(_local_state.midi); + reset(0); + clear(); + assert(_local_state.midi == _buf); + + cerr << "Creating MIDI Buffer " << _buf << ", capacity = " << _buf->capacity << endl; +} + + /** Use another buffer's data instead of the local one. * @@ -38,7 +54,7 @@ MidiBuffer::join(Buffer* buf) _joined_buf = mbuf; - _state = mbuf->data(); + _state = mbuf->_state; return true; } diff --git a/src/libs/engine/MidiBuffer.h b/src/libs/engine/MidiBuffer.h index 79f7098b..54a245df 100644 --- a/src/libs/engine/MidiBuffer.h +++ b/src/libs/engine/MidiBuffer.h @@ -27,19 +27,8 @@ namespace Ingen { class MidiBuffer : public Buffer { public: - MidiBuffer(size_t capacity) - : Buffer(DataType(DataType::MIDI), capacity) - , _buf(lv2midi_new((uint32_t)capacity)) - , _joined_buf(NULL) - { - _local_state.midi = _buf; - _state = &_local_state; - assert(_local_state.midi); - reset(0); - clear(); - assert(_local_state.midi == _buf); - } - + MidiBuffer(size_t capacity); + ~MidiBuffer() { lv2midi_free(_local_state.midi); } void prepare_read(SampleCount nframes); @@ -51,11 +40,11 @@ public: uint32_t this_nframes() const { return _this_nframes; } - inline LV2_MIDIState* data() - { return ((_joined_buf != NULL) ? _joined_buf->data() : _state); } + inline LV2_MIDI* data() + { return ((_joined_buf != NULL) ? _joined_buf->data() : _state->midi); } - inline const LV2_MIDIState* data() const - { return ((_joined_buf != NULL) ? _joined_buf->data() : _state); } + inline const LV2_MIDI* data() const + { return ((_joined_buf != NULL) ? _joined_buf->data() : _state->midi); } inline void clear() { assert(_state); assert(_state->midi); lv2midi_reset_buffer(_state->midi); _state->position = 0; } -- cgit v1.2.1