+
+ delete dptr;
+}
+
+void
+GenericMidiControlProtocol::delete_binding (PBD::Controllable* control)
+{
+ if (control != 0) {
+ Glib::Mutex::Lock lm2 (controllables_lock);
+
+ for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
+ MIDIControllable* existingBinding = (*iter);
+
+ if (control == &(existingBinding->get_controllable())) {
+ delete existingBinding;
+ controllables.erase (iter);
+ }
+
+ }
+ }
+}
+
+void
+GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos, int control_number)
+{
+ if (control != NULL) {
+ Glib::Mutex::Lock lm2 (controllables_lock);
+
+ MIDI::channel_t channel = (pos & 0xf);
+ MIDI::byte value = control_number;
+
+ // Create a MIDIControllable
+ MIDIControllable* mc = new MIDIControllable (*_port, *control);
+
+ // 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(); ++iter) {
+ MIDIControllable* existingBinding = (*iter);
+
+ if ((existingBinding->get_control_channel() & 0xf ) == channel &&
+ existingBinding->get_control_additional() == value &&
+ (existingBinding->get_control_type() & 0xf0 ) == MIDI::controller) {
+
+ delete existingBinding;
+ controllables.erase (iter);
+ }
+
+ }
+
+ // Update the MIDI Controllable based on the the pos param
+ // Here is where a table lookup for user mappings could go; for now we'll just wing it...
+ mc->bind_midi(channel, MIDI::controller, value);
+
+ controllables.insert (mc);
+ }
+}
+
+void
+GenericMidiControlProtocol::auto_binding_on()
+{
+ auto_binding = TRUE;
+}
+
+void
+GenericMidiControlProtocol::auto_binding_off()
+{
+ auto_binding = FALSE;