summaryrefslogtreecommitdiffstats
path: root/src/server/internals
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/internals')
-rw-r--r--src/server/internals/BlockDelay.cpp40
-rw-r--r--src/server/internals/BlockDelay.hpp20
-rw-r--r--src/server/internals/Controller.cpp89
-rw-r--r--src/server/internals/Controller.hpp23
-rw-r--r--src/server/internals/Note.cpp158
-rw-r--r--src/server/internals/Note.hpp65
-rw-r--r--src/server/internals/Time.cpp44
-rw-r--r--src/server/internals/Time.hpp19
-rw-r--r--src/server/internals/Trigger.cpp103
-rw-r--r--src/server/internals/Trigger.hpp25
10 files changed, 340 insertions, 246 deletions
diff --git a/src/server/internals/BlockDelay.cpp b/src/server/internals/BlockDelay.cpp
index 0176c9b1..acc68851 100644
--- a/src/server/internals/BlockDelay.cpp
+++ b/src/server/internals/BlockDelay.cpp
@@ -14,33 +14,35 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "internals/BlockDelay.hpp"
+#include "BlockDelay.hpp"
+#include "BlockImpl.hpp"
#include "Buffer.hpp"
+#include "BufferFactory.hpp"
#include "InputPort.hpp"
#include "InternalPlugin.hpp"
#include "OutputPort.hpp"
+#include "PortType.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/URIs.hpp"
-#include "raul/Array.hpp"
-#include "raul/Maid.hpp"
+#include <ingen/Forge.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIs.hpp>
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+#include <raul/Symbol.hpp>
-namespace ingen {
-namespace server {
+#include <memory>
-class RunContext;
-
-namespace internals {
+namespace ingen::server::internals {
InternalPlugin* BlockDelayNode::internal_plugin(URIs& uris) {
return new InternalPlugin(
- uris, URI(NS_INTERNALS "BlockDelay"), Raul::Symbol("blockDelay"));
+ uris, URI(NS_INTERNALS "BlockDelay"), raul::Symbol("blockDelay"));
}
BlockDelayNode::BlockDelayNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate)
@@ -49,12 +51,12 @@ BlockDelayNode::BlockDelayNode(InternalPlugin* plugin,
const ingen::URIs& uris = bufs.uris();
_ports = bufs.maid().make_managed<Ports>(2);
- _in_port = new InputPort(bufs, this, Raul::Symbol("in"), 0, 1,
+ _in_port = new InputPort(bufs, this, raul::Symbol("in"), 0, 1,
PortType::AUDIO, 0, bufs.forge().make(0.0f));
_in_port->set_property(uris.lv2_name, bufs.forge().alloc("In"));
_ports->at(0) = _in_port;
- _out_port = new OutputPort(bufs, this, Raul::Symbol("out"), 0, 1,
+ _out_port = new OutputPort(bufs, this, raul::Symbol("out"), 0, 1,
PortType::AUDIO, 0, bufs.forge().make(0.0f));
_out_port->set_property(uris.lv2_name, bufs.forge().alloc("Out"));
_ports->at(1) = _out_port;
@@ -75,15 +77,13 @@ BlockDelayNode::activate(BufferFactory& bufs)
}
void
-BlockDelayNode::run(RunContext& context)
+BlockDelayNode::run(RunContext& ctx)
{
// Copy buffer from last cycle to output
- _out_port->buffer(0)->copy(context, _buffer.get());
+ _out_port->buffer(0)->copy(ctx, _buffer.get());
// Copy input from this cycle to buffer
- _buffer->copy(context, _in_port->buffer(0).get());
+ _buffer->copy(ctx, _in_port->buffer(0).get());
}
-} // namespace internals
-} // namespace server
-} // namespace ingen
+} // namespace ingen::server::internals
diff --git a/src/server/internals/BlockDelay.hpp b/src/server/internals/BlockDelay.hpp
index 0e8fadce..a9667fa0 100644
--- a/src/server/internals/BlockDelay.hpp
+++ b/src/server/internals/BlockDelay.hpp
@@ -21,13 +21,21 @@
#include "InternalBlock.hpp"
#include "types.hpp"
+namespace raul {
+class Symbol;
+} // namespace raul
+
namespace ingen {
+
+class URIs;
+
namespace server {
+class BufferFactory;
+class GraphImpl;
class InputPort;
-class OutputPort;
class InternalPlugin;
-class BufferFactory;
+class OutputPort;
namespace internals {
@@ -36,16 +44,16 @@ class BlockDelayNode : public InternalBlock
public:
BlockDelayNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate);
- ~BlockDelayNode();
+ ~BlockDelayNode() override;
void activate(BufferFactory& bufs) override;
- void run(RunContext& context) override;
+ void run(RunContext& ctx) override;
static InternalPlugin* internal_plugin(URIs& uris);
@@ -55,8 +63,8 @@ private:
BufferRef _buffer;
};
+} // namespace internals
} // namespace server
} // namespace ingen
-} // namespace internals
#endif // INGEN_INTERNALS_BLOCKDELAY_HPP
diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp
index b8738e1e..9103649e 100644
--- a/src/server/internals/Controller.cpp
+++ b/src/server/internals/Controller.cpp
@@ -14,42 +14,51 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Controller.hpp"
+
#include "Buffer.hpp"
-#include "Engine.hpp"
+#include "BufferFactory.hpp"
+#include "BufferRef.hpp"
#include "InputPort.hpp"
#include "InternalPlugin.hpp"
#include "OutputPort.hpp"
-#include "PostProcessor.hpp"
+#include "PortType.hpp"
#include "RunContext.hpp"
-#include "util.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/URIs.hpp"
-#include "internals/Controller.hpp"
-#include "lv2/atom/util.h"
-#include "lv2/midi/midi.h"
+#include <ingen/Atom.hpp>
+#include <ingen/Forge.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIs.hpp>
+#include <lv2/atom/atom.h>
+#include <lv2/atom/util.h>
+#include <lv2/midi/midi.h>
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+#include <raul/Symbol.hpp>
#include <cassert>
#include <cmath>
#include <initializer_list>
+#include <memory>
+
+namespace ingen::server {
+
+class GraphImpl;
-namespace ingen {
-namespace server {
namespace internals {
InternalPlugin* ControllerNode::internal_plugin(URIs& uris) {
return new InternalPlugin(
- uris, URI(NS_INTERNALS "Controller"), Raul::Symbol("controller"));
+ uris, URI(NS_INTERNALS "Controller"), raul::Symbol("controller"));
}
ControllerNode::ControllerNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate)
: InternalBlock(plugin, symbol, false, parent, srate)
- , _learning(false)
{
const ingen::URIs& uris = bufs.uris();
_ports = bufs.maid().make_managed<Ports>(7);
@@ -58,21 +67,21 @@ ControllerNode::ControllerNode(InternalPlugin* plugin,
const Atom one = bufs.forge().make(1.0f);
const Atom atom_Float = bufs.forge().make_urid(URI(LV2_ATOM__Float));
- _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1,
+ _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"));
_midi_in_port->set_property(uris.atom_supports,
bufs.forge().make_urid(uris.midi_MidiEvent));
_ports->at(0) = _midi_in_port;
- _midi_out_port = new OutputPort(bufs, this, Raul::Symbol("event"), 1, 1,
+ _midi_out_port = new OutputPort(bufs, this, raul::Symbol("event"), 1, 1,
PortType::ATOM, uris.atom_Sequence, Atom());
_midi_out_port->set_property(uris.lv2_name, bufs.forge().alloc("Event"));
_midi_out_port->set_property(uris.atom_supports,
bufs.forge().make_urid(uris.midi_MidiEvent));
_ports->at(1) = _midi_out_port;
- _param_port = new InputPort(bufs, this, Raul::Symbol("controller"), 2, 1,
+ _param_port = new InputPort(bufs, this, raul::Symbol("controller"), 2, 1,
PortType::ATOM, uris.atom_Sequence, zero);
_param_port->set_property(uris.atom_supports, atom_Float);
_param_port->set_property(uris.lv2_minimum, zero);
@@ -81,26 +90,26 @@ ControllerNode::ControllerNode(InternalPlugin* plugin,
_param_port->set_property(uris.lv2_name, bufs.forge().alloc("Controller"));
_ports->at(2) = _param_port;
- _log_port = new InputPort(bufs, this, Raul::Symbol("logarithmic"), 3, 1,
+ _log_port = new InputPort(bufs, this, raul::Symbol("logarithmic"), 3, 1,
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(3) = _log_port;
- _min_port = new InputPort(bufs, this, Raul::Symbol("minimum"), 4, 1,
+ _min_port = new InputPort(bufs, this, raul::Symbol("minimum"), 4, 1,
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(4) = _min_port;
- _max_port = new InputPort(bufs, this, Raul::Symbol("maximum"), 5, 1,
+ _max_port = new InputPort(bufs, this, raul::Symbol("maximum"), 5, 1,
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(5) = _max_port;
- _audio_port = new OutputPort(bufs, this, Raul::Symbol("output"), 6, 1,
+ _audio_port = new OutputPort(bufs, this, raul::Symbol("output"), 6, 1,
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"));
@@ -108,17 +117,18 @@ ControllerNode::ControllerNode(InternalPlugin* plugin,
}
void
-ControllerNode::run(RunContext& context)
+ControllerNode::run(RunContext& ctx)
{
- const BufferRef midi_in = _midi_in_port->buffer(0);
- LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>();
- const BufferRef midi_out = _midi_out_port->buffer(0);
- LV2_ATOM_SEQUENCE_FOREACH(seq, ev) {
- const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body);
+ const BufferRef midi_in = _midi_in_port->buffer(0);
+ auto* seq = midi_in->get<LV2_Atom_Sequence>();
+ const BufferRef midi_out = _midi_out_port->buffer(0);
+
+ LV2_ATOM_SEQUENCE_FOREACH (seq, ev) {
+ const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body));
if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent &&
ev->body.size >= 3 &&
lv2_midi_message_type(buf) == LV2_MIDI_MSG_CONTROLLER) {
- if (control(context, buf[1], buf[2], ev->time.frames + context.start())) {
+ if (control(ctx, buf[1], buf[2], ev->time.frames + ctx.start())) {
midi_out->append_event(ev->time.frames, &ev->body);
}
}
@@ -126,15 +136,15 @@ ControllerNode::run(RunContext& context)
}
bool
-ControllerNode::control(RunContext& context, uint8_t control_num, uint8_t val, FrameTime time)
+ControllerNode::control(RunContext& ctx, uint8_t control_num, uint8_t val, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
- const uint32_t offset = time - context.start();
+ assert(time >= ctx.start() && time <= ctx.end());
+ const uint32_t offset = time - ctx.start();
const Sample nval = (val / 127.0f); // normalized [0, 1]
if (_learning) {
- _param_port->set_control_value(context, time, control_num);
+ _param_port->set_control_value(ctx, time, control_num);
_param_port->force_monitor_update();
_learning = false;
} else {
@@ -153,25 +163,24 @@ ControllerNode::control(RunContext& context, uint8_t control_num, uint8_t val, F
const Sample max_port_val = _max_port->buffer(0)->value_at(offset);
const Sample log_port_val = _log_port->buffer(0)->value_at(offset);
- Sample scaled_value;
+ Sample scaled_value = 0.0f;
if (log_port_val > 0.0f) {
// haaaaack, stupid negatives and logarithms
- Sample log_offset = 0;
+ Sample log_offset = 0.0f;
if (min_port_val < 0) {
- log_offset = fabs(min_port_val);
+ log_offset = fabsf(min_port_val);
}
- const Sample min = log(min_port_val + 1 + log_offset);
- const Sample max = log(max_port_val + 1 + log_offset);
- scaled_value = expf(nval * (max - min) + min) - 1 - log_offset;
+ const Sample min = logf(min_port_val + 1 + log_offset);
+ const Sample max = logf(max_port_val + 1 + log_offset);
+ scaled_value = expf((nval * (max - min)) + min) - 1 - log_offset;
} else {
scaled_value = ((nval) * (max_port_val - min_port_val)) + min_port_val;
}
- _audio_port->set_control_value(context, time, scaled_value);
+ _audio_port->set_control_value(ctx, time, scaled_value);
return true;
}
} // namespace internals
-} // namespace server
-} // namespace ingen
+} // namespace ingen::server
diff --git a/src/server/internals/Controller.hpp b/src/server/internals/Controller.hpp
index 0a62b235..2a0bc834 100644
--- a/src/server/internals/Controller.hpp
+++ b/src/server/internals/Controller.hpp
@@ -18,15 +18,26 @@
#define INGEN_INTERNALS_CONTROLLER_HPP
#include "InternalBlock.hpp"
+#include "types.hpp"
#include <cstdint>
+namespace raul {
+class Symbol;
+} // namespace raul
+
namespace ingen {
+
+class URIs;
+
namespace server {
+class BufferFactory;
+class GraphImpl;
class InputPort;
-class OutputPort;
class InternalPlugin;
+class OutputPort;
+class RunContext;
namespace internals {
@@ -42,14 +53,14 @@ class ControllerNode : public InternalBlock
public:
ControllerNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate);
- void run(RunContext& context) override;
+ void run(RunContext& ctx) override;
- bool control(RunContext& context, uint8_t control_num, uint8_t val, FrameTime time);
+ bool control(RunContext& ctx, uint8_t control_num, uint8_t val, FrameTime time);
void learn() override { _learning = true; }
@@ -63,11 +74,11 @@ private:
InputPort* _min_port;
InputPort* _max_port;
OutputPort* _audio_port;
- bool _learning;
+ bool _learning{false};
};
+} // namespace internals
} // namespace server
} // namespace ingen
-} // namespace internals
#endif // INGEN_INTERNALS_CONTROLLER_HPP
diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp
index cfc0c157..960bca85 100644
--- a/src/server/internals/Note.cpp
+++ b/src/server/internals/Note.cpp
@@ -14,45 +14,54 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "internals/Note.hpp"
+#include "Note.hpp"
+#include "BlockImpl.hpp"
#include "Buffer.hpp"
+#include "BufferFactory.hpp"
#include "InputPort.hpp"
#include "InternalPlugin.hpp"
#include "OutputPort.hpp"
+#include "PortType.hpp"
#include "RunContext.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/URIs.hpp"
-#include "lv2/atom/util.h"
-#include "lv2/midi/midi.h"
-#include "raul/Array.hpp"
-#include "raul/Maid.hpp"
+#include <ingen/Atom.hpp>
+#include <ingen/Forge.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIs.hpp>
+#include <lv2/atom/atom.h>
+#include <lv2/atom/util.h>
+#include <lv2/midi/midi.h>
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+#include <raul/Symbol.hpp>
#include <cassert>
#include <cmath>
+#include <memory>
#include <utility>
// #define NOTE_DEBUG 1
-namespace ingen {
-namespace server {
+namespace ingen::server {
+
+class GraphImpl;
+
namespace internals {
InternalPlugin* NoteNode::internal_plugin(URIs& uris) {
return new InternalPlugin(
- uris, URI(NS_INTERNALS "Note"), Raul::Symbol("note"));
+ uris, URI(NS_INTERNALS "Note"), raul::Symbol("note"));
}
NoteNode::NoteNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate)
: InternalBlock(plugin, symbol, polyphonic, parent, srate)
, _voices(bufs.maid().make_managed<Voices>(_polyphony))
- , _sustain(false)
{
const ingen::URIs& uris = bufs.uris();
_ports = bufs.maid().make_managed<Ports>(8);
@@ -60,14 +69,14 @@ NoteNode::NoteNode(InternalPlugin* plugin,
const Atom zero = bufs.forge().make(0.0f);
const Atom one = bufs.forge().make(1.0f);
- _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1,
+ _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"));
_midi_in_port->set_property(uris.atom_supports,
bufs.forge().make_urid(uris.midi_MidiEvent));
_ports->at(0) = _midi_in_port;
- _freq_port = new OutputPort(bufs, this, Raul::Symbol("frequency"), 1, _polyphony,
+ _freq_port = new OutputPort(bufs, this, raul::Symbol("frequency"), 1, _polyphony,
PortType::ATOM, uris.atom_Sequence,
bufs.forge().make(440.0f));
_freq_port->set_property(uris.atom_supports, bufs.uris().atom_Float);
@@ -76,7 +85,7 @@ NoteNode::NoteNode(InternalPlugin* plugin,
_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,
+ _num_port = new OutputPort(bufs, this, raul::Symbol("number"), 1, _polyphony,
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);
@@ -85,7 +94,7 @@ NoteNode::NoteNode(InternalPlugin* plugin,
_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,
+ _vel_port = new OutputPort(bufs, this, raul::Symbol("velocity"), 2, _polyphony,
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);
@@ -93,21 +102,21 @@ NoteNode::NoteNode(InternalPlugin* plugin,
_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,
+ _gate_port = new OutputPort(bufs, this, raul::Symbol("gate"), 3, _polyphony,
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,
+ _trig_port = new OutputPort(bufs, this, raul::Symbol("trigger"), 4, _polyphony,
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;
- _bend_port = new OutputPort(bufs, this, Raul::Symbol("bend"), 5, _polyphony,
+ _bend_port = new OutputPort(bufs, this, raul::Symbol("bend"), 5, _polyphony,
PortType::ATOM, uris.atom_Sequence, zero);
_bend_port->set_property(uris.atom_supports, bufs.uris().atom_Float);
_bend_port->set_property(uris.lv2_name, bufs.forge().alloc("Bender"));
@@ -116,7 +125,7 @@ NoteNode::NoteNode(InternalPlugin* plugin,
_bend_port->set_property(uris.lv2_maximum, one);
_ports->at(6) = _bend_port;
- _pressure_port = new OutputPort(bufs, this, Raul::Symbol("pressure"), 6, _polyphony,
+ _pressure_port = new OutputPort(bufs, this, raul::Symbol("pressure"), 6, _polyphony,
PortType::ATOM, uris.atom_Sequence, zero);
_pressure_port->set_property(uris.atom_supports, bufs.uris().atom_Float);
_pressure_port->set_property(uris.lv2_name, bufs.forge().alloc("Pressure"));
@@ -146,9 +155,9 @@ NoteNode::prepare_poly(BufferFactory& bufs, uint32_t poly)
}
bool
-NoteNode::apply_poly(RunContext& context, uint32_t poly)
+NoteNode::apply_poly(RunContext& ctx, uint32_t poly)
{
- if (!BlockImpl::apply_poly(context, poly)) {
+ if (!BlockImpl::apply_poly(ctx, poly)) {
return false;
}
@@ -162,50 +171,58 @@ NoteNode::apply_poly(RunContext& context, uint32_t poly)
}
void
-NoteNode::run(RunContext& context)
+NoteNode::run(RunContext& ctx)
{
- Buffer* const midi_in = _midi_in_port->buffer(0).get();
- LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>();
- LV2_ATOM_SEQUENCE_FOREACH(seq, ev) {
- const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY_CONST(&ev->body);
- const FrameTime time = context.start() + (FrameTime)ev->time.frames;
+ Buffer* const midi_in = _midi_in_port->buffer(0).get();
+ auto* seq = midi_in->get<LV2_Atom_Sequence>();
+
+ LV2_ATOM_SEQUENCE_FOREACH (seq, ev) {
+ const auto* buf =
+ static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body));
+
+ const FrameTime time =
+ ctx.start() + static_cast<FrameTime>(ev->time.frames);
+
if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent &&
ev->body.size >= 3) {
switch (lv2_midi_message_type(buf)) {
case LV2_MIDI_MSG_NOTE_ON:
if (buf[2] == 0) {
- note_off(context, buf[1], time);
+ note_off(ctx, buf[1], time);
} else {
- note_on(context, buf[1], buf[2], time);
+ note_on(ctx, buf[1], buf[2], time);
}
break;
case LV2_MIDI_MSG_NOTE_OFF:
- note_off(context, buf[1], time);
+ note_off(ctx, buf[1], time);
break;
case LV2_MIDI_MSG_CONTROLLER:
switch (buf[1]) {
case LV2_MIDI_CTL_ALL_NOTES_OFF:
case LV2_MIDI_CTL_ALL_SOUNDS_OFF:
- all_notes_off(context, time);
+ all_notes_off(ctx, time);
break;
case LV2_MIDI_CTL_SUSTAIN:
if (buf[2] > 63) {
- sustain_on(context, time);
+ sustain_on(ctx, time);
} else {
- sustain_off(context, time);
+ sustain_off(ctx, time);
}
break;
}
break;
case LV2_MIDI_MSG_BENDER:
- bend(context, time, (((((uint16_t)buf[2] << 7) | buf[1]) - 8192.0f)
- / 8192.0f));
+ bend(ctx,
+ time,
+ ((((static_cast<uint16_t>(buf[2]) << 7) | buf[1]) -
+ 8192.0f) /
+ 8192.0f));
break;
case LV2_MIDI_MSG_CHANNEL_PRESSURE:
- channel_pressure(context, time, buf[1] / 127.0f);
+ channel_pressure(ctx, time, buf[1] / 127.0f);
break;
case LV2_MIDI_MSG_NOTE_PRESSURE:
- note_pressure(context, time, buf[1], buf[2] / 127.0f);
+ note_pressure(ctx, time, buf[1], buf[2] / 127.0f);
break;
default:
break;
@@ -218,13 +235,13 @@ static inline float
note_to_freq(uint8_t num)
{
static const float A4 = 440.0f;
- return A4 * powf(2.0f, (float)(num - 57.0f) / 12.0f);
+ return A4 * powf(2.0f, static_cast<float>(num - 57.0f) / 12.0f);
}
void
-NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time)
+NoteNode::note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
+ assert(time >= ctx.start() && time <= ctx.end());
assert(note_num <= 127);
Key* key = &_keys[note_num];
@@ -285,13 +302,13 @@ NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Frame
assert(_keys[voice->note].state == Key::State::ON_ASSIGNED);
assert(_keys[voice->note].voice == voice_num);
- _freq_port->set_voice_value(context, voice_num, time, note_to_freq(note_num));
- _num_port->set_voice_value(context, voice_num, time, (float)note_num);
- _vel_port->set_voice_value(context, voice_num, time, velocity / 127.0f);
- _gate_port->set_voice_value(context, voice_num, time, 1.0f);
+ _freq_port->set_voice_value(ctx, voice_num, time, note_to_freq(note_num));
+ _num_port->set_voice_value(ctx, voice_num, time, static_cast<float>(note_num));
+ _vel_port->set_voice_value(ctx, voice_num, time, velocity / 127.0f);
+ _gate_port->set_voice_value(ctx, voice_num, time, 1.0f);
if (!double_trigger) {
- _trig_port->set_voice_value(context, voice_num, time, 1.0f);
- _trig_port->set_voice_value(context, voice_num, time + 1, 0.0f);
+ _trig_port->set_voice_value(ctx, voice_num, time, 1.0f);
+ _trig_port->set_voice_value(ctx, voice_num, time + 1, 0.0f);
}
assert(key->state == Key::State::ON_ASSIGNED);
@@ -301,9 +318,9 @@ NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Frame
}
void
-NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time)
+NoteNode::note_off(RunContext& ctx, uint8_t note_num, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
+ assert(time >= ctx.start() && time <= ctx.end());
Key* key = &_keys[note_num];
@@ -312,7 +329,7 @@ NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time)
if ((*_voices)[key->voice].state == Voice::State::ACTIVE) {
assert((*_voices)[key->voice].note == note_num);
if ( ! _sustain) {
- free_voice(context, key->voice, time);
+ free_voice(ctx, key->voice, time);
} else {
(*_voices)[key->voice].state = Voice::State::HOLDING;
}
@@ -323,9 +340,9 @@ NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time)
}
void
-NoteNode::free_voice(RunContext& context, uint32_t voice, FrameTime time)
+NoteNode::free_voice(RunContext& ctx, uint32_t voice, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
+ assert(time >= ctx.start() && time <= ctx.end());
// Find a key to reassign to the freed voice (the newest, if there is one)
Key* replace_key = nullptr;
@@ -340,13 +357,13 @@ NoteNode::free_voice(RunContext& context, uint32_t voice, FrameTime time)
}
}
- if (replace_key != nullptr) { // Found a key to assign to freed voice
+ if (replace_key != nullptr) { // Found a key to assign to freed voice
assert(&_keys[replace_key_num] == replace_key);
assert(replace_key->state == Key::State::ON_UNASSIGNED);
// Change the freq but leave the gate high and don't retrigger
- _freq_port->set_voice_value(context, voice, time, note_to_freq(replace_key_num));
- _num_port->set_voice_value(context, voice, time, replace_key_num);
+ _freq_port->set_voice_value(ctx, voice, time, note_to_freq(replace_key_num));
+ _num_port->set_voice_value(ctx, voice, time, replace_key_num);
replace_key->state = Key::State::ON_ASSIGNED;
replace_key->voice = voice;
@@ -355,67 +372,66 @@ NoteNode::free_voice(RunContext& context, uint32_t voice, FrameTime time)
(*_voices)[voice].state = Voice::State::ACTIVE;
} else {
// No new note for voice, deactivate (set gate low)
- _gate_port->set_voice_value(context, voice, time, 0.0f);
+ _gate_port->set_voice_value(ctx, voice, time, 0.0f);
(*_voices)[voice].state = Voice::State::FREE;
}
}
void
-NoteNode::all_notes_off(RunContext& context, FrameTime time)
+NoteNode::all_notes_off(RunContext& ctx, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
+ assert(time >= ctx.start() && time <= ctx.end());
// FIXME: set all keys to Key::OFF?
for (uint32_t i = 0; i < _polyphony; ++i) {
- _gate_port->set_voice_value(context, i, time, 0.0f);
+ _gate_port->set_voice_value(ctx, i, time, 0.0f);
(*_voices)[i].state = Voice::State::FREE;
}
}
void
-NoteNode::sustain_on(RunContext& context, FrameTime time)
+NoteNode::sustain_on(RunContext&, FrameTime)
{
_sustain = true;
}
void
-NoteNode::sustain_off(RunContext& context, FrameTime time)
+NoteNode::sustain_off(RunContext& ctx, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
+ assert(time >= ctx.start() && time <= ctx.end());
_sustain = false;
for (uint32_t i=0; i < _polyphony; ++i) {
if ((*_voices)[i].state == Voice::State::HOLDING) {
- free_voice(context, i, time);
+ free_voice(ctx, i, time);
}
}
}
void
-NoteNode::bend(RunContext& context, FrameTime time, float amount)
+NoteNode::bend(RunContext& ctx, FrameTime time, float amount)
{
- _bend_port->set_control_value(context, time, amount);
+ _bend_port->set_control_value(ctx, time, amount);
}
void
-NoteNode::note_pressure(RunContext& context, FrameTime time, uint8_t note_num, float amount)
+NoteNode::note_pressure(RunContext& ctx, FrameTime time, uint8_t note_num, float amount)
{
for (uint32_t i=0; i < _polyphony; ++i) {
if ((*_voices)[i].state != Voice::State::FREE && (*_voices)[i].note == note_num) {
- _pressure_port->set_voice_value(context, i, time, amount);
+ _pressure_port->set_voice_value(ctx, i, time, amount);
return;
}
}
}
void
-NoteNode::channel_pressure(RunContext& context, FrameTime time, float amount)
+NoteNode::channel_pressure(RunContext& ctx, FrameTime time, float amount)
{
- _pressure_port->set_control_value(context, time, amount);
+ _pressure_port->set_control_value(ctx, time, amount);
}
} // namespace internals
-} // namespace server
-} // namespace ingen
+} // namespace ingen::server
diff --git a/src/server/internals/Note.hpp b/src/server/internals/Note.hpp
index eed5dda7..2cf6c1e2 100644
--- a/src/server/internals/Note.hpp
+++ b/src/server/internals/Note.hpp
@@ -20,14 +20,27 @@
#include "InternalBlock.hpp"
#include "types.hpp"
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+
#include <cstdint>
+namespace raul {
+class Symbol;
+} // namespace raul
+
namespace ingen {
+
+class URIs;
+
namespace server {
+class BufferFactory;
+class GraphImpl;
class InputPort;
-class OutputPort;
class InternalPlugin;
+class OutputPort;
+class RunContext;
namespace internals {
@@ -42,26 +55,26 @@ class NoteNode : public InternalBlock
public:
NoteNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate);
bool prepare_poly(BufferFactory& bufs, uint32_t poly) override;
- bool apply_poly(RunContext& context, uint32_t poly) override;
+ bool apply_poly(RunContext& ctx, uint32_t poly) override;
- void run(RunContext& context) override;
+ void run(RunContext& ctx) override;
- void note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time);
- void note_off(RunContext& context, uint8_t note_num, FrameTime time);
- void all_notes_off(RunContext& context, FrameTime time);
+ void note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time);
+ void note_off(RunContext& ctx, uint8_t note_num, FrameTime time);
+ void all_notes_off(RunContext& ctx, FrameTime time);
- void sustain_on(RunContext& context, FrameTime time);
- void sustain_off(RunContext& context, FrameTime time);
+ void sustain_on(RunContext& ctx, FrameTime time);
+ void sustain_off(RunContext& ctx, FrameTime time);
- void bend(RunContext& context, FrameTime time, float amount);
- void note_pressure(RunContext& context, FrameTime time, uint8_t note_num, float amount);
- void channel_pressure(RunContext& context, FrameTime time, float amount);
+ void bend(RunContext& ctx, FrameTime time, float amount);
+ void note_pressure(RunContext& ctx, FrameTime time, uint8_t note_num, float amount);
+ void channel_pressure(RunContext& ctx, FrameTime time, float amount);
static InternalPlugin* internal_plugin(URIs& uris);
@@ -69,30 +82,30 @@ private:
/** Key, one for each key on the keyboard */
struct Key {
enum class State { OFF, ON_ASSIGNED, ON_UNASSIGNED };
- Key() : state(State::OFF), voice(0), time(0) {}
- State state;
- uint32_t voice;
- SampleCount time;
+
+ State state = State::OFF;
+ uint32_t voice = 0;
+ SampleCount time = 0;
};
/** Voice, one of these always exists for each voice */
struct Voice {
enum class State { FREE, ACTIVE, HOLDING };
- Voice() : state(State::FREE), note(0), time(0) {}
- State state;
- uint8_t note;
- SampleCount time;
+
+ State state = State::FREE;
+ uint8_t note = 0;
+ SampleCount time = 0;
};
- using Voices = Raul::Array<Voice>;
+ using Voices = raul::Array<Voice>;
- void free_voice(RunContext& context, uint32_t voice, FrameTime time);
+ void free_voice(RunContext& ctx, uint32_t voice, FrameTime time);
- MPtr<Voices> _voices;
- MPtr<Voices> _prepared_voices;
+ raul::managed_ptr<Voices> _voices;
+ raul::managed_ptr<Voices> _prepared_voices;
Key _keys[128];
- bool _sustain; ///< Whether or not hold pedal is depressed
+ bool _sustain{false}; ///< Whether or not hold pedal is depressed
InputPort* _midi_in_port;
OutputPort* _freq_port;
@@ -104,8 +117,8 @@ private:
OutputPort* _pressure_port;
};
+} // namespace internals
} // namespace server
} // namespace ingen
-} // namespace internals
#endif // INGEN_INTERNALS_NOTE_HPP
diff --git a/src/server/internals/Time.cpp b/src/server/internals/Time.cpp
index 3b6f12ba..2ea09b0b 100644
--- a/src/server/internals/Time.cpp
+++ b/src/server/internals/Time.cpp
@@ -14,33 +14,43 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "internals/Time.hpp"
+#include "Time.hpp"
#include "Buffer.hpp"
+#include "BufferFactory.hpp"
+#include "BufferRef.hpp"
#include "Driver.hpp"
#include "Engine.hpp"
#include "InternalPlugin.hpp"
#include "OutputPort.hpp"
+#include "PortType.hpp"
#include "RunContext.hpp"
-#include "util.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/URIs.hpp"
-#include "lv2/atom/util.h"
-#include "lv2/midi/midi.h"
+#include <ingen/Atom.hpp>
+#include <ingen/Forge.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIs.hpp>
+#include <lv2/atom/atom.h>
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+#include <raul/Symbol.hpp>
+
+#include <memory>
+
+namespace ingen::server {
+
+class GraphImpl;
-namespace ingen {
-namespace server {
namespace internals {
InternalPlugin* TimeNode::internal_plugin(URIs& uris) {
return new InternalPlugin(
- uris, URI(NS_INTERNALS "Time"), Raul::Symbol("time"));
+ uris, URI(NS_INTERNALS "Time"), raul::Symbol("time"));
}
TimeNode::TimeNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate)
@@ -50,7 +60,7 @@ TimeNode::TimeNode(InternalPlugin* plugin,
_ports = bufs.maid().make_managed<Ports>(1);
_notify_port = new OutputPort(
- bufs, this, Raul::Symbol("notify"), 0, 1,
+ bufs, this, raul::Symbol("notify"), 0, 1,
PortType::ATOM, uris.atom_Sequence, Atom(), 1024);
_notify_port->set_property(uris.lv2_name, bufs.forge().alloc("Notify"));
_notify_port->set_property(uris.atom_supports,
@@ -59,10 +69,10 @@ TimeNode::TimeNode(InternalPlugin* plugin,
}
void
-TimeNode::run(RunContext& context)
+TimeNode::run(RunContext& ctx)
{
- BufferRef buf = _notify_port->buffer(0);
- LV2_Atom_Sequence* seq = buf->get<LV2_Atom_Sequence>();
+ const BufferRef buf = _notify_port->buffer(0);
+ auto* const seq = buf->get<LV2_Atom_Sequence>();
// Initialise output to the empty sequence
seq->atom.type = _notify_port->bufs().uris().atom_Sequence;
@@ -71,10 +81,8 @@ TimeNode::run(RunContext& context)
seq->body.pad = 0;
// Ask the driver to append any time events for this cycle
- context.engine().driver()->append_time_events(
- context, *_notify_port->buffer(0));
+ ctx.engine().driver()->append_time_events(ctx, *_notify_port->buffer(0));
}
} // namespace internals
-} // namespace server
-} // namespace ingen
+} // namespace ingen::server
diff --git a/src/server/internals/Time.hpp b/src/server/internals/Time.hpp
index 958cd239..228e67a8 100644
--- a/src/server/internals/Time.hpp
+++ b/src/server/internals/Time.hpp
@@ -18,13 +18,22 @@
#define INGEN_INTERNALS_TIME_HPP
#include "InternalBlock.hpp"
+#include "types.hpp"
+
+namespace raul {
+class Symbol;
+} // namespace raul
namespace ingen {
+
+class URIs;
+
namespace server {
-class InputPort;
-class OutputPort;
+class BufferFactory;
+class GraphImpl;
class InternalPlugin;
+class OutputPort;
namespace internals {
@@ -39,12 +48,12 @@ class TimeNode : public InternalBlock
public:
TimeNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate);
- void run(RunContext& context) override;
+ void run(RunContext& ctx) override;
static InternalPlugin* internal_plugin(URIs& uris);
@@ -52,8 +61,8 @@ private:
OutputPort* _notify_port;
};
+} // namespace internals
} // namespace server
} // namespace ingen
-} // namespace internals
#endif // INGEN_INTERNALS_TIME_HPP
diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp
index 4ceae3c8..f033a345 100644
--- a/src/server/internals/Trigger.cpp
+++ b/src/server/internals/Trigger.cpp
@@ -14,63 +14,71 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "internals/Trigger.hpp"
+#include "Trigger.hpp"
#include "Buffer.hpp"
-#include "Engine.hpp"
+#include "BufferFactory.hpp"
+#include "BufferRef.hpp"
#include "InputPort.hpp"
#include "InternalPlugin.hpp"
#include "OutputPort.hpp"
+#include "PortType.hpp"
#include "RunContext.hpp"
-#include "ingen_config.h"
-#include "util.hpp"
-#include "ingen/Forge.hpp"
-#include "ingen/URIs.hpp"
-#include "lv2/atom/util.h"
-#include "lv2/midi/midi.h"
+#include <ingen/Atom.hpp>
+#include <ingen/Forge.hpp>
+#include <ingen/URI.hpp>
+#include <ingen/URIs.hpp>
+#include <lv2/atom/atom.h>
+#include <lv2/atom/util.h>
+#include <lv2/midi/midi.h>
+#include <raul/Array.hpp>
+#include <raul/Maid.hpp>
+#include <raul/Symbol.hpp>
#include <cassert>
#include <cmath>
+#include <memory>
+
+namespace ingen::server {
+
+class GraphImpl;
-namespace ingen {
-namespace server {
namespace internals {
InternalPlugin* TriggerNode::internal_plugin(URIs& uris) {
return new InternalPlugin(
- uris, URI(NS_INTERNALS "Trigger"), Raul::Symbol("trigger"));
+ uris, URI(NS_INTERNALS "Trigger"), raul::Symbol("trigger"));
}
TriggerNode::TriggerNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate)
: InternalBlock(plugin, symbol, false, parent, srate)
- , _learning(false)
{
const ingen::URIs& uris = bufs.uris();
_ports = bufs.maid().make_managed<Ports>(6);
const Atom zero = bufs.forge().make(0.0f);
- _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1,
+ _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"));
_midi_in_port->set_property(uris.atom_supports,
bufs.forge().make_urid(uris.midi_MidiEvent));
_ports->at(0) = _midi_in_port;
- _midi_out_port = new OutputPort(bufs, this, Raul::Symbol("event"), 1, 1,
+ _midi_out_port = new OutputPort(bufs, this, raul::Symbol("event"), 1, 1,
PortType::ATOM, uris.atom_Sequence, Atom());
_midi_out_port->set_property(uris.lv2_name, bufs.forge().alloc("Event"));
_midi_out_port->set_property(uris.atom_supports,
bufs.forge().make_urid(uris.midi_MidiEvent));
_ports->at(1) = _midi_out_port;
- _note_port = new InputPort(bufs, this, Raul::Symbol("note"), 2, 1,
+ _note_port = new InputPort(bufs, this, raul::Symbol("note"), 2, 1,
PortType::ATOM, uris.atom_Sequence,
bufs.forge().make(60.0f));
_note_port->set_property(uris.atom_supports, bufs.uris().atom_Float);
@@ -80,21 +88,21 @@ TriggerNode::TriggerNode(InternalPlugin* plugin,
_note_port->set_property(uris.lv2_name, bufs.forge().alloc("Note"));
_ports->at(2) = _note_port;
- _gate_port = new OutputPort(bufs, this, Raul::Symbol("gate"), 3, 1,
+ _gate_port = new OutputPort(bufs, this, raul::Symbol("gate"), 3, 1,
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(3) = _gate_port;
- _trig_port = new OutputPort(bufs, this, Raul::Symbol("trigger"), 4, 1,
+ _trig_port = new OutputPort(bufs, this, raul::Symbol("trigger"), 4, 1,
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(4) = _trig_port;
- _vel_port = new OutputPort(bufs, this, Raul::Symbol("velocity"), 5, 1,
+ _vel_port = new OutputPort(bufs, this, raul::Symbol("velocity"), 5, 1,
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);
@@ -104,40 +112,42 @@ TriggerNode::TriggerNode(InternalPlugin* plugin,
}
void
-TriggerNode::run(RunContext& context)
+TriggerNode::run(RunContext& ctx)
{
- const BufferRef midi_in = _midi_in_port->buffer(0);
- LV2_Atom_Sequence* const seq = midi_in->get<LV2_Atom_Sequence>();
- const BufferRef midi_out = _midi_out_port->buffer(0);
+ const BufferRef midi_in = _midi_in_port->buffer(0);
+ auto* const seq = midi_in->get<LV2_Atom_Sequence>();
+ const BufferRef midi_out = _midi_out_port->buffer(0);
// Initialise output to the empty sequence
- midi_out->prepare_write(context);
+ midi_out->prepare_write(ctx);
- LV2_ATOM_SEQUENCE_FOREACH(seq, ev) {
- const int64_t t = ev->time.frames;
- const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body);
- bool emit = false;
+ LV2_ATOM_SEQUENCE_FOREACH (seq, ev) {
+ const int64_t t = ev->time.frames;
+ const auto* buf =
+ static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body));
+ bool emit = false;
if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent &&
ev->body.size >= 3) {
- const FrameTime time = context.start() + t;
+ const FrameTime time = ctx.start() + t;
switch (lv2_midi_message_type(buf)) {
case LV2_MIDI_MSG_NOTE_ON:
if (buf[2] == 0) {
- emit = note_off(context, buf[1], time);
+ emit = note_off(ctx, buf[1], time);
} else {
- emit = note_on(context, buf[1], buf[2], time);
+ emit = note_on(ctx, buf[1], buf[2], time);
}
break;
case LV2_MIDI_MSG_NOTE_OFF:
- emit = note_off(context, buf[1], time);
+ emit = note_off(ctx, buf[1], time);
break;
case LV2_MIDI_MSG_CONTROLLER:
switch (buf[1]) {
case LV2_MIDI_CTL_ALL_NOTES_OFF:
case LV2_MIDI_CTL_ALL_SOUNDS_OFF:
- _gate_port->set_control_value(context, time, 0.0f);
+ _gate_port->set_control_value(ctx, time, 0.0f);
emit = true;
}
+ break;
default:
break;
}
@@ -150,35 +160,35 @@ TriggerNode::run(RunContext& context)
}
bool
-TriggerNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time)
+TriggerNode::note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
- const uint32_t offset = time - context.start();
+ assert(time >= ctx.start() && time <= ctx.end());
+ const uint32_t offset = time - ctx.start();
if (_learning) {
- _note_port->set_control_value(context, time, (float)note_num);
+ _note_port->set_control_value(ctx, time, static_cast<float>(note_num));
_note_port->force_monitor_update();
_learning = false;
}
if (note_num == lrintf(_note_port->buffer(0)->value_at(offset))) {
- _gate_port->set_control_value(context, time, 1.0f);
- _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);
+ _gate_port->set_control_value(ctx, time, 1.0f);
+ _trig_port->set_control_value(ctx, time, 1.0f);
+ _trig_port->set_control_value(ctx, time + 1, 0.0f);
+ _vel_port->set_control_value(ctx, time, velocity / 127.0f);
return true;
}
return false;
}
bool
-TriggerNode::note_off(RunContext& context, uint8_t note_num, FrameTime time)
+TriggerNode::note_off(RunContext& ctx, uint8_t note_num, FrameTime time)
{
- assert(time >= context.start() && time <= context.end());
- const uint32_t offset = time - context.start();
+ assert(time >= ctx.start() && time <= ctx.end());
+ const uint32_t offset = time - ctx.start();
if (note_num == lrintf(_note_port->buffer(0)->value_at(offset))) {
- _gate_port->set_control_value(context, time, 0.0f);
+ _gate_port->set_control_value(ctx, time, 0.0f);
return true;
}
@@ -186,5 +196,4 @@ TriggerNode::note_off(RunContext& context, uint8_t note_num, FrameTime time)
}
} // namespace internals
-} // namespace server
-} // namespace ingen
+} // namespace ingen::server
diff --git a/src/server/internals/Trigger.hpp b/src/server/internals/Trigger.hpp
index 0508b615..74634202 100644
--- a/src/server/internals/Trigger.hpp
+++ b/src/server/internals/Trigger.hpp
@@ -18,15 +18,26 @@
#define INGEN_INTERNALS_TRIGGER_HPP
#include "InternalBlock.hpp"
+#include "types.hpp"
#include <cstdint>
+namespace raul {
+class Symbol;
+} // namespace raul
+
namespace ingen {
+
+class URIs;
+
namespace server {
+class BufferFactory;
+class GraphImpl;
class InputPort;
-class OutputPort;
class InternalPlugin;
+class OutputPort;
+class RunContext;
namespace internals {
@@ -45,22 +56,22 @@ class TriggerNode : public InternalBlock
public:
TriggerNode(InternalPlugin* plugin,
BufferFactory& bufs,
- const Raul::Symbol& symbol,
+ const raul::Symbol& symbol,
bool polyphonic,
GraphImpl* parent,
SampleRate srate);
- void run(RunContext& context) override;
+ void run(RunContext& ctx) override;
- bool note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time);
- bool note_off(RunContext& context, uint8_t note_num, FrameTime time);
+ bool note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time);
+ bool note_off(RunContext& ctx, uint8_t note_num, FrameTime time);
void learn() override { _learning = true; }
static InternalPlugin* internal_plugin(URIs& uris);
private:
- bool _learning;
+ bool _learning{false};
InputPort* _midi_in_port;
OutputPort* _midi_out_port;
@@ -70,8 +81,8 @@ private:
OutputPort* _vel_port;
};
+} // namespace internals
} // namespace server
} // namespace ingen
-} // namespace internals
#endif // INGEN_INTERNALS_TRIGGER_HPP