#include <ardour/processor.h>
#include <ardour/plugin_insert.h>
#include <ardour/port_insert.h>
-#include <ardour/bundle.h>
+#include <ardour/auto_bundle.h>
#include <ardour/slave.h>
#include <ardour/tempo.h>
#include <ardour/audio_track.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
+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::EndTimeChanged;
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()),
diskstreams (new DiskstreamList),
routes (new RouteList),
auditioner ((Auditioner*) 0),
+ _bundle_xml_node (0),
_click_io ((IO*) 0),
- main_outs (0),
- _automation_interval (0)
+ main_outs (0)
{
+ bool new_session;
+
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);
- initialize_start_and_end_locations(0, compute_initial_length ());
-
- if(mix_template) {
- // try and create a new session directory
- try
- {
- if(!_session_dir->create()) {
- // an existing session.
- // throw a_more_meaningful_exception()
- destroy ();
- throw failed_constructor ();
- }
- }
- catch(sys::filesystem_error& ex)
- {
- destroy ();
- throw failed_constructor ();
- }
-
- if(!create_session_file_from_template (*mix_template)) {
+ 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())) {
destroy ();
throw failed_constructor ();
}
-
- cerr << "Creating session " << fullpath
- <<" using template" << *mix_template
- << endl;
- } else {
- // must be an existing session
- try
- {
- // ensure the necessary session subdirectories exist
- // in case the directory structure has changed etc.
- _session_dir->create();
- }
- catch(sys::filesystem_error& ex)
- {
- destroy ();
- throw failed_constructor ();
- }
-
- cerr << "Loading session " << fullpath
- << " using snapshot " << snapshot_name << " (1)"
- << endl;
}
-
- if (second_stage_init (false)) {
+
+ if (second_stage_init (new_session)) {
destroy ();
throw failed_constructor ();
}
_send_smpte_update (false),
diskstreams (new DiskstreamList),
routes (new RouteList),
- main_outs (0),
- _automation_interval (0)
+ _bundle_xml_node (0),
+ main_outs (0)
{
+ bool new_session;
+
if (!eng.connected()) {
throw failed_constructor();
}
first_stage_init (fullpath, snapshot_name);
- initialize_start_and_end_locations(0, initial_length);
-
- if (!_session_dir->create () || !create_session_file ()) {
- destroy ();
- throw failed_constructor ();
+ 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, string(), initial_length)) {
+ destroy ();
+ throw failed_constructor ();
+ }
}
{
}
if (!rl.empty()) {
- add_routes (rl);
+ add_routes (rl, false);
}
}
Config->set_input_auto_connect (input_ac);
Config->set_output_auto_connect (output_ac);
- if (second_stage_init (true)) {
+ if (second_stage_init (new_session)) {
destroy ();
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 */
i = tmp;
}
-#ifdef TRACK_DESTRUCTION
- cerr << "delete bundles\n";
-#endif /* TRACK_DESTRUCTION */
- for (BundleList::iterator i = _bundles.begin(); i != _bundles.end(); ) {
- BundleList::iterator tmp;
-
- tmp = i;
- ++tmp;
-
- delete *i;
-
- i = tmp;
- }
-
if (butler_mixdown_buffer) {
delete [] butler_mixdown_buffer;
}
char buf[32];
snprintf (buf, sizeof (buf), _("out %" PRIu32), np+1);
- Bundle* c = new OutputBundle (buf, true);
- c->set_nchannels (1);
- c->add_port_to_channel (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
+ shared_ptr<AutoBundle> c (new AutoBundle (buf, true));
+ c->set_channels (1);
+ c->set_port (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
- add_bundle (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);
- Bundle* c = new InputBundle (buf, true);
- c->set_nchannels (1);
- c->add_port_to_channel (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_bundle (c);
+ add_bundle (c);
}
/* TWO: STEREO */
char buf[32];
snprintf (buf, sizeof (buf), _("out %" PRIu32 "+%" PRIu32), np+1, np+2);
- Bundle* c = new OutputBundle (buf, true);
- c->set_nchannels (2);
- c->add_port_to_channel (0, _engine.get_nth_physical_output (DataType::AUDIO, np));
- c->add_port_to_channel (1, _engine.get_nth_physical_output (DataType::AUDIO, np+1));
+ 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));
- add_bundle (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);
- Bundle* c = new InputBundle (buf, true);
- c->set_nchannels (2);
- c->add_port_to_channel (0, _engine.get_nth_physical_input (DataType::AUDIO, np));
- c->add_port_to_channel (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_bundle (c);
+ add_bundle (c);
}
/* THREE MASTER */
}
- Bundle* c = new OutputBundle (_("Master Out"), true);
+ shared_ptr<AutoBundle> c (new AutoBundle (_("Master Out"), true));
- c->set_nchannels (_master_out->n_inputs().n_total());
- for (uint32_t n = 0; n < _master_out->n_inputs ().n_total(); ++n) {
- c->add_port_to_channel ((int) n, _master_out->input(n)->name());
- }
- add_bundle (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
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 */
_state_of_the_state = StateOfTheState (_state_of_the_state & ~InitialConnecting);
+
/* now handle the whole enchilada as if it was one
graph reorder event.
*/
sync_time_vars();
- _automation_interval = ((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 */
{
if (dynamic_cast<MidiTrack*>((*i).get()) != 0) {
if (!(*i)->is_hidden()) {
n++;
- channels_used += (*i)->n_inputs().n_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 ().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);
failed:
if (!new_routes.empty()) {
- add_routes (new_routes, false);
- save_state (_current_snapshot_name);
+ add_routes (new_routes, true);
}
return ret;
failure:
if (!ret.empty()) {
- add_routes (ret, false);
- save_state (_current_snapshot_name);
+ add_routes (ret, true);
}
return ret;
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) {
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) */
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
{
sys::path peakfile_path(_session_dir->peak_path());
-
- peakfile_path /= basename_nosuffix (audio_path) + peakfile_suffix;
-
+ peakfile_path /= basename_nosuffix (base) + peakfile_suffix;
return peakfile_path.to_string();
}
return spath;
}
-
+
boost::shared_ptr<MidiSource>
Session::create_midi_source_for_session (MidiDiskstream& ds)
{
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 = audio_filenames.begin(); i != audio_filenames.end(); ++i) {
-
- // never remove files that appear to be a tape track
-
- if (regexec (&compiled_tape_track_pattern, i->c_str(), 0, 0, 0) == 0) {
- continue;
- }
sys::path audio_file_path (_session_dir->sound_path());
if (AudioFileSource::is_empty (*this, audio_file_path.to_string())) {
- unlink (audio_file_path.to_string().c_str());
-
- string peak_path = peak_path_from_audio_path (audio_file_path.to_string());
- unlink (peak_path.c_str());
+ 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;
+ }
}
}
}
}
void
-Session::add_bundle (ARDOUR::Bundle* bundle)
+Session::add_bundle (shared_ptr<Bundle> bundle)
{
{
Glib::Mutex::Lock guard (bundle_lock);
}
void
-Session::remove_bundle (ARDOUR::Bundle* bundle)
+Session::remove_bundle (shared_ptr<Bundle> bundle)
{
bool removed = false;
set_dirty();
}
-ARDOUR::Bundle *
+shared_ptr<Bundle>
Session::bundle_by_name (string name) const
{
Glib::Mutex::Lock lm (bundle_lock);
}
}
- return 0;
+ return boost::shared_ptr<Bundle> ();
}
void
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);
+ }
+}
+