fix DSP load bounds 0..1 and add unbound API
[ardour.git] / libs / ardour / midi_ui.cc
index 26005b5b9c228731babd2b990555f58513015401..0f2392108f25fcbe37b97d45ad430c48f60f8da7 100644 (file)
@@ -52,7 +52,11 @@ MidiControlUI::MidiControlUI (Session& s)
 
 MidiControlUI::~MidiControlUI ()
 {
+       /* stop the thread */
+       quit ();
+       /* drop all ports as GIO::Sources */
        clear_ports ();
+       /* we no longer exist */
        _instance = 0;
 }
 
@@ -61,6 +65,8 @@ MidiControlUI::do_request (MidiUIRequest* req)
 {
        if (req->type == Quit) {
                BaseUI::quit ();
+       } else if (req->type == CallSlot) {
+               req->the_slot ();
        }
 }
 
@@ -75,9 +81,10 @@ MidiControlUI::midi_input_handler (IOCondition ioc, AsyncMIDIPort* port)
 
        if (ioc & IO_IN) {
 
-#ifndef PLATFORM_WINDOWS
-               CrossThreadChannel::drain (port->selectable());
-#endif
+               AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*> (port);
+               if (asp) {
+                       asp->clear ();
+               }
 
                DEBUG_TRACE (DEBUG::MidiIO, string_compose ("data available on %1\n", ((ARDOUR::Port*)port)->name()));
                framepos_t now = _session.engine().sample_time();
@@ -90,21 +97,11 @@ MidiControlUI::midi_input_handler (IOCondition ioc, AsyncMIDIPort* port)
 void
 MidiControlUI::clear_ports ()
 {
-       for (PortSources::iterator i = port_sources.begin(); i != port_sources.end(); ++i) {
-               g_source_destroy (*i);
-               g_source_unref (*i);
-       }
-
-       port_sources.clear ();
 }
 
 void
 MidiControlUI::reset_ports ()
 {
-       if (!port_sources.empty()) {
-               return;
-       }
-       
        vector<AsyncMIDIPort*> ports;
        AsyncMIDIPort* p;
        
@@ -116,25 +113,18 @@ MidiControlUI::reset_ports ()
        if ((p = dynamic_cast<AsyncMIDIPort*> (_session.mmc_input_port()))) {
                ports.push_back (p);
        }
+
+       if ((p = dynamic_cast<AsyncMIDIPort*> (_session.scene_input_port()))) {
+               ports.push_back (p);
+       }
        
        if (ports.empty()) {
                return;
        }
        
-       int fd;
        for (vector<AsyncMIDIPort*>::const_iterator pi = ports.begin(); pi != ports.end(); ++pi) {
-
-               if ((fd = (*pi)->selectable ()) >= 0) {
-                       Glib::RefPtr<IOSource> psrc = IOSource::create (fd, IO_IN|IO_HUP|IO_ERR);
-                       
-                       psrc->connect (sigc::bind (sigc::mem_fun (this, &MidiControlUI::midi_input_handler), *pi));
-                       psrc->attach (_main_loop->get_context());
-                       
-                       // glibmm hack: for now, store only the GSource*
-                       
-                       port_sources.push_back (psrc->gobj());
-                       g_source_ref (psrc->gobj());
-               }
+               (*pi)->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &MidiControlUI::midi_input_handler), *pi));
+               (*pi)->xthread().attach (_main_loop->get_context());
        }
 }