+ int offset = (msg->value & 0x3f);
+ switch (get_encoder()) {
+ case Enc_L:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value - offset + 1), Controllable::NoGroup);
+ } else {
+ controllable->set_value (midi_to_control (last_value + offset + 1), Controllable::NoGroup);
+ }
+ break;
+ case Enc_R:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value + offset + 1), Controllable::NoGroup);
+ } else {
+ controllable->set_value (midi_to_control (last_value - offset + 1), Controllable::NoGroup);
+ }
+ break;
+ case Enc_2:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value - (0x7f - msg->value) + 1), Controllable::NoGroup);
+ } else {
+ controllable->set_value (midi_to_control (last_value + offset + 1), Controllable::NoGroup);
+ }
+ break;
+ case Enc_B:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value + offset + 1), Controllable::NoGroup);
+ } else {
+ controllable->set_value (midi_to_control (last_value - (0x40 - offset)), Controllable::NoGroup);
+ }
+ break;
+ default:
+ break;
+ }
+ DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI CC %1 value %2 %3\n", (int) msg->controller_number, (int) last_value, current_uri() ));
+
+ }
+ } else {
+
+ /* toggle control: make the toggle flip only if the
+ * incoming control value exceeds 0.5 (0x40), so that
+ * the typical button which sends "CC N=0x7f" on press
+ * and "CC N=0x0" on release can be used to drive
+ * toggles on press.
+ *
+ * No other arrangement really makes sense for a toggle
+ * controllable. Acting on the press+release makes the
+ * action momentary, which is almost never
+ * desirable. If the physical button only sends a
+ * message on press (or release), then it will be
+ * expected to send a controller value >= 0.5
+ * (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::NoGroup);
+ DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Midi CC %1 value 1 %2\n", (int) msg->controller_number, current_uri()));