summaryrefslogtreecommitdiffstats
path: root/src/libs/engine
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-10-13 22:15:26 +0000
committerDavid Robillard <d@drobilla.net>2007-10-13 22:15:26 +0000
commit1c92f8782006264e94dd25a650841f72f91650cf (patch)
tree7791a64365510fc1599cdbdb998ae95e929c84f5 /src/libs/engine
parentcf63c971c2a8ee8cc2ddcddb52ce8135cd29619b (diff)
downloadingen-1c92f8782006264e94dd25a650841f72f91650cf.tar.gz
ingen-1c92f8782006264e94dd25a650841f72f91650cf.tar.bz2
ingen-1c92f8782006264e94dd25a650841f72f91650cf.zip
Dynamic polyphony fixes.
git-svn-id: http://svn.drobilla.net/lad/ingen@883 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine')
-rw-r--r--src/libs/engine/LADSPANode.cpp72
-rw-r--r--src/libs/engine/LADSPANode.hpp11
-rw-r--r--src/libs/engine/LV2Node.cpp35
-rw-r--r--src/libs/engine/LV2Node.hpp6
-rw-r--r--src/libs/engine/NodeBase.cpp2
5 files changed, 86 insertions, 40 deletions
diff --git a/src/libs/engine/LADSPANode.cpp b/src/libs/engine/LADSPANode.cpp
index 033f3d50..f8ecb1f5 100644
--- a/src/libs/engine/LADSPANode.cpp
+++ b/src/libs/engine/LADSPANode.cpp
@@ -19,6 +19,7 @@
#include <cassert>
#include <cmath>
#include <stdint.h>
+#include <raul/Maid.hpp>
#include "LADSPANode.hpp"
#include "AudioBuffer.hpp"
#include "InputPort.hpp"
@@ -37,14 +38,63 @@ namespace Ingen {
* (It _will_ crash!)
*/
LADSPANode::LADSPANode(PluginImpl* plugin, const string& path, bool polyphonic, PatchImpl* parent, const LADSPA_Descriptor* descriptor, SampleRate srate, size_t buffer_size)
-: NodeBase(plugin, path, polyphonic, parent, srate, buffer_size),
- _descriptor(descriptor),
- _instances(NULL)
+ : NodeBase(plugin, path, polyphonic, parent, srate, buffer_size)
+ , _descriptor(descriptor)
+ , _instances(NULL)
+ , _prepared_instances(NULL)
{
assert(_descriptor != NULL);
}
+bool
+LADSPANode::prepare_poly(uint32_t poly)
+{
+ NodeBase::prepare_poly(poly);
+
+ if ( (!_polyphonic)
+ || (_prepared_instances && poly <= _prepared_instances->size()) ) {
+ return true;
+ }
+
+ _prepared_instances = new Raul::Array<LADSPA_Handle>(poly, *_instances);
+ for (uint32_t i = _polyphony; i < _prepared_instances->size(); ++i) {
+ _prepared_instances->at(i) = _descriptor->instantiate(_descriptor, _srate);
+ if ((*_prepared_instances)[i] == NULL) {
+ cerr << "Failed to instantiate plugin!" << endl;
+ return false;
+ }
+
+ if (_activated)
+ _descriptor->activate((*_prepared_instances)[i]);
+ }
+
+ return true;
+}
+
+
+bool
+LADSPANode::apply_poly(Raul::Maid& maid, uint32_t poly)
+{
+ if (!_polyphonic)
+ return true;
+
+ if (_prepared_instances) {
+ assert(poly <= _prepared_instances->size());
+ maid.push(_instances);
+ _instances = _prepared_instances;
+ _prepared_instances = NULL;
+ }
+
+ assert(poly <= _instances->size());
+ _polyphony = poly;
+
+ NodeBase::apply_poly(maid, poly);
+
+ return true;
+}
+
+
/** Instantiate self from LADSPA plugin descriptor.
*
* Implemented as a seperate function (rather than in the constructor) to
@@ -59,13 +109,13 @@ LADSPANode::instantiate()
if (!_ports)
_ports = new Raul::Array<PortImpl*>(_descriptor->PortCount);
- _instances = new LADSPA_Handle[_polyphony];
+ _instances = new Raul::Array<LADSPA_Handle>(_polyphony, NULL);
size_t port_buffer_size = 0;
for (uint32_t i=0; i < _polyphony; ++i) {
- _instances[i] = _descriptor->instantiate(_descriptor, _srate);
- if (_instances[i] == NULL) {
+ (*_instances)[i] = _descriptor->instantiate(_descriptor, _srate);
+ if ((*_instances)[i] == NULL) {
cerr << "Failed to instantiate plugin!" << endl;
return false;
}
@@ -157,7 +207,7 @@ LADSPANode::instantiate()
LADSPANode::~LADSPANode()
{
for (uint32_t i=0; i < _polyphony; ++i)
- _descriptor->cleanup(_instances[i]);
+ _descriptor->cleanup((*_instances)[i]);
delete[] _instances;
}
@@ -177,7 +227,7 @@ LADSPANode::activate()
port->set_value(0.0f, 0);*/
}
if (_descriptor->activate != NULL)
- _descriptor->activate(_instances[i]);
+ _descriptor->activate((*_instances)[i]);
}
}
@@ -189,7 +239,7 @@ LADSPANode::deactivate()
for (uint32_t i=0; i < _polyphony; ++i)
if (_descriptor->deactivate != NULL)
- _descriptor->deactivate(_instances[i]);
+ _descriptor->deactivate((*_instances)[i]);
}
@@ -199,7 +249,7 @@ LADSPANode::process(ProcessContext& context)
NodeBase::pre_process(context);
for (uint32_t i=0; i < _polyphony; ++i)
- _descriptor->run(_instances[i], context.nframes());
+ _descriptor->run((*_instances)[i], context.nframes());
NodeBase::post_process(context);
}
@@ -214,7 +264,7 @@ LADSPANode::set_port_buffer(uint32_t voice, uint32_t port_num, Buffer* buf)
assert(audio_buffer);
if (port_num < _descriptor->PortCount)
- _descriptor->connect_port(_instances[voice], port_num,
+ _descriptor->connect_port((*_instances)[voice], port_num,
audio_buffer->data());
}
diff --git a/src/libs/engine/LADSPANode.hpp b/src/libs/engine/LADSPANode.hpp
index 6d6cd442..abadcf9f 100644
--- a/src/libs/engine/LADSPANode.hpp
+++ b/src/libs/engine/LADSPANode.hpp
@@ -42,9 +42,12 @@ public:
SampleRate srate,
size_t buffer_size);
- virtual ~LADSPANode();
+ ~LADSPANode();
- virtual bool instantiate();
+ bool instantiate();
+
+ bool prepare_poly(uint32_t poly);
+ bool apply_poly(Raul::Maid& maid, uint32_t poly);
void activate();
void deactivate();
@@ -54,11 +57,11 @@ public:
void set_port_buffer(uint32_t voice, uint32_t port_num, Buffer* buf);
protected:
- //void get_port_vals(ulong port_index, PortInfo* info);
void get_port_limits(unsigned long port_index, Sample& default_value, Sample& lower_bound, Sample& upper_bound);
const LADSPA_Descriptor* _descriptor;
- LADSPA_Handle* _instances;
+ Raul::Array<LADSPA_Handle>* _instances;
+ Raul::Array<LADSPA_Handle>* _prepared_instances;
};
diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp
index bfcc619a..eb8f86b7 100644
--- a/src/libs/engine/LV2Node.cpp
+++ b/src/libs/engine/LV2Node.cpp
@@ -58,14 +58,13 @@ LV2Node::LV2Node(PluginImpl* plugin,
bool
LV2Node::prepare_poly(uint32_t poly)
{
- if (!_polyphonic)
- return true;
-
NodeBase::prepare_poly(poly);
-
- if (_prepared_instances && poly <= _prepared_instances->size())
- return true;
+ if ( (!_polyphonic)
+ || (_prepared_instances && poly <= _prepared_instances->size()) ) {
+ return true;
+ }
+
_prepared_instances = new Raul::Array<SLV2Instance>(poly, *_instances);
for (uint32_t i = _polyphony; i < _prepared_instances->size(); ++i) {
_prepared_instances->at(i) = slv2_plugin_instantiate(_lv2_plugin, _srate, NULL);
@@ -88,22 +87,14 @@ LV2Node::apply_poly(Raul::Maid& maid, uint32_t poly)
if (!_polyphonic)
return true;
- assert(poly <= _prepared_instances->size());
-
if (_prepared_instances) {
+ assert(poly <= _prepared_instances->size());
maid.push(_instances);
_instances = _prepared_instances;
-
-#if 0
- for (uint32_t port=0; port < num_ports(); ++port)
- for (uint32_t voice = /*_polyphony*/0; voice < _prepared_instances->size(); ++voice)
- slv2_instance_connect_port((*_instances)[voice], port,
- _ports->at(port)->buffer(voice)->raw_data());
-#endif
-
_prepared_instances = NULL;
}
+ assert(poly <= _instances->size());
_polyphony = poly;
NodeBase::apply_poly(maid, poly);
@@ -219,12 +210,16 @@ LV2Node::activate()
for (uint32_t i=0; i < _polyphony; ++i) {
for (unsigned long j=0; j < num_ports(); ++j) {
PortImpl* const port = _ports->at(j);
+
set_port_buffer(i, j, port->buffer(i));
+
if (port->type() == DataType::CONTROL) {
- ((AudioBuffer*)port->buffer(i))->set(
- slv2_port_get_default_value(_lv2_plugin,
- slv2_plugin_get_port_by_index(_lv2_plugin, j)),
- 0);
+
+ const float val = slv2_port_get_default_value(_lv2_plugin,
+ slv2_plugin_get_port_by_index(_lv2_plugin, j));
+
+ ((AudioBuffer*)port->buffer(i))->set(val, 0);
+
} else if (port->type() == DataType::AUDIO) {
((AudioBuffer*)port->buffer(i))->set(0.0f, 0);
}
diff --git a/src/libs/engine/LV2Node.hpp b/src/libs/engine/LV2Node.hpp
index dbd79671..b0257bb8 100644
--- a/src/libs/engine/LV2Node.hpp
+++ b/src/libs/engine/LV2Node.hpp
@@ -41,9 +41,9 @@ public:
SampleRate srate,
size_t buffer_size);
- virtual ~LV2Node();
+ ~LV2Node();
- virtual bool instantiate();
+ bool instantiate();
bool prepare_poly(uint32_t poly);
bool apply_poly(Raul::Maid& maid, uint32_t poly);
@@ -56,8 +56,6 @@ public:
void set_port_buffer(uint32_t voice, uint32_t port_num, Buffer* buf);
protected:
- //void get_port_vals(ulong port_index, PortInfo* info);
-
SLV2Plugin _lv2_plugin;
Raul::Array<SLV2Instance>* _instances;
Raul::Array<SLV2Instance>* _prepared_instances;
diff --git a/src/libs/engine/NodeBase.cpp b/src/libs/engine/NodeBase.cpp
index 78825e7a..6fe320e8 100644
--- a/src/libs/engine/NodeBase.cpp
+++ b/src/libs/engine/NodeBase.cpp
@@ -116,7 +116,7 @@ NodeBase::apply_poly(Raul::Maid& maid, uint32_t poly)
if (_ports)
for (size_t i=0; i < _ports->size(); ++i)
_ports->at(i)->apply_poly(maid, poly);
-
+
return true;
}