From 1b964e850bbe3207fe9a65849520634955d141f0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 29 Jan 2010 04:01:29 +0000 Subject: Send binding information to client. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2392 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/ControlBindings.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/engine/ControlBindings.cpp') diff --git a/src/engine/ControlBindings.cpp b/src/engine/ControlBindings.cpp index 00241b54..b74a3124 100644 --- a/src/engine/ControlBindings.cpp +++ b/src/engine/ControlBindings.cpp @@ -18,6 +18,7 @@ #include "raul/log.hpp" #include "raul/midi_events.h" #include "events/SendPortValue.hpp" +#include "events/SendBinding.hpp" #include "ControlBindings.hpp" #include "EventBuffer.hpp" #include "PortImpl.hpp" @@ -41,20 +42,34 @@ ControlBindings::learn(PortImpl* port) void -ControlBindings::set_port_value(ProcessContext& context, PortImpl* port, int8_t value) +ControlBindings::set_port_value(ProcessContext& context, PortImpl* port, int8_t cc_value) { + // TODO: cache these to avoid the lookup float min = port->get_property("lv2:minimum").get_float(); float max = port->get_property("lv2:maximum").get_float(); - Raul::Atom scaled_value(static_cast(((float)value / 127.0) * (max - min) + min)); - port->set_value(scaled_value); + Raul::Atom value(static_cast(((float)cc_value / 127.0) * (max - min) + min)); + port->set_value(value); const Events::SendPortValue ev(context.engine(), context.start(), port, true, 0, - scaled_value.get_float()); + value.get_float()); context.event_sink().write(sizeof(ev), &ev); } +void +ControlBindings::bind(ProcessContext& context, int8_t cc_num) +{ + _bindings.insert(make_pair(cc_num, _learn_port)); + + const Events::SendBinding ev(context.engine(), context.start(), _learn_port, + MessageType(MessageType::MIDI_CC, cc_num)); + context.event_sink().write(sizeof(ev), &ev); + + _learn_port = NULL; +} + + void ControlBindings::process(ProcessContext& context, EventBuffer* buffer) { @@ -69,8 +84,7 @@ ControlBindings::process(ProcessContext& context, EventBuffer* buffer) while (buffer->get_event(&frames, &subframes, &type, &size, &buf)) { if (type == _map->midi_event && (buf[0] & 0xF0) == MIDI_CMD_CONTROL) { const int8_t controller = static_cast(buf[1]); - _bindings.insert(make_pair(controller, _learn_port)); - _learn_port = NULL; + bind(context, controller); break; } buffer->increment(); -- cgit v1.2.1