13
0

Handle the 4 common encoder types.

This commit is contained in:
Len Ovens 2015-07-24 17:34:22 -07:00 committed by Paul Davis
parent 938f365cc1
commit 8b4a237ee3
3 changed files with 59 additions and 15 deletions

View File

@ -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;

View File

@ -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() ));

View File

@ -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;