diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 28dd679f10..a4675f4a21 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -115,7 +115,7 @@ sigc::signal ARDOUR_UI::Clock; ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[]) - : Gtkmm2ext::UI (X_("Ardour"), argcp, argvp), + : Gtkmm2ext::UI (X_("gui"), argcp, argvp), primary_clock (X_("primary"), false, X_("TransportClockDisplay"), true, true, false, true), secondary_clock (X_("secondary"), false, X_("SecondaryClockDisplay"), true, true, false, true), diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index b54fe9225a..d12ed9a817 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -478,7 +478,7 @@ void ARDOUR_UI::solo_alert_toggle () { if (session) { - session->set_all_solo (!session->soloing()); + session->set_solo (session->get_routes(), !session->soloing()); } } diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index f8b6d7c141..fb3828ab53 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -491,7 +491,7 @@ Editor::import_sndfiles (vector paths, ImportMode mode, SrcQuality qual (the GUI) to direct additional steps after that. */ - pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this); + pthread_create_and_store ("import", &import_status.thread, _import_thread, this); pthread_detach (import_status.thread); while (!import_status.done && !import_status.cancel) { @@ -879,7 +879,6 @@ Editor::finish_bringing_in_material (boost::shared_ptr region, uint32_t void * Editor::_import_thread (void *arg) { - PBD::notify_gui_about_thread_creation (pthread_self(), X_("Import")); SessionEvent::create_per_thread_pool ("import events", 64); Editor *ed = (Editor *) arg; diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 833ac580a2..449ea42132 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -3653,7 +3653,6 @@ Editor::unfreeze_route () void* Editor::_freeze_thread (void* arg) { - PBD::notify_gui_about_thread_creation (pthread_self(), X_("Freeze")); SessionEvent::create_per_thread_pool ("freeze events", 64); return static_cast(arg)->freeze_thread (); @@ -3702,13 +3701,7 @@ Editor::freeze_route () itt.cancel = false; itt.progress = 0.0f; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 500000); - - pthread_create_and_store (X_("freezer"), &itt.thread, &attr, _freeze_thread, this); - - pthread_attr_destroy(&attr); + pthread_create_and_store (X_("freezer"), &itt.thread, _freeze_thread, this); track_canvas->get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH)); diff --git a/gtk2_ardour/editor_timefx.cc b/gtk2_ardour/editor_timefx.cc index b52121f9c5..65c8a833e8 100644 --- a/gtk2_ardour/editor_timefx.cc +++ b/gtk2_ardour/editor_timefx.cc @@ -225,7 +225,7 @@ Editor::time_fx (RegionSelection& regions, float val, bool pitching) current_timefx->first_delete = current_timefx->signal_delete_event().connect (mem_fun (current_timefx, &TimeFXDialog::delete_in_progress)); - if (pthread_create_and_store ("timefx", ¤t_timefx->request.thread, 0, timefx_thread, current_timefx)) { + if (pthread_create_and_store ("timefx", ¤t_timefx->request.thread, timefx_thread, current_timefx)) { current_timefx->hide (); error << _("timefx cannot be started - thread creation error") << endmsg; return -1; @@ -337,7 +337,6 @@ Editor::do_timefx (TimeFXDialog& dialog) void* Editor::timefx_thread (void *arg) { - PBD::notify_gui_about_thread_creation (pthread_self(), X_("TimeFX")); SessionEvent::create_per_thread_pool ("timefx events", 64); TimeFXDialog* tsd = static_cast(arg); diff --git a/gtk2_ardour/gui_thread.h b/gtk2_ardour/gui_thread.h index 388902fa28..f9e5165a03 100644 --- a/gtk2_ardour/gui_thread.h +++ b/gtk2_ardour/gui_thread.h @@ -21,16 +21,11 @@ #define __ardour_gtk_gui_thread_h__ #include -#include "pbd/crossthread.h" #define ENSURE_GUI_THREAD(slot) \ - if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {\ + if (!Gtkmm2ext::UI::instance()->caller_is_self()) { \ Gtkmm2ext::UI::instance()->call_slot ((slot));\ return;\ } -#define GTK_SAFE(theSlot) crossthread_safe (Gtkmm2ext::UI::instance()->thread_id(),\ - *Gtkmm2ext::UI::instance(), \ - (theSlot)) - #endif /* __ardour_gtk_gui_thread_h__ */ diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index fdea4cb754..406ad714e9 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -393,7 +393,8 @@ int main (int argc, char *argv[]) ui = 0; ARDOUR::cleanup (); - pthread_cancel_all (); + // pthread_cancel (); + #ifdef HAVE_LV2 close_external_ui_windows(); #endif diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc index 8597995a88..c8956961c5 100644 --- a/gtk2_ardour/rc_option_editor.cc +++ b/gtk2_ardour/rc_option_editor.cc @@ -183,6 +183,7 @@ private: node.add_property ("mode", smod); if (MIDI::Manager::instance()->add_port (node) != 0) { + cerr << " there are now " << MIDI::Manager::instance()->nports() << endl; ports_changed (); } } diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 9a849257a2..9eb356ddd1 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -262,18 +262,21 @@ RouteUI::mute_press(GdkEventButton* ev) if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { +#if 0 /* Primary-Tertiary-click applies change to all routes */ _session.begin_reversible_command (_("mute change")); Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this); - _session.set_all_mute (!_route->muted()); + _session.set_mute (!_route->muted()); cmd->mark(); _session.add_command(cmd); _session.commit_reversible_command (); multiple_mute_change = true; +#endif } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) { +#if 0 /* Primary-button1 applies change to the mix group. NOTE: Primary-button2 is MIDI learn. */ @@ -281,15 +284,18 @@ RouteUI::mute_press(GdkEventButton* ev) if (ev->button == 1) { set_route_group_mute (_route, !_route->muted()); } +#endif } else { +#if 0 /* plain click applies change to this route */ if (wait_for_release) { _route->set_mute (!_route->muted(), this); } else { reversibly_apply_route_boolean ("mute change", &Route::set_mute, !_route->muted(), this); } +#endif } } } @@ -318,6 +324,18 @@ RouteUI::mute_release(GdkEventButton*) return true; } +void +RouteUI::post_solo_cleanup (SessionEvent* ev, bool was_not_latched) +{ + ENSURE_GUI_THREAD (bind (mem_fun (*this, &RouteUI::post_solo_cleanup), ev, was_not_latched)); + + delete ev; + + if (was_not_latched) { + Config->set_solo_latched (false); + } +} + bool RouteUI::solo_press(GdkEventButton* ev) { @@ -364,6 +382,7 @@ RouteUI::solo_press(GdkEventButton* ev) /* Primary-Tertiary-click applies change to all routes */ bool was_not_latched = false; + if (!Config->get_solo_latched ()) { was_not_latched = true; /* @@ -373,28 +392,25 @@ RouteUI::solo_press(GdkEventButton* ev) */ Config->set_solo_latched (true); } - _session.begin_reversible_command (_("solo change")); - Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this); - _session.set_all_solo (!_route->soloed()); - cmd->mark(); - _session.add_command (cmd); - _session.commit_reversible_command (); - multiple_solo_change = true; - if (was_not_latched) { - Config->set_solo_latched (false); - } + + SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0); + ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_solo), _session.get_routes(), !_route->soloed()); + ev->rt_return = bind (sigc::mem_fun (*this, &RouteUI::post_solo_cleanup), was_not_latched); + + _session.queue_event (ev); } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) { // Primary-Secondary-click: exclusively solo this track, not a toggle */ + + //boost::shared_ptr rl (new RouteList); + //rl->push_back (route()); - _session.begin_reversible_command (_("solo change")); - Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this); - _session.set_all_solo (false); - _route->set_solo (true, this); - cmd->mark(); - _session.add_command(cmd); - _session.commit_reversible_command (); + //SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0); + // ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_just_one_solo), rl, true); + //ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup); + + //_session.queue_event (ev); } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) { @@ -405,22 +421,29 @@ RouteUI::solo_press(GdkEventButton* ev) } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) { +#if 0 /* Primary-button1: solo mix group. NOTE: Primary-button2 is MIDI learn. */ if (ev->button == 1) { - set_route_group_solo (_route, !_route->soloed()); + queue_route_group_op (RouteGroup::Solo, &Session::set_all_solo, !_route->soloed()); } +#endif + } else { /* click: solo this route */ - if (wait_for_release) { - _route->set_solo (!_route->soloed(), this); - } else { - reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this); - } + + boost::shared_ptr rl (new RouteList); + rl->push_back (route()); + + SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0); + ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_solo), rl, !rec_enable_button->get_active()); + ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup); + + _session.queue_event (ev); } } } @@ -521,7 +544,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev) } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0); - ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_all_record_enable), _session.get_routes(), !rec_enable_button->get_active()); + ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_record_enable), _session.get_routes(), !rec_enable_button->get_active()); ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup); _session.queue_event (ev); @@ -533,7 +556,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev) */ if (ev->button == 1) { - queue_route_group_op (RouteGroup::RecEnable, &Session::set_all_record_enable, !rec_enable_button->get_active()); + queue_route_group_op (RouteGroup::RecEnable, &Session::set_record_enable, !rec_enable_button->get_active()); } } else if (Keyboard::is_context_menu_event (ev)) { @@ -543,9 +566,9 @@ RouteUI::rec_enable_press(GdkEventButton* ev) } else { boost::shared_ptr rl (new RouteList); rl->push_back (route()); - + SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0); - ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_all_record_enable), rl, !rec_enable_button->get_active()); + ev->rt_slot = bind (sigc::mem_fun (_session, &Session::set_record_enable), rl, !rec_enable_button->get_active()); ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup); _session.queue_event (ev); diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 275366cbe6..90bdaa7fb7 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -217,6 +217,7 @@ class RouteUI : public virtual AxisView void post_rtop_cleanup (ARDOUR::SessionEvent* ev); void post_group_rtop_cleanup (ARDOUR::SessionEvent* ev, ARDOUR::RouteGroup*, ARDOUR::RouteGroup::Property); + void post_solo_cleanup (ARDOUR::SessionEvent* ev, bool was_not_latched); }; #endif /* __ardour_route_ui__ */ diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index aa8d7b77f2..c719bb6515 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -733,7 +733,6 @@ SoundFileBrowser::found_search_clicked () void* freesound_search_thread_entry (void* arg) { - PBD::notify_gui_about_thread_creation (pthread_self(), X_("Freesound Search")); SessionEvent::create_per_thread_pool ("freesound events", 64); static_cast(arg)->freesound_search_thread (); @@ -757,7 +756,7 @@ SoundFileBrowser::freesound_search_clicked () searching = true; freesound_search_btn.set_label(_("Cancel")); pthread_t freesound_thr; - pthread_create_and_store ("freesound_search", &freesound_thr, 0, freesound_search_thread_entry, this); + pthread_create_and_store ("freesound_search", &freesound_thr, freesound_search_thread_entry, this); } } diff --git a/libs/ardour/analyser.cc b/libs/ardour/analyser.cc index 8e2ec99f27..992e5c5246 100644 --- a/libs/ardour/analyser.cc +++ b/libs/ardour/analyser.cc @@ -76,7 +76,6 @@ Analyser::queue_source_for_analysis (boost::shared_ptr src, bool force) void Analyser::work () { - PBD::notify_gui_about_thread_creation (pthread_self(), string ("analyser-") + to_string (pthread_self(), std::dec)); SessionEvent::create_per_thread_pool ("Analyser", 64); while (true) { diff --git a/libs/ardour/ardour/midi_ui.h b/libs/ardour/ardour/midi_ui.h new file mode 100644 index 0000000000..e1f322ddd1 --- /dev/null +++ b/libs/ardour/ardour/midi_ui.h @@ -0,0 +1,52 @@ +#ifndef __libardour_midi_ui_h__ +#define __libardour_midi_ui_h__ + +#include +#include "pbd/abstract_ui.h" + +namespace MIDI { + class port; +} + +namespace ARDOUR { + +class Session; + +/* this is mostly a placeholder because I suspect that at some + point we will want to add more members to accomodate + certain types of requests to the MIDI UI +*/ + +struct MidiUIRequest : public BaseUI::BaseRequestObject { + public: + MidiUIRequest () {} + ~MidiUIRequest() {} +}; + +class MidiControlUI : public AbstractUI +{ + public: + MidiControlUI (Session& s); + ~MidiControlUI (); + + static BaseUI::RequestType PortChange; + + void change_midi_ports (); + + protected: + void thread_init (); + void do_request (MidiUIRequest*); + + private: + typedef std::list > PortSources; + PortSources port_sources; + ARDOUR::Session& _session; + + bool midi_input_handler (Glib::IOCondition, MIDI::Port*); + void reset_ports (); + void clear_ports (); +}; + +} + +#endif /* __libardour_midi_ui_h__ */ diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index ed34c387e8..4e1721bae0 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -97,6 +97,7 @@ class MidiDiskstream; class MidiRegion; class MidiSource; class MidiTrack; +class MidiControlUI; class NamedSelection; class Playlist; class PluginInsert; @@ -616,14 +617,14 @@ class Session : public PBD::StatefulDestructible, public SessionEventManager, pu bool soloing() const { return _non_soloed_outs_muted; } bool listening() const { return _listen_cnt > 0; } - void set_all_solo (bool); - void set_all_mute (bool); - void set_all_listen (bool); + void set_solo (boost::shared_ptr, bool); + void set_mute (boost::shared_ptr, bool); + void set_listen (boost::shared_ptr, bool); sigc::signal SoloActive; sigc::signal SoloChanged; - void set_all_record_enable (boost::shared_ptr, bool); + void set_record_enable (boost::shared_ptr, bool); /* control/master out */ @@ -1253,25 +1254,11 @@ class Session : public PBD::StatefulDestructible, public SessionEventManager, pu bool non_realtime_work_pending() const { return static_cast(post_transport_work()); } bool process_can_proceed() const { return !(post_transport_work() & ProcessCannotProceedMask); } - struct MIDIRequest { - enum Type { - PortChange, - Quit - }; - Type type; - }; - - Glib::Mutex midi_lock; - pthread_t midi_thread; - int midi_request_pipe[2]; - RingBuffer midi_requests; + MidiControlUI* midi_control_ui; int start_midi_thread (); void terminate_midi_thread (); - void poke_midi_thread (); - static void *_midi_thread_work (void *arg); - void midi_thread_work (); - void change_midi_ports (); + int use_config_midi_ports (); void set_play_loop (bool yn); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index b69b06c4db..2c16c52296 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -135,7 +135,9 @@ _thread_init_callback (void * /*arg*/) knows about it. */ - PBD::notify_gui_about_thread_creation (pthread_self(), X_("Audioengine"), 4096); + PBD::notify_gui_about_thread_creation ("gui", pthread_self(), X_("Audioengine"), 4096); + PBD::notify_gui_about_thread_creation ("midiui", pthread_self(), X_("Audioengine"), 128); + SessionEvent::create_per_thread_pool (X_("Audioengine"), 512); MIDI::JACK_MidiPort::set_process_thread (pthread_self()); diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index 76a7fb2424..05ac7316ec 100644 --- a/libs/ardour/butler.cc +++ b/libs/ardour/butler.cc @@ -89,7 +89,7 @@ Butler::start_thread() return -1; } - if (pthread_create_and_store ("disk butler", &thread, 0, _thread_work, this)) { + if (pthread_create_and_store ("disk butler", &thread, _thread_work, this)) { error << _("Session: could not create butler thread") << endmsg; return -1; } @@ -113,7 +113,6 @@ Butler::terminate_thread () void * Butler::_thread_work (void* arg) { - PBD::notify_gui_about_thread_creation (pthread_self(), X_("Butler")); SessionEvent::create_per_thread_pool ("butler events", 64); return ((Butler *) arg)->thread_work (); } diff --git a/libs/ardour/export_channel_configuration.cc b/libs/ardour/export_channel_configuration.cc index 047aadc671..89a4952feb 100644 --- a/libs/ardour/export_channel_configuration.cc +++ b/libs/ardour/export_channel_configuration.cc @@ -176,7 +176,6 @@ ExportChannelConfiguration::write_file () void * ExportChannelConfiguration::_write_files (void *arg) { - notify_gui_about_thread_creation (pthread_self(), "Export post-processing"); SessionEvent::create_per_thread_pool ("exporter events", 64); // cc can be trated like 'this' diff --git a/libs/ardour/midi_ui.cc b/libs/ardour/midi_ui.cc new file mode 100644 index 0000000000..5a0640b3f6 --- /dev/null +++ b/libs/ardour/midi_ui.cc @@ -0,0 +1,150 @@ +/* + Copyright (C) 2009 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ +#include + +#include "pbd/pthread_utils.h" + +#include "midi++/manager.h" +#include "midi++/port.h" + +#include "ardour/debug.h" +#include "ardour/audioengine.h" +#include "ardour/midi_ui.h" +#include "ardour/session.h" +#include "ardour/session_event.h" +#include "ardour/types.h" + +using namespace std; +using namespace ARDOUR; +using namespace Glib; + +#include "i18n.h" + +BaseUI::RequestType MidiControlUI::PortChange = BaseUI::new_request_type(); + +#include "pbd/abstract_ui.cc" /* instantiate the template */ + +MidiControlUI::MidiControlUI (Session& s) + : AbstractUI (_("midiui")) + , _session (s) +{ + MIDI::Manager::instance()->PortsChanged.connect (mem_fun (*this, &MidiControlUI::change_midi_ports)); +} + +MidiControlUI::~MidiControlUI () +{ + clear_ports (); +} + +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 (); + + } else if (req->type == CallSlot) { + + req->the_slot (); + } +} + +void +MidiControlUI::change_midi_ports () +{ + MidiUIRequest* req = get_request (PortChange); + if (req == 0) { + return; + } + send_request (req); +} + +bool +MidiControlUI::midi_input_handler (IOCondition ioc, MIDI::Port* port) +{ + if (ioc & ~IO_IN) { + return false; + } + + if (ioc & IO_IN) { + + if (port->must_drain_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(); + port->parse (now); + } + + return true; +} + +void +MidiControlUI::clear_ports () +{ + for (PortSources::iterator i = port_sources.begin(); i != port_sources.end(); ++i) { + /* remove existing sources from the event loop */ + (*i)->destroy (); + } + + port_sources.clear (); +} + +void +MidiControlUI::reset_ports () +{ + clear_ports (); + + MIDI::Manager::PortList plist = MIDI::Manager::instance()->get_midi_ports (); + + for (MIDI::Manager::PortList::iterator i = plist.begin(); i != plist.end(); ++i) { + int fd; + if ((fd = (*i)->selectable ()) >= 0) { + Glib::RefPtr psrc = IOSource::create (fd, IO_IN|IO_HUP|IO_ERR); + psrc->connect (bind (mem_fun (*this, &MidiControlUI::midi_input_handler), (*i))); + port_sources.push_back (psrc); + } + } + + for (PortSources::iterator i = port_sources.begin(); i != port_sources.end(); ++i) { + (*i)->attach (_main_loop->get_context()); + } +} + +void +MidiControlUI::thread_init () +{ + struct sched_param rtparam; + + PBD::notify_gui_about_thread_creation (X_("gui"), pthread_self(), X_("MIDI"), 2048); + SessionEvent::create_per_thread_pool (X_("MIDI I/O"), 128); + + memset (&rtparam, 0, sizeof (rtparam)); + rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */ + + if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) { + // do we care? not particularly. + } + + reset_ports (); +} + diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index cdd5041856..9c3b28049f 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -71,6 +71,7 @@ #include "ardour/midi_playlist.h" #include "ardour/midi_region.h" #include "ardour/midi_track.h" +#include "ardour/midi_ui.h" #include "ardour/named_selection.h" #include "ardour/playlist.h" #include "ardour/plugin_insert.h" @@ -137,8 +138,6 @@ Session::Session (AudioEngine &eng, _butler (new Butler (this)), _post_transport_work (0), _send_timecode_update (false), - midi_thread (pthread_t (0)), - midi_requests (128), // the size of this should match the midi request pool size diskstreams (new DiskstreamList), routes (new RouteList), _total_free_4k_blocks (0), @@ -224,8 +223,6 @@ Session::Session (AudioEngine &eng, _butler (new Butler (this)), _post_transport_work (0), _send_timecode_update (false), - midi_thread (pthread_t (0)), - midi_requests (16), diskstreams (new DiskstreamList), routes (new RouteList), _total_free_4k_blocks (0), @@ -366,7 +363,8 @@ Session::destroy () Stateful::loading_state_version = 0; _butler->terminate_thread (); - //terminate_midi_thread (); + + delete midi_control_ui; if (click_data != default_click) { delete [] click_data; @@ -3518,10 +3516,8 @@ Session::is_auditioning () const } void -Session::set_all_solo (bool yn) +Session::set_solo (boost::shared_ptr r, bool yn) { - shared_ptr r = routes.reader (); - for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { if (!(*i)->is_hidden()) { (*i)->set_solo (yn, this); @@ -3532,10 +3528,8 @@ Session::set_all_solo (bool yn) } void -Session::set_all_listen (bool yn) +Session::set_listen (boost::shared_ptr r, bool yn) { - shared_ptr r = routes.reader (); - for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { if (!(*i)->is_hidden()) { (*i)->set_listen (yn, this); @@ -3546,10 +3540,8 @@ Session::set_all_listen (bool yn) } void -Session::set_all_mute (bool yn) +Session::set_mute (boost::shared_ptr r, bool yn) { - shared_ptr r = routes.reader (); - for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { if (!(*i)->is_hidden()) { (*i)->set_mute (yn, this); @@ -3605,7 +3597,7 @@ Session::graph_reordered () } void -Session::set_all_record_enable (boost::shared_ptr rl, bool yn) +Session::set_record_enable (boost::shared_ptr rl, bool yn) { if (!writable()) { return; @@ -4037,8 +4029,7 @@ Session::write_one_track (AudioTrack& track, nframes_t start, nframes_t end, return result; } - // any bigger than this seems to cause stack overflows in called functions - const nframes_t chunk_size = (128 * 1024)/4; + const nframes_t chunk_size = (256 * 1024)/4; // block all process callback handling @@ -4323,9 +4314,9 @@ Session::solo_control_mode_changed () /* cancel all solo or all listen when solo control mode changes */ if (Config->get_solo_control_is_listen_control()) { - set_all_solo (false); + set_solo (routes.reader(), false); } else { - set_all_listen (false); + set_listen (routes.reader(), false); } } diff --git a/libs/ardour/session_midi.cc b/libs/ardour/session_midi.cc index a0366dd6e8..4388fe6dca 100644 --- a/libs/ardour/session_midi.cc +++ b/libs/ardour/session_midi.cc @@ -28,6 +28,7 @@ #include +#include #include "midi++/mmc.h" #include "midi++/port.h" @@ -41,6 +42,7 @@ #include "ardour/session.h" #include "ardour/audio_track.h" #include "ardour/midi_track.h" +#include "ardour/midi_ui.h" #include "ardour/audio_diskstream.h" #include "ardour/slave.h" #include "ardour/cycles.h" @@ -52,6 +54,7 @@ using namespace std; using namespace ARDOUR; using namespace PBD; using namespace MIDI; +using namespace Glib; MachineControl::CommandSignature MMC_CommandSignature; MachineControl::ResponseSignature MMC_ResponseSignature; @@ -146,7 +149,6 @@ Session::set_mtc_port (string port_tag) out: MTC_PortChanged(); /* EMIT SIGNAL */ - change_midi_ports (); set_dirty(); return 0; } @@ -244,7 +246,6 @@ Session::set_mmc_port (string port_tag) out: MMC_PortChanged(); /* EMIT SIGNAL */ - change_midi_ports (); set_dirty(); return 0; } @@ -278,7 +279,6 @@ Session::set_midi_port (string /*port_tag*/) out: #endif MIDI_PortChanged(); /* EMIT SIGNAL */ - change_midi_ports (); set_dirty(); return 0; } @@ -320,7 +320,6 @@ Session::set_midi_clock_port (string port_tag) out: MIDIClock_PortChanged(); /* EMIT SIGNAL */ - change_midi_ports (); set_dirty(); return 0; } @@ -640,8 +639,12 @@ Session::mmc_step (MIDI::MachineControl &/*mmc*/, int steps) last_mmc_step = now; if (!step_queued) { - midi_timeouts.push_back (mem_fun (*this, &Session::mmc_step_timeout)); - step_queued = true; + if (midi_control_ui) { + RefPtr tsrc = TimeoutSource::create (100); + tsrc->connect (mem_fun (*this, &Session::mmc_step_timeout)); + tsrc->attach (midi_control_ui->main_loop()->get_context()); + step_queued = true; + } } } @@ -741,16 +744,6 @@ Session::mmc_record_enable (MIDI::MachineControl &mmc, size_t trk, bool enabled) } } -void -Session::change_midi_ports () -{ - MIDIRequest* request = new MIDIRequest; - - request->type = MIDIRequest::PortChange; - midi_requests.write (&request, 1); - poke_midi_thread (); -} - /** Send MTC Full Frame message (complete Timecode time) for the start of this cycle. * This resets the MTC code, the next quarter frame message that is sent will be * the first one with the beginning of this cycle as the new start point. @@ -1022,495 +1015,17 @@ Session::mmc_step_timeout () int Session::start_midi_thread () { - if (pipe (midi_request_pipe)) { - error << string_compose(_("Cannot create transport request signal pipe (%1)"), strerror (errno)) << endmsg; - return -1; - } - - if (fcntl (midi_request_pipe[0], F_SETFL, O_NONBLOCK)) { - error << string_compose(_("UI: cannot set O_NONBLOCK on " "signal read pipe (%1)"), strerror (errno)) << endmsg; - return -1; - } - - if (fcntl (midi_request_pipe[1], F_SETFL, O_NONBLOCK)) { - error << string_compose(_("UI: cannot set O_NONBLOCK on " "signal write pipe (%1)"), strerror (errno)) << endmsg; - return -1; - } - - if (pthread_create_and_store ("transport", &midi_thread, 0, _midi_thread_work, this)) { - error << _("Session: could not create transport thread") << endmsg; - return -1; - } - + midi_control_ui = new MidiControlUI (*this); + midi_control_ui->run (); return 0; } void Session::terminate_midi_thread () { - if (midi_thread) { - - MIDIRequest* request = new MIDIRequest; - void* status; - - request->type = MIDIRequest::Quit; - - midi_requests.write (&request, 1); - poke_midi_thread (); - - pthread_join (midi_thread, &status); + if (midi_control_ui) { + midi_control_ui->quit (); } } -void -Session::poke_midi_thread () -{ - static char c = 0; - - if (write (midi_request_pipe[1], &c, 1) != 1) { - error << string_compose(_("cannot send signal to midi thread! (%1)"), strerror (errno)) << endmsg; - } -} - -void * -Session::_midi_thread_work (void* arg) -{ - pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0); - pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); - - ((Session *) arg)->midi_thread_work (); - return 0; -} - -#if 0 -void -Session::midi_thread_work () -{ - MIDIRequest* request; - GPollFD pfd[4]; - int nfds = 0; - int timeout; - int fds_ready; - struct sched_param rtparam; - int x; - bool restart; - vector ports; - - PBD::notify_gui_about_thread_creation (pthread_self(), X_("MIDI"), 2048); - SessionEvent::create_per_thread_pool (X_("MIDI I/O"), 128); - - memset (&rtparam, 0, sizeof (rtparam)); - rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */ - - if ((x = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) { - // do we care? not particularly. - } - - /* set up the port vector; 5 is the largest possible size for now */ - - ports.assign (5, (MIDI::Port*) 0); - - GMainContext* main_context = g_main_context_new (); - - while (1) { - - nfds = 0; - - gpfd[nfds].fd = midi_request_pipe[0]; - gpfd[nfds].events = POLLIN|POLLHUP|POLLERR; - nfds++; - - if (Config->get_mmc_control() && _mmc_port && _mmc_port->selectable() >= 0) { - gpfd[nfds].fd = _mmc_port->selectable(); - gpfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _mmc_port; - g_main_context_add_poll (&gpfd[nfds]); - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mmc @ %2\n", nfds, _mmc_port)); - nfds++; - } - - /* if MTC is being handled on a different port from MMC - or we are not handling MMC at all, poll - the relevant port. - */ - - if (_mtc_port && (_mtc_port != _mmc_port || !Config->get_mmc_control()) && _mtc_port->selectable() >= 0) { - gpfd[nfds].fd = _mtc_port->selectable(); - gpfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _mtc_port; - g_main_context_add_poll (&gpfd[nfds]); - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mtc @ %2\n", nfds, _mtc_port)); - nfds++; - } - - if (_midi_clock_port && (_midi_clock_port != _mmc_port || !Config->get_mmc_control()) && _midi_clock_port->selectable() >= 0) { - gpfd[nfds].fd = _midi_clock_port->selectable(); - gpfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _midi_clock_port; - g_main_context_add_poll (&gpfd[nfds]); - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi clock @ %2\n", nfds, _midi_clock_port)); - nfds++; - } - - /* if we are using MMC control, we obviously have to listen - the relevant port. - */ - - if (_midi_port && (_midi_port != _mmc_port || !Config->get_mmc_control()) && (_midi_port != _mtc_port) && _midi_port->selectable() >= 0) { - gpfd[nfds].fd = _midi_port->selectable(); - gpfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _midi_port; - g_main_context_add_poll (&gpfd[nfds]); - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi @ %2\n", nfds, _midi_port)); - nfds++; - } - - if (!midi_timeouts.empty()) { - timeout = 100; /* 10msecs */ - } else { - timeout = -1; /* if there is no data, we don't care */ - } - - again: - - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI poll on %1 fds for %2\n", nfds, timeout)); - if (g_poll (gpfd, nfds, timeout) < 0) { - if (errno == EINTR) { - /* gdb at work, perhaps */ - goto again; - } - - error << string_compose(_("MIDI thread poll failed (%1)"), strerror (errno)) << endmsg; - - break; - } - - nframes64_t now = engine().frame_time(); - - DEBUG_TRACE (DEBUG::MidiIO, "MIDI thread awake\n"); - - fds_ready = 0; - - /* check the transport request pipe */ - - if (gpfd[0].revents & ~POLLIN) { - error << _("Error on transport thread request pipe") << endmsg; - break; - } - - if (gpfd[0].revents & POLLIN) { - - char foo[16]; - - DEBUG_TRACE (DEBUG::MidiIO, "MIDI request FIFO ready\n"); - fds_ready++; - - /* empty the pipe of all current requests */ - - while (1) { - size_t nread = read (midi_request_pipe[0], &foo, sizeof (foo)); - - if (nread > 0) { - if ((size_t) nread < sizeof (foo)) { - break; - } else { - continue; - } - } else if (nread == 0) { - break; - } else if (errno == EAGAIN) { - break; - } else { - fatal << _("Error reading from transport request pipe") << endmsg; - /*NOTREACHED*/ - } - } - - while (midi_requests.read (&request, 1) == 1) { - - switch (request->type) { - case MIDIRequest::PortChange: - /* restart poll with new ports */ - DEBUG_TRACE (DEBUG::MidiIO, "rebind\n"); - restart = true; - break; - - case MIDIRequest::Quit: - delete request; - DEBUG_TRACE (DEBUG::MidiIO, "thread quit\n"); - pthread_exit_pbd (0); - /*NOTREACHED*/ - break; - - default: - break; - } - - - delete request; - } - - } - - if (restart) { - DEBUG_TRACE (DEBUG::MidiIO, "ports changed, restart poll\n"); - restart = false; - continue; - } - - /* now read the rest of the ports */ - - for (int p = 1; p < nfds; ++p) { - - DEBUG_STR_SET(foo, "port #%1 revents = "); - DEBUG_STR(foo) << hex << pfd[p].revents << dec << endl; - DEBUG_TRACE (DEBUG::MidiIO, string_compose (DEBUG_STR(foo).str(), p)); - - if ((pfd[p].revents & ~POLLIN)) { - // error << string_compose(_("Transport: error polling MIDI port %1 (revents =%2%3%4"), p, &hex, pfd[p].revents, &dec) << endmsg; - break; - } - - if (pfd[p].revents & POLLIN) { - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI fd # %1 has data ready @ %2\n", p, now)); - fds_ready++; - ports[p]->parse (now); - } - - g_main_context_remove_poll (&gpfd[p]); - } - - /* timeout driven */ - - if (fds_ready < 2 && timeout != -1) { - - DEBUG_TRACE (DEBUG::MidiIO, "Check timeouts\n"); - for (MidiTimeoutList::iterator i = midi_timeouts.begin(); i != midi_timeouts.end(); ) { - - MidiTimeoutList::iterator tmp; - tmp = i; - ++tmp; - - if (!(*i)()) { - midi_timeouts.erase (i); - } - - i = tmp; - } - } - } - -} -#endif - -void -Session::midi_thread_work () -{ - MIDIRequest* request; - struct pollfd pfd[4]; - int nfds = 0; - int timeout; - int fds_ready; - struct sched_param rtparam; - int x; - bool restart; - vector ports; - - PBD::notify_gui_about_thread_creation (pthread_self(), X_("MIDI"), 2048); - SessionEvent::create_per_thread_pool (X_("MIDI I/O"), 128); - - memset (&rtparam, 0, sizeof (rtparam)); - rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */ - - if ((x = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) { - // do we care? not particularly. - } - - /* set up the port vector; 5 is the largest possible size for now */ - - ports.assign (5, (MIDI::Port*) 0); - - while (1) { - - nfds = 0; - - pfd[nfds].fd = midi_request_pipe[0]; - pfd[nfds].events = POLLIN|POLLHUP|POLLERR; - nfds++; - - if (Config->get_mmc_control() && _mmc_port && _mmc_port->selectable() >= 0) { - pfd[nfds].fd = _mmc_port->selectable(); - pfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _mmc_port; - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mmc @ %2\n", nfds, _mmc_port)); - nfds++; - } - - /* if MTC is being handled on a different port from MMC - or we are not handling MMC at all, poll - the relevant port. - */ - - if (_mtc_port && (_mtc_port != _mmc_port || !Config->get_mmc_control()) && _mtc_port->selectable() >= 0) { - pfd[nfds].fd = _mtc_port->selectable(); - pfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _mtc_port; - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for mtc @ %2\n", nfds, _mtc_port)); - nfds++; - } - - if (_midi_clock_port && (_midi_clock_port != _mmc_port || !Config->get_mmc_control()) && _midi_clock_port->selectable() >= 0) { - pfd[nfds].fd = _midi_clock_port->selectable(); - pfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _midi_clock_port; - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi clock @ %2\n", nfds, _midi_clock_port)); - nfds++; - } - - /* if we are using MMC control, we obviously have to listen - the relevant port. - */ - - if (_midi_port && (_midi_port != _mmc_port || !Config->get_mmc_control()) && (_midi_port != _mtc_port) && _midi_port->selectable() >= 0) { - pfd[nfds].fd = _midi_port->selectable(); - pfd[nfds].events = POLLIN|POLLHUP|POLLERR; - ports[nfds] = _midi_port; - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("set up port #%1 for midi @ %2\n", nfds, _midi_port)); - nfds++; - } - - if (!midi_timeouts.empty()) { - timeout = 100; /* 10msecs */ - } else { - timeout = -1; /* if there is no data, we don't care */ - } - - again: - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI poll on %1 fds for %2\n", nfds, timeout)); - if (poll (pfd, nfds, timeout) < 0) { - if (errno == EINTR) { - /* gdb at work, perhaps */ - goto again; - } - - error << string_compose(_("MIDI thread poll failed (%1)"), strerror (errno)) << endmsg; - - break; - } - - nframes64_t now = engine().frame_time(); - - DEBUG_TRACE (DEBUG::MidiIO, "MIDI thread awake\n"); - - fds_ready = 0; - - /* check the transport request pipe */ - - if (pfd[0].revents & ~POLLIN) { - error << _("Error on transport thread request pipe") << endmsg; - break; - } - - if (pfd[0].revents & POLLIN) { - - char foo[16]; - - DEBUG_TRACE (DEBUG::MidiIO, "MIDI request FIFO ready\n"); - fds_ready++; - - /* empty the pipe of all current requests */ - - while (1) { - size_t nread = read (midi_request_pipe[0], &foo, sizeof (foo)); - - if (nread > 0) { - if ((size_t) nread < sizeof (foo)) { - break; - } else { - continue; - } - } else if (nread == 0) { - break; - } else if (errno == EAGAIN) { - break; - } else { - fatal << _("Error reading from transport request pipe") << endmsg; - /*NOTREACHED*/ - } - } - - while (midi_requests.read (&request, 1) == 1) { - - switch (request->type) { - case MIDIRequest::PortChange: - /* restart poll with new ports */ - DEBUG_TRACE (DEBUG::MidiIO, "rebind\n"); - restart = true; - break; - - case MIDIRequest::Quit: - delete request; - DEBUG_TRACE (DEBUG::MidiIO, "thread quit\n"); - pthread_exit_pbd (0); - /*NOTREACHED*/ - break; - - default: - break; - } - - - delete request; - } - - } - - if (restart) { - DEBUG_TRACE (DEBUG::MidiIO, "ports changed, restart poll\n"); - restart = false; - continue; - } - - /* now read the rest of the ports */ - - for (int p = 1; p < nfds; ++p) { - -#ifndef NDEBUG - DEBUG_STR_SET(foo, "port #%1 revents = "); - DEBUG_STR(foo) << hex << pfd[p].revents << dec << endl; - DEBUG_TRACE (DEBUG::MidiIO, string_compose (DEBUG_STR(foo).str(), p)); -#endif - - if ((pfd[p].revents & ~POLLIN)) { - // error << string_compose(_("Transport: error polling MIDI port %1 (revents =%2%3%4"), p, &hex, pfd[p].revents, &dec) << endmsg; - break; - } - - if (pfd[p].revents & POLLIN) { - DEBUG_TRACE (DEBUG::MidiIO, string_compose ("MIDI fd # %1 has data ready @ %2\n", p, now)); - fds_ready++; - ports[p]->parse (now); - } - } - - /* timeout driven */ - - if (fds_ready < 2 && timeout != -1) { - - DEBUG_TRACE (DEBUG::MidiIO, "Check timeouts\n"); - for (MidiTimeoutList::iterator i = midi_timeouts.begin(); i != midi_timeouts.end(); ) { - - MidiTimeoutList::iterator tmp; - tmp = i; - ++tmp; - - if (!(*i)()) { - midi_timeouts.erase (i); - } - - i = tmp; - } - } - } -} diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index 078ef260c6..882694cccf 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -51,10 +51,6 @@ using namespace std; void Session::process (nframes_t nframes) { - // This is no more the appropriate place to call cycle - // start. cycle_start needs to be called at the Route::roll() - // where the signals which we want to mixdown have been calculated. - // MIDI::Manager::instance()->cycle_start(nframes); _silent = false; diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 3aaa3dbf22..f1bfa5ea92 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -219,7 +219,7 @@ Session::first_stage_init (string fullpath, string snapshot_name) first_file_data_format_reset = true; first_file_header_format_reset = true; post_export_sync = false; - //midi_thread = (pthread_t) 0; + midi_control_ui = 0; AudioDiskstream::allocate_working_buffers(); diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index 7c8943a4f1..a44a372726 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -58,7 +58,6 @@ std::list > SourceFactory::files_with_peaks; static void peak_thread_work () { - PBD::notify_gui_about_thread_creation (pthread_self(), string ("peakbuilder-") + to_string (pthread_self(), std::dec)); SessionEvent::create_per_thread_pool (X_("PeakFile Builder "), 64); while (true) { diff --git a/libs/ardour/wscript b/libs/ardour/wscript index b01260a30b..3e5f763461 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -124,6 +124,7 @@ libardour_sources = [ 'midi_state_tracker.cc', 'midi_stretch.cc', 'midi_track.cc', + 'midi_ui.cc', 'mix.cc', 'mtc_slave.cc', 'mtdm.cc', diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc index 944019d4c3..fb251e8078 100644 --- a/libs/gtkmm2ext/gtk_ui.cc +++ b/libs/gtkmm2ext/gtk_ui.cc @@ -47,7 +47,6 @@ using namespace Glib; using namespace PBD; using std::map; -pthread_t UI::gui_thread; UI *UI::theGtkUI = 0; BaseUI::RequestType Gtkmm2ext::ErrorMessage = BaseUI::new_request_type(); @@ -58,11 +57,10 @@ BaseUI::RequestType Gtkmm2ext::SetTip = BaseUI::new_request_type(); BaseUI::RequestType Gtkmm2ext::AddIdle = BaseUI::new_request_type(); BaseUI::RequestType Gtkmm2ext::AddTimeout = BaseUI::new_request_type(); -#include /* instantiate the template */ - +#include "pbd/abstract_ui.cc" /* instantiate the template */ UI::UI (string namestr, int *argc, char ***argv) - : AbstractUI (namestr, true) + : AbstractUI (namestr) { theMain = new Main (argc, argv); #ifndef GTK_NEW_TOOLTIP_API @@ -73,18 +71,20 @@ UI::UI (string namestr, int *argc, char ***argv) if (!theGtkUI) { theGtkUI = this; - gui_thread = pthread_self (); } else { fatal << "duplicate UI requested" << endmsg; /* NOTREACHED */ } - /* add the pipe to the select/poll loop that GDK does */ + /* the GUI event loop runs in the main thread of the app, + which is assumed to have called this. + */ - gdk_input_add (signal_pipe[0], - GDK_INPUT_READ, - UI::signal_pipe_callback, - this); + run_loop_thread = Thread::self(); + + /* attach our request source to the default main context */ + + request_channel.ios()->attach (MainContext::get_default()); errors = new TextViewer (800,600); errors->text().set_editable (false); @@ -100,8 +100,6 @@ UI::UI (string namestr, int *argc, char ***argv) errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors)); errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY); - register_thread (pthread_self(), X_("GUI")); - //load_rcfile (rcfile); } @@ -113,7 +111,7 @@ UI::~UI () bool UI::caller_is_ui_thread () { - return pthread_equal (gui_thread, pthread_self()); + return Thread::self() == run_loop_thread; } int @@ -122,7 +120,9 @@ UI::load_rcfile (string path, bool themechange) /* Yes, pointers to Glib::RefPtr. If these are not kept around, * a segfault somewhere deep in the wonderfully robust glib will result. * This does not occur if wiget.get_style is used instead of rc.get_style below, - * except that doesn't actually work... */ + * except that doesn't actually work... + */ + static Glib::RefPtr