From 44859a84f0bad75cb358dc1d91e5cfcdeda10ba7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 3 Feb 2010 06:08:08 +0000 Subject: Bind ports with lv2:portProperty lv2:toggled specially (on iff value >= half). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2410 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/ControlBindings.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/engine/ControlBindings.cpp') diff --git a/src/engine/ControlBindings.cpp b/src/engine/ControlBindings.cpp index 2144aba7..ee41bd51 100644 --- a/src/engine/ControlBindings.cpp +++ b/src/engine/ControlBindings.cpp @@ -69,8 +69,10 @@ void ControlBindings::set_port_value(ProcessContext& context, PortImpl* port, Type type, int16_t value) { // TODO: cache these to avoid the lookup - float min = port->get_property(Shared::LV2URIMap::instance().lv2_minimum).get_float(); - float max = port->get_property(Shared::LV2URIMap::instance().lv2_maximum).get_float(); + const Shared::LV2URIMap& uris = Shared::LV2URIMap::instance(); + float min = port->get_property(uris.lv2_minimum).get_float(); + float max = port->get_property(uris.lv2_maximum).get_float(); + bool toggled = port->has_property(uris.lv2_portProperty, uris.lv2_toggled); float normal; switch (type) { @@ -84,7 +86,11 @@ ControlBindings::set_port_value(ProcessContext& context, PortImpl* port, Type ty break; } - Raul::Atom atom(static_cast(normal * (max - min) + min)); + float scaled_value = normal * (max - min) + min; + if (toggled) + scaled_value = (scaled_value < 0.5) ? 0.0 : 1.0; + + Raul::Atom atom(scaled_value); port->set_value(atom); const Events::SendPortValue ev(context.engine(), context.start(), port, true, 0, -- cgit v1.2.1