summaryrefslogtreecommitdiff
path: root/libs/surfaces/generic_midi
diff options
context:
space:
mode:
authorJan Lentfer <jan.lentfer@web.de>2018-03-03 14:04:12 +0100
committerJan Lentfer <jan.lentfer@web.de>2018-03-03 14:04:12 +0100
commita2af019c95243fb8ee738e7cdd240885ce4ee103 (patch)
tree672e0d2dd3854d8f3a4477b02b14f794685a524d /libs/surfaces/generic_midi
parent7e5a488d811dda42a13363599dbbdddc31128b71 (diff)
generic_midi: add proper handling of midi controll toggles
Diffstat (limited to 'libs/surfaces/generic_midi')
-rw-r--r--libs/surfaces/generic_midi/generic_midi_control_protocol.cc6
-rw-r--r--libs/surfaces/generic_midi/midicontrollable.cc12
-rw-r--r--libs/surfaces/generic_midi/midicontrollable.h9
3 files changed, 26 insertions, 1 deletions
diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
index 4d394e5082..1e1bda82e2 100644
--- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
+++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
@@ -813,6 +813,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
MIDI::eventType ev;
int intval;
bool momentary;
+ MIDIControllable::CtlType ctltype;
MIDIControllable::Encoder encoder = MIDIControllable::No_enc;
bool rpn_value = false;
bool nrpn_value = false;
@@ -820,6 +821,10 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
bool nrpn_change = false;
if ((prop = node.property (X_("ctl"))) != 0) {
+ ctltype = MIDIControllable::Ctl_Momentary;
+ ev = MIDI::controller;
+ } else if ((prop = node.property (X_("ctl-toggle"))) !=0) {
+ ctltype = MIDIControllable::Ctl_Toggle;
ev = MIDI::controller;
} else if ((prop = node.property (X_("note"))) != 0) {
ev = MIDI::on;
@@ -895,6 +900,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
} else if (nrpn_change) {
mc->bind_nrpn_change (channel, detail);
} else {
+ mc->set_ctltype (ctltype);
mc->set_encoder (encoder);
mc->bind_midi (channel, ev, detail);
}
diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc
index 92c86d665c..fe592965ee 100644
--- a/libs/surfaces/generic_midi/midicontrollable.cc
+++ b/libs/surfaces/generic_midi/midicontrollable.cc
@@ -54,6 +54,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
, _momentary (m)
{
_learned = false; /* from URI */
+ _ctltype = Ctl_Momentary;
_encoder = No_enc;
setting = false;
last_value = 0; // got a better idea ?
@@ -74,6 +75,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
set_controllable (&c);
_learned = true; /* from controllable */
+ _ctltype = Ctl_Momentary;
_encoder = No_enc;
setting = false;
last_value = 0; // got a better idea ?
@@ -392,10 +394,18 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
* (0x40). It is hard to imagine why anyone would make
* a MIDI controller button that sent 0x0 when pressed.
*/
-
if (msg->value >= 0x40) {
controllable->set_value (controllable->get_value() >= 0.5 ? 0.0 : 1.0, Controllable::UseGroup);
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Midi CC %1 value 1 %2\n", (int) msg->controller_number, current_uri()));
+ } else {
+ switch (get_ctltype()) {
+ case Ctl_Momentary:
+ break;
+ case Ctl_Toggle:
+ controllable->set_value (0.0, Controllable::NoGroup);
+ DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Midi CC %1 value 0 %2\n", (int) msg->controller_number, current_uri()));
+ break;
+ }
}
}
diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h
index c88b0b6441..b6486dc873 100644
--- a/libs/surfaces/generic_midi/midicontrollable.h
+++ b/libs/surfaces/generic_midi/midicontrollable.h
@@ -59,6 +59,11 @@ class MIDIControllable : public PBD::Stateful
uint32_t rid() const { return _rid; }
std::string what() const { return _what; }
+ enum CtlType {
+ Ctl_Momentary,
+ Ctl_Toggle,
+ };
+
enum Encoder {
No_enc,
Enc_R,
@@ -80,6 +85,9 @@ class MIDIControllable : public PBD::Stateful
bool learned() const { return _learned; }
+ CtlType get_ctltype() const { return _ctltype; }
+ void set_ctltype (CtlType val) { _ctltype = val; }
+
Encoder get_encoder() const { return _encoder; }
void set_encoder (Encoder val) { _encoder = val; }
@@ -122,6 +130,7 @@ class MIDIControllable : public PBD::Stateful
bool _momentary;
bool _is_gain_controller;
bool _learned;
+ CtlType _ctltype;
Encoder _encoder;
int midi_msg_id; /* controller ID or note number */
PBD::ScopedConnection midi_sense_connection[2];