summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-12-09 03:05:14 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-12-09 03:05:14 +0000
commitc38e02285fda1fd7966c9e4ad85994445247e6a6 (patch)
treea5f46d4350b8df3e0a74558169c696cbb837ce7f /libs/ardour
parent90f95df20707995e267bd624b28980cfd9200bed (diff)
major design changes: use glib event loop for MIDI thread/UI; rework design of BaseUI and AbstractUI; solo & mute are both temporarily broken; OSC control up next; may segfault during exit
git-svn-id: svn://localhost/ardour2/branches/3.0@6328 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/analyser.cc1
-rw-r--r--libs/ardour/ardour/midi_ui.h52
-rw-r--r--libs/ardour/ardour/session.h27
-rw-r--r--libs/ardour/audioengine.cc4
-rw-r--r--libs/ardour/butler.cc3
-rw-r--r--libs/ardour/export_channel_configuration.cc1
-rw-r--r--libs/ardour/midi_ui.cc150
-rw-r--r--libs/ardour/session.cc29
-rw-r--r--libs/ardour/session_midi.cc511
-rw-r--r--libs/ardour/session_process.cc4
-rw-r--r--libs/ardour/session_state.cc2
-rw-r--r--libs/ardour/source_factory.cc1
-rw-r--r--libs/ardour/wscript1
13 files changed, 238 insertions, 548 deletions
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<Source> 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 <list>
+#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<MidiUIRequest>
+{
+ 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<Glib::RefPtr<Glib::IOSource> > 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<RouteList>, bool);
+ void set_mute (boost::shared_ptr<RouteList>, bool);
+ void set_listen (boost::shared_ptr<RouteList>, bool);
sigc::signal<void,bool> SoloActive;
sigc::signal<void> SoloChanged;
- void set_all_record_enable (boost::shared_ptr<RouteList>, bool);
+ void set_record_enable (boost::shared_ptr<RouteList>, 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<bool>(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<MIDIRequest*> 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 <cstdlib>
+
+#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<MidiUIRequest> (_("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<IOSource> 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<RouteList> r, bool yn)
{
- shared_ptr<RouteList> 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<RouteList> r, bool yn)
{
- shared_ptr<RouteList> 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<RouteList> r, bool yn)
{
- shared_ptr<RouteList> 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<RouteList> rl, bool yn)
+Session::set_record_enable (boost::shared_ptr<RouteList> 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 <boost/shared_ptr.hpp>
+#include <glibmm/main.h>
#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<TimeoutSource> 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);
- }
-}
-
-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<MIDI::Port*> 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;
- }
- }
+ if (midi_control_ui) {
+ midi_control_ui->quit ();
}
-
}
-#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<MIDI::Port*> 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<boost::weak_ptr<AudioSource> > 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',