summaryrefslogtreecommitdiffstats
path: root/src/engine/internals
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-11-16 00:30:35 +0000
committerDavid Robillard <d@drobilla.net>2009-11-16 00:30:35 +0000
commit3d89115a67a9c947a28539ffdd2399808a53279b (patch)
tree826b900de3979eed9c31aae0d3ac560d39b53460 /src/engine/internals
parent597fa9212f27d2448c0cdd20fbf616928c662cc1 (diff)
downloadingen-3d89115a67a9c947a28539ffdd2399808a53279b.tar.gz
ingen-3d89115a67a9c947a28539ffdd2399808a53279b.tar.bz2
ingen-3d89115a67a9c947a28539ffdd2399808a53279b.zip
Rework objects extension to have "value ports" and "message ports".
Make audio and control buffers in ingen actually object buffers (towards interop). Overhaul the hell out of ingen buffer and mixing stuff. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2266 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/internals')
-rw-r--r--src/engine/internals/Controller.cpp37
-rw-r--r--src/engine/internals/Controller.hpp2
-rw-r--r--src/engine/internals/Note.cpp39
-rw-r--r--src/engine/internals/Note.hpp4
-rw-r--r--src/engine/internals/Transport.cpp158
-rw-r--r--src/engine/internals/Transport.hpp47
-rw-r--r--src/engine/internals/Trigger.cpp34
-rw-r--r--src/engine/internals/Trigger.hpp2
8 files changed, 62 insertions, 261 deletions
diff --git a/src/engine/internals/Controller.cpp b/src/engine/internals/Controller.cpp
index 9788206e..3d003a43 100644
--- a/src/engine/internals/Controller.cpp
+++ b/src/engine/internals/Controller.cpp
@@ -38,36 +38,37 @@ using namespace Shared;
static InternalPlugin controller_plugin(NS_INTERNALS "Controller", "controller");
-ControllerNode::ControllerNode(const string& path,
- bool polyphonic,
- PatchImpl* parent,
- SampleRate srate,
- size_t buffer_size)
+ControllerNode::ControllerNode(BufferFactory& bufs,
+ const string& path,
+ bool polyphonic,
+ PatchImpl* parent,
+ SampleRate srate,
+ size_t buffer_size)
: NodeBase(&controller_plugin, path, false, parent, srate, buffer_size)
, _learning(false)
{
_ports = new Raul::Array<PortImpl*>(6);
- _midi_in_port = new InputPort(this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
+ _midi_in_port = new InputPort(bufs, this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
_ports->at(0) = _midi_in_port;
- _param_port = new InputPort(this, "controller", 1, 1, DataType::CONTROL, 0.0f, 1);
+ _param_port = new InputPort(bufs, this, "controller", 1, 1, DataType::CONTROL, 0.0f, sizeof(Sample));
_param_port->set_property("lv2:minimum", 0.0f);
_param_port->set_property("lv2:maximum", 127.0f);
_param_port->set_property("lv2:integer", true);
_ports->at(1) = _param_port;
- _log_port = new InputPort(this, "logarithmic", 2, 1, DataType::CONTROL, 0.0f, 1);
+ _log_port = new InputPort(bufs, this, "logarithmic", 2, 1, DataType::CONTROL, 0.0f, sizeof(Sample));
_log_port->set_property("lv2:toggled", true);
_ports->at(2) = _log_port;
- _min_port = new InputPort(this, "minimum", 3, 1, DataType::CONTROL, 0.0f, 1);
+ _min_port = new InputPort(bufs, this, "minimum", 3, 1, DataType::CONTROL, 0.0f, sizeof(Sample));
_ports->at(3) = _min_port;
- _max_port = new InputPort(this, "maximum", 4, 1, DataType::CONTROL, 1.0f, 1);
+ _max_port = new InputPort(bufs, this, "maximum", 4, 1, DataType::CONTROL, 1.0f, sizeof(Sample));
_ports->at(4) = _max_port;
- _audio_port = new OutputPort(this, "ar_output", 5, 1, DataType::AUDIO, 0.0f, _buffer_size);
+ _audio_port = new OutputPort(bufs, this, "ar_output", 5, 1, DataType::AUDIO, 0.0f, _buffer_size);
_ports->at(5) = _audio_port;
}
@@ -83,7 +84,7 @@ ControllerNode::process(ProcessContext& context)
uint16_t size = 0;
uint8_t* buf = NULL;
- EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
+ EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0).get();
midi_in->rewind();
@@ -110,15 +111,15 @@ ControllerNode::control(ProcessContext& context, uint8_t control_num, uint8_t va
if (_learning) {
_param_port->set_value(control_num);
- ((AudioBuffer*)_param_port->buffer(0))->set_value(
+ ((AudioBuffer*)_param_port->buffer(0).get())->set_value(
(float)control_num, context.start(), context.end());
_param_port->broadcast_value(context, true);
_learning = false;
}
- const Sample min_port_val = ((AudioBuffer*)_min_port->buffer(0))->value_at(0);
- const Sample max_port_val = ((AudioBuffer*)_max_port->buffer(0))->value_at(0);
- const Sample log_port_val = ((AudioBuffer*)_log_port->buffer(0))->value_at(0);
+ const Sample min_port_val = ((AudioBuffer*)_min_port->buffer(0).get())->value_at(0);
+ const Sample max_port_val = ((AudioBuffer*)_max_port->buffer(0).get())->value_at(0);
+ const Sample log_port_val = ((AudioBuffer*)_log_port->buffer(0).get())->value_at(0);
if (log_port_val > 0.0f) {
// haaaaack, stupid negatives and logarithms
@@ -132,8 +133,8 @@ ControllerNode::control(ProcessContext& context, uint8_t control_num, uint8_t va
scaled_value = ((nval) * (max_port_val - min_port_val)) + min_port_val;
}
- if (control_num == ((AudioBuffer*)_param_port->buffer(0))->value_at(0))
- ((AudioBuffer*)_audio_port->buffer(0))->set_value(scaled_value, context.start(), time);
+ if (control_num == ((AudioBuffer*)_param_port->buffer(0).get())->value_at(0))
+ ((AudioBuffer*)_audio_port->buffer(0).get())->set_value(scaled_value, context.start(), time);
}
diff --git a/src/engine/internals/Controller.hpp b/src/engine/internals/Controller.hpp
index 4f02a9ca..bca26ed5 100644
--- a/src/engine/internals/Controller.hpp
+++ b/src/engine/internals/Controller.hpp
@@ -39,7 +39,7 @@ namespace Internals {
class ControllerNode : public NodeBase
{
public:
- ControllerNode(const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
+ ControllerNode(BufferFactory& bufs, const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
void process(ProcessContext& context);
diff --git a/src/engine/internals/Note.cpp b/src/engine/internals/Note.cpp
index 4dc11891..ffe9ceca 100644
--- a/src/engine/internals/Note.cpp
+++ b/src/engine/internals/Note.cpp
@@ -40,7 +40,7 @@ using namespace Shared;
static InternalPlugin note_plugin(NS_INTERNALS "Note", "note");
-NoteNode::NoteNode(const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size)
+NoteNode::NoteNode(BufferFactory& bufs, const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size)
: NodeBase(&note_plugin, path, polyphonic, parent, srate, buffer_size)
, _voices(new Raul::Array<Voice>(_polyphony))
, _prepared_voices(NULL)
@@ -48,22 +48,22 @@ NoteNode::NoteNode(const string& path, bool polyphonic, PatchImpl* parent, Sampl
{
_ports = new Raul::Array<PortImpl*>(5);
- _midi_in_port = new InputPort(this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
+ _midi_in_port = new InputPort(bufs, this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
_ports->at(0) = _midi_in_port;
- _freq_port = new OutputPort(this, "frequency", 1, _polyphony, DataType::AUDIO, 440.0f, _buffer_size);
+ _freq_port = new OutputPort(bufs, this, "frequency", 1, _polyphony, DataType::AUDIO, 440.0f, _buffer_size);
_ports->at(1) = _freq_port;
- _vel_port = new OutputPort(this, "velocity", 2, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
+ _vel_port = new OutputPort(bufs, this, "velocity", 2, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
_vel_port->set_property("lv2:minimum", 0.0f);
_vel_port->set_property("lv2:maximum", 1.0f);
_ports->at(2) = _vel_port;
- _gate_port = new OutputPort(this, "gate", 3, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
+ _gate_port = new OutputPort(bufs, this, "gate", 3, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
_gate_port->set_property("lv2:toggled", true);
_ports->at(3) = _gate_port;
- _trig_port = new OutputPort(this, "trigger", 4, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
+ _trig_port = new OutputPort(bufs, this, "trigger", 4, _polyphony, DataType::AUDIO, 0.0f, _buffer_size);
_trig_port->set_property("lv2:toggled", true);
_ports->at(4) = _trig_port;
}
@@ -76,12 +76,12 @@ NoteNode::~NoteNode()
bool
-NoteNode::prepare_poly(uint32_t poly)
+NoteNode::prepare_poly(BufferFactory& bufs, uint32_t poly)
{
if (!_polyphonic)
return true;
- NodeBase::prepare_poly(poly);
+ NodeBase::prepare_poly(bufs, poly);
if (_prepared_voices && poly <= _prepared_voices->size())
return true;
@@ -117,7 +117,7 @@ NoteNode::apply_poly(Raul::Maid& maid, uint32_t poly)
void
NoteNode::process(ProcessContext& context)
{
- EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
+ EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0).get();
NodeBase::pre_process(context);
uint32_t frames = 0;
@@ -248,13 +248,18 @@ NoteNode::note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity, F
assert(_keys[voice->note].state == Key::Key::ON_ASSIGNED);
assert(_keys[voice->note].voice == voice_num);
- ((AudioBuffer*)_freq_port->buffer(voice_num))->set_value(note_to_freq(note_num), context.start(), time);
- ((AudioBuffer*)_vel_port->buffer(voice_num))->set_value(velocity/127.0, context.start(), time);
- ((AudioBuffer*)_gate_port->buffer(voice_num))->set_value(1.0f, context.start(), time);
+ ((AudioBuffer*)_freq_port->buffer(voice_num).get())->set_value(
+ note_to_freq(note_num), context.start(), time);
+ ((AudioBuffer*)_vel_port->buffer(voice_num).get())->set_value(
+ velocity/127.0, context.start(), time);
+ ((AudioBuffer*)_gate_port->buffer(voice_num).get())->set_value(
+ 1.0f, context.start(), time);
// trigger (one sample)
- ((AudioBuffer*)_trig_port->buffer(voice_num))->set_value(1.0f, context.start(), time);
- ((AudioBuffer*)_trig_port->buffer(voice_num))->set_value(0.0f, context.start(), time + 1);
+ ((AudioBuffer*)_trig_port->buffer(voice_num).get())->set_value(
+ 1.0f, context.start(), time);
+ ((AudioBuffer*)_trig_port->buffer(voice_num).get())->set_value(
+ 0.0f, context.start(), time + 1);
assert(key->state == Key::Key::ON_ASSIGNED);
assert(voice->state == Voice::Voice::ACTIVE);
@@ -321,7 +326,7 @@ NoteNode::free_voice(ProcessContext& context, uint32_t voice, FrameTime time)
assert(replace_key->state == Key::ON_UNASSIGNED);
// Change the freq but leave the gate high and don't retrigger
- ((AudioBuffer*)_freq_port->buffer(voice))->set_value(note_to_freq(replace_key_num), context.start(), time);
+ ((AudioBuffer*)_freq_port->buffer(voice).get())->set_value(note_to_freq(replace_key_num), context.start(), time);
replace_key->state = Key::ON_ASSIGNED;
replace_key->voice = voice;
@@ -331,7 +336,7 @@ NoteNode::free_voice(ProcessContext& context, uint32_t voice, FrameTime time)
} else {
// No new note for voice, deactivate (set gate low)
//cerr << "[NoteNode] Note off. Key " << (int)note_num << ", Voice " << voice << " Killed" << endl;
- ((AudioBuffer*)_gate_port->buffer(voice))->set_value(0.0f, context.start(), time);
+ ((AudioBuffer*)_gate_port->buffer(voice).get())->set_value(0.0f, context.start(), time);
(*_voices)[voice].state = Voice::FREE;
}
}
@@ -348,7 +353,7 @@ NoteNode::all_notes_off(ProcessContext& context, FrameTime time)
// FIXME: set all keys to Key::OFF?
for (uint32_t i = 0; i < _polyphony; ++i) {
- ((AudioBuffer*)_gate_port->buffer(i))->set_value(0.0f, context.start(), time);
+ ((AudioBuffer*)_gate_port->buffer(i).get())->set_value(0.0f, context.start(), time);
(*_voices)[i].state = Voice::FREE;
}
}
diff --git a/src/engine/internals/Note.hpp b/src/engine/internals/Note.hpp
index d4c4c851..7f091231 100644
--- a/src/engine/internals/Note.hpp
+++ b/src/engine/internals/Note.hpp
@@ -39,10 +39,10 @@ namespace Internals {
class NoteNode : public NodeBase
{
public:
- NoteNode(const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
+ NoteNode(BufferFactory& bufs, const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
~NoteNode();
- bool prepare_poly(uint32_t poly);
+ bool prepare_poly(BufferFactory& bufs, uint32_t poly);
bool apply_poly(Raul::Maid& maid, uint32_t poly);
void process(ProcessContext& context);
diff --git a/src/engine/internals/Transport.cpp b/src/engine/internals/Transport.cpp
deleted file mode 100644
index 8fccc436..00000000
--- a/src/engine/internals/Transport.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/* This file is part of Ingen.
- * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
- *
- * Ingen is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "internals/Transport.hpp"
-#include <jack/transport.h>
-#include "OutputPort.hpp"
-#include "InternalPlugin.hpp"
-#include "JackAudioDriver.hpp"
-#include "PortImpl.hpp"
-#include "util.hpp"
-//#include "Engine.hpp"
-
-using namespace std;
-
-namespace Ingen {
-namespace Internals {
-
-static InternalPlugin transport_plugin(NS_INTERNALS "Transport", "transport");
-
-TransportNode::TransportNode(const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size)
- : NodeBase(&transport_plugin, path, false, parent, srate, buffer_size)
-{
-#if 0
- _num_ports = 10;
- _ports.alloc(_num_ports);
-
- OutputPort<Sample>* spb_port = new OutputPort<Sample>(this, "Seconds per Beat", 0, 1,
- // new PortInfo("Seconds per Beat", CONTROL, OUTPUT, 0, 0, 1), 1);
- _ports.at(0) = spb_port;
-
- OutputPort<Sample>* bpb_port = new OutputPort<Sample>(this, "Beats per Bar", 1, 1,
- // new PortInfo("Beats per Bar", CONTROL, OUTPUT, 0, 0, 1), 1);
- _ports.at(1) = bpb_port;
-
- OutputPort<Sample>* bar_port = new OutputPort<Sample>(this, "Bar", 3, 1,
-// new PortInfo("Bar", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(2) = bar_port;
-
- OutputPort<Sample>* beat_port = new OutputPort<Sample>(this, "Beat", 3, 1,
- // new PortInfo("Beat", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(3) = beat_port;
-
- OutputPort<Sample>* frame_port = new OutputPort<Sample>(this, "Frame", 3, 1,
- // new PortInfo("Frame", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(4) = frame_port;
-
- OutputPort<Sample>* hour_port = new OutputPort<Sample>(this, "Hour", 3, 1,
- // new PortInfo("Hour", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(5) = hour_port;
-
- OutputPort<Sample>* minute_port = new OutputPort<Sample>(this, "Minute", 3, 1,
- // new PortInfo("Minute", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(6) = minute_port;
-
- OutputPort<Sample>* second_port = new OutputPort<Sample>(this, "Second", 3, 1,
- // new PortInfo("Second", CONTROL, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(7) = second_port;
-
- OutputPort<Sample>* trg_port = new OutputPort<Sample>(this, "Beat Tick", 2, 1,
- // new PortInfo("Beat Tick", AUDIO, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(8) = trg_port;
-
- OutputPort<Sample>* bar_trig_port = new OutputPort<Sample>(this, "Bar Tick", 3, 1,
- // new PortInfo("Bar Tick", AUDIO, OUTPUT, 0, 0, 1), buffer_size);
- _ports.at(9) = bar_trig_port;
-#endif
-}
-
-
-void
-TransportNode::process(ProcessContext& context)
-{
- NodeBase::pre_process(context);
-#if 0
-
- // FIXME: this will die horribly with any driver other than jack (in theory)
- const jack_position_t* const position = ((JackAudioDriver*)Engine::instance().audio_driver())->position();
- jack_transport_state_t state = ((JackAudioDriver*)Engine::instance().audio_driver())->transport_state();
- double bpm = position->beats_per_minute;
- float bpb = position->beats_per_bar;
- float spb = 60.0 / bpm;
-
- //cerr << "bpm = " << bpm << endl;
- //cerr << "spb = " << spb << endl;
-
- if (position->valid & JackPositionBBT) {
- cerr << "bar: " << position->bar << endl;
- cerr << "beat: " << position->beat << endl;
- cerr << "tick: " << position->tick << endl;
- } else {
- cerr << "No BBT" << endl;
- }
-
- if (position->valid & JackBBTFrameOffset) {
- cerr << "bbt_offset: " << position->bbt_offset << endl;
- } else {
- cerr << "No BBT offset" << endl;
- }
-
- if (position->valid & JackPositionTimecode) {
- double time = position->frame_time;
- cerr << "Seconds: " << time << " : " << endl;
- /*time /= 60.0;
- cerr << "Minutes: " << time << " : ";
- time /= 60.0;
- cerr << "Hours: " << time << " : ";*/
- } else {
- cerr << "No timecode." << endl;
- }
-
-
- ((OutputPort<Sample>*)_ports.at(0))->buffer(0)->set(spb, 0, 0);
- ((OutputPort<Sample>*)_ports.at(1))->buffer(0)->set(bpb, 0, 0);
-
- // fill the trigger buffers with zeros
- ((OutputPort<Sample>*)_ports.at(2))->buffer(0)->set(0.0f, 0, nframes - 1);
- ((OutputPort<Sample>*)_ports.at(3))->buffer(0)->set(0.0f, 0, nframes - 1);
-
- // if the transport is rolling, add triggers at the right frame positions
- if ((position->valid & JackTransportBBT) && (state == JackTransportRolling)) {
- double frames_per_beat = position->frame_rate * spb;
- double first_beat = (1.0f - position->tick / position->ticks_per_beat) * frames_per_beat;
- int first_beat_no = position->beat;
- if (first_beat >= frames_per_beat) {
- first_beat -= frames_per_beat;
- --first_beat_no;
- }
- for ( ; first_beat < nframes; first_beat += frames_per_beat) {
- ((OutputPort<Sample>*)_ports.at(2))->buffer(0)->set(1.0f, size_t(first_beat));
- if (first_beat_no % int(bpb) == 0) {
- ((OutputPort<Sample>*)_ports.at(3))->buffer(0)->set(1.0f, size_t(first_beat));
- ++first_beat_no;
- }
- }
- }
- #endif
-
- NodeBase::post_process(context);
-}
-
-
-} // namespace Ingen
-} // namespace Internals
-
diff --git a/src/engine/internals/Transport.hpp b/src/engine/internals/Transport.hpp
deleted file mode 100644
index 78e12f4f..00000000
--- a/src/engine/internals/Transport.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* This file is part of Ingen.
- * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
- *
- * Ingen is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef TRANSPORTNODE_H
-#define TRANSPORTNODE_H
-
-#include <string>
-#include <jack/transport.h>
-#include "NodeBase.hpp"
-
-namespace Ingen {
-namespace Internals {
-
-
-/** Transport Node, brings timing information into patches.
- *
- * This node uses the Jack transport API to get information about BPM, time
- * signature, etc.. all sample accurate. Using this you can do
- * tempo-synced effects or even synthesis, etc.
- */
-class TransportNode : public NodeBase
-{
-public:
- TransportNode(const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
-
- virtual void process(ProcessContext& context);
-};
-
-
-} // namespace Ingen
-} // namespace Internals
-
-#endif // TRANSPORTNODE_H
diff --git a/src/engine/internals/Trigger.cpp b/src/engine/internals/Trigger.cpp
index 428a1b8f..15251f88 100644
--- a/src/engine/internals/Trigger.cpp
+++ b/src/engine/internals/Trigger.cpp
@@ -35,30 +35,30 @@ using namespace Shared;
static InternalPlugin trigger_plugin(NS_INTERNALS "Trigger", "trigger");
-TriggerNode::TriggerNode(const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size)
+TriggerNode::TriggerNode(BufferFactory& bufs, const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size)
: NodeBase(&trigger_plugin, path, false, parent, srate, buffer_size)
, _learning(false)
{
_ports = new Raul::Array<PortImpl*>(5);
- _midi_in_port = new InputPort(this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
+ _midi_in_port = new InputPort(bufs, this, "input", 0, 1, DataType::EVENTS, Raul::Atom(), _buffer_size);
_ports->at(0) = _midi_in_port;
- _note_port = new InputPort(this, "note", 1, 1, DataType::CONTROL, 60.0f, 1);
+ _note_port = new InputPort(bufs, this, "note", 1, 1, DataType::CONTROL, 60.0f, sizeof(Sample));
_note_port->set_property("lv2:minimum", 0.0f);
_note_port->set_property("lv2:maximum", 127.0f);
_note_port->set_property("lv2:integer", true);
_ports->at(1) = _note_port;
- _gate_port = new OutputPort(this, "gate", 2, 1, DataType::AUDIO, 0.0f, _buffer_size);
+ _gate_port = new OutputPort(bufs, this, "gate", 2, 1, DataType::AUDIO, 0.0f, _buffer_size);
_gate_port->set_property("lv2:toggled", true);
_ports->at(2) = _gate_port;
- _trig_port = new OutputPort(this, "trigger", 3, 1, DataType::AUDIO, 0.0f, _buffer_size);
+ _trig_port = new OutputPort(bufs, this, "trigger", 3, 1, DataType::AUDIO, 0.0f, _buffer_size);
_trig_port->set_property("lv2:toggled", true);
_ports->at(3) = _trig_port;
- _vel_port = new OutputPort(this, "velocity", 4, 1, DataType::AUDIO, 0.0f, _buffer_size);
+ _vel_port = new OutputPort(bufs, this, "velocity", 4, 1, DataType::AUDIO, 0.0f, _buffer_size);
_vel_port->set_property("lv2:minimum", 0.0f);
_vel_port->set_property("lv2:maximum", 1.0f);
_ports->at(4) = _vel_port;
@@ -76,7 +76,7 @@ TriggerNode::process(ProcessContext& context)
uint16_t size = 0;
uint8_t* buf = NULL;
- EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
+ EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0).get();
midi_in->rewind();
@@ -97,7 +97,7 @@ TriggerNode::process(ProcessContext& context)
case MIDI_CMD_CONTROL:
if (buf[1] == MIDI_CTL_ALL_NOTES_OFF
|| buf[1] == MIDI_CTL_ALL_SOUNDS_OFF)
- ((AudioBuffer*)_gate_port->buffer(0))->set_value(0.0f, context.start(), time);
+ ((AudioBuffer*)_gate_port->buffer(0).get())->set_value(0.0f, context.start(), time);
default:
break;
}
@@ -118,7 +118,7 @@ TriggerNode::note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity
if (_learning) {
_note_port->set_value(note_num);
- ((AudioBuffer*)_note_port->buffer(0))->set_value(
+ ((AudioBuffer*)_note_port->buffer(0).get())->set_value(
(float)note_num, context.start(), context.end());
_note_port->broadcast_value(context, true);
_learning = false;
@@ -126,13 +126,13 @@ TriggerNode::note_on(ProcessContext& context, uint8_t note_num, uint8_t velocity
/*cerr << "[TriggerNode] " << path() << " Note " << (int)note_num << " on @ " << time << endl;*/
- Sample filter_note = ((AudioBuffer*)_note_port->buffer(0))->value_at(0);
+ Sample filter_note = ((AudioBuffer*)_note_port->buffer(0).get())->value_at(0);
if (filter_note >= 0.0 && filter_note < 127.0 && (note_num == (uint8_t)filter_note)) {
- ((AudioBuffer*)_gate_port->buffer(0))->set_value(1.0f, context.start(), time);
- ((AudioBuffer*)_trig_port->buffer(0))->set_value(1.0f, context.start(), time);
- ((AudioBuffer*)_trig_port->buffer(0))->set_value(0.0f, context.start(), time + 1);
- ((AudioBuffer*)_vel_port->buffer(0))->set_value(velocity / 127.0f, context.start(), time);
- assert(((AudioBuffer*)_trig_port->buffer(0))->data()[time - context.start()] == 1.0f);
+ ((AudioBuffer*)_gate_port->buffer(0).get())->set_value(1.0f, context.start(), time);
+ ((AudioBuffer*)_trig_port->buffer(0).get())->set_value(1.0f, context.start(), time);
+ ((AudioBuffer*)_trig_port->buffer(0).get())->set_value(0.0f, context.start(), time + 1);
+ ((AudioBuffer*)_vel_port->buffer(0).get())->set_value(velocity / 127.0f, context.start(), time);
+ assert(((AudioBuffer*)_trig_port->buffer(0).get())->data()[time - context.start()] == 1.0f);
}
}
@@ -143,8 +143,8 @@ TriggerNode::note_off(ProcessContext& context, uint8_t note_num, FrameTime time)
assert(time >= context.start() && time <= context.end());
assert(time - context.start() < _buffer_size);
- if (note_num == lrintf(((AudioBuffer*)_note_port->buffer(0))->value_at(0)))
- ((AudioBuffer*)_gate_port->buffer(0))->set_value(0.0f, context.start(), time);
+ if (note_num == lrintf(((AudioBuffer*)_note_port->buffer(0).get())->value_at(0)))
+ ((AudioBuffer*)_gate_port->buffer(0).get())->set_value(0.0f, context.start(), time);
}
diff --git a/src/engine/internals/Trigger.hpp b/src/engine/internals/Trigger.hpp
index dfb4f899..84281ac7 100644
--- a/src/engine/internals/Trigger.hpp
+++ b/src/engine/internals/Trigger.hpp
@@ -42,7 +42,7 @@ namespace Internals {
class TriggerNode : public NodeBase
{
public:
- TriggerNode(const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
+ TriggerNode(BufferFactory& bufs, const std::string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size);
void process(ProcessContext& context);