mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 00:04:56 +01:00
Handle the 4 common encoder types.
This commit is contained in:
parent
938f365cc1
commit
8b4a237ee3
3 changed files with 59 additions and 15 deletions
|
|
@ -772,7 +772,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
||||||
MIDI::eventType ev;
|
MIDI::eventType ev;
|
||||||
int intval;
|
int intval;
|
||||||
bool momentary;
|
bool momentary;
|
||||||
bool encoder = false;
|
MIDIControllable::Encoder encoder = MIDIControllable::No_enc;
|
||||||
|
|
||||||
if ((prop = node.property (X_("ctl"))) != 0) {
|
if ((prop = node.property (X_("ctl"))) != 0) {
|
||||||
ev = MIDI::controller;
|
ev = MIDI::controller;
|
||||||
|
|
@ -782,8 +782,17 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
||||||
ev = MIDI::program;
|
ev = MIDI::program;
|
||||||
} else if ((prop = node.property (X_("pb"))) != 0) {
|
} else if ((prop = node.property (X_("pb"))) != 0) {
|
||||||
ev = MIDI::pitchbend;
|
ev = MIDI::pitchbend;
|
||||||
} else if ((prop = node.property (X_("enc"))) != 0) {
|
} else if ((prop = node.property (X_("enc-l"))) != 0) {
|
||||||
encoder = true;
|
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;
|
ev = MIDI::controller;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
|
||||||
, _momentary (m)
|
, _momentary (m)
|
||||||
{
|
{
|
||||||
_learned = false; /* from URI */
|
_learned = false; /* from URI */
|
||||||
_encoder = false;
|
_encoder = No_enc;
|
||||||
setting = false;
|
setting = false;
|
||||||
last_value = 0; // got a better idea ?
|
last_value = 0; // got a better idea ?
|
||||||
last_controllable_value = 0.0f;
|
last_controllable_value = 0.0f;
|
||||||
|
|
@ -73,7 +73,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, MIDI::Parser&
|
||||||
set_controllable (&c);
|
set_controllable (&c);
|
||||||
|
|
||||||
_learned = true; /* from controllable */
|
_learned = true; /* from controllable */
|
||||||
_encoder = false;
|
_encoder = No_enc;
|
||||||
setting = false;
|
setting = false;
|
||||||
last_value = 0; // got a better idea ?
|
last_value = 0; // got a better idea ?
|
||||||
last_controllable_value = 0.0f;
|
last_controllable_value = 0.0f;
|
||||||
|
|
@ -304,7 +304,7 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg)
|
||||||
if (control_additional == msg->controller_number) {
|
if (control_additional == msg->controller_number) {
|
||||||
|
|
||||||
if (!controllable->is_toggle()) {
|
if (!controllable->is_toggle()) {
|
||||||
if (!is_encoder()) {
|
if (get_encoder() == No_enc) {
|
||||||
float new_value = msg->value;
|
float new_value = msg->value;
|
||||||
float max_value = max(last_controllable_value, new_value);
|
float max_value = max(last_controllable_value, new_value);
|
||||||
float min_value = min(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;
|
last_controllable_value = new_value;
|
||||||
} else {
|
} else {
|
||||||
// add or subtract ticks from last value
|
|
||||||
int offset = (msg->value & 0x3f);
|
int offset = (msg->value & 0x3f);
|
||||||
if (msg->value > 0x40) {
|
switch (get_encoder()) {
|
||||||
controllable->set_value (midi_to_control (last_value - offset + 1));
|
case Enc_L:
|
||||||
} else {
|
if (msg->value > 0x40) {
|
||||||
controllable->set_value (midi_to_control (last_value + offset + 1));
|
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() ));
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI CC %1 value %2 %3\n", (int) msg->controller_number, (int) last_value, current_uri() ));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,14 @@ class MIDIControllable : public PBD::Stateful
|
||||||
uint32_t rid() const { return _rid; }
|
uint32_t rid() const { return _rid; }
|
||||||
std::string what() const { return _what; }
|
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);
|
MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
|
||||||
|
|
||||||
void midi_rebind (MIDI::channel_t channel=-1);
|
void midi_rebind (MIDI::channel_t channel=-1);
|
||||||
|
|
@ -75,10 +83,10 @@ class MIDIControllable : public PBD::Stateful
|
||||||
|
|
||||||
bool learned() const { return _learned; }
|
bool learned() const { return _learned; }
|
||||||
|
|
||||||
bool is_encoder() const { return _encoder; }
|
Encoder get_encoder() const { return _encoder; }
|
||||||
void set_encoder(bool val) { _encoder = val; }
|
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; }
|
PBD::Controllable* get_controllable() const { return controllable; }
|
||||||
void set_controllable (PBD::Controllable*);
|
void set_controllable (PBD::Controllable*);
|
||||||
const std::string& current_uri() const { return _current_uri; }
|
const std::string& current_uri() const { return _current_uri; }
|
||||||
|
|
@ -112,7 +120,7 @@ class MIDIControllable : public PBD::Stateful
|
||||||
bool _momentary;
|
bool _momentary;
|
||||||
bool _is_gain_controller;
|
bool _is_gain_controller;
|
||||||
bool _learned;
|
bool _learned;
|
||||||
bool _encoder;
|
Encoder _encoder;
|
||||||
int midi_msg_id; /* controller ID or note number */
|
int midi_msg_id; /* controller ID or note number */
|
||||||
PBD::ScopedConnection midi_sense_connection[2];
|
PBD::ScopedConnection midi_sense_connection[2];
|
||||||
PBD::ScopedConnection midi_learn_connection;
|
PBD::ScopedConnection midi_learn_connection;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue