diff options
-rw-r--r-- | libs/surfaces/generic_midi/generic_midi_control_protocol.cc | 77 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/generic_midi_control_protocol.h | 2 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.cc | 107 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.h | 14 | ||||
-rw-r--r-- | mcp/bcf2000.device | 1 | ||||
-rw-r--r-- | mcp/cmc.device | 1 | ||||
-rw-r--r-- | mcp/mc.device | 1 | ||||
-rw-r--r-- | mcp/mcpro.device | 1 | ||||
-rw-r--r-- | mcp/mcproxt.device | 1 | ||||
-rw-r--r-- | mcp/nucleus.device | 1 | ||||
-rw-r--r-- | mcp/qcon.device | 1 |
11 files changed, 172 insertions, 35 deletions
diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index 44d04e532d..0ed6a90942 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -299,6 +299,7 @@ GenericMidiControlProtocol::start_learning (Controllable* c) } Glib::Threads::Mutex::Lock lm2 (controllables_lock); + DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Learn binding: Controlable number: %1\n", c)); MIDIControllables::iterator tmp; for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ) { @@ -350,7 +351,6 @@ GenericMidiControlProtocol::start_learning (Controllable* c) pending_controllables.push_back (element); } - mc->learn_about_external_control (); return true; } @@ -425,6 +425,7 @@ GenericMidiControlProtocol::delete_binding (PBD::Controllable* control) } } +// This next function seems unused void GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos, int control_number) { @@ -462,6 +463,65 @@ GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos, } } +void +GenericMidiControlProtocol::check_used_event (int pos, int control_number) +{ + Glib::Threads::Mutex::Lock lm2 (controllables_lock); + + MIDI::channel_t channel = (pos & 0xf); + MIDI::byte value = control_number; + + DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("checking for used event: Channel: %1 Controller: %2 value: %3\n", (int) channel, (pos & 0xf0), (int) value)); + + // Remove any old binding for this midi channel/type/value pair + // Note: can't use delete_binding() here because we don't know the specific controllable we want to remove, only the midi information + for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end();) { + MIDIControllable* existingBinding = (*iter); + if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) { + if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) { + DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n"); + delete existingBinding; + iter = controllables.erase (iter); + } else { + ++iter; + } + } else { + ++iter; + } + } + + for (MIDIFunctions::iterator iter = functions.begin(); iter != functions.end();) { + MIDIFunction* existingBinding = (*iter); + if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) { + if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) { + DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n"); + delete existingBinding; + iter = functions.erase (iter); + } else { + ++iter; + } + } else { + ++iter; + } + } + + for (MIDIActions::iterator iter = actions.begin(); iter != actions.end();) { + MIDIAction* existingBinding = (*iter); + if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) { + if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) { + DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n"); + delete existingBinding; + iter = actions.erase (iter); + } else { + ++iter; + } + } else { + ++iter; + } + } + +} + XMLNode& GenericMidiControlProtocol::get_state () { @@ -550,7 +610,6 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version) { Glib::Threads::Mutex::Lock lm2 (controllables_lock); - controllables.clear (); nlist = node.children(); // "Controls" if (!nlist.empty()) { @@ -713,6 +772,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node) MIDI::eventType ev; int intval; bool momentary; + MIDIControllable::Encoder encoder = MIDIControllable::No_enc; if ((prop = node.property (X_("ctl"))) != 0) { ev = MIDI::controller; @@ -722,6 +782,18 @@ 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-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; } @@ -761,6 +833,7 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node) return 0; } + mc->set_encoder (encoder); mc->bind_midi (channel, ev, detail); return mc; diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.h b/libs/surfaces/generic_midi/generic_midi_control_protocol.h index a4a51b7f99..bb38a48401 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.h +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.h @@ -71,6 +71,8 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol { int load_bindings (const std::string&); void drop_bindings (); + + void check_used_event (int, int); std::string current_binding() const { return _current_binding; } diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index f03a113cfe..21b2b96314 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 = No_enc; 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 = No_enc; 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,67 @@ MIDIControllable::midi_sense_controller (Parser &, EventTwoBytes *msg) if (control_additional == msg->controller_number) { if (!controllable->is_toggle()) { + 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); + 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 { + int offset = (msg->value & 0x3f); + 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() )); - 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); @@ -347,14 +387,16 @@ MIDIControllable::midi_sense_program_change (Parser &, MIDI::byte msg) return; } } + if (msg == control_additional) { - if (!controllable->is_toggle()) { - controllable->set_value (midi_to_control (msg)); - DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI program %1 value %2 %3\n", (int) msg, (float) midi_to_control (msg), current_uri() )); - } else if (msg == control_additional) { - float new_value = controllable->get_value() > 0.5f ? 0.0f : 1.0f; - controllable->set_value (new_value); - DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI program %1 value %2 %3\n", (int) msg, (float) new_value, current_uri())); + if (!controllable->is_toggle()) { + controllable->set_value (1.0); + DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI program %1 value 1.0 %3\n", (int) msg, current_uri() )); + } else { + float new_value = controllable->get_value() > 0.5f ? 0.0f : 1.0f; + controllable->set_value (new_value); + DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("MIDI program %1 value %2 %3\n", (int) msg, (float) new_value, current_uri())); + } } last_value = (MIDI::byte) (controllable->get_value() * 127.0); // to prevent feedback fights @@ -394,6 +436,7 @@ MIDIControllable::midi_receiver (Parser &, MIDI::byte *msg, size_t /*len*/) return; } + _surface->check_used_event(msg[0], msg[1]); bind_midi ((channel_t) (msg[0] & 0xf), eventType (msg[0] & 0xF0), msg[1]); if (controllable) { diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h index aeed05db4a..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,7 +83,10 @@ class MIDIControllable : public PBD::Stateful bool learned() const { return _learned; } - MIDI::Parser& get_parser() { return _parser; } + Encoder get_encoder() const { return _encoder; } + void set_encoder (Encoder val) { _encoder = val; } + + 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; } @@ -109,6 +120,7 @@ class MIDIControllable : public PBD::Stateful bool _momentary; bool _is_gain_controller; bool _learned; + Encoder _encoder; int midi_msg_id; /* controller ID or note number */ PBD::ScopedConnection midi_sense_connection[2]; PBD::ScopedConnection midi_learn_connection; diff --git a/mcp/bcf2000.device b/mcp/bcf2000.device index f3207d88b0..ebfaf39283 100644 --- a/mcp/bcf2000.device +++ b/mcp/bcf2000.device @@ -6,6 +6,7 @@ <TimecodeDisplay value="no"/> <TwoCharacterDisplay value="yes"/> <Extenders value="0"/> + <MasterPosition value="0"/> <GlobalControls value="yes"/> <JogWheel value="yes"/> <TouchSenseFaders value="no"/> diff --git a/mcp/cmc.device b/mcp/cmc.device index b23c8497b1..2e06a0a3ae 100644 --- a/mcp/cmc.device +++ b/mcp/cmc.device @@ -2,6 +2,7 @@ <Name value="Steinberg CMC series"/> <Strips value="1"/> <Extenders value="0"/> + <MasterPosition value="0"/> <MasterFader value="yes"/> <TimecodeDisplay value="no"/> <TwoCharacterDisplay value="no"/> diff --git a/mcp/mc.device b/mcp/mc.device index baa0711cc9..11dc0e8668 100644 --- a/mcp/mc.device +++ b/mcp/mc.device @@ -6,6 +6,7 @@ <TimecodeDisplay value="yes"/> <TwoCharacterDisplay value="yes"/> <Extenders value="0"/> + <MasterPosition value="0"/> <GlobalControls value="yes"/> <JogWheel value="yes"/> <TouchSenseFaders value="yes"/> diff --git a/mcp/mcpro.device b/mcp/mcpro.device index 9ac1ed0fa6..0ace09abf8 100644 --- a/mcp/mcpro.device +++ b/mcp/mcpro.device @@ -6,6 +6,7 @@ <TimecodeDisplay value="yes"/> <TwoCharacterDisplay value="yes"/> <Extenders value="0"/> + <MasterPosition value="0"/> <GlobalControls value="yes"/> <JogWheel value="yes"/> <TouchSenseFaders value="yes"/> diff --git a/mcp/mcproxt.device b/mcp/mcproxt.device index 6bddee0177..41361d00fb 100644 --- a/mcp/mcproxt.device +++ b/mcp/mcproxt.device @@ -6,6 +6,7 @@ <TimecodeDisplay value="yes"/> <TwoCharacterDisplay value="yes"/> <Extenders value="0"/> + <MasterPosition value="0"/> <GlobalControls value="no"/> <JogWheel value="no"/> <TouchSenseFaders value="yes"/> diff --git a/mcp/nucleus.device b/mcp/nucleus.device index 1ab96c3be4..d9dbba4a97 100644 --- a/mcp/nucleus.device +++ b/mcp/nucleus.device @@ -3,6 +3,7 @@ <Name value="SSL Nucleus"/> <Strips value="8"/> <Extenders value="1"/> + <MasterPosition value="0"/> <MasterFader value="no"/> <TimecodeDisplay value="no"/> <TwoCharacterDisplay value="yes"/> diff --git a/mcp/qcon.device b/mcp/qcon.device index 48c5390835..37d618e874 100644 --- a/mcp/qcon.device +++ b/mcp/qcon.device @@ -2,6 +2,7 @@ <Name value="Qcon"/> <Strips value="8"/> <Extenders value="0"/> + <MasterPosition value="0"/> <MasterFader value="yes"/> <TimecodeDisplay value="yes"/> <TwoCharacterDisplay value="no"/> |