summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLen Ovens <len@ovenwerks.net>2015-07-24 17:34:22 -0700
committerPaul Davis <paul@linuxaudiosystems.com>2015-07-27 16:17:38 -0400
commit8b4a237ee359dea9038daacc6e9b620d68431263 (patch)
tree7431358036b7b12391c4a795c1bc27d2cbfb84e5
parent938f365cc14de448d177f438df4d0de76190cf16 (diff)
Handle the 4 common encoder types.
-rw-r--r--libs/surfaces/generic_midi/generic_midi_control_protocol.cc15
-rw-r--r--libs/surfaces/generic_midi/midicontrollable.cc43
-rw-r--r--libs/surfaces/generic_midi/midicontrollable.h16
3 files changed, 59 insertions, 15 deletions
diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
index e171cfbcc3..0ed6a90942 100644
--- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
+++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc
@@ -772,7 +772,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
MIDI::eventType ev;
int intval;
bool momentary;
- bool encoder = false;
+ MIDIControllable::Encoder encoder = MIDIControllable::No_enc;
if ((prop = node.property (X_("ctl"))) != 0) {
ev = MIDI::controller;
@@ -782,8 +782,17 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
ev = MIDI::program;
} else if ((prop = node.property (X_("pb"))) != 0) {
ev = MIDI::pitchbend;
- } else if ((prop = node.property (X_("enc"))) != 0) {
- encoder = true;
+ } else if ((prop = node.property (X_("enc-l"))) != 0) {
+ encoder = MIDIControllable::Enc_L;
+ ev = MIDI::controller;
+ } else if ((prop = node.property (X_("enc-r"))) != 0) {
+ encoder = MIDIControllable::Enc_R;
+ ev = MIDI::controller;
+ } else if ((prop = node.property (X_("enc-2"))) != 0) {
+ encoder = MIDIControllable::Enc_2;
+ ev = MIDI::controller;
+ } else if ((prop = node.property (X_("enc-b"))) != 0) {
+ encoder = MIDIControllable::Enc_B;
ev = MIDI::controller;
} else {
return 0;
diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc
index 9ac8c794e8..c7d1028b82 100644
--- a/libs/surfaces/generic_midi/midicontrollable.cc
+++ b/libs/surfaces/generic_midi/midicontrollable.cc
@@ -54,7 +54,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
, _momentary (m)
{
_learned = false; /* from URI */
- _encoder = false;
+ _encoder = No_enc;
setting = false;
last_value = 0; // got a better idea ?
last_controllable_value = 0.0f;
@@ -73,7 +73,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
set_controllable (&c);
_learned = true; /* from controllable */
- _encoder = false;
+ _encoder = No_enc;
setting = false;
last_value = 0; // got a better idea ?
last_controllable_value = 0.0f;
@@ -304,7 +304,7 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
if (control_additional == msg->controller_number) {
if (!controllable->is_toggle()) {
- if (!is_encoder()) {
+ if (get_encoder() == No_enc) {
float new_value = msg->value;
float max_value = max(last_controllable_value, new_value);
float min_value = min(last_controllable_value, new_value);
@@ -329,12 +329,39 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
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));
+ switch (get_encoder()) {
+ case Enc_L:
+ 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));
+ }
+ break;
+ case Enc_R:
+ 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));
+ }
+ break;
+ case Enc_2:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value - (0x7f - msg->value) + 1));
+ } else {
+ controllable->set_value (midi_to_control (last_value + offset + 1));
+ }
+ break;
+ case Enc_B:
+ if (msg->value > 0x40) {
+ controllable->set_value (midi_to_control (last_value + offset + 1));
+ } else {
+ controllable->set_value (midi_to_control (last_value - (0x40 - offset)));
+ }
+ 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() ));
diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h
index 51ee60bb1e..1ea13ecb84 100644
--- a/libs/surfaces/generic_midi/midicontrollable.h
+++ b/libs/surfaces/generic_midi/midicontrollable.h
@@ -59,6 +59,14 @@ class MIDIControllable : public PBD::Stateful
uint32_t rid() const { return _rid; }
std::string what() const { return _what; }
+ enum Encoder {
+ No_enc,
+ Enc_R,
+ Enc_L,
+ Enc_2,
+ Enc_B,
+ };
+
MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
void midi_rebind (MIDI::channel_t channel=-1);
@@ -75,10 +83,10 @@ class MIDIControllable : public PBD::Stateful
bool learned() const { return _learned; }
- bool is_encoder() const { return _encoder; }
- void set_encoder(bool val) { _encoder = val; }
+ Encoder get_encoder() const { return _encoder; }
+ void set_encoder (Encoder val) { _encoder = val; }
- MIDI::Parser& get_parser() { return _parser; }
+ MIDI::Parser& get_parser() { return _parser; }
PBD::Controllable* get_controllable() const { return controllable; }
void set_controllable (PBD::Controllable*);
const std::string& current_uri() const { return _current_uri; }
@@ -112,7 +120,7 @@ class MIDIControllable : public PBD::Stateful
bool _momentary;
bool _is_gain_controller;
bool _learned;
- bool _encoder;
+ Encoder _encoder;
int midi_msg_id; /* controller ID or note number */
PBD::ScopedConnection midi_sense_connection[2];
PBD::ScopedConnection midi_learn_connection;