2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glibmm/timer.h>
28 #include <pbd/pthread_utils.h>
29 #include <pbd/stacktrace.h>
30 #include <pbd/unknown_type.h>
32 #include <midi++/jack.h>
34 #include <ardour/audioengine.h>
35 #include <ardour/buffer.h>
36 #include <ardour/port.h>
37 #include <ardour/jack_audio_port.h>
38 #include <ardour/jack_midi_port.h>
39 #include <ardour/audio_port.h>
40 #include <ardour/session.h>
41 #include <ardour/cycle_timer.h>
42 #include <ardour/utils.h>
47 #include <ardour/timestamps.h>
52 using namespace ARDOUR;
55 gint AudioEngine::m_meter_exit;
58 ardour_jack_error (const char* msg)
60 error << "JACK: " << msg << endmsg;
63 AudioEngine::AudioEngine (string client_name)
67 session_remove_pending = false;
70 last_monitor_check = 0;
71 monitor_check_interval = max_frames;
72 _processed_frames = 0;
77 _freewheel_thread_registered = false;
78 _freewheeling = false;
81 g_atomic_int_set (&m_meter_exit, 0);
83 if (connect_to_jack (client_name)) {
84 throw NoBackendAvailable ();
87 Port::set_engine (this);
89 // Initialize parameter metadata (e.g. ranges)
90 Evoral::Parameter p(NullAutomation);
91 p = EventTypeMap::instance().new_parameter(NullAutomation);
92 p = EventTypeMap::instance().new_parameter(GainAutomation);
93 p = EventTypeMap::instance().new_parameter(PanAutomation);
94 p = EventTypeMap::instance().new_parameter(PluginAutomation);
95 p = EventTypeMap::instance().new_parameter(SoloAutomation);
96 p = EventTypeMap::instance().new_parameter(MuteAutomation);
97 p = EventTypeMap::instance().new_parameter(MidiCCAutomation);
98 p = EventTypeMap::instance().new_parameter(MidiPgmChangeAutomation);
99 p = EventTypeMap::instance().new_parameter(MidiPitchBenderAutomation);
100 p = EventTypeMap::instance().new_parameter(MidiChannelPressureAutomation);
101 p = EventTypeMap::instance().new_parameter(FadeInAutomation);
102 p = EventTypeMap::instance().new_parameter(FadeOutAutomation);
103 p = EventTypeMap::instance().new_parameter(EnvelopeAutomation);
104 p = EventTypeMap::instance().new_parameter(MidiCCAutomation);
107 AudioEngine::~AudioEngine ()
110 Glib::Mutex::Lock tm (_process_lock);
111 session_removed.signal ();
114 jack_client_close (_jack);
118 stop_metering_thread ();
123 AudioEngine::jack() const
129 _thread_init_callback (void *arg)
131 /* make sure that anybody who needs to know about this thread
135 PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096);
136 MIDI::JACK_MidiPort::set_process_thread (pthread_self());
140 AudioEngine::start ()
143 error << _("AudioEngine::start() called while disconnected from JACK") << endmsg;
150 nframes_t blocksize = jack_get_buffer_size (_jack);
152 BootMessage (_("Connect session to engine"));
154 session->set_block_size (blocksize);
155 session->set_frame_rate (jack_get_sample_rate (_jack));
157 /* page in as much of the session process code as we
158 can before we really start running.
161 session->process (blocksize);
162 session->process (blocksize);
163 session->process (blocksize);
164 session->process (blocksize);
165 session->process (blocksize);
166 session->process (blocksize);
167 session->process (blocksize);
168 session->process (blocksize);
171 _processed_frames = 0;
172 last_monitor_check = 0;
174 jack_on_shutdown (_jack, halted, this);
175 jack_set_graph_order_callback (_jack, _graph_order_callback, this);
176 jack_set_thread_init_callback (_jack, _thread_init_callback, this);
177 jack_set_process_callback (_jack, _process_callback, this);
178 jack_set_sample_rate_callback (_jack, _sample_rate_callback, this);
179 jack_set_buffer_size_callback (_jack, _bufsize_callback, this);
180 jack_set_xrun_callback (_jack, _xrun_callback, this);
181 jack_set_sync_callback (_jack, _jack_sync_callback, this);
182 jack_set_freewheel_callback (_jack, _freewheel_callback, this);
184 if (Config->get_jack_time_master()) {
185 jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
188 if (jack_activate (_jack) == 0) {
191 Running(); /* EMIT SIGNAL */
193 // error << _("cannot activate JACK client") << endmsg;
196 start_metering_thread();
199 return _running ? 0 : -1;
203 AudioEngine::stop (bool forever)
207 disconnect_from_jack ();
209 jack_deactivate (_jack);
210 Stopped(); /* EMIT SIGNAL */
214 return _running ? -1 : 0;
219 AudioEngine::get_sync_offset (nframes_t& offset) const
222 #ifdef HAVE_JACK_VIDEO_SUPPORT
227 (void) jack_transport_query (_jack, &pos);
229 if (pos.valid & JackVideoFrameOffset) {
230 offset = pos.video_offset;
241 AudioEngine::_jack_timebase_callback (jack_transport_state_t state, nframes_t nframes,
242 jack_position_t* pos, int new_position, void *arg)
244 static_cast<AudioEngine*> (arg)->jack_timebase_callback (state, nframes, pos, new_position);
248 AudioEngine::jack_timebase_callback (jack_transport_state_t state, nframes_t nframes,
249 jack_position_t* pos, int new_position)
251 if (_jack && session && session->synced_to_jack()) {
252 session->jack_timebase_callback (state, nframes, pos, new_position);
257 AudioEngine::_jack_sync_callback (jack_transport_state_t state, jack_position_t* pos, void* arg)
259 return static_cast<AudioEngine*> (arg)->jack_sync_callback (state, pos);
263 AudioEngine::jack_sync_callback (jack_transport_state_t state, jack_position_t* pos)
265 if (_jack && session) {
266 return session->jack_sync_callback (state, pos);
273 AudioEngine::_xrun_callback (void *arg)
275 AudioEngine* ae = static_cast<AudioEngine*> (arg);
276 if (ae->connected()) {
277 ae->Xrun (); /* EMIT SIGNAL */
283 AudioEngine::_graph_order_callback (void *arg)
285 AudioEngine* ae = static_cast<AudioEngine*> (arg);
286 if (ae->connected()) {
287 ae->GraphReordered (); /* EMIT SIGNAL */
292 /** Wrapped which is called by JACK as its process callback. It is just
293 * here to get us back into C++ land by calling AudioEngine::process_callback()
294 * @param nframes Number of frames passed by JACK.
295 * @param arg User argument passed by JACK, which will be the AudioEngine*.
298 AudioEngine::_process_callback (nframes_t nframes, void *arg)
300 return static_cast<AudioEngine *> (arg)->process_callback (nframes);
304 AudioEngine::_freewheel_callback (int onoff, void *arg)
306 static_cast<AudioEngine*>(arg)->_freewheeling = onoff;
309 /** Method called by JACK (via _process_callback) which says that there
310 * is work to be done.
311 * @param nframes Number of frames to process.
314 AudioEngine::process_callback (nframes_t nframes)
316 // CycleTimer ct ("AudioEngine::process");
317 Glib::Mutex::Lock tm (_process_lock, Glib::TRY_LOCK);
319 /// The number of frames that will have been processed when we've finished
320 nframes_t next_processed_frames;
322 /* handle wrap around of total frames counter */
324 if (max_frames - _processed_frames < nframes) {
325 next_processed_frames = nframes - (max_frames - _processed_frames);
327 next_processed_frames = _processed_frames + nframes;
330 if (!tm.locked() || session == 0) {
331 /* return having done nothing */
332 _processed_frames = next_processed_frames;
336 if (session_remove_pending) {
337 /* perform the actual session removal */
339 session_remove_pending = false;
340 session_removed.signal();
341 _processed_frames = next_processed_frames;
345 boost::shared_ptr<Ports> p = ports.reader();
347 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
349 /* Only run cycle_start() on output ports, because
350 inputs must be done in the correct processing order,
351 which requires interleaving with route processing.
354 (*i)->cycle_start (nframes, 0);
358 /* emit the Freewheel signal and stop freewheeling in the event of trouble */
359 if (Freewheel (nframes)) {
360 jack_set_freewheel (_jack, false);
365 session->process (nframes);
374 _processed_frames = next_processed_frames;
378 if (last_monitor_check + monitor_check_interval < next_processed_frames) {
380 boost::shared_ptr<Ports> p = ports.reader();
382 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
387 if (port->_last_monitor != (x = port->monitoring_input ())) {
388 port->_last_monitor = x;
389 /* XXX I think this is dangerous, due to
390 a likely mutex in the signal handlers ...
392 port->MonitorInputChanged (x); /* EMIT SIGNAL */
395 last_monitor_check = next_processed_frames;
398 if (session->silent()) {
400 boost::shared_ptr<Ports> p = ports.reader();
402 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
406 if (port->sends_output()) {
407 port->get_buffer(nframes, 0 ).silence(nframes);
412 // Finalize ports (ie write data if necessary)
414 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
416 (*i)->cycle_end (nframes, 0);
419 _processed_frames = next_processed_frames;
424 AudioEngine::_sample_rate_callback (nframes_t nframes, void *arg)
426 return static_cast<AudioEngine *> (arg)->jack_sample_rate_callback (nframes);
430 AudioEngine::jack_sample_rate_callback (nframes_t nframes)
432 _frame_rate = nframes;
433 _usecs_per_cycle = (int) floor ((((double) frames_per_cycle() / nframes)) * 1000000.0);
435 /* check for monitor input change every 1/10th of second */
437 monitor_check_interval = nframes / 10;
438 last_monitor_check = 0;
441 session->set_frame_rate (nframes);
444 SampleRateChanged (nframes); /* EMIT SIGNAL */
450 AudioEngine::_bufsize_callback (nframes_t nframes, void *arg)
452 return static_cast<AudioEngine *> (arg)->jack_bufsize_callback (nframes);
456 AudioEngine::jack_bufsize_callback (nframes_t nframes)
458 _buffer_size = nframes;
459 _usecs_per_cycle = (int) floor ((((double) nframes / frame_rate())) * 1000000.0);
460 last_monitor_check = 0;
462 boost::shared_ptr<Ports> p = ports.reader();
464 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
469 session->set_block_size (_buffer_size);
476 AudioEngine::stop_metering_thread ()
478 if (m_meter_thread) {
479 g_atomic_int_set (&m_meter_exit, 1);
480 m_meter_thread->join ();
486 AudioEngine::start_metering_thread ()
488 if (m_meter_thread == 0) {
489 g_atomic_int_set (&m_meter_exit, 0);
490 m_meter_thread = Glib::Thread::create (sigc::mem_fun(this, &AudioEngine::meter_thread),
491 500000, true, true, Glib::THREAD_PRIORITY_NORMAL);
496 AudioEngine::meter_thread ()
499 Glib::usleep (10000); /* 1/100th sec interval */
500 if (g_atomic_int_get(&m_meter_exit)) {
503 IO::update_meters ();
508 AudioEngine::set_session (Session *s)
510 Glib::Mutex::Lock pl (_process_lock);
516 nframes_t blocksize = jack_get_buffer_size (_jack);
518 /* page in as much of the session process code as we
519 can before we really start running.
522 boost::shared_ptr<Ports> p = ports.reader();
524 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
525 (*i)->cycle_start (blocksize, 0);
528 s->process (blocksize);
529 s->process (blocksize);
530 s->process (blocksize);
531 s->process (blocksize);
532 s->process (blocksize);
533 s->process (blocksize);
534 s->process (blocksize);
535 s->process (blocksize);
537 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
538 (*i)->cycle_end (blocksize, 0);
544 AudioEngine::remove_session ()
546 Glib::Mutex::Lock lm (_process_lock);
551 session_remove_pending = true;
552 session_removed.wait(_process_lock);
559 //FIXME: Preliminary bugfix for http://tracker.ardour.org/view.php?id=1985
560 //remove_all_ports ();
564 AudioEngine::port_registration_failure (const std::string& portname)
566 string full_portname = jack_client_name;
567 full_portname += ':';
568 full_portname += portname;
571 jack_port_t* p = jack_port_by_name (_jack, full_portname.c_str());
575 reason = _("a port with this name already exists: check for duplicated track/bus names");
577 reason = _("unknown error");
580 throw PortRegistrationFailure (string_compose (_("AudioEngine: cannot register port \"%1\": %2"), portname, reason).c_str());
584 AudioEngine::register_port (DataType dtype, const string& portname, bool input, bool publish)
588 /*cerr << "trying to register port with name " << portname << endl;*/
590 if (dtype == DataType::AUDIO) {
591 newport = new AudioPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
592 } else if (dtype == DataType::MIDI) {
593 newport = new MidiPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
595 throw unknown_type();
598 /*cerr << "successfully got port " << portname << " with address " << newport << endl;*/
600 RCUWriter<Ports> writer (ports);
601 boost::shared_ptr<Ports> ps = writer.get_copy ();
602 /*cerr << "Address of ports list: " << ps << endl
603 << "Ports set size before insert: " << ps->size() << endl;*/
604 ps->insert (ps->begin(), newport);
605 /*cerr << "Ports set size after insert: " << ps->size() << endl;*/
607 /* writer goes out of scope, forces update */
613 throw PortRegistrationFailure("unable to create port (unknown type?)");
618 AudioEngine::get_port (const std::string& full_name)
620 boost::shared_ptr<Ports> p = ports.reader();
622 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
623 //cerr << "comparing port name '" << (*i)->name() << "' with '" << full_name << "'" << endl;
624 if ((*i)->name() == full_name) {
633 AudioEngine::register_input_port (DataType type, const string& portname, bool publish)
635 return register_port (type, portname, true, publish);
639 AudioEngine::register_output_port (DataType type, const string& portname, bool publish)
641 return register_port (type, portname, false, publish);
645 AudioEngine::unregister_port (Port& port)
647 /* caller must hold process lock */
649 cerr << "about to unregister Port xx x" << &port << "\n";
652 /* probably happening when the engine has been halted by JACK,
653 in which case, there is nothing we can do here.
655 cerr << "not running\n";
660 cerr << "before getcopy\n";
662 RCUWriter<Ports> writer (ports);
663 boost::shared_ptr<Ports> ps = writer.get_copy ();
665 cerr << "Ports set size: " << ps.get()->size() << endl;
667 for (Ports::iterator i = ps->begin(); i != ps->end(); ++i) {
668 cerr << "before delete" << endl;
670 cerr << "About to delete " << &port << endl;
673 cerr << "After erasing ports size: " << ps->size();
678 /* writer goes out of scope, forces update */
681 cerr << "before remove_connections\n";
682 remove_connections_for (port);
688 AudioEngine::connect (const string& source, const string& destination)
694 fatal << _("connect called before engine was started") << endmsg;
701 string s = make_port_name_non_relative (source);
702 string d = make_port_name_non_relative (destination);
704 //cerr << "Trying to connect source: " << s << " with destination " << d << endl;
706 Port* src = get_port (s);
707 Port* dst = get_port (d);
711 /* both ports are known to us, so do the internal connect stuff */
713 if ((ret = src->connect (*dst)) == 0) {
714 ret = dst->connect (*src);
717 } else if (src || dst) {
719 /* one port is known to us, try to connect it to something external */
721 PortConnectableByName* pcn;
725 pcn = dynamic_cast<PortConnectableByName*>(src);
728 pcn = dynamic_cast<PortConnectableByName*>(dst);
733 ret = pcn->connect (other);
740 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
747 error << string_compose(_("AudioEngine: connection already exists: %1 (%2) to %3 (%4)"),
748 source, s, destination, d)
750 } else if (ret < 0) {
751 error << string_compose(_("AudioEngine: cannot connect %1 (%2) to %3 (%4)"),
752 source, s, destination, d)
760 AudioEngine::disconnect (const string& source, const string& destination)
766 fatal << _("disconnect called before engine was started") << endmsg;
773 string s = make_port_name_non_relative (source);
774 string d = make_port_name_non_relative (destination);
776 //cerr << "trying to disconnect port '" << s << "' from port '" << d << endl;
778 Port* src = get_port (s);
779 Port* dst = get_port (d);
783 /* both ports are known to us, so do the internal connect stuff */
785 if ((ret = src->disconnect (*dst)) == 0) {
786 ret = dst->disconnect (*src);
789 } else if (src || dst) {
791 /* one port is known to us, try to connect it to something external */
794 PortConnectableByName* pcn;
798 pcn = dynamic_cast<PortConnectableByName*>(src);
801 pcn = dynamic_cast<PortConnectableByName*>(dst);
806 ret = pcn->disconnect (other);
813 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
823 AudioEngine::disconnect (Port& port)
827 fatal << _("disconnect called before engine was started") << endmsg;
834 return port.disconnect_all ();
838 AudioEngine::frame_rate ()
841 if (_frame_rate == 0) {
842 return (_frame_rate = jack_get_sample_rate (_jack));
847 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
855 AudioEngine::frames_per_cycle ()
858 if (_buffer_size == 0) {
859 return (_buffer_size = jack_get_buffer_size (_jack));
864 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
871 /** Get a port by name.
872 * Note this can return NULL, it will NOT create a port if it is not found (any more).
875 AudioEngine::get_port_by_name (const string& portname, bool keep)
877 Glib::Mutex::Lock lm (_process_lock);
881 fatal << _("get_port_by_name() called before engine was started") << endmsg;
888 boost::shared_ptr<Ports> pr = ports.reader();
890 for (Ports::iterator i = pr->begin(); i != pr->end(); ++i) {
891 if (portname == (*i)->name()) {
900 AudioEngine::get_ports (const string& port_name_pattern, const string& type_name_pattern, uint32_t flags)
904 fatal << _("get_ports called before engine was started") << endmsg;
910 return jack_get_ports (_jack, port_name_pattern.c_str(), type_name_pattern.c_str(), flags);
914 AudioEngine::halted (void *arg)
916 AudioEngine* ae = static_cast<AudioEngine *> (arg);
917 bool was_running = ae->_running;
919 ae->stop_metering_thread ();
921 ae->_running = false;
922 ae->_buffer_size = 0;
925 cerr << "!!! HALTED !!!\n";
928 ae->Halted(); /* EMIT SIGNAL */
933 AudioEngine::can_request_hardware_monitoring ()
941 if ((ports = jack_get_ports (_jack, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortCanMonitor)) == 0) {
952 AudioEngine::n_physical_outputs (DataType type) const
961 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
965 for (i = 0; ports[i]; ++i);
972 AudioEngine::n_physical_inputs (DataType type) const
981 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
986 for (i = 0; ports[i]; ++i);
993 AudioEngine::get_physical_inputs (DataType type, vector<string>& ins)
1002 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
1007 for (i = 0; ports[i]; ++i) {
1008 ins.push_back (ports[i]);
1015 AudioEngine::get_physical_outputs (DataType type, vector<string>& outs)
1017 const char ** ports;
1024 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
1029 for (i = 0; ports[i]; ++i) {
1030 outs.push_back (ports[i]);
1037 AudioEngine::get_nth_physical (DataType type, uint32_t n, int flag)
1039 const char ** ports;
1043 assert(type != DataType::NIL);
1045 if (!_running || !_jack) {
1047 fatal << _("get_nth_physical called before engine was started") << endmsg;
1054 ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|flag);
1060 for (i = 0; i < n && ports[i]; ++i);
1066 free ((char *) ports);
1072 AudioEngine::get_port_total_latency (const Port& port)
1074 return port.total_latency ();
1078 AudioEngine::update_total_latency (const Port& port)
1081 fatal << _("update_total_latency() called with no JACK client connection") << endmsg;
1087 fatal << _("update_total_latency() called before engine was started") << endmsg;
1092 port.recompute_total_latency ();
1096 AudioEngine::transport_stop ()
1099 jack_transport_stop (_jack);
1104 AudioEngine::transport_start ()
1107 jack_transport_start (_jack);
1112 AudioEngine::transport_locate (nframes_t where)
1114 // cerr << "tell JACK to locate to " << where << endl;
1116 jack_transport_locate (_jack, where);
1120 AudioEngine::TransportState
1121 AudioEngine::transport_state ()
1124 jack_position_t pos;
1125 return (TransportState) jack_transport_query (_jack, &pos);
1127 return (TransportState) JackTransportStopped;
1132 AudioEngine::reset_timebase ()
1135 if (Config->get_jack_time_master()) {
1136 return jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1138 return jack_release_timebase (_jack);
1146 AudioEngine::freewheel (bool onoff)
1150 if (onoff != _freewheeling) {
1153 _freewheel_thread_registered = false;
1156 return jack_set_freewheel (_jack, onoff);
1159 /* already doing what has been asked for */
1169 AudioEngine::remove_all_ports ()
1171 /* process lock MUST be held */
1174 RCUWriter<Ports> writer (ports);
1175 boost::shared_ptr<Ports> ps = writer.get_copy ();
1181 AudioEngine::remove_connections_for (Port& port)
1183 for (PortConnections::iterator i = port_connections.begin(); i != port_connections.end(); ) {
1184 PortConnections::iterator tmp;
1189 if ((*i).first == port.name()) {
1190 port_connections.erase (i);
1198 #ifdef HAVE_JACK_CLIENT_OPEN
1201 AudioEngine::connect_to_jack (string client_name)
1203 jack_options_t options = JackNullOption;
1204 jack_status_t status;
1205 const char *server_name = NULL;
1207 jack_client_name = client_name; /* might be reset below */
1208 _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name);
1210 if (_jack == NULL) {
1211 // error message is not useful here
1215 if (status & JackNameNotUnique) {
1216 jack_client_name = jack_get_client_name (_jack);
1219 jack_set_error_function (ardour_jack_error);
1227 AudioEngine::connect_to_jack (string client_name)
1229 jack_client_name = client_name;
1231 if ((_jack = jack_client_new (client_name.c_str())) == 0) {
1238 #endif /* HAVE_JACK_CLIENT_OPEN */
1241 AudioEngine::disconnect_from_jack ()
1249 stop_metering_thread ();
1253 Glib::Mutex::Lock lm (_process_lock);
1254 jack_client_close (_jack);
1263 Stopped(); /* EMIT SIGNAL */
1270 AudioEngine::reconnect_to_jack ()
1273 disconnect_from_jack ();
1274 /* XXX give jackd a chance */
1275 Glib::usleep (250000);
1278 if (connect_to_jack (jack_client_name)) {
1279 error << _("failed to connect to JACK") << endmsg;
1285 boost::shared_ptr<Ports> p = ports.reader ();
1287 for (i = p->begin(); i != p->end(); ++i) {
1288 if ((*i)->reestablish ()) {
1293 if (i != p->end()) {
1295 remove_all_ports ();
1301 session->reset_jack_connection (_jack);
1302 nframes_t blocksize = jack_get_buffer_size (_jack);
1303 session->set_block_size (blocksize);
1304 session->set_frame_rate (jack_get_sample_rate (_jack));
1307 last_monitor_check = 0;
1309 jack_on_shutdown (_jack, halted, this);
1310 jack_set_graph_order_callback (_jack, _graph_order_callback, this);
1311 jack_set_thread_init_callback (_jack, _thread_init_callback, this);
1312 jack_set_process_callback (_jack, _process_callback, this);
1313 jack_set_sample_rate_callback (_jack, _sample_rate_callback, this);
1314 jack_set_buffer_size_callback (_jack, _bufsize_callback, this);
1315 jack_set_xrun_callback (_jack, _xrun_callback, this);
1316 jack_set_sync_callback (_jack, _jack_sync_callback, this);
1317 jack_set_freewheel_callback (_jack, _freewheel_callback, this);
1319 if (Config->get_jack_time_master()) {
1320 jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1323 if (jack_activate (_jack) == 0) {
1330 /* re-establish connections */
1332 for (i = p->begin(); i != p->end(); ++i) {
1336 Running (); /* EMIT SIGNAL*/
1338 start_metering_thread ();
1344 AudioEngine::request_buffer_size (nframes_t nframes)
1348 if (nframes == jack_get_buffer_size (_jack)) {
1352 return jack_set_buffer_size (_jack, nframes);
1360 AudioEngine::update_total_latencies ()
1362 #ifdef HAVE_JACK_RECOMPUTE_LATENCIES
1364 jack_recompute_total_latencies (_jack);
1370 AudioEngine::make_port_name_relative (string portname)
1372 string::size_type len;
1373 string::size_type n;
1375 len = portname.length();
1377 for (n = 0; n < len; ++n) {
1378 if (portname[n] == ':') {
1383 if ((n != len) && (portname.substr (0, n) == jack_client_name)) {
1384 return portname.substr (n+1);
1391 AudioEngine::make_port_name_non_relative (string portname)
1395 if (portname.find_first_of (':') != string::npos) {
1399 str = jack_client_name;
1407 AudioEngine::is_realtime () const
1410 return jack_is_realtime (_jack);