styleguide #10
authorRobin Gareus <robin@gareus.org>
Tue, 26 Apr 2016 02:02:58 +0000 (04:02 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 26 Apr 2016 02:02:58 +0000 (04:02 +0200)
sigc keeps a reference to the shared_ptr, AsyncMidiPorts were never
unregistered, causing issues when loading a new session w/o Engine
restart.

libs/ardour/ardour/midi_ui.h
libs/ardour/midi_ui.cc

index 2f0f7d3a45e47b0372d4e7646f83edca97a500df..88ea021361a8e2a754dd69574c29fe4ef99a3f8c 100644 (file)
@@ -62,7 +62,7 @@ class LIBARDOUR_API MidiControlUI : public AbstractUI<MidiUIRequest>
   private:
        ARDOUR::Session& _session;
 
-       bool midi_input_handler (Glib::IOCondition, boost::shared_ptr<AsyncMIDIPort>);
+       bool midi_input_handler (Glib::IOCondition, boost::weak_ptr<AsyncMIDIPort>);
        void reset_ports ();
        void clear_ports ();
 
index 1d2fe7c7e1b4a2b2b6fcdb02357c7f54a9231f2e..c11f96c071a0a693f7b852f1d1ad64296c7a03a2 100644 (file)
@@ -82,8 +82,13 @@ MidiControlUI::do_request (MidiUIRequest* req)
 }
 
 bool
-MidiControlUI::midi_input_handler (IOCondition ioc, boost::shared_ptr<AsyncMIDIPort> port)
+MidiControlUI::midi_input_handler (IOCondition ioc, boost::weak_ptr<AsyncMIDIPort> wport)
 {
+       boost::shared_ptr<AsyncMIDIPort> port = wport.lock ();
+       if (!port) {
+               return false;
+       }
+
        DEBUG_TRACE (DEBUG::MidiIO, string_compose ("something happend on  %1\n", boost::shared_ptr<ARDOUR::Port> (port)->name()));
 
        if (ioc & ~IO_IN) {
@@ -130,7 +135,8 @@ MidiControlUI::reset_ports ()
        }
 
        for (vector<boost::shared_ptr<AsyncMIDIPort> >::const_iterator pi = ports.begin(); pi != ports.end(); ++pi) {
-               (*pi)->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &MidiControlUI::midi_input_handler), *pi));
+               (*pi)->xthread().set_receive_handler (sigc::bind (
+                                       sigc::mem_fun (this, &MidiControlUI::midi_input_handler), boost::weak_ptr<AsyncMIDIPort>(*pi)));
                (*pi)->xthread().attach (_main_loop->get_context());
        }
 }