diff options
author | David Robillard <d@drobilla.net> | 2012-03-19 20:16:46 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-03-19 20:16:46 +0000 |
commit | 254b434f0a79fea54bd963e8ff2e845a5b0cd3a6 (patch) | |
tree | ddf849fc5b64d1096846c28c1f1a742f54c3adff /src/server/internals/Trigger.cpp | |
parent | bc3afd8380d59c750c8f8e9bf1ed1b8d4a6826e9 (diff) | |
download | ingen-254b434f0a79fea54bd963e8ff2e845a5b0cd3a6.tar.gz ingen-254b434f0a79fea54bd963e8ff2e845a5b0cd3a6.tar.bz2 ingen-254b434f0a79fea54bd963e8ff2e845a5b0cd3a6.zip |
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
Diffstat (limited to 'src/server/internals/Trigger.cpp')
-rw-r--r-- | src/server/internals/Trigger.cpp | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp index 885144fe..3ccc44d7 100644 --- a/src/server/internals/Trigger.cpp +++ b/src/server/internals/Trigger.cpp @@ -19,11 +19,11 @@ #include "ingen/shared/LV2URIMap.hpp" #include "ingen/shared/URIs.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" #include "raul/log.hpp" #include "raul/midi_events.h" #include "AudioBuffer.hpp" -#include "EventBuffer.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" @@ -58,35 +58,36 @@ TriggerNode::TriggerNode( const Ingen::Shared::URIs& uris = bufs.uris(); _ports = new Raul::Array<PortImpl*>(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")); + _midi_in_port = new InputPort(bufs, this, "input", 0, 1, + 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; _note_port = new InputPort(bufs, this, "note", 1, 1, - PortType::CONTROL, bufs.forge().make(60.0f)); + PortType::CONTROL, 0, bufs.forge().make(60.0f)); _note_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); _note_port->set_property(uris.lv2_maximum, bufs.forge().make(127.0f)); _note_port->set_property(uris.lv2_integer, bufs.forge().make(true)); - _note_port->set_property(uris.lv2_name, bufs.forge().make("Note")); + _note_port->set_property(uris.lv2_name, bufs.forge().alloc("Note")); _ports->at(1) = _note_port; _gate_port = new OutputPort(bufs, this, "gate", 2, 1, - 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(2) = _gate_port; _trig_port = new OutputPort(bufs, this, "trigger", 3, 1, - 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(3) = _trig_port; _vel_port = new OutputPort(bufs, this, "velocity", 4, 1, - 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(4) = _vel_port; } @@ -95,40 +96,35 @@ TriggerNode::process(ProcessContext& context) { NodeImpl::pre_process(context); - uint32_t frames = 0; - uint32_t subframes = 0; - uint16_t type = 0; - uint16_t size = 0; - uint8_t* buf = NULL; - - EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0).get(); - - midi_in->rewind(); - - while (midi_in->get_event(&frames, &subframes, &type, &size, &buf)) { - 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); + if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && + ev->body.size >= 3) { + const FrameTime time = context.start() + ev->time.frames; 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); break; case MIDI_CMD_CONTROL: - if (buf[1] == MIDI_CTL_ALL_NOTES_OFF - || buf[1] == MIDI_CTL_ALL_SOUNDS_OFF) - ((AudioBuffer*)_gate_port->buffer(0).get())->set_value(0.0f, context.start(), time); + if (buf[1] == MIDI_CTL_ALL_NOTES_OFF || + buf[1] == MIDI_CTL_ALL_SOUNDS_OFF) { + ((AudioBuffer*)_gate_port->buffer(0).get())->set_value( + 0.0f, context.start(), time); + } default: break; } } - - midi_in->increment(); } NodeImpl::post_process(context); |