#include <sstream>
#include <glibmm/timer.h>
-#include <pbd/pthread_utils.h>
-#include <pbd/stacktrace.h>
-#include <pbd/unknown_type.h>
-
-#include <midi++/jack.h>
-
-#include <ardour/audioengine.h>
-#include <ardour/buffer.h>
-#include <ardour/port.h>
-#include <ardour/audio_port.h>
-#include <ardour/midi_port.h>
-#include <ardour/session.h>
-#include <ardour/cycle_timer.h>
-#include <ardour/utils.h>
-#include <ardour/event_type_map.h>
-#include <ardour/io.h>
-#ifdef VST_SUPPORT
-#include <fst.h>
-#endif
-
-#include <ardour/timestamps.h>
+#include "pbd/pthread_utils.h"
+#include "pbd/stacktrace.h"
+#include "pbd/unknown_type.h"
+
+#include "midi++/jack.h"
+
+#include "ardour/amp.h"
+#include "ardour/audio_port.h"
+#include "ardour/audioengine.h"
+#include "ardour/buffer.h"
+#include "ardour/buffer_set.h"
+#include "ardour/cycle_timer.h"
+#include "ardour/delivery.h"
+#include "ardour/event_type_map.h"
+#include "ardour/internal_return.h"
+#include "ardour/io.h"
+#include "ardour/meter.h"
+#include "ardour/midi_port.h"
+#include "ardour/port.h"
+#include "ardour/port_set.h"
+#include "ardour/session.h"
+#include "ardour/timestamps.h"
+#include "ardour/utils.h"
#include "i18n.h"
gint AudioEngine::m_meter_exit;
-static void
-ardour_jack_error (const char* msg)
-{
- error << "JACK: " << msg << endmsg;
-}
-
AudioEngine::AudioEngine (string client_name)
: ports (new Ports)
{
if (!_running) {
+ nframes_t blocksize = jack_get_buffer_size (_jack);
+
if (session) {
- nframes_t blocksize = jack_get_buffer_size (_jack);
-
BootMessage (_("Connect session to engine"));
session->set_block_size (blocksize);
session->set_frame_rate (jack_get_sample_rate (_jack));
-
+
/* page in as much of the session process code as we
can before we really start running.
*/
jack_set_sync_callback (_jack, _jack_sync_callback, this);
jack_set_freewheel_callback (_jack, _freewheel_callback, this);
- if (Config->get_jack_time_master()) {
+ if (session && session->config.get_jack_time_master()) {
jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
}
}
start_metering_thread();
+
+ _raw_buffer_sizes[DataType::AUDIO] = blocksize * sizeof(float);
}
return _running ? 0 : -1;
static_cast<AudioEngine*>(arg)->_freewheeling = onoff;
}
+void
+AudioEngine::split_cycle (nframes_t offset)
+{
+ /* caller must hold process lock */
+
+ Port::increment_port_offset (offset);
+
+ /* 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) {
+ (*i)->cycle_split ();
+ }
+}
+
/** Method called by JACK (via _process_callback) which says that there
* is work to be done.
* @param nframes Number of frames to process.
AudioEngine::process_callback (nframes_t nframes)
{
// CycleTimer ct ("AudioEngine::process");
+
Glib::Mutex::Lock tm (_process_lock, Glib::TRY_LOCK);
/// The number of frames that will have been processed when we've finished
return 0;
}
- boost::shared_ptr<Ports> p = ports.reader();
+ /* tell all relevant objects that we're starting a new cycle */
- for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+ Delivery::CycleStart (nframes);
+ Port::set_port_offset (0);
+ InternalReturn::CycleStart (nframes);
- /* Only run cycle_start() on output ports, because
- inputs must be done in the correct processing order,
- which requires interleaving with route processing.
- */
+ /* tell all Ports that we're starting a new cycle */
- /* XXX: we're running this on both inputs and outputs... */
- (*i)->cycle_start (nframes, 0);
+ boost::shared_ptr<Ports> p = ports.reader();
+
+ for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+ (*i)->cycle_start (nframes);
}
if (_freewheeling) {
Port *port = (*i);
if (port->sends_output()) {
- port->get_buffer(nframes, 0 ).silence(nframes);
+ port->get_buffer(nframes).silence(nframes);
}
}
- }
+ }
- // Finalize ports (ie write data if necessary)
+ // Finalize ports
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
-
- (*i)->cycle_end (nframes, 0);
+ (*i)->cycle_end (nframes);
}
_processed_frames = next_processed_frames;
AudioEngine::jack_bufsize_callback (nframes_t nframes)
{
_buffer_size = nframes;
+ _raw_buffer_sizes[DataType::AUDIO] = nframes * sizeof(float);
+ cout << "FIXME: Assuming maximum MIDI buffer size " << nframes * 4 << "bytes" << endl;
+ _raw_buffer_sizes[DataType::MIDI] = nframes * 4;
_usecs_per_cycle = (int) floor ((((double) nframes / frame_rate())) * 1000000.0);
last_monitor_check = 0;
if (g_atomic_int_get(&m_meter_exit)) {
break;
}
- IO::update_meters ();
+ Metering::update_meters ();
}
}
boost::shared_ptr<Ports> p = ports.reader();
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
- (*i)->cycle_start (blocksize, 0);
+ (*i)->cycle_start (blocksize);
}
s->process (blocksize);
s->process (blocksize);
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
- (*i)->cycle_end (blocksize, 0);
+ (*i)->cycle_end (blocksize);
}
}
}
string reason;
if (p) {
- reason = _("a port with this name already exists: check for duplicated track/bus names");
+ reason = string_compose (_("a port with the name \"%1\" already exists: check for duplicated track/bus names"), portname);
} else {
- reason = _("unknown error");
+ reason = _("No more JACK ports are available. You will need to stop Ardour and restart JACK with ports if you need this many tracks.");
}
throw PortRegistrationFailure (string_compose (_("AudioEngine: cannot register port \"%1\": %2"), portname, reason).c_str());
}
Port *
-AudioEngine::register_port (DataType dtype, const string& portname, bool input, bool publish)
+AudioEngine::register_port (DataType dtype, const string& portname, bool input)
{
Port* newport = 0;
- /*cerr << "trying to register port with name " << portname << endl;*/
try {
if (dtype == DataType::AUDIO) {
- newport = new AudioPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
+ newport = new AudioPort (portname, (input ? Port::IsInput : Port::IsOutput));
} else if (dtype == DataType::MIDI) {
- newport = new MidiPort (portname, (input ? Port::IsInput : Port::IsOutput), publish, frames_per_cycle());
+ newport = new MidiPort (portname, (input ? Port::IsInput : Port::IsOutput));
} else {
- throw unknown_type();
+ throw PortRegistrationFailure("unable to create port (unknown type)");
+ }
+
+ size_t& old_buffer_size = _raw_buffer_sizes[newport->type()];
+ size_t port_buffer_size = newport->raw_buffer_size(0);
+ if (port_buffer_size > old_buffer_size) {
+ old_buffer_size = port_buffer_size;
}
-
- /*cerr << "successfully got port " << portname << " with address " << newport << endl;*/
RCUWriter<Ports> writer (ports);
boost::shared_ptr<Ports> ps = writer.get_copy ();
- /*cerr << "Address of ports list: " << ps << endl
- << "Ports set size before insert: " << ps->size() << endl;*/
ps->insert (ps->begin(), newport);
- /*cerr << "Ports set size after insert: " << ps->size() << endl;*/
/* writer goes out of scope, forces update */
return newport;
}
- catch (...) {
- throw PortRegistrationFailure("unable to create port (unknown type?)");
+ catch (PortRegistrationFailure& err) {
+ throw err;
+ } catch (std::exception& e) {
+ throw PortRegistrationFailure(string_compose(
+ _("unable to create port: %1"), e.what()).c_str());
+ } catch (...) {
+ throw PortRegistrationFailure("unable to create port (unknown error)");
}
}
Port *
-AudioEngine::register_input_port (DataType type, const string& portname, bool publish)
+AudioEngine::register_input_port (DataType type, const string& portname)
{
- return register_port (type, portname, true, publish);
+ return register_port (type, portname, true);
}
Port *
-AudioEngine::register_output_port (DataType type, const string& portname, bool publish)
+AudioEngine::register_output_port (DataType type, const string& portname)
{
- return register_port (type, portname, false, publish);
+ return register_port (type, portname, false);
}
int
{
/* caller must hold process lock */
- cerr << "about to unregister Port xx x" << &port << "\n";
-
if (!_running) {
/* probably happening when the engine has been halted by JACK,
in which case, there is nothing we can do here.
*/
- cerr << "not running\n";
return 0;
}
{
- cerr << "before getcopy\n";
-
RCUWriter<Ports> writer (ports);
boost::shared_ptr<Ports> ps = writer.get_copy ();
- cerr << "Ports set size: " << ps.get()->size() << endl;
-
for (Ports::iterator i = ps->begin(); i != ps->end(); ++i) {
- cerr << "before delete" << endl;
if ((*i) == &port) {
- cerr << "About to delete " << &port << endl;
delete *i;
ps->erase (i);
- cerr << "After erasing ports size: " << ps->size();
break;
}
}
/* writer goes out of scope, forces update */
}
- cerr << "before remove_connections\n";
remove_connections_for (port);
return 0;
Port* src = get_port_by_name_locked (s);
Port* dst = get_port_by_name_locked (d);
- if (src && dst) {
-
- /* both ports are known to us, so do the internal connect stuff */
-
- ret = src->connect (dst);
-
- } else if (src || dst) {
-
- /* one port is known to us, try to connect it to something external */
-
if (src) {
ret = src->connect (d);
- } else {
+ } else if (dst) {
ret = dst->connect (s);
- }
-
} else {
-
/* neither port is known to us, and this API isn't intended for use as a general patch bay */
-
ret = -1;
-
}
if (ret > 0) {
- error << string_compose(_("AudioEngine: connection already exists: %1 (%2) to %3 (%4)"),
- source, s, destination, d)
- << endmsg;
+ /* already exists - no error, no warning */
} else if (ret < 0) {
error << string_compose(_("AudioEngine: cannot connect %1 (%2) to %3 (%4)"),
source, s, destination, d)
Port* src = get_port_by_name_locked (s);
Port* dst = get_port_by_name_locked (d);
- if (src && dst) {
-
- /* both ports are known to us, so do the internal disconnect stuff */
-
- ret = src->disconnect (dst);
-
- } else if (src || dst) {
-
- /* one port is known to us, try to disconnect it from something external */
-
- if (src) {
+ if (src) {
ret = src->disconnect (d);
- } else {
+ } else if (dst) {
ret = dst->disconnect (s);
- }
-
} else {
-
/* neither port is known to us, and this API isn't intended for use as a general patch bay */
-
ret = -1;
-
}
-
return ret;
}
}
}
+size_t
+AudioEngine::raw_buffer_size (DataType t)
+{
+ std::map<DataType,size_t>::const_iterator s = _raw_buffer_sizes.find(t);
+ return (s != _raw_buffer_sizes.end()) ? s->second : 0;
+}
+
ARDOUR::nframes_t
AudioEngine::frames_per_cycle ()
{
Port *
AudioEngine::get_port_by_name (const string& portname)
{
+ string s;
+ if (portname.find_first_of (':') == string::npos) {
+ s = make_port_name_non_relative (portname);
+ } else {
+ s = portname;
+ }
+
Glib::Mutex::Lock lm (_process_lock);
- return get_port_by_name_locked (portname);
+ return get_port_by_name_locked (s);
}
Port *
return 0;
}
- for (i = 0; ports[i]; ++i);
+ for (i = 0; ports[i]; ++i) {}
free (ports);
return i;
}
if (ports) {
- for (i = 0; ports[i]; ++i);
+ for (i = 0; ports[i]; ++i) {}
free (ports);
}
return i;
return "";
}
- for (i = 0; i < n && ports[i]; ++i);
+ for (i = 0; i < n && ports[i]; ++i) {}
if (ports[i]) {
ret = ports[i];
int
AudioEngine::reset_timebase ()
{
- if (_jack) {
- if (Config->get_jack_time_master()) {
+ if (_jack && session) {
+ if (session->config.get_jack_time_master()) {
return jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
} else {
return jack_release_timebase (_jack);
}
-#ifdef HAVE_JACK_CLIENT_OPEN
+static void
+ardour_jack_error (const char* msg)
+{
+ error << "JACK: " << msg << endmsg;
+}
int
AudioEngine::connect_to_jack (string client_name)
return 0;
}
-#else
-
-int
-AudioEngine::connect_to_jack (string client_name)
-{
- jack_client_name = client_name;
-
- if ((_jack = jack_client_new (client_name.c_str())) == 0) {
- return -1;
- }
-
- return 0;
-}
-
-#endif /* HAVE_JACK_CLIENT_OPEN */
-
int
AudioEngine::disconnect_from_jack ()
{
return 0;
}
-
if (_running) {
stop_metering_thread ();
}
_buffer_size = 0;
_frame_rate = 0;
+ _raw_buffer_sizes.clear();
if (_running) {
_running = false;
nframes_t blocksize = jack_get_buffer_size (_jack);
session->set_block_size (blocksize);
session->set_frame_rate (jack_get_sample_rate (_jack));
+
+ _raw_buffer_sizes[DataType::AUDIO] = blocksize * sizeof(float);
+ cout << "FIXME: Assuming maximum MIDI buffer size " << blocksize * 4 << "bytes" << endl;
+ _raw_buffer_sizes[DataType::MIDI] = blocksize * 4;
}
last_monitor_check = 0;
jack_set_sync_callback (_jack, _jack_sync_callback, this);
jack_set_freewheel_callback (_jack, _freewheel_callback, this);
- if (Config->get_jack_time_master()) {
+ if (session && session->config.get_jack_time_master()) {
jack_set_timebase_callback (_jack, 0, _jack_timebase_callback, this);
}