diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index d39886e0fc..a6d0b1c5ac 100644 --- a/libs/surfaces/generic_midi/midicontrollable.cc +++ b/libs/surfaces/generic_midi/midicontrollable.cc @@ -30,6 +30,7 @@ #include "midi++/channel.h" #include "ardour/automation_control.h" +#include "ardour/midi_ui.h" #include "ardour/utils.h" #include "midicontrollable.h" @@ -76,7 +77,7 @@ MIDIControllable::MIDIControllable (GenericMidiControlProtocol* s, Port& p, Cont MIDIControllable::~MIDIControllable () { - drop_external_control (); + drop_controllable (); } int @@ -111,6 +112,7 @@ MIDIControllable::drop_external_control () void MIDIControllable::set_controllable (Controllable* c) { + drop_controllable (); controllable = c; } @@ -198,10 +200,21 @@ MIDIControllable::lookup_controllable() } controllable = c.get(); + controllable->Destroyed.connect (controllable_death_connection, MISSING_INVALIDATOR, + boost::bind (&MIDIControllable::drop_controllable, this), + MidiControlUI::instance()); return 0; } +void +MIDIControllable::drop_controllable () +{ + drop_external_control (); + controllable_death_connection.disconnect (); + controllable = 0; +} + void MIDIControllable::midi_sense_note (Parser &, EventTwoBytes *msg, bool /*is_on*/) { diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h index 571f71edfe..ff4411a9ca 100644 --- a/libs/surfaces/generic_midi/midicontrollable.h +++ b/libs/surfaces/generic_midi/midicontrollable.h @@ -107,6 +107,7 @@ class MIDIControllable : public PBD::Stateful int midi_msg_id; /* controller ID or note number */ PBD::ScopedConnection midi_sense_connection[2]; PBD::ScopedConnection midi_learn_connection; + PBD::ScopedConnection controllable_death_connection; /** the type of MIDI message that is used for this control */ MIDI::eventType control_type; MIDI::byte control_additional; @@ -118,7 +119,8 @@ class MIDIControllable : public PBD::Stateful bool _bank_relative; int lookup_controllable(); - + void drop_controllable(); + void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t); void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on); void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);