+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;
+ }
+ }
+
+}
+