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 | |
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')
-rw-r--r-- | src/server/internals/Controller.cpp | 52 | ||||
-rw-r--r-- | src/server/internals/Controller.hpp | 3 | ||||
-rw-r--r-- | src/server/internals/Delay.cpp | 13 | ||||
-rw-r--r-- | src/server/internals/Note.cpp | 75 | ||||
-rw-r--r-- | src/server/internals/Trigger.cpp | 60 |
5 files changed, 87 insertions, 116 deletions
diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp index e93d5f27..3c29edd3 100644 --- a/src/server/internals/Controller.cpp +++ b/src/server/internals/Controller.cpp @@ -20,10 +20,10 @@ #include "ingen/shared/LV2URIMap.hpp" #include "ingen/shared/URIs.hpp" #include "internals/Controller.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" #include "raul/midi_events.h" #include "AudioBuffer.hpp" -#include "EventBuffer.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "Notification.hpp" @@ -54,37 +54,38 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, const Ingen::Shared::URIs& uris = bufs.uris(); _ports = new Raul::Array<PortImpl*>(6); - _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; _param_port = new InputPort(bufs, this, "controller", 1, 1, - PortType::CONTROL, bufs.forge().make(0.0f)); + PortType::CONTROL, 0, bufs.forge().make(0.0f)); _param_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); _param_port->set_property(uris.lv2_maximum, bufs.forge().make(127.0f)); _param_port->set_property(uris.lv2_integer, bufs.forge().make(true)); - _param_port->set_property(uris.lv2_name, bufs.forge().make("Controller")); + _param_port->set_property(uris.lv2_name, bufs.forge().alloc("Controller")); _ports->at(1) = _param_port; _log_port = new InputPort(bufs, this, "logarithmic", 2, 1, - PortType::CONTROL, bufs.forge().make(0.0f)); + PortType::CONTROL, 0, bufs.forge().make(0.0f)); _log_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); - _log_port->set_property(uris.lv2_name, bufs.forge().make("Logarithmic")); + _log_port->set_property(uris.lv2_name, bufs.forge().alloc("Logarithmic")); _ports->at(2) = _log_port; _min_port = new InputPort(bufs, this, "minimum", 3, 1, - PortType::CONTROL, bufs.forge().make(0.0f)); - _min_port->set_property(uris.lv2_name, bufs.forge().make("Minimum")); + PortType::CONTROL, 0, bufs.forge().make(0.0f)); + _min_port->set_property(uris.lv2_name, bufs.forge().alloc("Minimum")); _ports->at(3) = _min_port; _max_port = new InputPort(bufs, this, "maximum", 4, 1, - PortType::CONTROL, bufs.forge().make(1.0f)); - _max_port->set_property(uris.lv2_name, bufs.forge().make("Maximum")); + PortType::CONTROL, 0, bufs.forge().make(1.0f)); + _max_port->set_property(uris.lv2_name, bufs.forge().alloc("Maximum")); _ports->at(4) = _max_port; _audio_port = new OutputPort(bufs, this, "ar_output", 5, 1, - PortType::AUDIO, bufs.forge().make(0.0f)); - _audio_port->set_property(uris.lv2_name, bufs.forge().make("Output")); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); + _audio_port->set_property(uris.lv2_name, bufs.forge().alloc("Output")); _ports->at(5) = _audio_port; } @@ -93,22 +94,15 @@ ControllerNode::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)) { - // FIXME: type - if (size >= 3 && (buf[0] & 0xF0) == MIDI_CMD_CONTROL) - control(context, buf[1], buf[2], frames + context.start()); - - midi_in->increment(); + 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 && (buf[0] & 0xF0) == MIDI_CMD_CONTROL) { + control(context, buf[1], buf[2], ev->time.frames + context.start()); + } } NodeImpl::post_process(context); diff --git a/src/server/internals/Controller.hpp b/src/server/internals/Controller.hpp index d664bf55..ac412c10 100644 --- a/src/server/internals/Controller.hpp +++ b/src/server/internals/Controller.hpp @@ -57,14 +57,13 @@ public: static InternalPlugin* internal_plugin(Shared::URIs& uris); private: - bool _learning; - InputPort* _midi_in_port; InputPort* _param_port; InputPort* _log_port; InputPort* _min_port; InputPort* _max_port; OutputPort* _audio_port; + bool _learning; }; } // namespace Server diff --git a/src/server/internals/Delay.cpp b/src/server/internals/Delay.cpp index 21cc23d5..dc55355e 100644 --- a/src/server/internals/Delay.cpp +++ b/src/server/internals/Delay.cpp @@ -28,7 +28,6 @@ #include "internals/Delay.hpp" #include "AudioBuffer.hpp" #include "Driver.hpp" -#include "EventBuffer.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" @@ -75,22 +74,22 @@ DelayNode::DelayNode( _delay_samples = default_delay; _delay_port = new InputPort(bufs, this, "delay", 1, _polyphony, - PortType::CONTROL, bufs.forge().make(default_delay)); - _delay_port->set_property(uris.lv2_name, bufs.forge().make("Delay")); + PortType::CONTROL, 0, bufs.forge().make(default_delay)); + _delay_port->set_property(uris.lv2_name, bufs.forge().alloc("Delay")); _delay_port->set_property(uris.lv2_default, bufs.forge().make(default_delay)); _delay_port->set_property(uris.lv2_minimum, bufs.forge().make((float)(1.0/(double)srate))); _delay_port->set_property(uris.lv2_maximum, bufs.forge().make(MAX_DELAY_SECONDS)); _ports->at(0) = _delay_port; _in_port = new InputPort(bufs, this, "in", 0, 1, - PortType::AUDIO, bufs.forge().make(0.0f)); - _in_port->set_property(uris.lv2_name, bufs.forge().make("Input")); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); + _in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); _ports->at(1) = _in_port; _out_port = new OutputPort(bufs, this, "out", 0, 1, - PortType::AUDIO, bufs.forge().make(0.0f)); + PortType::AUDIO, 0, bufs.forge().make(0.0f)); _out_port->set_property(uris.lv2_name, - bufs.forge().make("Output")); + bufs.forge().alloc("Output")); _ports->at(2) = _out_port; //_buffer = bufs.get(PortType::AUDIO, bufs.audio_buffer_size(buffer_length_frames), true); 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<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")); + 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: // ? 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); |