summaryrefslogtreecommitdiff
path: root/libs/surfaces/generic_midi/midicontrollable.cc
diff options
context:
space:
mode:
authorLen Ovens <len@ovenwerks.net>2015-07-20 23:15:53 -0700
committerPaul Davis <paul@linuxaudiosystems.com>2015-07-27 16:17:38 -0400
commitd3b4ef4eeda501cd5e5e954bdd8393504362ec44 (patch)
treee493a54f726fea40047041688c92f779d64a9d0f /libs/surfaces/generic_midi/midicontrollable.cc
parentae3d4efce0a39bb7f603a8b1e990cfdd36e34a59 (diff)
Add enc to midi map for mcp style encoders.
Diffstat (limited to 'libs/surfaces/generic_midi/midicontrollable.cc')
-rw-r--r--libs/surfaces/generic_midi/midicontrollable.cc64
1 files changed, 39 insertions, 25 deletions
diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc
index a5c2e9c017..9ac8c794e8 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 */
+ _encoder = false;
setting = false;
last_value = 0; // got a better idea ?
last_controllable_value = 0.0f;
@@ -72,6 +73,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
set_controllable (&c);
_learned = true; /* from controllable */
+ _encoder = false;
setting = false;
last_value = 0; // got a better idea ?
last_controllable_value = 0.0f;
@@ -188,8 +190,9 @@ MIDIControllable::control_to_midi (float val)
val = actl->internal_to_interface(val);
}
}
-
- return (val - control_min) / control_range * max_value_for_type ();
+ // fiddle value of max so value doesn't jump from 125 to 127 for 1.0
+ // otherwise decrement won't work.
+ return (val - control_min) / control_range * (max_value_for_type () - 1);
}
float
@@ -197,7 +200,7 @@ MIDIControllable::midi_to_control (int val)
{
/* fiddle with MIDI value so that we get an odd number of integer steps
and can thus represent "middle" precisely as 0.5. this maps to
- the range 0..+1.0
+ the range 0..+1.0 (0 to 126)
*/
float fv = (val == 0 ? 0 : float (val - 1) / (max_value_for_type() - 1));
@@ -301,30 +304,41 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
if (control_additional == msg->controller_number) {
if (!controllable->is_toggle()) {
+ if (!is_encoder()) {
+ float new_value = msg->value;
+ float max_value = max(last_controllable_value, new_value);
+ float min_value = min(last_controllable_value, new_value);
+ float range = max_value - min_value;
+ float threshold = (float) _surface->threshold ();
+
+ bool const in_sync = (
+ range < threshold &&
+ controllable->get_value() <= midi_to_control(max_value) &&
+ controllable->get_value() >= midi_to_control(min_value)
+ );
+
+ /* If the surface is not motorised, we try to prevent jumps when
+ the MIDI controller and controllable are out of sync.
+ There might be a better way of doing this.
+ */
+
+ if (in_sync || _surface->motorised ()) {
+ controllable->set_value (midi_to_control (new_value));
+ }
+ DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI CC %1 value %2 %3\n", (int) msg->controller_number, (float) midi_to_control(new_value), current_uri() ));
+
+ last_controllable_value = new_value;
+ } else {
+ // add or subtract ticks from last value
+ int offset = (msg->value & 0x3f);
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value - offset + 1));
+ } else {
+ controllable->set_value (midi_to_control (last_value + offset + 1));
+ }
+ DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI CC %1 value %2 %3\n", (int) msg->controller_number, (int) last_value, current_uri() ));
- float new_value = msg->value;
- float max_value = max(last_controllable_value, new_value);
- float min_value = min(last_controllable_value, new_value);
- float range = max_value - min_value;
- float threshold = (float) _surface->threshold ();
-
- bool const in_sync = (
- range < threshold &&
- controllable->get_value() <= midi_to_control(max_value) &&
- controllable->get_value() >= midi_to_control(min_value)
- );
-
- /* If the surface is not motorised, we try to prevent jumps when
- the MIDI controller and controllable are out of sync.
- There might be a better way of doing this.
- */
-
- if (in_sync || _surface->motorised ()) {
- controllable->set_value (midi_to_control (new_value));
}
- DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI CC %1 value %2 %3\n", (int) msg->controller_number, (float) midi_to_control(new_value), current_uri() ));
-
- last_controllable_value = new_value;
} else {
if (msg->value > 64.0f) {
controllable->set_value (1);