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();
345 // Prepare ports (ie read data if necessary)
346 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
347 (*i)->cycle_start (nframes, 0);
351 /* emit the Freewheel signal and stop freewheeling in the event of trouble */
352 if (Freewheel (nframes)) {
353 jack_set_freewheel (_jack, false);
358 session->process (nframes);
362 // Finalize ports (ie write data if necessary)
364 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
365 (*i)->cycle_end (nframes, 0);
373 _processed_frames = next_processed_frames;
377 if (last_monitor_check + monitor_check_interval < next_processed_frames) {
379 boost::shared_ptr<Ports> p = ports.reader();
381 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
386 if (port->_last_monitor != (x = port->monitoring_input ())) {
387 port->_last_monitor = x;
388 /* XXX I think this is dangerous, due to
389 a likely mutex in the signal handlers ...
391 port->MonitorInputChanged (x); /* EMIT SIGNAL */
394 last_monitor_check = next_processed_frames;
397 if (session->silent()) {
399 boost::shared_ptr<Ports> p = ports.reader();
401 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
405 if (port->sends_output()) {
406 port->get_buffer().silence(nframes);
411 _processed_frames = next_processed_frames;
416 AudioEngine::_sample_rate_callback (nframes_t nframes, void *arg)
418 return static_cast<AudioEngine *> (arg)->jack_sample_rate_callback (nframes);
422 AudioEngine::jack_sample_rate_callback (nframes_t nframes)
424 _frame_rate = nframes;
425 _usecs_per_cycle = (int) floor ((((double) frames_per_cycle() / nframes)) * 1000000.0);
427 /* check for monitor input change every 1/10th of second */
429 monitor_check_interval = nframes / 10;
430 last_monitor_check = 0;
433 session->set_frame_rate (nframes);
436 SampleRateChanged (nframes); /* EMIT SIGNAL */
442 AudioEngine::_bufsize_callback (nframes_t nframes, void *arg)
444 return static_cast<AudioEngine *> (arg)->jack_bufsize_callback (nframes);
448 AudioEngine::jack_bufsize_callback (nframes_t nframes)
450 _buffer_size = nframes;
451 _usecs_per_cycle = (int) floor ((((double) nframes / frame_rate())) * 1000000.0);
452 last_monitor_check = 0;
454 boost::shared_ptr<Ports> p = ports.reader();
456 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
461 session->set_block_size (_buffer_size);
468 AudioEngine::stop_metering_thread ()
470 if (m_meter_thread) {
471 g_atomic_int_set (&m_meter_exit, 1);
472 m_meter_thread->join ();
478 AudioEngine::start_metering_thread ()
480 if (m_meter_thread == 0) {
481 g_atomic_int_set (&m_meter_exit, 0);
482 m_meter_thread = Glib::Thread::create (sigc::mem_fun(this, &AudioEngine::meter_thread),
483 500000, true, true, Glib::THREAD_PRIORITY_NORMAL);
488 AudioEngine::meter_thread ()
491 Glib::usleep (10000); /* 1/100th sec interval */
492 if (g_atomic_int_get(&m_meter_exit)) {
495 IO::update_meters ();
500 AudioEngine::set_session (Session *s)
502 Glib::Mutex::Lock pl (_process_lock);
508 nframes_t blocksize = jack_get_buffer_size (_jack);
510 /* page in as much of the session process code as we
511 can before we really start running.
514 boost::shared_ptr<Ports> p = ports.reader();
516 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
517 (*i)->cycle_start (blocksize, 0);
520 s->process (blocksize);
521 s->process (blocksize);
522 s->process (blocksize);
523 s->process (blocksize);
524 s->process (blocksize);
525 s->process (blocksize);
526 s->process (blocksize);
527 s->process (blocksize);
529 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
530 (*i)->cycle_end (blocksize, 0);
536 AudioEngine::remove_session ()
538 Glib::Mutex::Lock lm (_process_lock);
543 session_remove_pending = true;
544 session_removed.wait(_process_lock);
551 //FIXME: Preliminary bugfix for http://tracker.ardour.org/view.php?id=1985
552 //remove_all_ports ();
556 AudioEngine::port_registration_failure (const std::string& portname)
558 string full_portname = jack_client_name;
559 full_portname += ':';
560 full_portname += portname;
563 jack_port_t* p = jack_port_by_name (_jack, full_portname.c_str());
567 reason = _("a port with this name already exists: check for duplicated track/bus names");
569 reason = _("unknown error");
572 throw PortRegistrationFailure (string_compose (_("AudioEngine: cannot register port \"%1\": %2"), portname, reason).c_str());
576 AudioEngine::register_port (DataType dtype, const string& portname, bool input, bool publish)
580 /*cerr << "trying to register port with name " << portname << endl;*/
582 if (dtype == DataType::AUDIO) {
583 newport = new AudioPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
584 } else if (dtype == DataType::MIDI) {
585 newport = new MidiPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
587 throw unknown_type();
590 /*cerr << "successfully got port " << portname << " with address " << newport << endl;*/
592 RCUWriter<Ports> writer (ports);
593 boost::shared_ptr<Ports> ps = writer.get_copy ();
594 /*cerr << "Address of ports list: " << ps << endl
595 << "Ports set size before insert: " << ps->size() << endl;*/
596 ps->insert (ps->begin(), newport);
597 /*cerr << "Ports set size after insert: " << ps->size() << endl;*/
599 /* writer goes out of scope, forces update */
605 throw PortRegistrationFailure("unable to create port (unknown type?)");
610 AudioEngine::get_port (const std::string& full_name)
612 boost::shared_ptr<Ports> p = ports.reader();
614 for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
615 //cerr << "comparing port name '" << (*i)->name() << "' with '" << full_name << "'" << endl;
616 if ((*i)->name() == full_name) {
625 AudioEngine::register_input_port (DataType type, const string& portname, bool publish)
627 return register_port (type, portname, true, publish);
631 AudioEngine::register_output_port (DataType type, const string& portname, bool publish)
633 return register_port (type, portname, false, publish);
637 AudioEngine::unregister_port (Port& port)
639 /* caller must hold process lock */
641 cerr << "about to unregister Port xx x" << &port << "\n";
644 /* probably happening when the engine has been halted by JACK,
645 in which case, there is nothing we can do here.
647 cerr << "not running\n";
652 cerr << "before getcopy\n";
654 RCUWriter<Ports> writer (ports);
655 boost::shared_ptr<Ports> ps = writer.get_copy ();
657 cerr << "Ports set size: " << ps.get()->size() << endl;
659 for (Ports::iterator i = ps->begin(); i != ps->end(); ++i) {
660 cerr << "before delete" << endl;
662 cerr << "About to delete " << &port << endl;
665 cerr << "After erasing ports size: " << ps->size();
670 /* writer goes out of scope, forces update */
673 cerr << "before remove_connections\n";
674 remove_connections_for (port);
680 AudioEngine::connect (const string& source, const string& destination)
686 fatal << _("connect called before engine was started") << endmsg;
693 string s = make_port_name_non_relative (source);
694 string d = make_port_name_non_relative (destination);
696 //cerr << "Trying to connect source: " << s << " with destination " << d << endl;
698 Port* src = get_port (s);
699 Port* dst = get_port (d);
703 /* both ports are known to us, so do the internal connect stuff */
705 if ((ret = src->connect (*dst)) == 0) {
706 ret = dst->connect (*src);
709 } else if (src || dst) {
711 /* one port is known to us, try to connect it to something external */
713 PortConnectableByName* pcn;
717 pcn = dynamic_cast<PortConnectableByName*>(src);
720 pcn = dynamic_cast<PortConnectableByName*>(dst);
725 ret = pcn->connect (other);
732 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
739 error << string_compose(_("AudioEngine: connection already exists: %1 (%2) to %3 (%4)"),
740 source, s, destination, d)
742 } else if (ret < 0) {
743 error << string_compose(_("AudioEngine: cannot connect %1 (%2) to %3 (%4)"),
744 source, s, destination, d)
752 AudioEngine::disconnect (const string& source, const string& destination)
758 fatal << _("disconnect called before engine was started") << endmsg;
765 string s = make_port_name_non_relative (source);
766 string d = make_port_name_non_relative (destination);
768 //cerr << "trying to disconnect port '" << s << "' from port '" << d << endl;
770 Port* src = get_port (s);
771 Port* dst = get_port (d);
775 /* both ports are known to us, so do the internal connect stuff */
777 if ((ret = src->disconnect (*dst)) == 0) {
778 ret = dst->disconnect (*src);
781 } else if (src || dst) {
783 /* one port is known to us, try to connect it to something external */
786 PortConnectableByName* pcn;
790 pcn = dynamic_cast<PortConnectableByName*>(src);
793 pcn = dynamic_cast<PortConnectableByName*>(dst);
798 ret = pcn->disconnect (other);
805 /* neither port is known to us, and this API isn't intended for use as a general patch bay */
815 AudioEngine::disconnect (Port& port)
819 fatal << _("disconnect called before engine was started") << endmsg;
826 return port.disconnect_all ();
830 AudioEngine::frame_rate ()
833 if (_frame_rate == 0) {
834 return (_frame_rate = jack_get_sample_rate (_jack));
839 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
847 AudioEngine::frames_per_cycle ()
850 if (_buffer_size == 0) {
851 return (_buffer_size = jack_get_buffer_size (_jack));
856 fatal << X_("programming error: AudioEngine::frame_rate() called while disconnected from JACK")
863 /** Get a port by name.
864 * Note this can return NULL, it will NOT create a port if it is not found (any more).
867 AudioEngine::get_port_by_name (const string& portname, bool keep)
869 Glib::Mutex::Lock lm (_process_lock);
873 fatal << _("get_port_by_name() called before engine was started") << endmsg;
880 boost::shared_ptr<Ports> pr = ports.reader();
882 for (Ports::iterator i = pr->begin(); i != pr->end(); ++i) {
883 if (portname == (*i)->name()) {
892 AudioEngine::get_ports (const string& port_name_pattern, const string& type_name_pattern, uint32_t flags)
896 fatal << _("get_ports called before engine was started") << endmsg;
902 return jack_get_ports (_jack, port_name_pattern.c_str(), type_name_pattern.c_str(), flags);
906 AudioEngine::halted (void *arg)
908 AudioEngine* ae = static_cast<AudioEngine *> (arg);
909 bool was_running = ae->_running;
911 ae->stop_metering_thread ();
913 ae->_running = false;
914 ae->_buffer_size = 0;
917 cerr << "!!! HALTED !!!\n";
920 ae->Halted(); /* EMIT SIGNAL */
925 AudioEngine::can_request_hardware_monitoring ()
933 if ((ports = jack_get_ports (_jack, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortCanMonitor)) == 0) {
944 AudioEngine::n_physical_outputs (DataType type) const
953 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
957 for (i = 0; ports[i]; ++i);
964 AudioEngine::n_physical_inputs (DataType type) const
973 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
978 for (i = 0; ports[i]; ++i);
985 AudioEngine::get_physical_inputs (DataType type, vector<string>& ins)
994 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsOutput)) == 0) {
999 for (i = 0; ports[i]; ++i) {
1000 ins.push_back (ports[i]);
1007 AudioEngine::get_physical_outputs (DataType type, vector<string>& outs)
1009 const char ** ports;
1016 if ((ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|JackPortIsInput)) == 0) {
1021 for (i = 0; ports[i]; ++i) {
1022 outs.push_back (ports[i]);
1029 AudioEngine::get_nth_physical (DataType type, uint32_t n, int flag)
1031 const char ** ports;
1035 assert(type != DataType::NIL);
1037 if (!_running || !_jack) {
1039 fatal << _("get_nth_physical called before engine was started") << endmsg;
1046 ports = jack_get_ports (_jack, NULL, type.to_jack_type(), JackPortIsPhysical|flag);
1052 for (i = 0; i < n && ports[i]; ++i);
1058 free ((char *) ports);
1064 AudioEngine::get_port_total_latency (const Port& port)
1066 return port.total_latency ();
1070 AudioEngine::update_total_latency (const Port& port)
1073 fatal << _("update_total_latency() called with no JACK client connection") << endmsg;
1079 fatal << _("update_total_latency() called before engine was started") << endmsg;
1084 port.recompute_total_latency ();
1088 AudioEngine::transport_stop ()
1091 jack_transport_stop (_jack);
1096 AudioEngine::transport_start ()
1098 // cerr << "tell JACK to start\n";
1100 jack_transport_start (_jack);
1105 AudioEngine::transport_locate (nframes_t where)
1107 // cerr << "tell JACK to locate to " << where << endl;
1109 jack_transport_locate (_jack, where);
1113 AudioEngine::TransportState
1114 AudioEngine::transport_state ()
1117 jack_position_t pos;
1118 return (TransportState) jack_transport_query (_jack, &pos);
1120 return (TransportState) JackTransportStopped;
1125 AudioEngine::reset_timebase ()
1128 if (Config->get_jack_time_master()) {
1129 return jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1131 return jack_release_timebase (_jack);
1139 AudioEngine::freewheel (bool onoff)
1143 if (onoff != _freewheeling) {
1146 _freewheel_thread_registered = false;
1149 return jack_set_freewheel (_jack, onoff);
1152 /* already doing what has been asked for */
1162 AudioEngine::remove_all_ports ()
1164 /* process lock MUST be held */
1167 RCUWriter<Ports> writer (ports);
1168 boost::shared_ptr<Ports> ps = writer.get_copy ();
1174 AudioEngine::remove_connections_for (Port& port)
1176 for (PortConnections::iterator i = port_connections.begin(); i != port_connections.end(); ) {
1177 PortConnections::iterator tmp;
1182 if ((*i).first == port.name()) {
1183 port_connections.erase (i);
1191 #ifdef HAVE_JACK_CLIENT_OPEN
1194 AudioEngine::connect_to_jack (string client_name)
1196 jack_options_t options = JackNullOption;
1197 jack_status_t status;
1198 const char *server_name = NULL;
1200 jack_client_name = client_name; /* might be reset below */
1201 _jack = jack_client_open (jack_client_name.c_str(), options, &status, server_name);
1203 if (_jack == NULL) {
1205 if (status & JackServerFailed) {
1206 error << _("Unable to connect to JACK server") << endmsg;
1209 // error message is not useful here
1213 if (status & JackServerStarted) {
1214 info << _("JACK server started") << endmsg;
1217 if (status & JackNameNotUnique) {
1218 jack_client_name = jack_get_client_name (_jack);
1221 jack_set_error_function (ardour_jack_error);
1229 AudioEngine::connect_to_jack (string client_name)
1231 jack_client_name = client_name;
1233 if ((_jack = jack_client_new (client_name.c_str())) == 0) {
1240 #endif /* HAVE_JACK_CLIENT_OPEN */
1243 AudioEngine::disconnect_from_jack ()
1251 stop_metering_thread ();
1255 Glib::Mutex::Lock lm (_process_lock);
1256 jack_client_close (_jack);
1265 Stopped(); /* EMIT SIGNAL */
1272 AudioEngine::reconnect_to_jack ()
1275 disconnect_from_jack ();
1276 /* XXX give jackd a chance */
1277 Glib::usleep (250000);
1280 if (connect_to_jack (jack_client_name)) {
1281 error << _("failed to connect to JACK") << endmsg;
1287 boost::shared_ptr<Ports> p = ports.reader ();
1289 for (i = p->begin(); i != p->end(); ++i) {
1290 if ((*i)->reestablish ()) {
1295 if (i != p->end()) {
1297 remove_all_ports ();
1303 session->reset_jack_connection (_jack);
1304 nframes_t blocksize = jack_get_buffer_size (_jack);
1305 session->set_block_size (blocksize);
1306 session->set_frame_rate (jack_get_sample_rate (_jack));
1309 last_monitor_check = 0;
1311 jack_on_shutdown (_jack, halted, this);
1312 jack_set_graph_order_callback (_jack, _graph_order_callback, this);
1313 jack_set_thread_init_callback (_jack, _thread_init_callback, this);
1314 jack_set_process_callback (_jack, _process_callback, this);
1315 jack_set_sample_rate_callback (_jack, _sample_rate_callback, this);
1316 jack_set_buffer_size_callback (_jack, _bufsize_callback, this);
1317 jack_set_xrun_callback (_jack, _xrun_callback, this);
1318 jack_set_sync_callback (_jack, _jack_sync_callback, this);
1319 jack_set_freewheel_callback (_jack, _freewheel_callback, this);
1321 if (Config->get_jack_time_master()) {
1322 jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
1325 if (jack_activate (_jack) == 0) {
1332 /* re-establish connections */
1334 for (i = p->begin(); i != p->end(); ++i) {
1338 Running (); /* EMIT SIGNAL*/
1340 start_metering_thread ();
1346 AudioEngine::request_buffer_size (nframes_t nframes)
1350 if (nframes == jack_get_buffer_size (_jack)) {
1354 return jack_set_buffer_size (_jack, nframes);
1362 AudioEngine::update_total_latencies ()
1364 #ifdef HAVE_JACK_RECOMPUTE_LATENCIES
1366 jack_recompute_total_latencies (_jack);
1372 AudioEngine::make_port_name_relative (string portname)
1374 string::size_type len;
1375 string::size_type n;
1377 len = portname.length();
1379 for (n = 0; n < len; ++n) {
1380 if (portname[n] == ':') {
1385 if ((n != len) && (portname.substr (0, n) == jack_client_name)) {
1386 return portname.substr (n+1);
1393 AudioEngine::make_port_name_non_relative (string portname)
1397 if (portname.find_first_of (':') != string::npos) {
1401 str = jack_client_name;
1409 AudioEngine::is_realtime () const
1412 return jack_is_realtime (_jack);