summaryrefslogtreecommitdiffstats
path: root/src/libs/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/engine')
-rw-r--r--src/libs/engine/LADSPANode.cpp79
-rw-r--r--src/libs/engine/LADSPANode.h1
-rw-r--r--src/libs/engine/LV2Node.cpp3
-rw-r--r--src/libs/engine/ObjectSender.cpp8
-rw-r--r--src/libs/engine/events/DisconnectionEvent.cpp75
5 files changed, 122 insertions, 44 deletions
diff --git a/src/libs/engine/LADSPANode.cpp b/src/libs/engine/LADSPANode.cpp
index 17a3e53d..da053b35 100644
--- a/src/libs/engine/LADSPANode.cpp
+++ b/src/libs/engine/LADSPANode.cpp
@@ -111,11 +111,7 @@ LADSPANode::instantiate()
}
assert(_ports->at(j) != NULL);
-
- /*PortInfo* pi = port->port_info();
- get_port_vals(j, pi);
- */
- float default_val = 0.; // FIXME
+ sample default_val = default_port_value(j);
// Set default control val
if (port->buffer_size() == 1)
@@ -264,5 +260,78 @@ LADSPANode::get_port_vals(ulong port_index, PortInfo* info)
}
#endif
+
+sample
+LADSPANode::default_port_value(ulong port_index)
+{
+ LADSPA_Data normal = 0.0f;
+ LADSPA_Data upper = 0.0f;
+ LADSPA_Data lower = 0.0f;
+ LADSPA_PortRangeHintDescriptor hint_descriptor = _descriptor->PortRangeHints[port_index].HintDescriptor;
+
+ /* set upper and lower, possibly adjusted to the sample rate */
+ if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
+ upper = _descriptor->PortRangeHints[port_index].UpperBound * _srate;
+ lower = _descriptor->PortRangeHints[port_index].LowerBound * _srate;
+ } else {
+ upper = _descriptor->PortRangeHints[port_index].UpperBound;
+ lower = _descriptor->PortRangeHints[port_index].LowerBound;
+ }
+
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ /* FLT_EPSILON is defined as the different between 1.0 and the minimum
+ * float greater than 1.0. So, if lower is < FLT_EPSILON, it will be 1.0
+ * and the logarithmic control will have a base of 1 and thus not change
+ */
+ if (lower < FLT_EPSILON) lower = FLT_EPSILON;
+ }
+
+
+ if (LADSPA_IS_HINT_HAS_DEFAULT(hint_descriptor)) {
+
+ if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_descriptor)) {
+ normal = lower;
+ } else if (LADSPA_IS_HINT_DEFAULT_LOW(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.75 + log(upper) * 0.25);
+ } else {
+ normal = lower * 0.75 + upper * 0.25;
+ }
+ } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.5 + log(upper) * 0.5);
+ } else {
+ normal = lower * 0.5 + upper * 0.5;
+ }
+ } else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint_descriptor)) {
+ if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
+ normal = exp(log(lower) * 0.25 + log(upper) * 0.75);
+ } else {
+ normal = lower * 0.25 + upper * 0.75;
+ }
+ } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_descriptor)) {
+ normal = upper;
+ } else if (LADSPA_IS_HINT_DEFAULT_0(hint_descriptor)) {
+ normal = 0.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_1(hint_descriptor)) {
+ normal = 1.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_100(hint_descriptor)) {
+ normal = 100.0;
+ } else if (LADSPA_IS_HINT_DEFAULT_440(hint_descriptor)) {
+ normal = 440.0;
+ }
+ } else { // No default hint
+ if (LADSPA_IS_HINT_BOUNDED_BELOW(hint_descriptor)) {
+ normal = lower;
+ } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint_descriptor)) {
+ normal = upper;
+ }
+ }
+
+ // FIXME: set min/max as metadata
+ return normal;
+}
+
+
} // namespace Om
diff --git a/src/libs/engine/LADSPANode.h b/src/libs/engine/LADSPANode.h
index 8efbc1ff..5abaf3a9 100644
--- a/src/libs/engine/LADSPANode.h
+++ b/src/libs/engine/LADSPANode.h
@@ -54,6 +54,7 @@ protected:
LADSPANode& operator=(const LADSPANode&);
//void get_port_vals(ulong port_index, PortInfo* info);
+ sample default_port_value(ulong port_index);
const LADSPA_Descriptor* _descriptor;
LADSPA_Handle* _instances;
diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp
index 562f7d9b..c94c9c01 100644
--- a/src/libs/engine/LV2Node.cpp
+++ b/src/libs/engine/LV2Node.cpp
@@ -59,7 +59,8 @@ LV2Node::instantiate()
{
size_t num_ports = slv2_plugin_get_num_ports(_lv2_plugin);
assert(num_ports > 0);
- _ports->alloc(num_ports);
+
+ _ports = new Array<Port*>(num_ports);
_instances = new SLV2Instance*[_poly];
diff --git a/src/libs/engine/ObjectSender.cpp b/src/libs/engine/ObjectSender.cpp
index c7a008d7..33f261fb 100644
--- a/src/libs/engine/ObjectSender.cpp
+++ b/src/libs/engine/ObjectSender.cpp
@@ -72,7 +72,8 @@ ObjectSender::send_patch(ClientInterface* client, const Patch* patch)
// Control port, send value
if (port->type() == DataType::FLOAT && port->buffer_size() == 1)
- client->control_change(port->path(), dynamic_cast<TypedPort<sample>*>(port)->buffer(0)->value_at(0));
+ client->control_change(port->path(),
+ dynamic_cast<TypedPort<sample>*>(port)->buffer(0)->value_at(0));
}
// Send metadata
@@ -161,6 +162,11 @@ ObjectSender::send_port(ClientInterface* client, const Port* port)
client->new_port(port->path(), type, port->is_output());
+ // Send control value
+ if (port->type() == DataType::FLOAT && port->buffer_size() == 1)
+ client->control_change(port->path(),
+ dynamic_cast<const TypedPort<sample>*>(port)->buffer(0)->value_at(0));
+
// Send metadata
const map<string, string>& data = port->metadata();
for (map<string, string>::const_iterator j = data.begin(); j != data.end(); ++j)
diff --git a/src/libs/engine/events/DisconnectionEvent.cpp b/src/libs/engine/events/DisconnectionEvent.cpp
index f3524500..f2f54387 100644
--- a/src/libs/engine/events/DisconnectionEvent.cpp
+++ b/src/libs/engine/events/DisconnectionEvent.cpp
@@ -96,48 +96,49 @@ DisconnectionEvent::pre_process()
m_src_port = om->object_store()->find_port(m_src_port_path);
m_dst_port = om->object_store()->find_port(m_dst_port_path);
+ }
+
+ if (m_src_port == NULL || m_dst_port == NULL) {
+ m_error = PORT_NOT_FOUND;
+ QueuedEvent::pre_process();
+ return;
+ }
- if (m_src_port == NULL || m_dst_port == NULL) {
- m_error = PORT_NOT_FOUND;
- QueuedEvent::pre_process();
- return;
- }
-
- if (m_src_port->type() != m_dst_port->type() || m_src_port->buffer_size() != m_dst_port->buffer_size()) {
- m_error = TYPE_MISMATCH;
- QueuedEvent::pre_process();
- return;
- }
-
- /*if (port1->is_output() && port2->is_input()) {
- m_src_port = port1;
- m_dst_port = port2;
- } else if (port2->is_output() && port1->is_input()) {
- m_src_port = port2;
- m_dst_port = port1;
- } else {
- m_error = TYPE_MISMATCH;
- QueuedEvent::pre_process();
- return;
- }*/
+ if (m_src_port->type() != m_dst_port->type() || m_src_port->buffer_size() != m_dst_port->buffer_size()) {
+ m_error = TYPE_MISMATCH;
+ QueuedEvent::pre_process();
+ return;
+ }
- // Create the typed event to actually do the work
- const DataType type = m_src_port->type();
- if (type == DataType::FLOAT) {
- m_typed_event = new TypedDisconnectionEvent<sample>(m_responder,
- dynamic_cast<OutputPort<sample>*>(m_src_port), dynamic_cast<InputPort<sample>*>(m_dst_port));
- } else if (type == DataType::MIDI) {
- m_typed_event = new TypedDisconnectionEvent<MidiMessage>(m_responder,
- dynamic_cast<OutputPort<MidiMessage>*>(m_src_port), dynamic_cast<InputPort<MidiMessage>*>(m_dst_port));
- } else {
- m_error = TYPE_MISMATCH;
- QueuedEvent::pre_process();
- return;
- }
+ /*if (port1->is_output() && port2->is_input()) {
+ m_src_port = port1;
+ m_dst_port = port2;
+ } else if (port2->is_output() && port1->is_input()) {
+ m_src_port = port2;
+ m_dst_port = port1;
+ } else {
+ m_error = TYPE_MISMATCH;
+ QueuedEvent::pre_process();
+ return;
+ }*/
+
+ // Create the typed event to actually do the work
+ const DataType type = m_src_port->type();
+ if (type == DataType::FLOAT) {
+ m_typed_event = new TypedDisconnectionEvent<sample>(m_responder,
+ dynamic_cast<OutputPort<sample>*>(m_src_port), dynamic_cast<InputPort<sample>*>(m_dst_port));
+ } else if (type == DataType::MIDI) {
+ m_typed_event = new TypedDisconnectionEvent<MidiMessage>(m_responder,
+ dynamic_cast<OutputPort<MidiMessage>*>(m_src_port), dynamic_cast<InputPort<MidiMessage>*>(m_dst_port));
+ } else {
+ m_error = TYPE_MISMATCH;
+ QueuedEvent::pre_process();
+ return;
}
+ assert(m_typed_event);
m_typed_event->pre_process();
-
+
QueuedEvent::pre_process();
}