summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-02-03 07:20:14 +0000
committerDavid Robillard <d@drobilla.net>2010-02-03 07:20:14 +0000
commit60968da24dd2b92fc392d1b91e73245770b5a4af (patch)
tree229be9f4a1ef68c6b96c06aec53fcc39bf981d49 /src
parentf186268d94b6435614c58d369f157fa203b04850 (diff)
downloadingen-60968da24dd2b92fc392d1b91e73245770b5a4af.tar.gz
ingen-60968da24dd2b92fc392d1b91e73245770b5a4af.tar.bz2
ingen-60968da24dd2b92fc392d1b91e73245770b5a4af.zip
Binding of MIDI notes to toggle parameters.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2412 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/engine/ControlBindings.cpp42
-rw-r--r--src/engine/ControlBindings.hpp3
-rw-r--r--src/engine/events/SendBinding.cpp3
-rw-r--r--src/shared/LV2URIMap.cpp2
-rw-r--r--src/shared/LV2URIMap.hpp2
5 files changed, 43 insertions, 9 deletions
diff --git a/src/engine/ControlBindings.cpp b/src/engine/ControlBindings.cpp
index ee41bd51..0c31c731 100644
--- a/src/engine/ControlBindings.cpp
+++ b/src/engine/ControlBindings.cpp
@@ -41,16 +41,22 @@ ControlBindings::update_port(ProcessContext& context, PortImpl* port)
const Raul::Atom& binding = port->get_property(uris.ingen_controlBinding);
if (binding.type() == Atom::DICT) {
Atom::DictValue::const_iterator t = binding.get_dict().find(uris.rdf_type);
- Atom::DictValue::const_iterator n = binding.get_dict().find(uris.midi_controllerNumber);
- if (t != binding.get_dict().end() && n != binding.get_dict().end()) {
- if (t->second == uris.midi_Controller) {
- _bindings->insert(make_pair(Key(MIDI_CC, n->second.get_int32()), port));
+ Atom::DictValue::const_iterator n;
+ if (t != binding.get_dict().end()) {
+ if (t->second == uris.midi_Bender) {
+ _bindings->insert(make_pair(Key(MIDI_BENDER), port));
} else if (t->second == uris.midi_Bender) {
_bindings->insert(make_pair(Key(MIDI_BENDER), port));
} else if (t->second == uris.midi_ChannelPressure) {
_bindings->insert(make_pair(Key(MIDI_CHANNEL_PRESSURE), port));
- } else {
- error << "Unknown binding type " << t->second << endl;
+ } else if (t->second == uris.midi_Controller) {
+ n = binding.get_dict().find(uris.midi_controllerNumber);
+ if (n != binding.get_dict().end())
+ _bindings->insert(make_pair(Key(MIDI_CC, n->second.get_int32()), port));
+ } else if (t->second == uris.midi_Note) {
+ n = binding.get_dict().find(uris.midi_noteNumber);
+ if (n != binding.get_dict().end())
+ _bindings->insert(make_pair(Key(MIDI_NOTE, n->second.get_int32()), port));
}
}
}
@@ -78,10 +84,14 @@ ControlBindings::set_port_value(ProcessContext& context, PortImpl* port, Type ty
switch (type) {
case MIDI_CC:
case MIDI_CHANNEL_PRESSURE:
- normal = (float)value / 127.0;
+ normal = (float)value / 127.0f;
break;
case MIDI_BENDER:
- normal = (float)value / 16383.0;
+ normal = (float)value / 16383.0f;
+ break;
+ case MIDI_NOTE:
+ normal = (value == 0.0f) ? 0.0f : 1.0f;
+ break;
default:
break;
}
@@ -162,6 +172,10 @@ ControlBindings::process(ProcessContext& context, EventBuffer* buffer)
case MIDI_CMD_CHANNEL_PRESSURE:
bind(context, MIDI_CHANNEL_PRESSURE);
break;
+ case MIDI_CMD_NOTE_ON:
+ num = static_cast<const int8_t>(buf[1]);
+ bind(context, MIDI_NOTE, num);
+ break;
default:
break;
}
@@ -197,6 +211,18 @@ ControlBindings::process(ProcessContext& context, EventBuffer* buffer)
const int8_t value = static_cast<const int8_t>(buf[1]);
set_port_value(context, i->second, MIDI_CHANNEL_PRESSURE, value);
}
+ } else if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
+ const int8_t num = static_cast<const int8_t>(buf[1]);
+ Bindings::const_iterator i = bindings->find(Key(MIDI_NOTE, num));
+ if (i != bindings->end()) {
+ set_port_value(context, i->second, MIDI_NOTE, 1.0f);
+ }
+ } else if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_OFF) {
+ const int8_t num = static_cast<const int8_t>(buf[1]);
+ Bindings::const_iterator i = bindings->find(Key(MIDI_NOTE, num));
+ if (i != bindings->end()) {
+ set_port_value(context, i->second, MIDI_NOTE, 0.0f);
+ }
}
}
buffer->increment();
diff --git a/src/engine/ControlBindings.hpp b/src/engine/ControlBindings.hpp
index bae3cc73..092a2730 100644
--- a/src/engine/ControlBindings.hpp
+++ b/src/engine/ControlBindings.hpp
@@ -38,7 +38,8 @@ public:
MIDI_CC,
MIDI_RPN,
MIDI_NRPN,
- MIDI_CHANNEL_PRESSURE
+ MIDI_CHANNEL_PRESSURE,
+ MIDI_NOTE
};
struct Key {
diff --git a/src/engine/events/SendBinding.cpp b/src/engine/events/SendBinding.cpp
index 8cc03c79..c3c83ea4 100644
--- a/src/engine/events/SendBinding.cpp
+++ b/src/engine/events/SendBinding.cpp
@@ -40,6 +40,9 @@ SendBinding::post_process()
dict[uris.rdf_type] = uris.midi_Bender;
} else if (_type == ControlBindings::MIDI_CHANNEL_PRESSURE) {
dict[uris.rdf_type] = uris.midi_ChannelPressure;
+ } else if (_type == ControlBindings::MIDI_NOTE) {
+ dict[uris.rdf_type] = uris.midi_Note;
+ dict[uris.midi_noteNumber] = _num;
}
// TODO: other event types
_port->set_property(uris.ingen_controlBinding, dict); // FIXME: thread unsafe
diff --git a/src/shared/LV2URIMap.cpp b/src/shared/LV2URIMap.cpp
index 9a4ae7c7..5717a4a9 100644
--- a/src/shared/LV2URIMap.cpp
+++ b/src/shared/LV2URIMap.cpp
@@ -87,8 +87,10 @@ LV2URIMap::LV2URIMap()
, midi_Bender(NS_MIDI "Bender")
, midi_ChannelPressure(NS_MIDI "ChannelPressure")
, midi_Controller(NS_MIDI "Controller")
+ , midi_Note(NS_MIDI "Note")
, midi_controllerNumber(NS_MIDI "controllerNumber")
, midi_event("http://lv2plug.in/ns/ext/midi#MidiEvent")
+ , midi_noteNumber(NS_MIDI "noteNumber")
, obj_MessagePort("http://lv2plug.in/ns/dev/objects#MessagePort")
, obj_ValuePort("http://lv2plug.in/ns/dev/objects#ValuePort")
, object_class_bool(LV2_OBJECT_URI "#Bool")
diff --git a/src/shared/LV2URIMap.hpp b/src/shared/LV2URIMap.hpp
index 923312c5..d14314b7 100644
--- a/src/shared/LV2URIMap.hpp
+++ b/src/shared/LV2URIMap.hpp
@@ -95,8 +95,10 @@ public:
const Quark midi_Bender;
const Quark midi_ChannelPressure;
const Quark midi_Controller;
+ const Quark midi_Note;
const Quark midi_controllerNumber;
const Quark midi_event;
+ const Quark midi_noteNumber;
const Quark obj_MessagePort;
const Quark obj_ValuePort;
const Quark object_class_bool;