#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 ()
{
+ /* stop the thread */
+ quit ();
+ /* drop all ports as GIO::Sources */
clear_ports ();
+ /* we no longer exist */
_instance = 0;
}
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<AsyncMIDIPort> 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<ARDOUR::Port> (port)->name()));
if (ioc & ~IO_IN) {
return false;
if (ioc & IO_IN) {
- CrossThreadChannel::drain (port->selectable());
-
- 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<ARDOUR::Port>(port)->name()));
framepos_t now = _session.engine().sample_time();
port->parse (now);
}
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<AsyncMIDIPort*> (AudioEngine::instance()->midi_input_port());
+ vector<boost::shared_ptr<AsyncMIDIPort> > ports;
+ boost::shared_ptr<AsyncMIDIPort> p;
+
+ if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_session.midi_input_port()))) {
+ ports.push_back (p);
+ }
- if (!async) {
- return;
- }
- int fd;
+ if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_session.mmc_input_port()))) {
+ ports.push_back (p);
+ }
- if ((fd = async->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), async));
- psrc->attach (_main_loop->get_context());
+ if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_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<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().attach (_main_loop->get_context());
}
}