From 254b434f0a79fea54bd963e8ff2e845a5b0cd3a6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Mar 2012 20:16:46 +0000 Subject: Partially functioning communication between Ingen LV2 plugin and UI. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4078 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/internals/Note.cpp | 75 +++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'src/server/internals/Note.cpp') diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp index a44c0c36..e591bfd8 100644 --- a/src/server/internals/Note.cpp +++ b/src/server/internals/Note.cpp @@ -19,22 +19,22 @@ #include "ingen/shared/LV2URIMap.hpp" #include "ingen/shared/URIs.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" #include "raul/Array.hpp" #include "raul/Maid.hpp" #include "raul/log.hpp" #include "raul/midi_events.h" -#include "internals/Note.hpp" #include "AudioBuffer.hpp" #include "Driver.hpp" -#include "EventBuffer.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" #include "PatchImpl.hpp" #include "ProcessContext.hpp" -#include "util.hpp" #include "ingen_config.h" +#include "internals/Note.hpp" +#include "util.hpp" #define LOG(s) s << "[NoteNode] " @@ -65,32 +65,32 @@ NoteNode::NoteNode( _ports = new Raul::Array(5); _midi_in_port = new InputPort(bufs, this, "input", 0, 1, - PortType::EVENTS, Raul::Atom()); - _midi_in_port->set_property(uris.lv2_name, bufs.forge().make("Input")); + PortType::MESSAGE, uris.atom_Sequence, Raul::Atom()); + _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); _ports->at(0) = _midi_in_port; _freq_port = new OutputPort(bufs, this, "frequency", 1, _polyphony, - PortType::AUDIO, bufs.forge().make(440.0f)); - _freq_port->set_property(uris.lv2_name, bufs.forge().make("Frequency")); + PortType::AUDIO, 0, bufs.forge().make(440.0f)); + _freq_port->set_property(uris.lv2_name, bufs.forge().alloc("Frequency")); _ports->at(1) = _freq_port; _vel_port = new OutputPort(bufs, this, "velocity", 2, _polyphony, - PortType::AUDIO, bufs.forge().make(0.0f)); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); _vel_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); _vel_port->set_property(uris.lv2_maximum, bufs.forge().make(1.0f)); - _vel_port->set_property(uris.lv2_name, bufs.forge().make("Velocity")); + _vel_port->set_property(uris.lv2_name, bufs.forge().alloc("Velocity")); _ports->at(2) = _vel_port; _gate_port = new OutputPort(bufs, this, "gate", 3, _polyphony, - PortType::AUDIO, bufs.forge().make(0.0f)); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); _gate_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); - _gate_port->set_property(uris.lv2_name, bufs.forge().make("Gate")); + _gate_port->set_property(uris.lv2_name, bufs.forge().alloc("Gate")); _ports->at(3) = _gate_port; _trig_port = new OutputPort(bufs, this, "trigger", 4, _polyphony, - PortType::AUDIO, bufs.forge().make(0.0f)); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); _trig_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); - _trig_port->set_property(uris.lv2_name, bufs.forge().make("Trigger")); + _trig_port->set_property(uris.lv2_name, bufs.forge().alloc("Trigger")); _ports->at(4) = _trig_port; } @@ -135,42 +135,24 @@ NoteNode::apply_poly(Raul::Maid& maid, uint32_t poly) void NoteNode::process(ProcessContext& context) { - EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0).get(); NodeImpl::pre_process(context); - - uint32_t frames = 0; - uint32_t subframes = 0; - uint16_t type = 0; - uint16_t size = 0; - uint8_t* buf = NULL; - - midi_in->rewind(); - - if (midi_in->event_count() > 0) - for (midi_in->rewind(); midi_in->get_event(&frames, &subframes, &type, &size, &buf); - midi_in->increment()) { - -#ifdef RAUL_LOG_DEBUG - LOG(debug) << "EVENT TYPE " << type << " @ " << frames << "." << subframes << ": "; - for (uint16_t i = 0; i < size; ++i) - debug << (int)((char)buf[i]) << " "; - debug << endl; -#endif - - if (frames < context.offset()) - continue; - if (frames > context.nframes()) - break; - - const FrameTime time = context.start() + (FrameTime)frames; - - if (size >= 3) { + + Buffer* const midi_in = _midi_in_port->buffer(0).get(); + LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)midi_in->atom(); + LV2_SEQUENCE_FOREACH(seq, i) { + LV2_Atom_Event* const ev = lv2_sequence_iter_get(i); + const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const FrameTime time = context.start() + (FrameTime)ev->time.frames; + + if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && + ev->body.size >= 3) { switch (buf[0] & 0xF0) { case MIDI_CMD_NOTE_ON: - if (buf[2] == 0) + if (buf[2] == 0) { note_off(context, buf[1], time); - else + } else { note_on(context, buf[1], buf[2], time); + } break; case MIDI_CMD_NOTE_OFF: note_off(context, buf[1], time); @@ -182,10 +164,11 @@ NoteNode::process(ProcessContext& context) all_notes_off(context, time); break; case MIDI_CTL_SUSTAIN: - if (buf[2] > 63) + if (buf[2] > 63) { sustain_on(context, time); - else + } else { sustain_off(context, time); + } break; case MIDI_CMD_BENDER: // ? -- cgit v1.2.1