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 Parameter::init_metadata(NullAutomation);
90 Parameter::init_metadata(GainAutomation);
91 Parameter::init_metadata(PanAutomation);
92 Parameter::init_metadata(PluginAutomation);
93 Parameter::init_metadata(SoloAutomation);
94 Parameter::init_metadata(MuteAutomation);
95 Parameter::init_metadata(MidiCCAutomation);
96 Parameter::init_metadata(MidiPgmChangeAutomation);
97 Parameter::init_metadata(MidiPitchBenderAutomation);
98 Parameter::init_metadata(MidiChannelPressureAutomation);
99 Parameter::init_metadata(FadeInAutomation);
100 Parameter::init_metadata(FadeOutAutomation);
101 Parameter::init_metadata(EnvelopeAutomation);
102 Parameter::init_metadata(MidiCCAutomation);
105 AudioEngine::~AudioEngine ()
108 Glib::Mutex::Lock tm (_process_lock);
109 session_removed.signal ();
112 jack_client_close (_jack);
116 stop_metering_thread ();
121 AudioEngine::jack() const
127 _thread_init_callback (void *arg)
129 /* make sure that anybody who needs to know about this thread
133 PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096);
134 MIDI::JACK_MidiPort::set_process_thread (pthread_self());
138 AudioEngine::start ()
141 error << _("AudioEngine::start() called while disconnected from JACK") << endmsg;
148 nframes_t blocksize = jack_get_buffer_size (_jack);
150 BootMessage (_("Connect session to engine"));
152 session->set_block_size (blocksize);
153 session->set_frame_rate (jack_get_sample_rate (_jack));
155 /* page in as much of the session process code as we
156 can before we really start running.
159 session->process (blocksize);
160 session->process (blocksize);
161 session->process (blocksize);
162 session->process (blocksize);
163 session->process (blocksize);
164 session->process (blocksize);
165 session->process (blocksize);
166 session->process (blocksize);
169 _processed_frames = 0;
170 last_monitor_check = 0;
172 jack_on_shutdown (_jack, halted, this);
173 jack_set_graph_order_callback (_jack, _graph_order_callback, this);
174 jack_set_thread_init_callback (_jack, _thread_init_callback, this);
175 jack_set_process_callback (_jack, _process_callback, this);
176 jack_set_sample_rate_callback (_jack, _sample_rate_callback, this);
177 jack_set_buffer_size_callback (_jack, _bufsize_callback, this);
178 jack_set_xrun_callback (_jack, _xrun_callback, this);
179 jack_set_sync_callback (_jack, _jack_sync_callback, this);
180 jack_set_freewheel_callback (_jack, _freewheel_callback, this);
182 if (Config->get_jack_time_master()) {
183 jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
186 if (jack_activate (_jack) == 0) {
189 Running(); /* EMIT SIGNAL */
191 // error << _("cannot activate JACK client") << endmsg;
194 start_metering_thread();
197 return _running ? 0 : -1;
201 AudioEngine::stop (bool forever)
205 disconnect_from_jack ();
207 jack_deactivate (_jack);
208 Stopped(); /* EMIT SIGNAL */
212 return _running ? -1 : 0;
217 AudioEngine::get_sync_offset (nframes_t& offset) const
220 #ifdef HAVE_JACK_VIDEO_SUPPORT
225 (void) jack_transport_query (_jack, &pos);
227 if (pos.valid & JackVideoFrameOffset) {
228 offset = pos.video_offset;
239 AudioEngine::_jack_timebase_callback (jack_transport_state_t state, nframes_t nframes,
240 jack_position_t* pos, int new_position, void *arg)
242 static_cast<AudioEngine*> (arg)->jack_timebase_callback (state, nframes, pos, new_position);
246 AudioEngine::jack_timebase_callback (jack_transport_state_t state, nframes_t nframes,
247 jack_position_t* pos, int new_position)
249 if (_jack && session && session->synced_to_jack()) {
250 session->jack_timebase_callback (state, nframes, pos, new_position);
255 AudioEngine::_jack_sync_callback (jack_transport_state_t state, jack_position_t* pos, void* arg)
257 return static_cast<AudioEngine*> (arg)->jack_sync_callback (state, pos);
261 AudioEngine::jack_sync_callback (jack_transport_state_t state, jack_position_t* pos)
263 if (_jack && session) {
264 return session->jack_sync_callback (state, pos);
271 AudioEngine::_xrun_callback (void *arg)
273 AudioEngine* ae = static_cast<AudioEngine*> (arg);
274 if (ae->connected()) {
275 ae->Xrun (); /* EMIT SIGNAL */
281 AudioEngine::_graph_order_callback (void *arg)
283 AudioEngine* ae = static_cast<AudioEngine*> (arg);
284 if (ae->connected()) {
285 ae->GraphReordered (); /* EMIT SIGNAL */
290 /** Wrapped which is called by JACK as its process callback. It is just
291 * here to get us back into C++ land by calling AudioEngine::process_callback()
292 * @param nframes Number of frames passed by JACK.
293 * @param arg User argument passed by JACK, which will be the AudioEngine*.
296 AudioEngine::_process_callback (nframes_t nframes, void *arg)
298 return static_cast<AudioEngine *> (arg)->process_callback (nframes);
302 AudioEngine::_freewheel_callback (int onoff, void *arg)
304 static_cast<AudioEngine*>(arg)->_freewheeling = onoff;
307 /** Method called by JACK (via _process_callback) which says that there
308 * is work to be done.
309 * @param nframes Number of frames to process.
312 AudioEngine::process_callback (nframes_t nframes)
314 // CycleTimer ct ("AudioEngine::process");
315 Glib::Mutex::Lock tm (_process_lock, Glib::TRY_LOCK);
317 /// The number of frames that will have been processed when we've finished
318 nframes_t next_processed_frames;
320 /* handle wrap around of total frames counter */
322 if (max_frames - _processed_frames < nframes) {
323 next_processed_frames = nframes - (max_frames - _processed_frames);
325 next_processed_frames = _processed_frames + nframes;
328 if (!tm.locked() || session == 0) {
329 /* return having done nothing */
330 _processed_frames = next_processed_frames;
334 if (session_remove_pending) {
335 /* perform the actual session removal */
337 session_remove_pending = false;
338 session_removed.signal();
339 _processed_frames = next_processed_frames;
343 boost::shared_ptr<Ports> p = ports.reader();
346 /* emit the Freewheel signal and stop freewheeling in the event of trouble */
347 if (Freewheel (nframes)) {
348 jack_set_freewheel (_jack, false);
353 session->process (nframes);
357 // Finalize ports (ie write data if necessary)
359 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
360 (*i)->cycle_end (nframes, 0);
368 _processed_frames = next_processed_frames;
372 if (last_monitor_check + monitor_check_interval < next_processed_frames) {
374 boost::shared_ptr<Ports> p = ports.reader();
376 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
381 if (port->_last_monitor != (x = port->monitoring_input ())) {
382 port->_last_monitor = x;
383 /* XXX I think this is dangerous, due to
384 a likely mutex in the signal handlers ...
386 port->MonitorInputChanged (x); /* EMIT SIGNAL */
389 last_monitor_check = next_processed_frames;
392 if (session->silent()) {
394 boost::shared_ptr<Ports> p = ports.reader();
396 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
400 if (port->sends_output()) {
401 port->get_buffer().silence(nframes);
406 _processed_frames = next_processed_frames;
411 AudioEngine::_sample_rate_callback (nframes_t nframes, void *arg)
413 return static_cast<AudioEngine *> (arg)->jack_sample_rate_callback (nframes);
417 AudioEngine::jack_sample_rate_callback (nframes_t nframes)
419 _frame_rate = nframes;
420 _usecs_per_cycle = (int) floor ((((double) frames_per_cycle() / nframes)) * 1000000.0);
422 /* check for monitor input change every 1/10th of second */
424 monitor_check_interval = nframes / 10;
425 last_monitor_check = 0;
428 session->set_frame_rate (nframes);
431 SampleRateChanged (nframes); /* EMIT SIGNAL */
437 AudioEngine::_bufsize_callback (nframes_t nframes, void *arg)
439 return static_cast<AudioEngine *> (arg)->jack_bufsize_callback (nframes);
443 AudioEngine::jack_bufsize_callback (nframes_t nframes)
445 _buffer_size = nframes;
446 _usecs_per_cycle = (int) floor ((((double) nframes / frame_rate())) * 1000000.0);
447 last_monitor_check = 0;
449 boost::shared_ptr<Ports> p = ports.reader();
451 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
456 session->set_block_size (_buffer_size);
463 AudioEngine::stop_metering_thread ()
465 if (m_meter_thread) {
466 g_atomic_int_set (&m_meter_exit, 1);
467 m_meter_thread->join ();
473 AudioEngine::start_metering_thread ()
475 if (m_meter_thread == 0) {
476 g_atomic_int_set (&m_meter_exit, 0);
477 m_meter_thread = Glib::Thread::create (sigc::mem_fun(this, &AudioEngine::meter_thread),
478 500000, true, true, Glib::THREAD_PRIORITY_NORMAL);
483 AudioEngine::meter_thread ()
486 Glib::usleep (10000); /* 1/100th sec interval */
487 if (g_atomic_int_get(&m_meter_exit)) {
490 IO::update_meters ();
495 AudioEngine::set_session (Session *s)
497 Glib::Mutex::Lock pl (_process_lock);
503 nframes_t blocksize = jack_get_buffer_size (_jack);
505 /* page in as much of the session process code as we
506 can before we really start running.
509 boost::shared_ptr<Ports> p = ports.reader();
511 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
512 (*i)->cycle_start (blocksize, 0);
515 s->process (blocksize);
516 s->process (blocksize);
517 s->process (blocksize);
518 s->process (blocksize);
519 s->process (blocksize);
520 s->process (blocksize);
521 s->process (blocksize);
522 s->process (blocksize);
524 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
525 (*i)->cycle_end (blocksize, 0);
531 AudioEngine::remove_session ()
533 Glib::Mutex::Lock lm (_process_lock);
538 session_remove_pending = true;
539 session_removed.wait(_process_lock);
546 //FIXME: Preliminary bugfix for http://tracker.ardour.org/view.php?id=1985
547 //remove_all_ports ();
551 AudioEngine::port_registration_failure (const std::string& portname)
553 string full_portname = jack_client_name;
554 full_portname += ':';
555 full_portname += portname;
558 jack_port_t* p = jack_port_by_name (_jack, full_portname.c_str());
562 reason = _("a port with this name already exists: check for duplicated track/bus names");
564 reason = _("unknown error");
567 throw PortRegistrationFailure (string_compose (_("AudioEngine: cannot register port \"%1\": %2"), portname, reason).c_str());
571 AudioEngine::register_port (DataType dtype, const string& portname, bool input, bool publish)
575 /*cerr << "trying to register port with name " << portname << endl;*/
577 if (dtype == DataType::AUDIO) {
578 newport = new AudioPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
579 } else if (dtype == DataType::MIDI) {
580 newport = new MidiPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
582 throw unknown_type();
585 /*cerr << "successfully got port " << portname << " with address " << newport << endl;*/
587 RCUWriter<Ports> writer (ports);
588 boost::shared_ptr<Ports> ps = writer.get_copy ();
589 /*cerr << "Address of ports list: " << ps << endl
590 << "Ports set size before insert: " << ps->size() << endl;*/
591 ps->insert (ps->begin(), newport);
592 /*cerr << "Ports set size after insert: " << ps->size() << endl;*/
594 /* writer goes out of scope, forces update */
600 throw PortRegistrationFailure("unable to create port (unknown type?)");
605 AudioEngine::get_port (const std::string& full_name)
607 boost::shared_ptr<Ports> p = ports.reader();
609 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
610 //cerr << "comparing port name '" << (*i)->name() << "' with '" << full_name << "'" << endl;
611 if ((*i)->name() == full_name) {
620 AudioEngine::register_input_port (DataType type, const string& portname, bool publish)
622 return register_port (type, portname, true, publish);
626 AudioEngine::register_output_port (DataType type, const string& portname, bool publish)
628 return register_port (type, portname, false, publish);
632 AudioEngine::unregister_port (Port& port)
634 /* caller must hold process lock */
636 cerr << "about to unregister Port xx x" << &port << "\n";
639 /* probably happening when the engine has been halted by JACK,
640 in which case, there is nothing we can do here.
642 cerr << "not running\n";
647 cerr << "before getcopy\n";
649 RCUWriter<Ports> writer (ports);
650 boost::shared_ptr<Ports> ps = writer.get_copy ();
652 cerr << "Ports set size: " << ps.get()->size() << endl;
654 for (Ports::iterator i = ps->begin(); i != ps->end(); ++i) {
655 cerr << "before delete" << endl;
657 cerr << "About to delete " << &port << endl;
660 cerr << "After erasing ports size: " << ps->size();
665 /* writer goes out of scope, forces update */
668 cerr << "before remove_connections\n";
669 remove_connections_for (port);
675 AudioEngine::connect (const string& source, const string& destination)
681 fatal << _("connect called before engine was started") << endmsg;
688 string s = make_port_name_non_relative (source);
689 string d = make_port_name_non_relative (destination);
691 //cerr << "Trying to connect source: " << s << " with destination " << d << endl;
693 Port* src = get_port (s);
694 Port* dst = get_port (d);
698 /* both ports are known to us, so do the internal connect stuff */
700 if ((ret = src->connect (*dst)) == 0) {
701 ret = dst->connect (*src);
704 } else if (src || dst) {
706 /* one port is known to us, try to connect it to something external */
708 PortConnectableByName* pcn;
712 pcn = dynamic_cast<PortConnectableByName*>(src);
715 pcn = dynamic_cast<PortConnectableByName*>(dst);
720 ret = pcn->connect (other);
727 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
734 error << string_compose(_("AudioEngine: connection already exists: %1 (%2) to %3 (%4)"),
735 source, s, destination, d)
737 } else if (ret < 0) {
738 error << string_compose(_("AudioEngine: cannot connect %1 (%2) to %3 (%4)"),
739 source, s, destination, d)
747 AudioEngine::disconnect (const string& source, const string& destination)
753 fatal << _("disconnect called before engine was started") << endmsg;
760 string s = make_port_name_non_relative (source);
761 string d = make_port_name_non_relative (destination);
763 //cerr << "trying to disconnect port '" << s << "' from port '" << d << endl;
765 Port* src = get_port (s);
766 Port* dst = get_port (d);
770 /* both ports are known to us, so do the internal connect stuff */
772 if ((ret = src->disconnect (*dst)) == 0) {
773 ret = dst->disconnect (*src);
776 } else if (src || dst) {
778 /* one port is known to us, try to connect it to something external */
781 PortConnectableByName* pcn;
785 pcn = dynamic_cast<PortConnectableByName*>(src);
788 pcn = dynamic_cast<PortConnectableByName*>(dst);
793 ret = pcn->disconnect (other);
800 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
810 AudioEngine::disconnect (Port& port)
814 fatal << _("disconnect called before engine was started") << endmsg;
821 return port.disconnect_all ();
825 AudioEngine::frame_rate ()
828 if (_frame_rate == 0) {
829 return (_frame_rate = jack_get_sample_rate (_jack));
834 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
842 AudioEngine::frames_per_cycle ()
845 if (_buffer_size == 0) {
846 return (_buffer_size = jack_get_buffer_size (_jack));
851 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
858 /** Get a port by name.
859 * Note this can return NULL, it will NOT create a port if it is not found (any more).
862 AudioEngine::get_port_by_name (const string& portname, bool keep)
864 Glib::Mutex::Lock lm (_process_lock);
868 fatal << _("get_port_by_name() called before engine was started") << endmsg;
875 boost::shared_ptr<Ports> pr = ports.reader();
877 for (Ports::iterator i = pr->begin(); i != pr->end(); ++i) {
878 if (portname == (*i)->name()) {
887 AudioEngine::get_ports (const string& port_name_pattern, const string& type_name_pattern, uint32_t flags)
891 fatal << _("get_ports called before engine was started") << endmsg;
897 return jack_get_ports (_jack, port_name_pattern.c_str(), type_name_pattern.c_str(), flags);
901 AudioEngine::halted (void *arg)
903 AudioEngine* ae = static_cast<AudioEngine *> (arg);
904 bool was_running = ae->_running;
906 ae->stop_metering_thread ();
908 ae->_running = false;
909 ae->_buffer_size = 0;
912 cerr << "!!! HALTED !!!\n";
915 ae->Halted(); /* EMIT SIGNAL */
920 AudioEngine::can_request_hardware_monitoring ()
928 if ((ports = jack_get_ports (_jack, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortCanMonitor)) == 0) {
939 AudioEngine::n_physical_outputs (DataType type) const
948 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
952 for (i = 0; ports[i]; ++i);
959 AudioEngine::n_physical_inputs (DataType type) const
968 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
973 for (i = 0; ports[i]; ++i);
980 AudioEngine::get_physical_inputs (DataType type, vector<string>& ins)
989 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
994 for (i = 0; ports[i]; ++i) {
995 ins.push_back (ports[i]);
1002 AudioEngine::get_physical_outputs (DataType type, vector<string>& outs)
1004 const char ** ports;
1011 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
1016 for (i = 0; ports[i]; ++i) {
1017 outs.push_back (ports[i]);
1024 AudioEngine::get_nth_physical (DataType type, uint32_t n, int flag)
1026 const char ** ports;
1030 assert(type != DataType::NIL);
1032 if (!_running || !_jack) {
1034 fatal << _("get_nth_physical called before engine was started") << endmsg;
1041 ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|flag);
1047 for (i = 0; i < n && ports[i]; ++i);
1053 free ((char *) ports);
1059 AudioEngine::get_port_total_latency (const Port& port)
1061 return port.total_latency ();
1065 AudioEngine::update_total_latency (const Port& port)
1068 fatal << _("update_total_latency() called with no JACK client connection") << endmsg;
1074 fatal << _("update_total_latency() called before engine was started") << endmsg;
1079 port.recompute_total_latency ();
1083 AudioEngine::transport_stop ()
1086 jack_transport_stop (_jack);
1091 AudioEngine::transport_start ()
1093 // cerr << "tell JACK to start\n";
1095 jack_transport_start (_jack);
1100 AudioEngine::transport_locate (nframes_t where)
1102 // cerr << "tell JACK to locate to " << where << endl;
1104 jack_transport_locate (_jack, where);
1108 AudioEngine::TransportState
1109 AudioEngine::transport_state ()
1112 jack_position_t pos;
1113 return (TransportState) jack_transport_query (_jack, &pos);
1115 return (TransportState) JackTransportStopped;
1120 AudioEngine::reset_timebase ()
1123 if (Config->get_jack_time_master()) {
1124 return jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1126 return jack_release_timebase (_jack);
1134 AudioEngine::freewheel (bool onoff)
1138 if (onoff != _freewheeling) {
1141 _freewheel_thread_registered = false;
1144 return jack_set_freewheel (_jack, onoff);
1147 /* already doing what has been asked for */
1157 AudioEngine::remove_all_ports ()
1159 /* process lock MUST be held */
1162 RCUWriter<Ports> writer (ports);
1163 boost::shared_ptr<Ports> ps = writer.get_copy ();
1169 AudioEngine::remove_connections_for (Port& port)
1171 for (PortConnections::iterator i = port_connections.begin(); i != port_connections.end(); ) {
1172 PortConnections::iterator tmp;
1177 if ((*i).first == port.name()) {
1178 port_connections.erase (i);
1186 #ifdef HAVE_JACK_CLIENT_OPEN
1189 AudioEngine::connect_to_jack (string client_name)
1191 jack_options_t options = JackNullOption;
1192 jack_status_t status;
1193 const char *server_name = NULL;
1195 jack_client_name = client_name; /* might be reset below */
1196 _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name);
1198 if (_jack == NULL) {
1200 if (status & JackServerFailed) {
1201 error << _("Unable to connect to JACK server") << endmsg;
1204 // error message is not useful here
1208 if (status & JackServerStarted) {
1209 info << _("JACK server started") << endmsg;
1212 if (status & JackNameNotUnique) {
1213 jack_client_name = jack_get_client_name (_jack);
1216 jack_set_error_function (ardour_jack_error);
1224 AudioEngine::connect_to_jack (string client_name)
1226 jack_client_name = client_name;
1228 if ((_jack = jack_client_new (client_name.c_str())) == 0) {
1235 #endif /* HAVE_JACK_CLIENT_OPEN */
1238 AudioEngine::disconnect_from_jack ()
1246 stop_metering_thread ();
1250 Glib::Mutex::Lock lm (_process_lock);
1251 jack_client_close (_jack);
1260 Stopped(); /* EMIT SIGNAL */
1267 AudioEngine::reconnect_to_jack ()
1270 disconnect_from_jack ();
1271 /* XXX give jackd a chance */
1272 Glib::usleep (250000);
1275 if (connect_to_jack (jack_client_name)) {
1276 error << _("failed to connect to JACK") << endmsg;
1282 boost::shared_ptr<Ports> p = ports.reader ();
1284 for (i = p->begin(); i != p->end(); ++i) {
1285 if ((*i)->reestablish ()) {
1290 if (i != p->end()) {
1292 remove_all_ports ();
1298 session->reset_jack_connection (_jack);
1299 nframes_t blocksize = jack_get_buffer_size (_jack);
1300 session->set_block_size (blocksize);
1301 session->set_frame_rate (jack_get_sample_rate (_jack));
1304 last_monitor_check = 0;
1306 jack_on_shutdown (_jack, halted, this);
1307 jack_set_graph_order_callback (_jack, _graph_order_callback, this);
1308 jack_set_thread_init_callback (_jack, _thread_init_callback, this);
1309 jack_set_process_callback (_jack, _process_callback, this);
1310 jack_set_sample_rate_callback (_jack, _sample_rate_callback, this);
1311 jack_set_buffer_size_callback (_jack, _bufsize_callback, this);
1312 jack_set_xrun_callback (_jack, _xrun_callback, this);
1313 jack_set_sync_callback (_jack, _jack_sync_callback, this);
1314 jack_set_freewheel_callback (_jack, _freewheel_callback, this);
1316 if (Config->get_jack_time_master()) {
1317 jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1320 if (jack_activate (_jack) == 0) {
1327 /* re-establish connections */
1329 for (i = p->begin(); i != p->end(); ++i) {
1333 Running (); /* EMIT SIGNAL*/
1335 start_metering_thread ();
1341 AudioEngine::request_buffer_size (nframes_t nframes)
1345 if (nframes == jack_get_buffer_size (_jack)) {
1349 return jack_set_buffer_size (_jack, nframes);
1357 AudioEngine::update_total_latencies ()
1359 #ifdef HAVE_JACK_RECOMPUTE_LATENCIES
1361 jack_recompute_total_latencies (_jack);
1367 AudioEngine::make_port_name_relative (string portname)
1369 string::size_type len;
1370 string::size_type n;
1372 len = portname.length();
1374 for (n = 0; n < len; ++n) {
1375 if (portname[n] == ':') {
1380 if ((n != len) && (portname.substr (0, n) == jack_client_name)) {
1381 return portname.substr (n+1);
1388 AudioEngine::make_port_name_non_relative (string portname)
1392 if (portname.find_first_of (':') != string::npos) {
1396 str = jack_client_name;
1404 AudioEngine::is_realtime () const
1407 return jack_is_realtime (_jack);