totally untested initial code for MidiPlaylistSource, to provide for compound MIDI...
[ardour.git] / libs / ardour / midi_ui.cc
index ffcec00de7f498767efaf5e344c4bdf93e8aab13..2b39d6c0329b12b3204ce509c0bdf3c9e9be648b 100644 (file)
@@ -18,6 +18,8 @@
 */
 #include <cstdlib>
 
+#include <sigc++/signal.h>
+
 #include "pbd/pthread_utils.h"
 
 #include "midi++/manager.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Glib;
 
 #include "i18n.h"
 
 BaseUI::RequestType MidiControlUI::PortChange = BaseUI::new_request_type();
+MidiControlUI* MidiControlUI::_instance = 0;
 
 #include "pbd/abstract_ui.cc"  /* instantiate the template */
 
@@ -44,12 +48,14 @@ MidiControlUI::MidiControlUI (Session& s)
        : AbstractUI<MidiUIRequest> (_("midiui"))
        , _session (s) 
 {
-       MIDI::Manager::instance()->PortsChanged.connect (mem_fun (*this, &MidiControlUI::change_midi_ports));
+       MIDI::Manager::instance()->PortsChanged.connect_same_thread (rebind_connection, boost::bind (&MidiControlUI::change_midi_ports, this));
+       _instance = this;
 }
 
 MidiControlUI::~MidiControlUI ()
 {
        clear_ports ();
+       _instance = 0;
 }
 
 void
@@ -63,6 +69,12 @@ MidiControlUI::do_request (MidiUIRequest* req)
 
        } else if (req->type == CallSlot) {
 
+#ifndef NDEBUG
+               if (getenv ("DEBUG_THREADED_SIGNALS")) {
+                       cerr << "MIDI UI calls a slot\n";
+               }
+#endif
+
                req->the_slot ();
 
        } else if (req->type == Quit) {
@@ -84,18 +96,18 @@ MidiControlUI::change_midi_ports ()
 bool
 MidiControlUI::midi_input_handler (IOCondition ioc, MIDI::Port* port)
 {
+       DEBUG_TRACE (DEBUG::MidiIO, string_compose ("something happend on  %1\n", port->name()));
+
        if (ioc & ~IO_IN) {
                return false;
        }
 
        if (ioc & IO_IN) {
 
-               if (port->must_drain_selectable()) {
-                       CrossThreadChannel::drain (port->selectable());
-               }
+               CrossThreadChannel::drain (port->selectable());
 
                DEBUG_TRACE (DEBUG::MidiIO, string_compose ("data available on %1\n", port->name()));
-               nframes64_t now = _session.engine().frame_time();
+               framepos_t now = _session.engine().frame_time();
                port->parse (now);
        }
 
@@ -122,10 +134,11 @@ MidiControlUI::reset_ports ()
 
        for (MIDI::Manager::PortList::iterator i = plist.begin(); i != plist.end(); ++i) {
                int fd;
+
                if ((fd = (*i)->selectable ()) >= 0) {
                        Glib::RefPtr<IOSource> psrc = IOSource::create (fd, IO_IN|IO_HUP|IO_ERR);
 
-                       psrc->connect (bind (mem_fun (*this, &MidiControlUI::midi_input_handler), (*i)));
+                       psrc->connect (sigc::bind (sigc::mem_fun (this, &MidiControlUI::midi_input_handler), *i));
                        psrc->attach (_main_loop->get_context());
 
                        // glibmm hack: for now, store only the GSource*
@@ -141,6 +154,8 @@ MidiControlUI::thread_init ()
 {      
        struct sched_param rtparam;
 
+       pthread_set_name (X_("midiUI"));
+
        PBD::notify_gui_about_thread_creation (X_("gui"), pthread_self(), X_("MIDI"), 2048);
        SessionEvent::create_per_thread_pool (X_("MIDI I/O"), 128);