summaryrefslogtreecommitdiffstats
path: root/src/server/internals/Note.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-03-19 20:16:46 +0000
committerDavid Robillard <d@drobilla.net>2012-03-19 20:16:46 +0000
commit254b434f0a79fea54bd963e8ff2e845a5b0cd3a6 (patch)
treeddf849fc5b64d1096846c28c1f1a742f54c3adff /src/server/internals/Note.cpp
parentbc3afd8380d59c750c8f8e9bf1ed1b8d4a6826e9 (diff)
downloadingen-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/Note.cpp')
-rw-r--r--src/server/internals/Note.cpp75
1 files changed, 29 insertions, 46 deletions
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:
// ?