X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fmidi_ui.cc;h=1d2fe7c7e1b4a2b2b6fcdb02357c7f54a9231f2e;hb=3fef6a3b8d14305e76728b4c21aeaf04b8b4dbe3;hp=e6d49175bd143ac4b9f4154732f170b1ad73f3fa;hpb=4a6412aebe4f18578f201e99ddc74fc5d9cb6bfc;p=ardour.git diff --git a/libs/ardour/midi_ui.cc b/libs/ardour/midi_ui.cc index e6d49175bd..1d2fe7c7e1 100644 --- a/libs/ardour/midi_ui.cc +++ b/libs/ardour/midi_ui.cc @@ -39,13 +39,12 @@ 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 */ MidiControlUI::MidiControlUI (Session& s) - : AbstractUI (X_("midiui")) + : AbstractUI (X_("midiUI")) , _session (s) { _instance = this; @@ -53,39 +52,39 @@ MidiControlUI::MidiControlUI (Session& s) MidiControlUI::~MidiControlUI () { + /* stop the thread */ + quit (); + /* drop all ports as GIO::Sources */ clear_ports (); + /* we no longer exist */ _instance = 0; } +void* +MidiControlUI::request_factory (uint32_t num_requests) +{ + /* AbstractUI::request_buffer_factory() is a template method only + instantiated in this source module. To provide something visible for + use when registering the factory, we have this static method that is + template-free. + */ + return request_buffer_factory (num_requests); +} + void MidiControlUI::do_request (MidiUIRequest* req) { - if (req->type == PortChange) { - - /* restart event loop with new ports */ - DEBUG_TRACE (DEBUG::MidiIO, "reset ports\n"); - reset_ports (); - + if (req->type == Quit) { + BaseUI::quit (); } 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) { - - BaseUI::quit (); } } bool -MidiControlUI::midi_input_handler (IOCondition ioc, AsyncMIDIPort* port) +MidiControlUI::midi_input_handler (IOCondition ioc, boost::shared_ptr port) { - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("something happend on %1\n", ((ARDOUR::Port*)port)->name())); + DEBUG_TRACE (DEBUG::MidiIO, string_compose ("something happend on %1\n", boost::shared_ptr (port)->name())); if (ioc & ~IO_IN) { return false; @@ -93,11 +92,8 @@ MidiControlUI::midi_input_handler (IOCondition ioc, AsyncMIDIPort* port) if (ioc & IO_IN) { -#ifndef PLATFORM_WINDOWS - CrossThreadChannel::drain (port->selectable()); -#endif - - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("data available on %1\n", ((ARDOUR::Port*)port)->name())); + port->clear (); + DEBUG_TRACE (DEBUG::MidiIO, string_compose ("data available on %1\n", boost::shared_ptr(port)->name())); framepos_t now = _session.engine().sample_time(); port->parse (now); } @@ -108,37 +104,34 @@ 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()) { - AsyncMIDIPort* async = dynamic_cast (_session.midi_input_port()); + vector > ports; + boost::shared_ptr p; - if (!async) { - return; - } + if ((p = boost::dynamic_pointer_cast (_session.midi_input_port()))) { + ports.push_back (p); + } - int fd; - if ((fd = async->selectable ()) >= 0) { - Glib::RefPtr psrc = IOSource::create (fd, IO_IN|IO_HUP|IO_ERR); - - psrc->connect (sigc::bind (sigc::mem_fun (this, &MidiControlUI::midi_input_handler), async)); - psrc->attach (_main_loop->get_context()); + if ((p = boost::dynamic_pointer_cast (_session.mmc_input_port()))) { + ports.push_back (p); + } + + if ((p = boost::dynamic_pointer_cast (_session.scene_input_port()))) { + ports.push_back (p); + } - // glibmm hack: for now, store only the GSource* + if (ports.empty()) { + return; + } - port_sources.push_back (psrc->gobj()); - g_source_ref (psrc->gobj()); - } + for (vector >::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().attach (_main_loop->get_context()); } } @@ -149,8 +142,8 @@ MidiControlUI::thread_init () 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); + PBD::notify_event_loops_about_thread_creation (pthread_self(), X_("midiUI"), 2048); + SessionEvent::create_per_thread_pool (X_("midiUI"), 128); memset (&rtparam, 0, sizeof (rtparam)); rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */