2008-06-02 21:41:35 +00:00
|
|
|
/*
|
2009-10-14 16:10:01 +00:00
|
|
|
Copyright (C) 2002 Paul Davis
|
2008-06-02 21:41:35 +00:00
|
|
|
|
|
|
|
|
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 <unistd.h>
|
|
|
|
|
#include <cerrno>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <exception>
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include <glibmm/timer.h>
|
2013-07-24 19:29:45 -04:00
|
|
|
#include <glibmm/pattern.h>
|
|
|
|
|
#include <glibmm/module.h>
|
2010-06-24 14:13:45 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
#include "pbd/epa.h"
|
|
|
|
|
#include "pbd/file_utils.h"
|
2009-02-25 18:26:51 +00:00
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
|
#include "pbd/stacktrace.h"
|
|
|
|
|
#include "pbd/unknown_type.h"
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2011-09-28 13:37:57 +00:00
|
|
|
#include <jack/weakjack.h>
|
|
|
|
|
|
2010-07-06 00:16:36 +00:00
|
|
|
#include "midi++/port.h"
|
2012-04-24 02:28:51 +00:00
|
|
|
#include "midi++/jack_midi_port.h"
|
2010-06-29 13:47:53 +00:00
|
|
|
#include "midi++/mmc.h"
|
2010-07-05 15:41:05 +00:00
|
|
|
#include "midi++/manager.h"
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2009-06-16 14:58:33 +00:00
|
|
|
#include "ardour/audio_port.h"
|
2013-07-24 19:29:45 -04:00
|
|
|
#include "ardour/audio_backend.h"
|
2009-02-25 18:26:51 +00:00
|
|
|
#include "ardour/audioengine.h"
|
2013-07-24 19:29:45 -04:00
|
|
|
#include "ardour/backend_search_path.h"
|
2009-02-25 18:26:51 +00:00
|
|
|
#include "ardour/buffer.h"
|
|
|
|
|
#include "ardour/cycle_timer.h"
|
2012-01-14 23:31:55 +00:00
|
|
|
#include "ardour/internal_send.h"
|
2009-06-16 14:58:33 +00:00
|
|
|
#include "ardour/meter.h"
|
|
|
|
|
#include "ardour/midi_port.h"
|
|
|
|
|
#include "ardour/port.h"
|
2012-05-24 06:09:29 +00:00
|
|
|
#include "ardour/process_thread.h"
|
2009-06-16 14:58:33 +00:00
|
|
|
#include "ardour/session.h"
|
2008-06-02 21:41:35 +00:00
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
|
|
gint AudioEngine::m_meter_exit;
|
2009-10-14 17:35:33 +00:00
|
|
|
AudioEngine* AudioEngine::_instance = 0;
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::AudioEngine (const std::string& bcn, const std::string& bsu)
|
|
|
|
|
: _backend (0)
|
|
|
|
|
, session_remove_pending (false)
|
2012-06-21 20:31:14 +00:00
|
|
|
, session_removal_countdown (-1)
|
|
|
|
|
, monitor_check_interval (INT32_MAX)
|
|
|
|
|
, last_monitor_check (0)
|
|
|
|
|
, _processed_frames (0)
|
|
|
|
|
, _freewheeling (false)
|
|
|
|
|
, _pre_freewheel_mmc_enabled (false)
|
|
|
|
|
, _usecs_per_cycle (0)
|
|
|
|
|
, port_remove_in_progress (false)
|
|
|
|
|
, m_meter_thread (0)
|
|
|
|
|
, _main_thread (0)
|
2013-07-24 19:29:45 -04:00
|
|
|
, backend_client_name (bcn)
|
|
|
|
|
, backend_session_uuid (bsu)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
|
|
|
|
g_atomic_int_set (&m_meter_exit, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioEngine::~AudioEngine ()
|
|
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
drop_backend ();
|
|
|
|
|
|
2012-10-15 15:57:35 +00:00
|
|
|
config_connection.disconnect ();
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2012-07-25 17:48:55 +00:00
|
|
|
Glib::Threads::Mutex::Lock tm (_process_lock);
|
2008-06-02 21:41:35 +00:00
|
|
|
session_removed.signal ();
|
|
|
|
|
stop_metering_thread ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
AudioEngine*
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::create (const std::string& bcn, const std::string& bsu)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
|
|
|
|
if (_instance) {
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return new AudioEngine (bcn, bsu);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
void
|
|
|
|
|
AudioEngine::drop_backend ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (_backend) {
|
|
|
|
|
_backend->stop ();
|
|
|
|
|
delete _backend;
|
|
|
|
|
_backend = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
AudioEngine::set_backend (const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
BackendMap::iterator b = _backends.find (name);
|
|
|
|
|
|
|
|
|
|
if (b == _backends.end()) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop_backend ();
|
|
|
|
|
|
|
|
|
|
_backend = b->second;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-07-21 15:55:17 +00:00
|
|
|
_thread_init_callback (void * /*arg*/)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
|
|
|
|
/* make sure that anybody who needs to know about this thread
|
|
|
|
|
knows about it.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-12-31 19:49:22 +00:00
|
|
|
pthread_set_name (X_("audioengine"));
|
2009-12-26 16:15:11 +00:00
|
|
|
|
2009-12-09 03:05:14 +00:00
|
|
|
PBD::notify_gui_about_thread_creation ("gui", pthread_self(), X_("Audioengine"), 4096);
|
|
|
|
|
PBD::notify_gui_about_thread_creation ("midiui", pthread_self(), X_("Audioengine"), 128);
|
|
|
|
|
|
2009-12-04 19:24:09 +00:00
|
|
|
SessionEvent::create_per_thread_pool (X_("Audioengine"), 512);
|
|
|
|
|
|
2012-04-24 02:28:51 +00:00
|
|
|
MIDI::JackMIDIPort::set_process_thread (pthread_self());
|
2009-12-02 21:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 01:39:52 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2009-04-23 17:48:37 +00:00
|
|
|
void
|
2010-12-03 22:26:29 +00:00
|
|
|
AudioEngine::split_cycle (pframes_t offset)
|
2009-04-23 17:48:37 +00:00
|
|
|
{
|
|
|
|
|
/* caller must hold process lock */
|
|
|
|
|
|
2011-03-11 02:55:52 +00:00
|
|
|
Port::increment_global_port_buffer_offset (offset);
|
2009-04-23 17:48:37 +00:00
|
|
|
|
|
|
|
|
/* tell all Ports that we're going to start a new (split) cycle */
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Ports> p = ports.reader();
|
|
|
|
|
|
|
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->cycle_split ();
|
2009-04-23 17:48:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
int
|
|
|
|
|
AudioEngine::sample_rate_change (pframes_t nframes)
|
|
|
|
|
{
|
|
|
|
|
/* check for monitor input change every 1/10th of second */
|
|
|
|
|
|
|
|
|
|
monitor_check_interval = nframes / 10;
|
|
|
|
|
last_monitor_check = 0;
|
|
|
|
|
|
|
|
|
|
if (_session) {
|
|
|
|
|
_session->set_frame_rate (nframes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SampleRateChanged (nframes); /* EMIT SIGNAL */
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
AudioEngine::buffer_size_change (pframes_t bufsiz)
|
|
|
|
|
{
|
|
|
|
|
if (_session) {
|
|
|
|
|
_session->set_block_size (bufsiz);
|
|
|
|
|
last_monitor_check = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-04-13 20:48:33 +00:00
|
|
|
|
2012-01-10 23:39:39 +00:00
|
|
|
/** Method called by our ::process_thread when there is work to be done.
|
|
|
|
|
* @param nframes Number of frames to process.
|
2008-06-02 21:41:35 +00:00
|
|
|
*/
|
|
|
|
|
int
|
2010-12-03 22:26:29 +00:00
|
|
|
AudioEngine::process_callback (pframes_t nframes)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2012-07-25 17:48:55 +00:00
|
|
|
Glib::Threads::Mutex::Lock tm (_process_lock, Glib::Threads::TRY_LOCK);
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2012-01-14 22:02:59 +00:00
|
|
|
PT_TIMING_REF;
|
|
|
|
|
PT_TIMING_CHECK (1);
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
/// The number of frames that will have been processed when we've finished
|
2010-12-03 22:26:29 +00:00
|
|
|
pframes_t next_processed_frames;
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
/* handle wrap around of total frames counter */
|
|
|
|
|
|
2010-09-17 16:24:22 +00:00
|
|
|
if (max_framepos - _processed_frames < nframes) {
|
|
|
|
|
next_processed_frames = nframes - (max_framepos - _processed_frames);
|
2008-06-02 21:41:35 +00:00
|
|
|
} else {
|
|
|
|
|
next_processed_frames = _processed_frames + nframes;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 16:24:41 +00:00
|
|
|
if (!tm.locked()) {
|
2008-06-02 21:41:35 +00:00
|
|
|
/* return having done nothing */
|
|
|
|
|
_processed_frames = next_processed_frames;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-20 22:24:14 +00:00
|
|
|
if (session_remove_pending) {
|
2012-06-21 20:31:14 +00:00
|
|
|
|
2012-06-20 22:24:14 +00:00
|
|
|
/* perform the actual session removal */
|
2012-06-21 15:00:10 +00:00
|
|
|
|
2012-06-21 20:31:14 +00:00
|
|
|
if (session_removal_countdown < 0) {
|
2012-06-21 15:00:10 +00:00
|
|
|
|
2012-06-21 20:31:14 +00:00
|
|
|
/* fade out over 1 second */
|
|
|
|
|
session_removal_countdown = _frame_rate/2;
|
|
|
|
|
session_removal_gain = 1.0;
|
|
|
|
|
session_removal_gain_step = 1.0/session_removal_countdown;
|
|
|
|
|
|
|
|
|
|
} else if (session_removal_countdown > 0) {
|
|
|
|
|
|
|
|
|
|
/* we'll be fading audio out.
|
|
|
|
|
|
|
|
|
|
if this is the last time we do this as part
|
|
|
|
|
of session removal, do a MIDI panic now
|
|
|
|
|
to get MIDI stopped. This relies on the fact
|
|
|
|
|
that "immediate data" (aka "out of band data") from
|
|
|
|
|
MIDI tracks is *appended* after any other data,
|
|
|
|
|
so that it emerges after any outbound note ons, etc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (session_removal_countdown <= nframes) {
|
|
|
|
|
_session->midi_panic ();
|
2012-06-21 15:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-21 20:31:14 +00:00
|
|
|
} else {
|
|
|
|
|
/* fade out done */
|
|
|
|
|
_session = 0;
|
|
|
|
|
session_removal_countdown = -1; // reset to "not in progress"
|
|
|
|
|
session_remove_pending = false;
|
|
|
|
|
session_removed.signal(); // wakes up thread that initiated session removal
|
|
|
|
|
}
|
2012-06-20 22:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-23 16:24:41 +00:00
|
|
|
if (_session == 0) {
|
2012-06-21 20:31:14 +00:00
|
|
|
|
2012-04-23 16:24:41 +00:00
|
|
|
if (!_freewheeling) {
|
|
|
|
|
MIDI::Manager::instance()->cycle_start(nframes);
|
|
|
|
|
MIDI::Manager::instance()->cycle_end();
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
_processed_frames = next_processed_frames;
|
2012-06-20 22:24:14 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-09 20:21:19 +00:00
|
|
|
/* tell all relevant objects that we're starting a new cycle */
|
2009-04-23 17:48:37 +00:00
|
|
|
|
2012-01-14 23:31:55 +00:00
|
|
|
InternalSend::CycleStart (nframes);
|
2011-03-11 02:55:52 +00:00
|
|
|
Port::set_global_port_buffer_offset (0);
|
|
|
|
|
Port::set_cycle_framecnt (nframes);
|
2009-04-23 17:48:37 +00:00
|
|
|
|
|
|
|
|
/* tell all Ports that we're starting a new cycle */
|
|
|
|
|
|
2008-06-03 12:14:59 +00:00
|
|
|
boost::shared_ptr<Ports> p = ports.reader();
|
|
|
|
|
|
2008-09-29 09:44:25 +00:00
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->cycle_start (nframes);
|
2008-09-29 09:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 21:06:12 +00:00
|
|
|
/* test if we are freewheeling and there are freewheel signals connected.
|
2012-12-06 19:56:33 +00:00
|
|
|
ardour should act normally even when freewheeling unless /it/ is
|
|
|
|
|
exporting
|
|
|
|
|
*/
|
2010-07-14 21:06:12 +00:00
|
|
|
|
|
|
|
|
if (_freewheeling && !Freewheel.empty()) {
|
2012-12-06 19:56:33 +00:00
|
|
|
|
|
|
|
|
Freewheel (nframes);
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2008-06-03 12:14:59 +00:00
|
|
|
} else {
|
2012-04-23 16:24:41 +00:00
|
|
|
MIDI::Manager::instance()->cycle_start(nframes);
|
|
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
if (_session) {
|
|
|
|
|
_session->process (nframes);
|
2008-06-03 12:14:59 +00:00
|
|
|
}
|
2012-04-23 16:24:41 +00:00
|
|
|
|
|
|
|
|
MIDI::Manager::instance()->cycle_end();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2008-06-03 12:14:59 +00:00
|
|
|
if (_freewheeling) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
if (!_running) {
|
|
|
|
|
_processed_frames = next_processed_frames;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_monitor_check + monitor_check_interval < next_processed_frames) {
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Ports> p = ports.reader();
|
|
|
|
|
|
|
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
bool x;
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 08:36:04 -04:00
|
|
|
if (i->second->last_monitor() != (x = i->second->monitoring_input ())) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->set_last_monitor (x);
|
2009-10-14 16:10:01 +00:00
|
|
|
/* XXX I think this is dangerous, due to
|
2008-06-02 21:41:35 +00:00
|
|
|
a likely mutex in the signal handlers ...
|
|
|
|
|
*/
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->MonitorInputChanged (x); /* EMIT SIGNAL */
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
last_monitor_check = next_processed_frames;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
if (_session->silent()) {
|
2008-06-02 21:41:35 +00:00
|
|
|
|
|
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2012-01-27 13:23:39 +00:00
|
|
|
if (i->second->sends_output()) {
|
|
|
|
|
i->second->get_buffer(nframes).silence(nframes);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2012-06-21 20:31:14 +00:00
|
|
|
if (session_remove_pending && session_removal_countdown) {
|
|
|
|
|
|
|
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
|
|
|
|
|
|
|
|
|
if (i->second->sends_output()) {
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<AudioPort> ap = boost::dynamic_pointer_cast<AudioPort> (i->second);
|
|
|
|
|
if (ap) {
|
|
|
|
|
Sample* s = ap->engine_get_whole_audio_buffer ();
|
|
|
|
|
gain_t g = session_removal_gain;
|
|
|
|
|
|
|
|
|
|
for (pframes_t n = 0; n < nframes; ++n) {
|
|
|
|
|
*s++ *= g;
|
|
|
|
|
g -= session_removal_gain_step;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (session_removal_countdown > nframes) {
|
|
|
|
|
session_removal_countdown -= nframes;
|
|
|
|
|
} else {
|
|
|
|
|
session_removal_countdown = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session_removal_gain -= (nframes * session_removal_gain_step);
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-23 17:48:37 +00:00
|
|
|
// Finalize ports
|
2008-10-08 20:14:22 +00:00
|
|
|
|
|
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->cycle_end (nframes);
|
2008-10-08 20:14:22 +00:00
|
|
|
}
|
2009-04-23 17:48:37 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
_processed_frames = next_processed_frames;
|
2012-01-14 22:02:59 +00:00
|
|
|
|
|
|
|
|
PT_TIMING_CHECK (2);
|
|
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::stop_metering_thread ()
|
|
|
|
|
{
|
|
|
|
|
if (m_meter_thread) {
|
|
|
|
|
g_atomic_int_set (&m_meter_exit, 1);
|
|
|
|
|
m_meter_thread->join ();
|
|
|
|
|
m_meter_thread = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::start_metering_thread ()
|
|
|
|
|
{
|
|
|
|
|
if (m_meter_thread == 0) {
|
|
|
|
|
g_atomic_int_set (&m_meter_exit, 0);
|
2012-07-25 17:48:55 +00:00
|
|
|
m_meter_thread = Glib::Threads::Thread::create (boost::bind (&AudioEngine::meter_thread, this));
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::meter_thread ()
|
|
|
|
|
{
|
2009-12-31 19:49:22 +00:00
|
|
|
pthread_set_name (X_("meter"));
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2013-07-07 13:07:00 +02:00
|
|
|
while (true) {
|
2013-07-23 22:14:52 -04:00
|
|
|
Glib::usleep (10000); /* 1/100th sec interval */
|
2013-07-07 13:07:00 +02:00
|
|
|
if (g_atomic_int_get(&m_meter_exit)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Metering::Meter ();
|
|
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-14 16:10:01 +00:00
|
|
|
void
|
2008-06-02 21:41:35 +00:00
|
|
|
AudioEngine::set_session (Session *s)
|
|
|
|
|
{
|
2012-07-25 17:48:55 +00:00
|
|
|
Glib::Threads::Mutex::Lock pl (_process_lock);
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
SessionHandlePtr::set_session (s);
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
if (_session) {
|
2009-12-31 19:49:22 +00:00
|
|
|
|
|
|
|
|
start_metering_thread ();
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
pframes_t blocksize = _backend->buffer_size ();
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
/* page in as much of the session process code as we
|
|
|
|
|
can before we really start running.
|
|
|
|
|
*/
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
boost::shared_ptr<Ports> p = ports.reader();
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->cycle_start (blocksize);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
|
|
|
|
_session->process (blocksize);
|
2011-06-01 16:50:12 +00:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
|
2012-01-27 13:23:39 +00:00
|
|
|
i->second->cycle_end (blocksize);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-01 16:50:12 +00:00
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2009-10-14 16:10:01 +00:00
|
|
|
void
|
2008-06-02 21:41:35 +00:00
|
|
|
AudioEngine::remove_session ()
|
|
|
|
|
{
|
2012-07-25 17:48:55 +00:00
|
|
|
Glib::Threads::Mutex::Lock lm (_process_lock);
|
2008-06-02 21:41:35 +00:00
|
|
|
|
|
|
|
|
if (_running) {
|
|
|
|
|
|
2009-12-31 19:49:22 +00:00
|
|
|
stop_metering_thread ();
|
|
|
|
|
|
2009-12-17 18:24:23 +00:00
|
|
|
if (_session) {
|
2008-06-02 21:41:35 +00:00
|
|
|
session_remove_pending = true;
|
|
|
|
|
session_removed.wait(_process_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2009-12-17 18:24:23 +00:00
|
|
|
SessionHandlePtr::set_session (0);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2009-09-02 22:59:12 +00:00
|
|
|
remove_all_ports ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
|
2008-06-02 21:41:35 +00:00
|
|
|
void
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::died ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
/* called from a signal handler for SIGPIPE */
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
stop_metering_thread ();
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
_running = false;
|
|
|
|
|
_buffer_size = 0;
|
|
|
|
|
_frame_rate = 0;
|
2009-10-14 16:10:01 +00:00
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
int
|
|
|
|
|
AudioEngine::reset_timebase ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (_session) {
|
|
|
|
|
if (_session->config.get_jack_time_master()) {
|
|
|
|
|
_backend->set_time_master (true);
|
2008-06-02 21:41:35 +00:00
|
|
|
} else {
|
2013-07-24 19:29:45 -04:00
|
|
|
_backend->set_time_master (false);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
void
|
|
|
|
|
AudioEngine::destroy ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
delete _instance;
|
|
|
|
|
_instance = 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::discover_backends ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
vector<std::string> backend_modules;
|
|
|
|
|
AudioBackend* backend;
|
2012-01-27 13:23:39 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
_backends.clear ();
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
Glib::PatternSpec so_extension_pattern("*.so");
|
|
|
|
|
Glib::PatternSpec dylib_extension_pattern("*.dylib");
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
find_matching_files_in_search_path (backend_search_path (),
|
|
|
|
|
so_extension_pattern, backend_modules);
|
2011-10-28 17:04:09 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
find_matching_files_in_search_path (backend_search_path (),
|
|
|
|
|
dylib_extension_pattern, backend_modules);
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for backends in %1"), backend_search_path().to_string()));
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
for (vector<std::string>::iterator i = backend_modules.begin(); i != backend_modules.end(); ++i) {
|
|
|
|
|
if ((backend = backend_discover (*i)) != 0) {
|
|
|
|
|
_backends.insert (make_pair (backend->name(), backend));
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backends.size();
|
|
|
|
|
}
|
2009-10-14 17:35:33 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioBackend*
|
|
|
|
|
AudioEngine::backend_discover (const string& path)
|
|
|
|
|
{
|
|
|
|
|
Glib::Module* module = new Glib::Module(path);
|
|
|
|
|
AudioBackend* (*dfunc)(void);
|
|
|
|
|
void* func = 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!module) {
|
|
|
|
|
error << string_compose(_("AudioEngine: cannot load module \"%1\" (%2)"), path,
|
|
|
|
|
Glib::Module::get_last_error()) << endmsg;
|
|
|
|
|
delete module;
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!module->get_symbol("backend_factory", func)) {
|
|
|
|
|
error << string_compose(_("AudioEngine: module \"%1\" has no factory function."), path) << endmsg;
|
|
|
|
|
error << Glib::Module::get_last_error() << endmsg;
|
|
|
|
|
delete module;
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
dfunc = (AudioBackend* (*)(void))func;
|
|
|
|
|
AudioBackend* backend = dfunc();
|
|
|
|
|
|
|
|
|
|
return backend;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
/* BACKEND PROXY WRAPPERS */
|
|
|
|
|
|
2009-10-14 16:10:01 +00:00
|
|
|
int
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::start ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_running) {
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (_session) {
|
|
|
|
|
BootMessage (_("Connect session to engine"));
|
|
|
|
|
_session->set_frame_rate (_backend->sample_rate());
|
|
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
_processed_frames = 0;
|
|
|
|
|
last_monitor_check = 0;
|
2009-10-14 17:35:33 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (_backend->start() == 0) {
|
|
|
|
|
_running = true;
|
|
|
|
|
_has_run = true;
|
2013-07-30 17:48:57 -04:00
|
|
|
last_monitor_check = 0;
|
|
|
|
|
|
|
|
|
|
if (_session && _session->config.get_jack_time_master()) {
|
|
|
|
|
_backend->set_time_master (true);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
Running(); /* EMIT SIGNAL */
|
2008-06-02 21:41:35 +00:00
|
|
|
} else {
|
2013-07-24 19:29:45 -04:00
|
|
|
/* should report error? */
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
|
|
|
|
|
return _running ? 0 : -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
int
|
|
|
|
|
AudioEngine::stop ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
|
Glib::Threads::Mutex::Lock lm (_process_lock);
|
|
|
|
|
|
|
|
|
|
if (_backend->stop () == 0) {
|
|
|
|
|
_running = false;
|
|
|
|
|
stop_metering_thread ();
|
|
|
|
|
|
|
|
|
|
Stopped (); /* EMIT SIGNAL */
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
int
|
|
|
|
|
AudioEngine::pause ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
if (_backend->pause () == 0) {
|
|
|
|
|
_running = false;
|
|
|
|
|
Stopped(); /* EMIT SIGNAL */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
int
|
|
|
|
|
AudioEngine::freewheel (bool start_stop)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2009-01-21 02:27:21 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
/* _freewheeling will be set when first Freewheel signal occurs */
|
2012-01-27 13:23:39 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->freewheel (start_stop);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
float
|
|
|
|
|
AudioEngine::get_cpu_load() const
|
2012-01-27 13:23:39 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0.0;
|
2012-01-27 13:23:39 +00:00
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
return _backend->cpu_load ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
AudioEngine::is_realtime() const
|
|
|
|
|
{
|
|
|
|
|
if (!_backend) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _backend->is_realtime();
|
2012-01-27 13:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
void
|
|
|
|
|
AudioEngine::transport_start ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->transport_start ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-14 17:35:33 +00:00
|
|
|
void
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::transport_stop ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->transport_stop ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
TransportState
|
|
|
|
|
AudioEngine::transport_state ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return TransportStopped;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->transport_state ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::transport_locate (framepos_t pos)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
2008-06-02 21:41:35 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->transport_locate (pos);
|
|
|
|
|
}
|
2008-06-02 21:41:35 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
framepos_t
|
|
|
|
|
AudioEngine::transport_frame()
|
|
|
|
|
{
|
|
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->transport_frame ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
framecnt_t
|
|
|
|
|
AudioEngine::sample_rate () const
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return _backend->sample_rate ();
|
2010-07-28 00:43:15 +00:00
|
|
|
}
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
pframes_t
|
|
|
|
|
AudioEngine::samples_per_cycle () const
|
2010-07-28 00:43:15 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
return _backend->buffer_size ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::usecs_per_cycle () const
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
return _backend->usecs_per_cycle ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
size_t
|
|
|
|
|
AudioEngine::raw_buffer_size (DataType t)
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return -1;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->raw_buffer_size (t);
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
pframes_t
|
|
|
|
|
AudioEngine::sample_time ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->sample_time ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
pframes_t
|
|
|
|
|
AudioEngine::sample_time_at_cycle_start ()
|
2008-06-02 21:41:35 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->sample_time_at_cycle_start ();
|
2008-06-02 21:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
pframes_t
|
|
|
|
|
AudioEngine::samples_since_cycle_start ()
|
2011-03-18 20:21:51 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return _backend->samples_since_cycle_start ();
|
2011-03-18 20:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-01 16:50:12 +00:00
|
|
|
bool
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::get_sync_offset (pframes_t& offset) const
|
2011-03-15 19:32:21 +00:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return _backend->get_sync_offset (offset);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
2011-03-15 19:32:21 +00:00
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
int
|
2013-07-24 19:29:45 -04:00
|
|
|
AudioEngine::create_process_thread (boost::function<void()> func, pthread_t* thr, size_t stacksize)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-24 19:29:45 -04:00
|
|
|
if (!_backend) {
|
|
|
|
|
return -1;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
2013-07-24 19:29:45 -04:00
|
|
|
return _backend->create_process_thread (func, thr, stacksize);
|
2011-09-21 17:28:13 +00:00
|
|
|
}
|
2011-12-15 14:33:20 +00:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::thread_init_callback (void* arg)
|
|
|
|
|
{
|
|
|
|
|
/* make sure that anybody who needs to know about this thread
|
|
|
|
|
knows about it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
pthread_set_name (X_("audioengine"));
|
|
|
|
|
|
|
|
|
|
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::JackMIDIPort::set_process_thread (pthread_self());
|
|
|
|
|
|
|
|
|
|
if (arg) {
|
|
|
|
|
AudioEngine* ae = static_cast<AudioEngine*> (arg);
|
|
|
|
|
/* the special thread created/managed by the backend */
|
|
|
|
|
ae->_main_thread = new ProcessThread;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXXX
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::timebase_callback (TransportState state, pframes_t nframes, jack_position_t pos, int new_position)
|
|
|
|
|
{
|
|
|
|
|
if (_session && _session->synced_to_jack()) {
|
|
|
|
|
// _session->timebase_callback (state, nframes, pos, new_position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
AudioEngine::sync_callback (TransportState state, framepos_t position)
|
|
|
|
|
{
|
|
|
|
|
if (_session) {
|
|
|
|
|
return _session->jack_sync_callback (state, position);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::freewheel_callback (bool onoff)
|
|
|
|
|
{
|
|
|
|
|
if (onoff) {
|
|
|
|
|
_pre_freewheel_mmc_enabled = MIDI::Manager::instance()->mmc()->send_enabled ();
|
|
|
|
|
MIDI::Manager::instance()->mmc()->enable_send (false);
|
|
|
|
|
} else {
|
|
|
|
|
MIDI::Manager::instance()->mmc()->enable_send (_pre_freewheel_mmc_enabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::latency_callback (bool for_playback)
|
|
|
|
|
{
|
|
|
|
|
if (_session) {
|
|
|
|
|
_session->update_latency (for_playback);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AudioEngine::halted_callback (const char* why)
|
|
|
|
|
{
|
|
|
|
|
stop_metering_thread ();
|
|
|
|
|
|
|
|
|
|
MIDI::JackMIDIPort::EngineHalted (); /* EMIT SIGNAL */
|
|
|
|
|
Halted (why); /* EMIT SIGNAL */
|
|
|
|
|
}
|