+
+ if (!controllable->is_toggle()) {
+
+ 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));
+ }
+
+ last_controllable_value = new_value;