diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-12-03 20:57:58 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-12-03 20:57:58 -0500 |
commit | d3e2de8b4e006ac652b004cb44b66afa9f6584f6 (patch) | |
tree | 925f79608f2b39f7da83ce822953a54b65783ab3 /libs/surfaces/mackie/mackie_control_protocol.cc | |
parent | f4726cc6fa4f351a97a4088a34c70207c3a371dc (diff) |
modify Mackie surface code to use crossthreadchannel on all platforms
Diffstat (limited to 'libs/surfaces/mackie/mackie_control_protocol.cc')
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.cc | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index 0e87c3a1e1..68c47effca 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -656,6 +656,13 @@ MackieControlProtocol::set_device (const string& device_name) return 0; } +gboolean +ipmidi_input_handler (GIOChannel*, GIOCondition condition, void *data) +{ + MackieControlProtocol::ipMIDIHandler* ipm = static_cast<MackieControlProtocol::ipMIDIHandler*>(data); + return ipm->mcp->midi_input_handler (Glib::IOCondition (condition), ipm->port); +} + int MackieControlProtocol::create_surfaces () { @@ -730,13 +737,13 @@ MackieControlProtocol::create_surfaces () MIDI::Port& input_port (surface->port().input_port()); AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*> (&input_port); - Glib::RefPtr<IOSource> psrc; - + if (asp) { /* async MIDI port */ - psrc = asp->ios(); + asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &MackieControlProtocol::midi_input_handler), &input_port)); + asp->xthread().attach (main_loop()->get_context()); } else { @@ -745,23 +752,25 @@ MackieControlProtocol::create_surfaces () int fd; if ((fd = input_port.selectable ()) >= 0) { - psrc = IOSource::create (fd, IO_IN|IO_HUP|IO_ERR); - } - } - - if (psrc) { - - psrc->connect (sigc::bind (sigc::mem_fun (this, &MackieControlProtocol::midi_input_handler), &input_port)); - psrc->attach (main_loop()->get_context()); - } else { - - if (n == 0) { - error << string_compose (_("Could not create IOSource for Mackie Control surface, MIDI port was called %1"), - input_port.name()); - } else { - error << string_compose (_("Could not create IOSource for Mackie Control extender #%1, MIDI port was called %2"), - n+1, input_port.name()); + GIOChannel* ioc = g_io_channel_unix_new (fd); + GSource* gsrc = g_io_create_watch (ioc, GIOCondition (G_IO_IN|G_IO_HUP|G_IO_ERR)); + + /* hack up an object so that in the callback from the event loop + we have both the MackieControlProtocol and the input port. + + If we were using C++ for this stuff we wouldn't need this + but a nasty, not-fixable bug in the binding between C + and C++ makes it necessary to avoid C++ for the IO + callback setup. + */ + + ipMIDIHandler* ipm = new ipMIDIHandler (); /* we will leak this sizeof(pointer)*2 sized object */ + ipm->mcp = this; + ipm->port = &input_port; + + g_source_set_callback (gsrc, (GSourceFunc) ipmidi_input_handler, ipm, NULL); + g_source_attach (gsrc, main_loop()->get_context()->gobj()); } } } |