#include <pbd/stl_delete.h>
#include <pbd/basename.h>
#include <pbd/stacktrace.h>
+#include <pbd/file_utils.h>
#include <ardour/audioengine.h>
#include <ardour/configuration.h>
#include <ardour/session.h>
+#include <ardour/session_directory.h>
#include <ardour/utils.h>
#include <ardour/audio_diskstream.h>
#include <ardour/audioplaylist.h>
#include <ardour/smf_source.h>
#include <ardour/auditioner.h>
#include <ardour/recent_sessions.h>
-#include <ardour/redirect.h>
+#include <ardour/io_processor.h>
#include <ardour/send.h>
-#include <ardour/insert.h>
-#include <ardour/connection.h>
+#include <ardour/processor.h>
+#include <ardour/plugin_insert.h>
+#include <ardour/port_insert.h>
+#include <ardour/auto_bundle.h>
#include <ardour/slave.h>
#include <ardour/tempo.h>
#include <ardour/audio_track.h>
#include <ardour/buffer_set.h>
#include <ardour/source_factory.h>
#include <ardour/region_factory.h>
+#include <ardour/filename_extensions.h>
+#include <ardour/session_directory.h>
+#include <ardour/tape_file_matcher.h>
#ifdef HAVE_LIBLO
#include <ardour/osc.h>
static const int CPU_CACHE_ALIGN = 16; /* arguably 32 on most arches, but it matters less */
#endif
-const char* Session::_template_suffix = X_(".template");
-const char* Session::_statefile_suffix = X_(".ardour");
-const char* Session::_pending_suffix = X_(".pending");
-const char* Session::old_sound_dir_name = X_("sounds");
-const char* Session::sound_dir_name = X_("audiofiles");
-const char* Session::peak_dir_name = X_("peaks");
-const char* Session::dead_sound_dir_name = X_("dead_sounds");
-const char* Session::interchange_dir_name = X_("interchange");
-const char* Session::export_dir_name = X_("export");
-
-Session::compute_peak_t Session::compute_peak = 0;
-Session::find_peaks_t Session::find_peaks = 0;
-Session::apply_gain_to_buffer_t Session::apply_gain_to_buffer = 0;
-Session::mix_buffers_with_gain_t Session::mix_buffers_with_gain = 0;
-Session::mix_buffers_no_gain_t Session::mix_buffers_no_gain = 0;
+bool Session::_disable_all_loaded_plugins = false;
+
+Session::compute_peak_t Session::compute_peak = 0;
+Session::find_peaks_t Session::find_peaks = 0;
+Session::apply_gain_to_buffer_t Session::apply_gain_to_buffer = 0;
+Session::mix_buffers_with_gain_t Session::mix_buffers_with_gain = 0;
+Session::mix_buffers_no_gain_t Session::mix_buffers_no_gain = 0;
sigc::signal<int> Session::AskAboutPendingState;
sigc::signal<void> Session::SendFeedback;
sigc::signal<void> Session::StartTimeChanged;
sigc::signal<void> Session::EndTimeChanged;
-int
-Session::find_session (string str, string& path, string& snapshot, bool& isnew)
-{
- struct stat statbuf;
- char buf[PATH_MAX+1];
-
- isnew = false;
-
- if (!realpath (str.c_str(), buf) && (errno != ENOENT && errno != ENOTDIR)) {
- error << string_compose (_("Could not resolve path: %1 (%2)"), buf, strerror(errno)) << endmsg;
- return -1;
- }
-
- str = buf;
-
- /* check to see if it exists, and what it is */
-
- if (stat (str.c_str(), &statbuf)) {
- if (errno == ENOENT) {
- isnew = true;
- } else {
- error << string_compose (_("cannot check session path %1 (%2)"), str, strerror (errno))
- << endmsg;
- return -1;
- }
- }
-
- if (!isnew) {
-
- /* it exists, so it must either be the name
- of the directory, or the name of the statefile
- within it.
- */
-
- if (S_ISDIR (statbuf.st_mode)) {
-
- string::size_type slash = str.find_last_of ('/');
-
- if (slash == string::npos) {
-
- /* a subdirectory of cwd, so statefile should be ... */
-
- string tmp;
- tmp = str;
- tmp += '/';
- tmp += str;
- tmp += _statefile_suffix;
-
- /* is it there ? */
-
- if (stat (tmp.c_str(), &statbuf)) {
- error << string_compose (_("cannot check statefile %1 (%2)"), tmp, strerror (errno))
- << endmsg;
- return -1;
- }
-
- path = str;
- snapshot = str;
-
- } else {
-
- /* some directory someplace in the filesystem.
- the snapshot name is the directory name
- itself.
- */
-
- path = str;
- snapshot = str.substr (slash+1);
-
- }
-
- } else if (S_ISREG (statbuf.st_mode)) {
-
- string::size_type slash = str.find_last_of ('/');
- string::size_type suffix;
-
- /* remove the suffix */
-
- if (slash != string::npos) {
- snapshot = str.substr (slash+1);
- } else {
- snapshot = str;
- }
-
- suffix = snapshot.find (_statefile_suffix);
-
- if (suffix == string::npos) {
- error << string_compose (_("%1 is not an Ardour snapshot file"), str) << endmsg;
- return -1;
- }
-
- /* remove suffix */
-
- snapshot = snapshot.substr (0, suffix);
-
- if (slash == string::npos) {
-
- /* we must be in the directory where the
- statefile lives. get it using cwd().
- */
-
- char cwd[PATH_MAX+1];
-
- if (getcwd (cwd, sizeof (cwd)) == 0) {
- error << string_compose (_("cannot determine current working directory (%1)"), strerror (errno))
- << endmsg;
- return -1;
- }
-
- path = cwd;
-
- } else {
-
- /* full path to the statefile */
-
- path = str.substr (0, slash);
- }
-
- } else {
-
- /* what type of file is it? */
- error << string_compose (_("unknown file type for session %1"), str) << endmsg;
- return -1;
- }
-
- } else {
-
- /* its the name of a new directory. get the name
- as "dirname" does.
- */
-
- string::size_type slash = str.find_last_of ('/');
-
- if (slash == string::npos) {
-
- /* no slash, just use the name, but clean it up */
-
- path = legalize_for_path (str);
- snapshot = path;
-
- } else {
-
- path = str;
- snapshot = str.substr (slash+1);
- }
- }
-
- return 0;
-}
-
Session::Session (AudioEngine &eng,
- string fullpath,
- string snapshot_name,
- string* mix_template)
+ const string& fullpath,
+ const string& snapshot_name,
+ string mix_template)
: _engine (eng),
_scratch_buffers(new BufferSet()),
_silent_buffers(new BufferSet()),
- _send_buffers(new BufferSet()),
+ _mix_buffers(new BufferSet()),
_mmc_port (default_mmc_port),
_mtc_port (default_mtc_port),
_midi_port (default_midi_port),
+ _session_dir (new SessionDirectory(fullpath)),
pending_events (2048),
//midi_requests (128), // the size of this should match the midi request pool size
_send_smpte_update (false),
diskstreams (new DiskstreamList),
routes (new RouteList),
auditioner ((Auditioner*) 0),
+ _bundle_xml_node (0),
_click_io ((IO*) 0),
main_outs (0)
{
if (!eng.connected()) {
throw failed_constructor();
}
-
+
cerr << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (1)" << endl;
n_physical_outputs = _engine.n_physical_outputs();
n_physical_inputs = _engine.n_physical_inputs();
first_stage_init (fullpath, snapshot_name);
-
+
new_session = !g_file_test (_path.c_str(), GFileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
if (new_session) {
if (create (new_session, mix_template, compute_initial_length())) {
- cerr << "create failed\n";
destroy ();
throw failed_constructor ();
}
: _engine (eng),
_scratch_buffers(new BufferSet()),
_silent_buffers(new BufferSet()),
- _send_buffers(new BufferSet()),
+ _mix_buffers(new BufferSet()),
_mmc_port (default_mmc_port),
_mtc_port (default_mtc_port),
_midi_port (default_midi_port),
+ _session_dir ( new SessionDirectory(fullpath)),
pending_events (2048),
//midi_requests (16),
_send_smpte_update (false),
diskstreams (new DiskstreamList),
routes (new RouteList),
+ _bundle_xml_node (0),
main_outs (0)
{
new_session = !g_file_test (_path.c_str(), GFileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
if (new_session) {
- if (create (new_session, 0, initial_length)) {
+ if (create (new_session, string(), initial_length)) {
destroy ();
throw failed_constructor ();
}
}
if (!rl.empty()) {
- add_routes (rl);
+ add_routes (rl, false);
}
}
throw failed_constructor ();
}
- store_recent_sessions(_name, _path);
+ store_recent_sessions (_name, _path);
- bool was_dirty = dirty ();
-
_state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty);
Config->ParameterChanged.connect (mem_fun (*this, &Session::config_changed));
-
- if (was_dirty) {
- DirtyChanged (); /* EMIT SIGNAL */
- }
}
Session::~Session ()
remove_pending_capture_state ();
_state_of_the_state = StateOfTheState (CannotSave|Deletion);
+
_engine.remove_session ();
GoingAway (); /* EMIT SIGNAL */
delete _scratch_buffers;
delete _silent_buffers;
- delete _send_buffers;
+ delete _mix_buffers;
AudioDiskstream::free_working_buffers();
i = tmp;
}
-#ifdef TRACK_DESTRUCTION
- cerr << "delete connections\n";
-#endif /* TRACK_DESTRUCTION */
- for (ConnectionList::iterator i = _connections.begin(); i != _connections.end(); ) {
- ConnectionList::iterator tmp;
-
- tmp = i;
- ++tmp;
-
- delete *i;
-
- i = tmp;
- }
-
if (butler_mixdown_buffer) {
delete [] butler_mixdown_buffer;
}
// XXX HOW TO ALERT UI TO THIS ? DO WE NEED TO?
}
- /* Create a set of Connection objects that map
+ /* Create a set of Bundle objects that map
to the physical outputs currently available
*/
char buf[32];
snprintf (buf, sizeof (buf), _("out %" PRIu32), np+1);
- Connection* c = new OutputConnection (buf, true);
+ shared_ptr<AutoBundle> c (new AutoBundle (buf, true));
+ c->set_channels (1);
+ c->set_port (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
- c->add_port ();
- c->add_connection (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
-
- add_connection (c);
+ add_bundle (c);
}
for (uint32_t np = 0; np < n_physical_inputs; ++np) {
char buf[32];
snprintf (buf, sizeof (buf), _("in %" PRIu32), np+1);
- Connection* c = new InputConnection (buf, true);
-
- c->add_port ();
- c->add_connection (0, _engine.get_nth_physical_input (DataType::AUDIO, np));
+ shared_ptr<AutoBundle> c (new AutoBundle (buf, false));
+ c->set_channels (1);
+ c->set_port (0, _engine.get_nth_physical_input (DataType::AUDIO, np));
- add_connection (c);
+ add_bundle (c);
}
/* TWO: STEREO */
char buf[32];
snprintf (buf, sizeof (buf), _("out %" PRIu32 "+%" PRIu32), np+1, np+2);
- Connection* c = new OutputConnection (buf, true);
+ shared_ptr<AutoBundle> c (new AutoBundle (buf, true));
+ c->set_channels (2);
+ c->set_port (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
+ c->set_port (1, _engine.get_nth_physical_output (DataType::AUDIO, np + 1));
- c->add_port ();
- c->add_port ();
- c->add_connection (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
- c->add_connection (1, _engine.get_nth_physical_output (DataType::AUDIO, np+1));
-
- add_connection (c);
+ add_bundle (c);
}
for (uint32_t np = 0; np < n_physical_inputs; np +=2) {
char buf[32];
snprintf (buf, sizeof (buf), _("in %" PRIu32 "+%" PRIu32), np+1, np+2);
- Connection* c = new InputConnection (buf, true);
-
- c->add_port ();
- c->add_port ();
- c->add_connection (0, _engine.get_nth_physical_input (DataType::AUDIO, np));
- c->add_connection (1, _engine.get_nth_physical_input (DataType::AUDIO, np+1));
+ shared_ptr<AutoBundle> c (new AutoBundle (buf, false));
+ c->set_channels (2);
+ c->set_port (0, _engine.get_nth_physical_input (DataType::AUDIO, np));
+ c->set_port (1, _engine.get_nth_physical_input (DataType::AUDIO, np + 1));
- add_connection (c);
+ add_bundle (c);
}
/* THREE MASTER */
_master_out->defer_pan_reset ();
- while (_master_out->n_inputs().get(DataType::AUDIO)
- < _master_out->input_maximum().get(DataType::AUDIO)) {
+ while (_master_out->n_inputs().n_audio()
+ < _master_out->input_maximum().n_audio()) {
if (_master_out->add_input_port ("", this, DataType::AUDIO)) {
error << _("cannot setup master inputs")
<< endmsg;
}
}
n = 0;
- while (_master_out->n_outputs().get(DataType::AUDIO)
- < _master_out->output_maximum().get(DataType::AUDIO)) {
+ while (_master_out->n_outputs().n_audio()
+ < _master_out->output_maximum().n_audio()) {
if (_master_out->add_output_port (_engine.get_nth_physical_output (DataType::AUDIO, n), this, DataType::AUDIO)) {
error << _("cannot setup master outputs")
<< endmsg;
}
- Connection* c = new OutputConnection (_("Master Out"), true);
+ shared_ptr<AutoBundle> c (new AutoBundle (_("Master Out"), true));
- for (uint32_t n = 0; n < _master_out->n_inputs ().get_total(); ++n) {
- c->add_port ();
- c->add_connection ((int) n, _master_out->input(n)->name());
- }
- add_connection (c);
+ c->set_channels (_master_out->n_inputs().n_total());
+ for (uint32_t n = 0; n < _master_out->n_inputs ().n_total(); ++n) {
+ c->set_port (n, _master_out->input(n)->name());
+ }
+ add_bundle (c);
}
hookup_io ();
_state_of_the_state = StateOfTheState (_state_of_the_state & ~(CannotSave|Dirty));
+
/* hook us up to the engine */
_engine.set_session (this);
osc->set_session (*this);
#endif
-
- _state_of_the_state = Clean;
-
- DirtyChanged (); /* EMIT SIGNAL */
+
}
void
_state_of_the_state = StateOfTheState (_state_of_the_state | InitialConnecting);
+
if (auditioner == 0) {
/* we delay creating the auditioner till now because
if (_control_out) {
uint32_t n;
+ vector<string> cports;
- while (_control_out->n_inputs().get(DataType::AUDIO) < _control_out->input_maximum().get(DataType::AUDIO)) {
+ while (_control_out->n_inputs().n_audio() < _control_out->input_maximum().n_audio()) {
if (_control_out->add_input_port ("", this)) {
error << _("cannot setup control inputs")
<< endmsg;
}
}
n = 0;
- while (_control_out->n_outputs().get(DataType::AUDIO) < _control_out->output_maximum().get(DataType::AUDIO)) {
+ while (_control_out->n_outputs().n_audio() < _control_out->output_maximum().n_audio()) {
if (_control_out->add_output_port (_engine.get_nth_physical_output (DataType::AUDIO, n), this)) {
error << _("cannot set up master outputs")
<< endmsg;
}
n++;
}
+
+
+ uint32_t ni = _control_out->n_inputs().get (DataType::AUDIO);
+
+ for (n = 0; n < ni; ++n) {
+ cports.push_back (_control_out->input(n)->name());
+ }
+
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator x = r->begin(); x != r->end(); ++x) {
+ (*x)->set_control_outs (cports);
+ }
}
+ /* load bundles, which we may have postponed earlier on */
+ if (_bundle_xml_node) {
+ load_bundles (*_bundle_xml_node);
+ delete _bundle_xml_node;
+ }
+
/* Tell all IO objects to connect themselves together */
IO::enable_connecting ();
_state_of_the_state = StateOfTheState (_state_of_the_state & ~InitialConnecting);
+
/* now handle the whole enchilada as if it was one
graph reorder event.
*/
if ((rs = (RecordState) g_atomic_int_get (&_record_status)) != Disabled) {
- if (!Config->get_latched_record_enable () || force) {
+ if ((!Config->get_latched_record_enable () && !play_loop) || force) {
g_atomic_int_set (&_record_status, Disabled);
} else {
if (rs == Recording) {
void
Session::step_back_from_record ()
{
- g_atomic_int_set (&_record_status, Enabled);
+ /* XXX really atomic compare+swap here */
+ if (g_atomic_int_get (&_record_status) == Recording) {
+ g_atomic_int_set (&_record_status, Enabled);
- if (Config->get_monitoring_model() == HardwareMonitoring) {
- boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-
- for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
- if (Config->get_auto_input() && (*i)->record_enabled ()) {
- //cerr << "switching from input" << __FILE__ << __LINE__ << endl << endl;
- (*i)->monitor_input (false);
+ if (Config->get_monitoring_model() == HardwareMonitoring) {
+ boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
+
+ for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+ if (Config->get_auto_input() && (*i)->record_enabled ()) {
+ //cerr << "switching from input" << __FILE__ << __LINE__ << endl << endl;
+ (*i)->monitor_input (false);
+ }
}
}
}
sync_time_vars();
- Route::set_automation_interval ((jack_nframes_t) ceil ((double) frames_per_second * 0.25));
+ Automatable::set_automation_interval ((jack_nframes_t) ceil ((double) frames_per_second * (0.001 * Config->get_automation_interval())));
+ clear_clicks ();
+
// XXX we need some equivalent to this, somehow
// SndFileSource::setup_standard_crossfades (frames_per_second);
char track_name[32];
uint32_t track_id = 0;
uint32_t n = 0;
- uint32_t channels_used = 0;
string port;
RouteList new_routes;
list<boost::shared_ptr<MidiTrack> > ret;
+ //uint32_t control_id;
+ // FIXME: need physical I/O and autoconnect stuff for MIDI
+
/* count existing midi tracks */
{
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if (dynamic_cast<MidiTrack*>((*i).get()) != 0) {
- if (!(*i)->hidden()) {
+ if (!(*i)->is_hidden()) {
n++;
- channels_used += (*i)->n_inputs().get(DataType::MIDI);
+ //channels_used += (*i)->n_inputs().n_midi();
}
}
}
}
+ /*
+ vector<string> physinputs;
+ vector<string> physoutputs;
+ uint32_t nphysical_in;
+ uint32_t nphysical_out;
+
+ _engine.get_physical_outputs (physoutputs);
+ _engine.get_physical_inputs (physinputs);
+ control_id = ntracks() + nbusses() + 1;
+ */
+
while (how_many) {
/* check for duplicate route names, since we might have pre-existing
- routes with this name (e.g. create Midi1, Midi2, delete Midi1,
+ routes with this name (e.g. create Audio1, Audio2, delete Audio1,
save, close,restart,add new route - first named route is now
- Midi2)
+ Audio2)
*/
} while (track_id < (UINT_MAX-1));
+ /*
+ if (Config->get_input_auto_connect() & AutoConnectPhysical) {
+ nphysical_in = min (n_physical_inputs, (uint32_t) physinputs.size());
+ } else {
+ nphysical_in = 0;
+ }
+
+ if (Config->get_output_auto_connect() & AutoConnectPhysical) {
+ nphysical_out = min (n_physical_outputs, (uint32_t) physinputs.size());
+ } else {
+ nphysical_out = 0;
+ }
+ */
+
+ shared_ptr<MidiTrack> track;
+
try {
- shared_ptr<MidiTrack> track (new MidiTrack (*this, track_name, Route::Flag (0), mode));
+ track = boost::shared_ptr<MidiTrack>((new MidiTrack (*this, track_name, Route::Flag (0), mode)));
- if (track->ensure_io (ChanCount(DataType::MIDI, 1), ChanCount(DataType::MIDI, 1), false, this)) {
+ if (track->ensure_io (ChanCount(DataType::MIDI, 1), ChanCount(DataType::AUDIO, 1), false, this)) {
error << "cannot configure 1 in/1 out configuration for new midi track" << endmsg;
+ goto failed;
+ }
+
+ /*
+ if (nphysical_in) {
+ for (uint32_t x = 0; x < track->n_inputs().n_midi() && x < nphysical_in; ++x) {
+
+ port = "";
+
+ if (Config->get_input_auto_connect() & AutoConnectPhysical) {
+ port = physinputs[(channels_used+x)%nphysical_in];
+ }
+
+ if (port.length() && track->connect_input (track->input (x), port, this)) {
+ break;
+ }
+ }
+ }
+
+ for (uint32_t x = 0; x < track->n_outputs().n_midi(); ++x) {
+
+ port = "";
+
+ if (nphysical_out && (Config->get_output_auto_connect() & AutoConnectPhysical)) {
+ port = physoutputs[(channels_used+x)%nphysical_out];
+ } else if (Config->get_output_auto_connect() & AutoConnectMaster) {
+ if (_master_out) {
+ port = _master_out->input (x%_master_out->n_inputs().n_midi())->name();
+ }
+ }
+
+ if (port.length() && track->connect_output (track->output (x), port, this)) {
+ break;
+ }
}
- channels_used += track->n_inputs ().get(DataType::MIDI);
+ channels_used += track->n_inputs ().n_midi();
+
+ */
+ track->midi_diskstream()->non_realtime_input_change();
+
track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes));
- track->set_remote_control_id (ntracks());
+ //track->set_remote_control_id (control_id);
new_routes.push_back (track);
ret.push_back (track);
catch (failed_constructor &err) {
error << _("Session: could not create new midi track.") << endmsg;
- // XXX should we delete the tracks already created?
- ret.clear ();
- return ret;
+
+ if (track) {
+ /* we need to get rid of this, since the track failed to be created */
+ /* XXX arguably, AudioTrack::AudioTrack should not do the Session::add_diskstream() */
+
+ {
+ RCUWriter<DiskstreamList> writer (diskstreams);
+ boost::shared_ptr<DiskstreamList> ds = writer.get_copy();
+ ds->remove (track->midi_diskstream());
+ }
+ }
+
+ goto failed;
}
-
+
+ catch (AudioEngine::PortRegistrationFailure& pfe) {
+
+ error << _("No more JACK ports are available. You will need to stop Ardour and restart JACK with ports if you need this many tracks.") << endmsg;
+
+ if (track) {
+ /* we need to get rid of this, since the track failed to be created */
+ /* XXX arguably, MidiTrack::MidiTrack should not do the Session::add_diskstream() */
+
+ {
+ RCUWriter<DiskstreamList> writer (diskstreams);
+ boost::shared_ptr<DiskstreamList> ds = writer.get_copy();
+ ds->remove (track->midi_diskstream());
+ }
+ }
+
+ goto failed;
+ }
+
--how_many;
}
+ failed:
if (!new_routes.empty()) {
add_routes (new_routes, false);
save_state (_current_snapshot_name);
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if (dynamic_cast<AudioTrack*>((*i).get()) != 0) {
- if (!(*i)->hidden()) {
+ if (!(*i)->is_hidden()) {
n++;
- channels_used += (*i)->n_inputs().get(DataType::AUDIO);
+ channels_used += (*i)->n_inputs().n_audio();
}
}
}
}
if (nphysical_in) {
- for (uint32_t x = 0; x < track->n_inputs().get(DataType::AUDIO) && x < nphysical_in; ++x) {
+ for (uint32_t x = 0; x < track->n_inputs().n_audio() && x < nphysical_in; ++x) {
port = "";
}
}
- for (uint32_t x = 0; x < track->n_outputs().get(DataType::MIDI); ++x) {
+ for (uint32_t x = 0; x < track->n_outputs().n_midi(); ++x) {
port = "";
port = physoutputs[(channels_used+x)%nphysical_out];
} else if (Config->get_output_auto_connect() & AutoConnectMaster) {
if (_master_out) {
- port = _master_out->input (x%_master_out->n_inputs().get(DataType::AUDIO))->name();
+ port = _master_out->input (x%_master_out->n_inputs().n_audio())->name();
}
}
}
}
- channels_used += track->n_inputs ().get(DataType::AUDIO);
+ channels_used += track->n_inputs ().n_audio();
- if (_control_out) {
- vector<string> cports;
- uint32_t ni = _control_out->n_inputs().get(DataType::AUDIO);
-
- for (n = 0; n < ni; ++n) {
- cports.push_back (_control_out->input(n)->name());
- }
-
- track->set_control_outs (cports);
- }
-
- // assert (current_thread != RT_thread)
-
track->audio_diskstream()->non_realtime_input_change();
track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes));
failed:
if (!new_routes.empty()) {
- add_routes (new_routes, false);
- save_state (_current_snapshot_name);
+ add_routes (new_routes, true);
}
return ret;
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if (dynamic_cast<AudioTrack*>((*i).get()) == 0) {
- if (!(*i)->hidden() && (*i)->name() != _("master")) {
+ if (!(*i)->is_hidden() && (*i)->name() != _("master")) {
bus_id++;
}
}
do {
snprintf (bus_name, sizeof(bus_name), "Bus %" PRIu32, bus_id);
+ bus_id++;
+
if (route_by_name (bus_name) == 0) {
break;
}
- } while (++bus_id < (UINT_MAX-1));
+ } while (bus_id < (UINT_MAX-1));
try {
shared_ptr<Route> bus (new Route (*this, bus_name, -1, -1, -1, -1, Route::Flag(0), DataType::AUDIO));
goto failure;
}
- for (uint32_t x = 0; n_physical_inputs && x < bus->n_inputs().get(DataType::AUDIO); ++x) {
+ for (uint32_t x = 0; n_physical_inputs && x < bus->n_inputs().n_audio(); ++x) {
port = "";
}
}
- for (uint32_t x = 0; n_physical_outputs && x < bus->n_outputs().get(DataType::AUDIO); ++x) {
+ for (uint32_t x = 0; n_physical_outputs && x < bus->n_outputs().n_audio(); ++x) {
port = "";
port = physoutputs[((n+x)%n_physical_outputs)];
} else if (Config->get_output_auto_connect() & AutoConnectMaster) {
if (_master_out) {
- port = _master_out->input (x%_master_out->n_inputs().get(DataType::AUDIO))->name();
+ port = _master_out->input (x%_master_out->n_inputs().n_audio())->name();
}
}
}
}
- if (_control_out) {
- vector<string> cports;
- uint32_t ni = _control_out->n_inputs().get(DataType::AUDIO);
-
- for (uint32_t n = 0; n < ni; ++n) {
- cports.push_back (_control_out->input(n)->name());
- }
- bus->set_control_outs (cports);
- }
-
bus->set_remote_control_id (control_id);
++control_id;
failure:
if (!ret.empty()) {
- add_routes (ret, false);
- save_state (_current_snapshot_name);
+ add_routes (ret, true);
}
return ret;
(*x)->solo_changed.connect (sigc::bind (mem_fun (*this, &Session::route_solo_changed), wpr));
(*x)->mute_changed.connect (mem_fun (*this, &Session::route_mute_changed));
(*x)->output_changed.connect (mem_fun (*this, &Session::set_worst_io_latencies_x));
- (*x)->redirects_changed.connect (mem_fun (*this, &Session::update_latency_compensation_proxy));
+ (*x)->processors_changed.connect (bind (mem_fun (*this, &Session::update_latency_compensation), false, false));
- if ((*x)->master()) {
+ if ((*x)->is_master()) {
_master_out = (*x);
}
- if ((*x)->control()) {
+ if ((*x)->is_control()) {
_control_out = (*x);
}
+
+ add_bundle ((*x)->bundle_for_inputs());
+ add_bundle ((*x)->bundle_for_outputs());
}
+ if (_control_out && IO::connecting_legal) {
+
+ vector<string> cports;
+ uint32_t ni = _control_out->n_inputs().n_audio();
+
+ for (uint32_t n = 0; n < ni; ++n) {
+ cports.push_back (_control_out->input(n)->name());
+ }
+
+ for (RouteList::iterator x = new_routes.begin(); x != new_routes.end(); ++x) {
+ (*x)->set_control_outs (cports);
+ }
+ }
+
set_dirty();
if (save) {
find_current_end ();
+ // We need to disconnect the routes inputs and outputs
+
+ route->disconnect_inputs (0);
+ route->disconnect_outputs (0);
+
update_latency_compensation (false, false);
set_dirty();
- // We need to disconnect the routes inputs and outputs
- route->disconnect_inputs(NULL);
- route->disconnect_outputs(NULL);
-
/* get rid of it from the dead wood collection in the route list manager */
/* XXX i think this is unsafe as it currently stands, but i am not sure. (pd, october 2nd, 2006) */
shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->soloed()) {
mute = true;
if (dynamic_cast<Track*>((*i).get())) {
{
Glib::Mutex::Lock lm (source_lock);
-
- {
- Glib::Mutex::Lock lm (source_lock);
-
- if ((i = sources.find (source->id())) != sources.end()) {
- sources.erase (i);
- }
- }
+
+ if ((i = sources.find (source->id())) != sources.end()) {
+ sources.erase (i);
+ }
}
if (!_state_of_the_state & InCleanup) {
source = i->second;
}
- /* XXX search MIDI or other searches here */
-
return source;
}
return boost::shared_ptr<Source>();
}
-string
-Session::peak_path_from_audio_path (string audio_path) const
+Glib::ustring
+Session::peak_path (Glib::ustring base) const
{
- string res;
-
- res = peak_dir ();
- res += PBD::basename_nosuffix (audio_path);
- res += ".peak";
-
- return res;
+ sys::path peakfile_path(_session_dir->peak_path());
+ peakfile_path /= basename_nosuffix (base) + peakfile_suffix;
+ return peakfile_path.to_string();
}
string
for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
- spath = (*i).path;
+ SessionDirectory sdir((*i).path);
- spath += sound_dir (false);
+ spath = sdir.sound_path().to_string();
if (destructive) {
if (nchan < 2) {
}
}
- if (g_file_test (buf, G_FILE_TEST_EXISTS)) {
+ if (sys::exists(buf)) {
existing++;
}
string foo = buf;
- spath = discover_best_sound_dir ();
+ SessionDirectory sdir(get_best_session_directory_for_new_source ());
+
+ spath = sdir.sound_path().to_string();
spath += '/';
string::size_type pos = foo.find_last_of ('/');
boost::shared_ptr<AudioFileSource>
Session::create_audio_source_for_session (AudioDiskstream& ds, uint32_t chan, bool destructive)
{
- string spath = audio_path_from_name (ds.name(), ds.n_channels().get(DataType::AUDIO), chan, destructive);
+ string spath = audio_path_from_name (ds.name(), ds.n_channels().n_audio(), chan, destructive);
return boost::dynamic_pointer_cast<AudioFileSource> (
SourceFactory::createWritable (DataType::AUDIO, *this, spath, destructive, frame_rate()));
}
for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
- spath = (*i).path;
+ SessionDirectory sdir((*i).path);
+
+ sys::path p = sdir.midi_path();
+
+ p /= legalized;
- // FIXME: different directory from audio?
- spath += sound_dir(false) + "/" + legalized;
+ spath = p.to_string();
snprintf (buf, sizeof(buf), "%s-%u.mid", spath.c_str(), cnt);
- if (g_file_test (buf, G_FILE_TEST_EXISTS)) {
+ if (sys::exists (buf)) {
existing++;
}
}
string foo = buf;
- // FIXME: different directory than audio?
- spath = discover_best_sound_dir ();
+ SessionDirectory sdir(get_best_session_directory_for_new_source ());
+
+ spath = sdir.midi_path().to_string();
spath += '/';
string::size_type pos = foo.find_last_of ('/');
return spath;
}
-
+
boost::shared_ptr<MidiSource>
Session::create_midi_source_for_session (MidiDiskstream& ds)
{
- string spath = midi_path_from_name (ds.name());
+ string mpath = midi_path_from_name (ds.name());
- return boost::dynamic_pointer_cast<SMFSource> (SourceFactory::createWritable (DataType::MIDI, *this, spath, false, frame_rate()));
+ return boost::dynamic_pointer_cast<SMFSource> (SourceFactory::createWritable (DataType::MIDI, *this, mpath, false, frame_rate()));
}
void
Session::remove_empty_sounds ()
{
- PathScanner scanner;
+ vector<string> audio_filenames;
- vector<string *>* possible_audiofiles = scanner (sound_dir(), "\\.(wav|aiff|caf|w64)$", false, true);
+ get_files_in_directory (_session_dir->sound_path(), audio_filenames);
Glib::Mutex::Lock lm (source_lock);
-
- regex_t compiled_tape_track_pattern;
- int err;
- if ((err = regcomp (&compiled_tape_track_pattern, "/T[0-9][0-9][0-9][0-9]-", REG_EXTENDED|REG_NOSUB))) {
+ TapeFileMatcher tape_file_matcher;
- char msg[256];
-
- regerror (err, &compiled_tape_track_pattern, msg, sizeof (msg));
-
- error << string_compose (_("Cannot compile tape track regexp for use (%1)"), msg) << endmsg;
- return;
- }
+ remove_if (audio_filenames.begin(), audio_filenames.end(),
+ sigc::mem_fun (tape_file_matcher, &TapeFileMatcher::matches));
- for (vector<string *>::iterator i = possible_audiofiles->begin(); i != possible_audiofiles->end(); ++i) {
-
- /* never remove files that appear to be a tape track */
+ for (vector<string>::iterator i = audio_filenames.begin(); i != audio_filenames.end(); ++i) {
- if (regexec (&compiled_tape_track_pattern, (*i)->c_str(), 0, 0, 0) == 0) {
- delete *i;
- continue;
- }
-
- if (AudioFileSource::is_empty (*this, *(*i))) {
+ sys::path audio_file_path (_session_dir->sound_path());
- unlink ((*i)->c_str());
+ audio_file_path /= *i;
- string peak_path = peak_path_from_audio_path (**i);
- unlink (peak_path.c_str());
- }
+ if (AudioFileSource::is_empty (*this, audio_file_path.to_string())) {
- delete* i;
+ try
+ {
+ sys::remove (audio_file_path);
+ const string peakfile = peak_path (audio_file_path.to_string());
+ sys::remove (peakfile);
+ }
+ catch (const sys::filesystem_error& err)
+ {
+ error << err.what() << endmsg;
+ }
+ }
}
-
- delete possible_audiofiles;
}
bool
shared_ptr<RouteList> r = routes.reader ();
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
- if (!(*i)->hidden()) {
+ if (!(*i)->is_hidden()) {
(*i)->set_solo (yn, this);
}
}
shared_ptr<RouteList> r = routes.reader ();
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
- if (!(*i)->hidden()) {
+ if (!(*i)->is_hidden()) {
(*i)->set_mute (yn, this);
}
}
}
void
-Session::add_redirect (Redirect* redirect)
+Session::add_processor (Processor* processor)
{
Send* send;
- Insert* insert;
PortInsert* port_insert;
PluginInsert* plugin_insert;
- if ((insert = dynamic_cast<Insert *> (redirect)) != 0) {
- if ((port_insert = dynamic_cast<PortInsert *> (insert)) != 0) {
- _port_inserts.insert (_port_inserts.begin(), port_insert);
- } else if ((plugin_insert = dynamic_cast<PluginInsert *> (insert)) != 0) {
- _plugin_inserts.insert (_plugin_inserts.begin(), plugin_insert);
- } else {
- fatal << _("programming error: unknown type of Insert created!") << endmsg;
- /*NOTREACHED*/
- }
- } else if ((send = dynamic_cast<Send *> (redirect)) != 0) {
+ if ((port_insert = dynamic_cast<PortInsert *> (processor)) != 0) {
+ _port_inserts.insert (_port_inserts.begin(), port_insert);
+ } else if ((plugin_insert = dynamic_cast<PluginInsert *> (processor)) != 0) {
+ _plugin_inserts.insert (_plugin_inserts.begin(), plugin_insert);
+ } else if ((send = dynamic_cast<Send *> (processor)) != 0) {
_sends.insert (_sends.begin(), send);
} else {
- fatal << _("programming error: unknown type of Redirect created!") << endmsg;
+ fatal << _("programming error: unknown type of Insert created!") << endmsg;
/*NOTREACHED*/
}
- redirect->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_redirect), redirect));
+ processor->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_processor), processor));
set_dirty();
}
void
-Session::remove_redirect (Redirect* redirect)
+Session::remove_processor (Processor* processor)
{
Send* send;
- Insert* insert;
PortInsert* port_insert;
PluginInsert* plugin_insert;
- if ((insert = dynamic_cast<Insert *> (redirect)) != 0) {
- if ((port_insert = dynamic_cast<PortInsert *> (insert)) != 0) {
- list<PortInsert*>::iterator x = find (_port_inserts.begin(), _port_inserts.end(), port_insert);
- if (x != _port_inserts.end()) {
- insert_bitset[port_insert->bit_slot()] = false;
- _port_inserts.erase (x);
- }
- } else if ((plugin_insert = dynamic_cast<PluginInsert *> (insert)) != 0) {
- _plugin_inserts.remove (plugin_insert);
- } else {
- fatal << string_compose (_("programming error: %1"),
- X_("unknown type of Insert deleted!"))
- << endmsg;
- /*NOTREACHED*/
- }
- } else if ((send = dynamic_cast<Send *> (redirect)) != 0) {
+ if ((port_insert = dynamic_cast<PortInsert *> (processor)) != 0) {
+ list<PortInsert*>::iterator x = find (_port_inserts.begin(), _port_inserts.end(), port_insert);
+ if (x != _port_inserts.end()) {
+ insert_bitset[port_insert->bit_slot()] = false;
+ _port_inserts.erase (x);
+ }
+ } else if ((plugin_insert = dynamic_cast<PluginInsert *> (processor)) != 0) {
+ _plugin_inserts.remove (plugin_insert);
+ } else if ((send = dynamic_cast<Send *> (processor)) != 0) {
list<Send*>::iterator x = find (_sends.begin(), _sends.end(), send);
if (x != _sends.end()) {
send_bitset[send->bit_slot()] = false;
_sends.erase (x);
}
} else {
- fatal << _("programming error: unknown type of Redirect deleted!") << endmsg;
+ fatal << _("programming error: unknown type of Insert deleted!") << endmsg;
/*NOTREACHED*/
}
sample_bytes_on_disk = 3.0;
break;
+ case FormatInt16:
+ sample_bytes_on_disk = 2.0;
+ break;
+
default:
/* impossible, but keep some gcc versions happy */
fatal << string_compose (_("programming error: %1"),
}
void
-Session::add_connection (ARDOUR::Connection* connection)
+Session::add_bundle (shared_ptr<Bundle> bundle)
{
{
- Glib::Mutex::Lock guard (connection_lock);
- _connections.push_back (connection);
+ Glib::Mutex::Lock guard (bundle_lock);
+ _bundles.push_back (bundle);
}
- ConnectionAdded (connection); /* EMIT SIGNAL */
+ BundleAdded (bundle); /* EMIT SIGNAL */
set_dirty();
}
void
-Session::remove_connection (ARDOUR::Connection* connection)
+Session::remove_bundle (shared_ptr<Bundle> bundle)
{
bool removed = false;
{
- Glib::Mutex::Lock guard (connection_lock);
- ConnectionList::iterator i = find (_connections.begin(), _connections.end(), connection);
+ Glib::Mutex::Lock guard (bundle_lock);
+ BundleList::iterator i = find (_bundles.begin(), _bundles.end(), bundle);
- if (i != _connections.end()) {
- _connections.erase (i);
+ if (i != _bundles.end()) {
+ _bundles.erase (i);
removed = true;
}
}
if (removed) {
- ConnectionRemoved (connection); /* EMIT SIGNAL */
+ BundleRemoved (bundle); /* EMIT SIGNAL */
}
set_dirty();
}
-ARDOUR::Connection *
-Session::connection_by_name (string name) const
+shared_ptr<Bundle>
+Session::bundle_by_name (string name) const
{
- Glib::Mutex::Lock lm (connection_lock);
+ Glib::Mutex::Lock lm (bundle_lock);
- for (ConnectionList::const_iterator i = _connections.begin(); i != _connections.end(); ++i) {
+ for (BundleList::const_iterator i = _bundles.begin(); i != _bundles.end(); ++i) {
if ((*i)->name() == name) {
return* i;
}
}
- return 0;
+ return boost::shared_ptr<Bundle> ();
}
void
void
Session::ensure_buffers (ChanCount howmany)
{
- // FIXME: NASTY assumption (midi block size == audio block size)
+ if (current_block_size == 0)
+ return; // too early? (is this ok?)
+
+ // We need at least 2 MIDI scratch buffers to mix/merge
+ if (howmany.n_midi() < 2)
+ howmany.set_midi(2);
+
+ // FIXME: JACK needs to tell us maximum MIDI buffer size
+ // Using nasty assumption (max # events == nframes) for now
_scratch_buffers->ensure_buffers(howmany, current_block_size);
- _send_buffers->ensure_buffers(howmany, current_block_size);
+ _mix_buffers->ensure_buffers(howmany, current_block_size);
_silent_buffers->ensure_buffers(howmany, current_block_size);
- allocate_pan_automation_buffers (current_block_size, howmany.get(DataType::AUDIO), false);
+ allocate_pan_automation_buffers (current_block_size, howmany.n_audio(), false);
}
uint32_t
boost::shared_ptr<AudioFileSource> fsource;
uint32_t x;
char buf[PATH_MAX+1];
- string dir;
ChanCount nchans(track.audio_diskstream()->n_channels());
nframes_t position;
nframes_t this_chunk;
nframes_t to_do;
BufferSet buffers;
+ SessionDirectory sdir(get_best_session_directory_for_new_source ());
+ const string sound_dir = sdir.sound_path().to_string();
// any bigger than this seems to cause stack overflows in called functions
const nframes_t chunk_size = (128 * 1024)/4;
if (track.has_external_redirects()) {
goto out;
}
-
- dir = discover_best_sound_dir ();
- for (uint32_t chan_n=0; chan_n < nchans.get(DataType::AUDIO); ++chan_n) {
+ for (uint32_t chan_n=0; chan_n < nchans.n_audio(); ++chan_n) {
for (x = 0; x < 99999; ++x) {
- snprintf (buf, sizeof(buf), "%s/%s-%d-bounce-%" PRIu32 ".wav", dir.c_str(), playlist->name().c_str(), chan_n, x+1);
+ snprintf (buf, sizeof(buf), "%s/%s-%d-bounce-%" PRIu32 ".wav", sound_dir.c_str(), playlist->name().c_str(), chan_n, x+1);
if (access (buf, F_OK) != 0) {
break;
}
boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*src);
if (afs) {
- if (afs->write (buffers.get_audio(n).data(this_chunk), this_chunk) != this_chunk) {
+ if (afs->write (buffers.get_audio(n).data(), this_chunk) != this_chunk) {
goto out;
}
}
g_atomic_int_set (&processing_prohibited, 0);
- itt.done = true;
-
return ret;
}
}
BufferSet&
-Session::get_send_buffers (ChanCount count)
+Session::get_mix_buffers (ChanCount count)
{
- assert(_send_buffers->available() >= count);
- _send_buffers->set_count(count);
- return *_send_buffers;
+ assert(_mix_buffers->available() >= count);
+ _mix_buffers->set_count(count);
+ return *_mix_buffers;
}
uint32_t
return _engine.frame_rate() * 60 * 5;
}
+void
+Session::sync_order_keys ()
+{
+ if (!Config->get_sync_all_route_ordering()) {
+ /* leave order keys as they are */
+ return;
+ }
+
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ (*i)->sync_order_keys ();
+ }
+
+ Route::SyncOrderKeys (); // EMIT SIGNAL
+}
+
+void
+Session::foreach_bundle (sigc::slot<void, boost::shared_ptr<Bundle> > sl)
+{
+ Glib::Mutex::Lock lm (bundle_lock);
+ for (BundleList::iterator i = _bundles.begin(); i != _bundles.end(); ++i) {
+ sl (*i);
+ }
+}
+