From a2792bd09212eed55bba1aa30dc09043a6955486 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 31 Aug 2014 01:24:57 +0000 Subject: Use float sequences for sample-accurate control ports. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5462 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/internals/Controller.cpp | 31 +++++++++++++++++-------------- src/server/internals/Controller.hpp | 2 +- src/server/internals/Delay.cpp | 6 +----- src/server/internals/Delay.hpp | 2 +- src/server/internals/Note.cpp | 28 ++++++++++++++++------------ src/server/internals/Note.hpp | 2 +- src/server/internals/Time.cpp | 6 +----- src/server/internals/Time.hpp | 2 +- src/server/internals/Trigger.cpp | 30 +++++++++++++++--------------- src/server/internals/Trigger.hpp | 2 +- 10 files changed, 55 insertions(+), 56 deletions(-) (limited to 'src/server/internals') diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp index 1f4f75cc..5f084f6f 100644 --- a/src/server/internals/Controller.cpp +++ b/src/server/internals/Controller.cpp @@ -53,6 +53,10 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, const Ingen::URIs& uris = bufs.uris(); _ports = new Raul::Array(6); + const Atom zero = bufs.forge().make(0.0f); + const Atom one = bufs.forge().make(1.0f); + const Atom atom_Float = bufs.forge().alloc_uri(LV2_ATOM__Float); + _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); @@ -61,40 +65,43 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, _ports->at(0) = _midi_in_port; _param_port = new InputPort(bufs, this, Raul::Symbol("controller"), 1, 1, - PortType::CONTROL, 0, bufs.forge().make(0.0f)); - _param_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _param_port->set_property(uris.atom_supports, atom_Float); + _param_port->set_property(uris.lv2_minimum, zero); _param_port->set_property(uris.lv2_maximum, bufs.forge().make(127.0f)); _param_port->set_property(uris.lv2_portProperty, uris.lv2_integer); _param_port->set_property(uris.lv2_name, bufs.forge().alloc("Controller")); _ports->at(1) = _param_port; _log_port = new InputPort(bufs, this, Raul::Symbol("logarithmic"), 2, 1, - PortType::CONTROL, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _log_port->set_property(uris.atom_supports, atom_Float); _log_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _log_port->set_property(uris.lv2_name, bufs.forge().alloc("Logarithmic")); _ports->at(2) = _log_port; _min_port = new InputPort(bufs, this, Raul::Symbol("minimum"), 3, 1, - PortType::CONTROL, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _min_port->set_property(uris.atom_supports, atom_Float); _min_port->set_property(uris.lv2_name, bufs.forge().alloc("Minimum")); _ports->at(3) = _min_port; _max_port = new InputPort(bufs, this, Raul::Symbol("maximum"), 4, 1, - PortType::CONTROL, 0, bufs.forge().make(1.0f)); + PortType::ATOM, uris.atom_Sequence, one); + _max_port->set_property(uris.atom_supports, atom_Float); _max_port->set_property(uris.lv2_name, bufs.forge().alloc("Maximum")); _ports->at(4) = _max_port; _audio_port = new OutputPort(bufs, this, Raul::Symbol("output"), 5, 1, - PortType::CV, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _audio_port->set_property(uris.atom_supports, atom_Float); _audio_port->set_property(uris.lv2_name, bufs.forge().alloc("Output")); _ports->at(5) = _audio_port; } void -ControllerNode::process(ProcessContext& context) +ControllerNode::run(ProcessContext& context) { - BlockImpl::pre_process(context); - Buffer* const midi_in = _midi_in_port->buffer(0).get(); LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)midi_in->atom(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { @@ -105,8 +112,6 @@ ControllerNode::process(ProcessContext& context) control(context, buf[1], buf[2], ev->time.frames + context.start()); } } - - BlockImpl::post_process(context); } void @@ -117,10 +122,8 @@ ControllerNode::control(ProcessContext& context, uint8_t control_num, uint8_t va const Sample nval = (val / 127.0f); // normalized [0, 1] if (_learning) { - // FIXME: not thread safe - _param_port->set_value(context.engine().world()->forge().make(control_num)); _param_port->set_control_value(context, time, control_num); - _param_port->monitor(context, true); + _param_port->force_monitor_update(); _learning = false; } diff --git a/src/server/internals/Controller.hpp b/src/server/internals/Controller.hpp index 6cb78397..a5fc5ef2 100644 --- a/src/server/internals/Controller.hpp +++ b/src/server/internals/Controller.hpp @@ -45,7 +45,7 @@ public: GraphImpl* parent, SampleRate srate); - void process(ProcessContext& context); + void run(ProcessContext& context); void control(ProcessContext& context, uint8_t control_num, uint8_t val, FrameTime time); diff --git a/src/server/internals/Delay.cpp b/src/server/internals/Delay.cpp index 78d2118c..92bbe45b 100644 --- a/src/server/internals/Delay.cpp +++ b/src/server/internals/Delay.cpp @@ -138,14 +138,12 @@ static inline float cube_interp(const float fr, const float inm1, const float } void -DelayNode::process(ProcessContext& context) +DelayNode::run(ProcessContext& context) { Buffer* const delay_buf = _delay_port->buffer(0).get(); Buffer* const in_buf = _in_port->buffer(0).get(); Buffer* const out_buf = _out_port->buffer(0).get(); - BlockImpl::pre_process(context); - DelayNode* plugin_data = this; const float* const in = in_buf->samples(); @@ -200,8 +198,6 @@ DelayNode::process(ProcessContext& context) } _write_phase = write_phase; - - BlockImpl::post_process(context); } } // namespace Internals diff --git a/src/server/internals/Delay.hpp b/src/server/internals/Delay.hpp index 0dc5fb21..9df7349f 100644 --- a/src/server/internals/Delay.hpp +++ b/src/server/internals/Delay.hpp @@ -46,7 +46,7 @@ public: void activate(BufferFactory& bufs); - void process(ProcessContext& context); + void run(ProcessContext& context); static InternalPlugin* internal_plugin(URIs& uris); diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp index e2ead4b7..7558334e 100644 --- a/src/server/internals/Note.cpp +++ b/src/server/internals/Note.cpp @@ -60,6 +60,8 @@ NoteNode::NoteNode(InternalPlugin* plugin, const Ingen::URIs& uris = bufs.uris(); _ports = new Raul::Array(6); + const Atom zero = bufs.forge().make(0.0f); + _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); @@ -68,35 +70,41 @@ NoteNode::NoteNode(InternalPlugin* plugin, _ports->at(0) = _midi_in_port; _freq_port = new OutputPort(bufs, this, Raul::Symbol("frequency"), 1, _polyphony, - PortType::CV, 0, bufs.forge().make(440.0f)); + PortType::ATOM, uris.atom_Sequence, + bufs.forge().make(440.0f)); + _freq_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _freq_port->set_property(uris.lv2_name, bufs.forge().alloc("Frequency")); _freq_port->set_property(uris.lv2_minimum, bufs.forge().make(16.0f)); _freq_port->set_property(uris.lv2_maximum, bufs.forge().make(25088.0f)); _ports->at(1) = _freq_port; _num_port = new OutputPort(bufs, this, Raul::Symbol("number"), 1, _polyphony, - PortType::CV, 0, bufs.forge().make(0.0f)); - _num_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _num_port->set_property(uris.atom_supports, bufs.uris().atom_Float); + _num_port->set_property(uris.lv2_minimum, zero); _num_port->set_property(uris.lv2_maximum, bufs.forge().make(127.0f)); _num_port->set_property(uris.lv2_portProperty, uris.lv2_integer); _num_port->set_property(uris.lv2_name, bufs.forge().alloc("Number")); _ports->at(2) = _num_port; _vel_port = new OutputPort(bufs, this, Raul::Symbol("velocity"), 2, _polyphony, - PortType::CV, 0, bufs.forge().make(0.0f)); - _vel_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _vel_port->set_property(uris.atom_supports, bufs.uris().atom_Float); + _vel_port->set_property(uris.lv2_minimum, zero); _vel_port->set_property(uris.lv2_maximum, bufs.forge().make(1.0f)); _vel_port->set_property(uris.lv2_name, bufs.forge().alloc("Velocity")); _ports->at(3) = _vel_port; _gate_port = new OutputPort(bufs, this, Raul::Symbol("gate"), 3, _polyphony, - PortType::CV, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _gate_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _gate_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _gate_port->set_property(uris.lv2_name, bufs.forge().alloc("Gate")); _ports->at(4) = _gate_port; _trig_port = new OutputPort(bufs, this, Raul::Symbol("trigger"), 4, _polyphony, - PortType::CV, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _trig_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _trig_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _trig_port->set_property(uris.lv2_name, bufs.forge().alloc("Trigger")); _ports->at(5) = _trig_port; @@ -141,10 +149,8 @@ NoteNode::apply_poly(ProcessContext& context, Raul::Maid& maid, uint32_t poly) } void -NoteNode::process(ProcessContext& context) +NoteNode::run(ProcessContext& context) { - BlockImpl::pre_process(context); - Buffer* const midi_in = _midi_in_port->buffer(0).get(); LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)midi_in->atom(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { @@ -182,8 +188,6 @@ NoteNode::process(ProcessContext& context) } } } - - BlockImpl::post_process(context); } static inline float diff --git a/src/server/internals/Note.hpp b/src/server/internals/Note.hpp index 027912b6..3b77cf12 100644 --- a/src/server/internals/Note.hpp +++ b/src/server/internals/Note.hpp @@ -50,7 +50,7 @@ public: bool prepare_poly(BufferFactory& bufs, uint32_t poly); bool apply_poly(ProcessContext& context, Raul::Maid& maid, uint32_t poly); - void process(ProcessContext& context); + void run(ProcessContext& context); void note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity, FrameTime time); void note_off(ProcessContext& context, uint8_t note_num, FrameTime time); diff --git a/src/server/internals/Time.cpp b/src/server/internals/Time.cpp index 6f090257..54901172 100644 --- a/src/server/internals/Time.cpp +++ b/src/server/internals/Time.cpp @@ -57,10 +57,8 @@ TimeNode::TimeNode(InternalPlugin* plugin, } void -TimeNode::process(ProcessContext& context) +TimeNode::run(ProcessContext& context) { - BlockImpl::pre_process(context); - BufferRef buf = _notify_port->buffer(0); LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)buf->atom(); @@ -73,8 +71,6 @@ TimeNode::process(ProcessContext& context) // Ask the driver to append any time events for this cycle context.engine().driver()->append_time_events( context, *_notify_port->buffer(0)); - - BlockImpl::post_process(context); } } // namespace Internals diff --git a/src/server/internals/Time.hpp b/src/server/internals/Time.hpp index 7efe5d6a..8c0114b7 100644 --- a/src/server/internals/Time.hpp +++ b/src/server/internals/Time.hpp @@ -44,7 +44,7 @@ public: GraphImpl* parent, SampleRate srate); - void process(ProcessContext& context); + void run(ProcessContext& context); static InternalPlugin* internal_plugin(URIs& uris); diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp index abef29ca..650126d4 100644 --- a/src/server/internals/Trigger.cpp +++ b/src/server/internals/Trigger.cpp @@ -53,6 +53,8 @@ TriggerNode::TriggerNode(InternalPlugin* plugin, const Ingen::URIs& uris = bufs.uris(); _ports = new Raul::Array(5); + const Atom zero = bufs.forge().make(0.0f); + _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); @@ -61,38 +63,41 @@ TriggerNode::TriggerNode(InternalPlugin* plugin, _ports->at(0) = _midi_in_port; _note_port = new InputPort(bufs, this, Raul::Symbol("note"), 1, 1, - PortType::CONTROL, 0, bufs.forge().make(60.0f)); - _note_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, + bufs.forge().make(60.0f)); + _note_port->set_property(uris.atom_supports, bufs.uris().atom_Float); + _note_port->set_property(uris.lv2_minimum, zero); _note_port->set_property(uris.lv2_maximum, bufs.forge().make(127.0f)); _note_port->set_property(uris.lv2_portProperty, uris.lv2_integer); _note_port->set_property(uris.lv2_name, bufs.forge().alloc("Note")); _ports->at(1) = _note_port; _gate_port = new OutputPort(bufs, this, Raul::Symbol("gate"), 2, 1, - PortType::CV, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _gate_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _gate_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _gate_port->set_property(uris.lv2_name, bufs.forge().alloc("Gate")); _ports->at(2) = _gate_port; _trig_port = new OutputPort(bufs, this, Raul::Symbol("trigger"), 3, 1, - PortType::CV, 0, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _trig_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _trig_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _trig_port->set_property(uris.lv2_name, bufs.forge().alloc("Trigger")); _ports->at(3) = _trig_port; _vel_port = new OutputPort(bufs, this, Raul::Symbol("velocity"), 4, 1, - PortType::CV, 0, bufs.forge().make(0.0f)); - _vel_port->set_property(uris.lv2_minimum, bufs.forge().make(0.0f)); + PortType::ATOM, uris.atom_Sequence, zero); + _vel_port->set_property(uris.atom_supports, bufs.uris().atom_Float); + _vel_port->set_property(uris.lv2_minimum, zero); _vel_port->set_property(uris.lv2_maximum, bufs.forge().make(1.0f)); _vel_port->set_property(uris.lv2_name, bufs.forge().alloc("Velocity")); _ports->at(4) = _vel_port; } void -TriggerNode::process(ProcessContext& context) +TriggerNode::run(ProcessContext& context) { - BlockImpl::pre_process(context); - Buffer* const midi_in = _midi_in_port->buffer(0).get(); LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)midi_in->atom(); LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { @@ -122,8 +127,6 @@ TriggerNode::process(ProcessContext& context) } } } - - BlockImpl::post_process(context); } void @@ -132,10 +135,8 @@ TriggerNode::note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity assert(time >= context.start() && time <= context.end()); if (_learning) { - // FIXME: not thread safe - _note_port->set_value(context.engine().world()->forge().make((float)note_num)); _note_port->set_control_value(context, time, (float)note_num); - _note_port->monitor(context, true); + _note_port->force_monitor_update(); _learning = false; } @@ -145,7 +146,6 @@ TriggerNode::note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity _trig_port->set_control_value(context, time, 1.0f); _trig_port->set_control_value(context, time + 1, 0.0f); _vel_port->set_control_value(context, time, velocity / 127.0f); - assert(_trig_port->buffer(0)->samples()[time - context.start()] == 1.0f); } } diff --git a/src/server/internals/Trigger.hpp b/src/server/internals/Trigger.hpp index b9ae4849..041bc801 100644 --- a/src/server/internals/Trigger.hpp +++ b/src/server/internals/Trigger.hpp @@ -48,7 +48,7 @@ public: GraphImpl* parent, SampleRate srate); - void process(ProcessContext& context); + void run(ProcessContext& context); void note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity, FrameTime time); void note_off(ProcessContext& context, uint8_t note_num, FrameTime time); -- cgit v1.2.1