#include <pbd/pathscanner.h>
#include <pbd/stl_delete.h>
#include <pbd/basename.h>
+#include <pbd/stacktrace.h>
#include <ardour/audioengine.h>
#include <ardour/configuration.h>
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, _engine.frame_rate() * 60 * 5)) {
+ if (create (new_session, mix_template, compute_initial_length())) {
cerr << "create failed\n";
+ destroy ();
throw failed_constructor ();
}
}
if (second_stage_init (new_session)) {
- cerr << "2nd state failed\n";
+ destroy ();
throw failed_constructor ();
}
cerr << "Loading session " << fullpath << " using snapshot " << snapshot_name << " (2)" << endl;
- n_physical_outputs = max (requested_physical_out, _engine.n_physical_outputs());
- n_physical_inputs = max (requested_physical_in, _engine.n_physical_inputs());
+ n_physical_outputs = _engine.n_physical_outputs();
+ n_physical_inputs = _engine.n_physical_inputs();
+
+ if (n_physical_inputs) {
+ n_physical_inputs = max (requested_physical_in, n_physical_inputs);
+ }
+
+ if (n_physical_outputs) {
+ n_physical_outputs = max (requested_physical_out, n_physical_outputs);
+ }
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, 0, initial_length)) {
+ destroy ();
throw failed_constructor ();
}
}
- if (control_out_channels) {
- shared_ptr<Route> r (new Route (*this, _("monitor"), -1, control_out_channels, -1, control_out_channels, Route::ControlOut));
- RouteList rl;
- rl.push_back (r);
- add_routes (rl);
- _control_out = r;
- }
-
- if (master_out_channels) {
- shared_ptr<Route> r (new Route (*this, _("master"), -1, master_out_channels, -1, master_out_channels, Route::MasterOut));
+ {
+ /* set up Master Out and Control Out if necessary */
+
RouteList rl;
- rl.push_back (r);
- add_routes (rl);
- _master_out = r;
- } else {
- /* prohibit auto-connect to master, because there isn't one */
- output_ac = AutoConnectOption (output_ac & ~AutoConnectMaster);
+ int control_id = 1;
+
+ if (control_out_channels) {
+ shared_ptr<Route> r (new Route (*this, _("monitor"), -1, control_out_channels, -1, control_out_channels, Route::ControlOut));
+ r->set_remote_control_id (control_id++);
+
+ rl.push_back (r);
+ }
+
+ if (master_out_channels) {
+ shared_ptr<Route> r (new Route (*this, _("master"), -1, master_out_channels, -1, master_out_channels, Route::MasterOut));
+ r->set_remote_control_id (control_id);
+
+ rl.push_back (r);
+ } else {
+ /* prohibit auto-connect to master, because there isn't one */
+ output_ac = AutoConnectOption (output_ac & ~AutoConnectMaster);
+ }
+
+ if (!rl.empty()) {
+ add_routes (rl);
+ }
+
}
Config->set_input_auto_connect (input_ac);
Config->set_output_auto_connect (output_ac);
if (second_stage_init (new_session)) {
+ destroy ();
throw failed_constructor ();
}
_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 ()
+{
+ destroy ();
+}
+
+void
+Session::destroy ()
{
/* if we got to here, leaving pending capture state around
is a mistake.
/* clear history so that no references to objects are held any more */
- history.clear ();
+ _history.clear ();
/* clear state tree so that no references to objects are held any more */
}
AudioDiskstream::free_working_buffers();
+
+ /* this should cause deletion of the auditioner */
+
+ // auditioner.reset ();
#undef TRACK_DESTRUCTION
#ifdef TRACK_DESTRUCTION
tmp = i;
++tmp;
- delete *i;
+ (*i)->drop_references ();
+
+ i = tmp;
+ }
+
+ for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ) {
+ PlaylistList::iterator tmp;
+
+ tmp = i;
+ ++tmp;
+
+ (*i)->drop_references ();
i = tmp;
}
+
+ playlists.clear ();
+ unused_playlists.clear ();
#ifdef TRACK_DESTRUCTION
cerr << "delete audio regions\n";
#endif /* TRACK_DESTRUCTION */
- for (AudioRegionList::iterator i = audio_regions.begin(); i != audio_regions.end(); ++i) {
+ for (AudioRegionList::iterator i = audio_regions.begin(); i != audio_regions.end(); ) {
+ AudioRegionList::iterator tmp;
+
+ tmp = i;
+ ++tmp;
+
i->second->drop_references ();
+
+ i = tmp;
}
audio_regions.clear ();
/* we don't want to run execute this again */
- first_time_running.disconnect ();
-
set_block_size (_engine.frames_per_cycle());
set_frame_rate (_engine.frame_rate());
// XXX HOW TO ALERT UI TO THIS ? DO WE NEED TO?
}
- if (auditioner == 0) {
-
- /* we delay creating the auditioner till now because
- it makes its own connections to ports named
- in the ARDOUR_RC config file. the engine has
- to be running for this to work.
- */
-
- try {
- auditioner.reset (new Auditioner (*this));
- }
-
- catch (failed_constructor& err) {
- warning << _("cannot create Auditioner: no auditioning of regions possible") << endmsg;
- }
- }
-
/* Create a set of Connection objects that map
to the physical outputs currently available
*/
}
}
+
_state_of_the_state = StateOfTheState (_state_of_the_state & ~(CannotSave|Dirty));
/* hook us up to the engine */
_state_of_the_state = StateOfTheState (_state_of_the_state | InitialConnecting);
+ if (auditioner == 0) {
+
+ /* we delay creating the auditioner till now because
+ it makes its own connections to ports.
+ the engine has to be running for this to work.
+ */
+
+ try {
+ auditioner.reset (new Auditioner (*this));
+ }
+
+ catch (failed_constructor& err) {
+ warning << _("cannot create Auditioner: no auditioning of regions possible") << endmsg;
+ }
+ }
+
/* Tell all IO objects to create their ports */
IO::enable_ports ();
}
void
-Session::playlist_length_changed (Playlist* pl)
+Session::playlist_length_changed ()
{
/* we can't just increase end_location->end() if pl->get_maximum_extent()
if larger. if the playlist used to be the longest playlist,
void
Session::diskstream_playlist_changed (boost::shared_ptr<Diskstream> dstream)
{
- Playlist *playlist;
+ boost::shared_ptr<Playlist> playlist;
if ((playlist = dstream->playlist()) != 0) {
- playlist->LengthChanged.connect (sigc::bind (mem_fun (this, &Session::playlist_length_changed), playlist));
+ playlist->LengthChanged.connect (mem_fun (this, &Session::playlist_length_changed));
}
/* see comment in playlist_length_changed () */
sync_time_vars();
+ Route::set_automation_interval ((jack_nframes_t) ceil ((double) frames_per_second * 0.25));
+
// XXX we need some equivalent to this, somehow
- // DestructiveFileSource::setup_standard_crossfades (frames_per_second);
+ // SndFileSource::setup_standard_crossfades (frames_per_second);
set_dirty();
for (i = r->begin(); i != r->end(); ++i) {
trace_terminal (*i, *i);
- }
-
+ }
+
RouteSorter cmp;
r->sort (cmp);
+ /* don't leave dangling references to routes in Route::fed_by */
+
+ for (i = r->begin(); i != r->end(); ++i) {
+ (*i)->fed_by.clear ();
+ }
+
#if 0
cerr << "finished route resort\n";
string port;
RouteList new_routes;
list<boost::shared_ptr<AudioTrack> > ret;
+ uint32_t control_id;
/* count existing audio tracks */
_engine.get_physical_outputs (physoutputs);
_engine.get_physical_inputs (physinputs);
+ control_id = ntracks() + nbusses() + 1;
while (how_many) {
}
track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes));
- track->set_remote_control_id (ntracks());
+ track->set_remote_control_id (control_id);
+ ++control_id;
new_routes.push_back (track);
ret.push_back (track);
uint32_t n = 0;
string port;
RouteList ret;
+ uint32_t control_id;
/* count existing audio busses */
_engine.get_physical_outputs (physoutputs);
_engine.get_physical_inputs (physinputs);
+ control_id = ntracks() + nbusses() + 1;
while (how_many) {
<< endmsg;
}
- for (uint32_t x = 0; x < bus->n_inputs(); ++x) {
+ for (uint32_t x = 0; n_physical_inputs && x < bus->n_inputs(); ++x) {
port = "";
-
+
if (Config->get_input_auto_connect() & AutoConnectPhysical) {
- port = physinputs[((n+x)%n_physical_inputs)];
+ port = physinputs[((n+x)%n_physical_inputs)];
}
if (port.length() && bus->connect_input (bus->input (x), port, this)) {
}
}
- for (uint32_t x = 0; x < bus->n_outputs(); ++x) {
+ for (uint32_t x = 0; n_physical_outputs && x < bus->n_outputs(); ++x) {
port = "";
bus->set_control_outs (cports);
}
+ bus->set_remote_control_id (control_id);
+ ++control_id;
+
ret.push_back (bus);
}
{
RCUWriter<RouteList> writer (routes);
shared_ptr<RouteList> rs = writer.get_copy ();
- rs->remove (route);
+ rs->remove (route);
+
/* deleting the master out seems like a dumb
idea, but its more of a UI policy issue
than our concern.
boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
for (DiskstreamList::const_iterator i = dsl->begin(); i != dsl->end(); ++i) {
- Playlist* pl = (*i)->playlist();
+ boost::shared_ptr<Playlist> pl = (*i)->playlist();
if ((me = pl->get_maximum_extent()) > max) {
max = me;
}
set_dirty();
if (added) {
- region->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_region), region));
- region->StateChanged.connect (sigc::bind (mem_fun (*this, &Session::region_changed), region));
+ region->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_region), boost::weak_ptr<Region>(region)));
+ region->StateChanged.connect (sigc::bind (mem_fun (*this, &Session::region_changed), boost::weak_ptr<Region>(region)));
AudioRegionAdded (ar); /* EMIT SIGNAL */
}
}
void
-Session::region_changed (Change what_changed, boost::shared_ptr<Region> region)
+Session::region_changed (Change what_changed, boost::weak_ptr<Region> weak_region)
{
+ boost::shared_ptr<Region> region (weak_region.lock ());
+
+ if (!region) {
+ return;
+ }
+
if (what_changed & Region::HiddenChanged) {
/* relay hidden changes */
RegionHiddenChange (region);
}
void
-Session::region_renamed (boost::shared_ptr<Region> region)
-{
- add_region (region);
-}
-
-void
-Session::remove_region (boost::shared_ptr<Region> region)
+Session::remove_region (boost::weak_ptr<Region> weak_region)
{
AudioRegionList::iterator i;
+ boost::shared_ptr<Region> region (weak_region.lock ());
+
+ if (!region) {
+ return;
+ }
+
boost::shared_ptr<AudioRegion> ar;
bool removed = false;
if ((i = audio_regions.find (region->id())) != audio_regions.end()) {
audio_regions.erase (i);
removed = true;
- cerr << "done\n";
}
} else {
set_dirty();
if (removed) {
- AudioRegionRemoved(ar); /* EMIT SIGNAL */
+ AudioRegionRemoved (ar); /* EMIT SIGNAL */
}
}
boost::shared_ptr<AudioRegion>
-Session::find_whole_file_parent (boost::shared_ptr<AudioRegion> child)
+Session::find_whole_file_parent (boost::shared_ptr<AudioRegion const> child)
{
AudioRegionList::iterator i;
boost::shared_ptr<AudioRegion> region;
int
Session::destroy_region (boost::shared_ptr<Region> region)
{
- boost::shared_ptr<AudioRegion> aregion;
-
- if ((aregion = boost::dynamic_pointer_cast<AudioRegion> (region)) == 0) {
- return 0;
- }
-
- if (aregion->playlist()) {
- aregion->playlist()->destroy_region (region);
- }
-
vector<boost::shared_ptr<Source> > srcs;
-
- for (uint32_t n = 0; n < aregion->n_channels(); ++n) {
- srcs.push_back (aregion->source (n));
+
+ {
+ boost::shared_ptr<AudioRegion> aregion;
+
+ if ((aregion = boost::dynamic_pointer_cast<AudioRegion> (region)) == 0) {
+ return 0;
+ }
+
+ if (aregion->playlist()) {
+ aregion->playlist()->destroy_region (region);
+ }
+
+ for (uint32_t n = 0; n < aregion->n_channels(); ++n) {
+ srcs.push_back (aregion->source (n));
+ }
}
+ region->drop_references ();
+
for (vector<boost::shared_ptr<Source> >::iterator i = srcs.begin(); i != srcs.end(); ++i) {
-
- if ((*i).use_count() == 1) {
- boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*i);
+ if (!(*i)->used()) {
+ boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*i);
+
if (afs) {
(afs)->mark_for_remove ();
}
(*i)->drop_references ();
+
+ cerr << "source was not used by any playlist\n";
}
}
result = audio_sources.insert (entry);
}
- if (!result.second) {
- cerr << "\tNOT inserted ? " << result.second << endl;
+ if (result.second) {
+ source->GoingAway.connect (sigc::bind (mem_fun (this, &Session::remove_source), boost::weak_ptr<Source> (source)));
+ set_dirty();
}
- source->GoingAway.connect (sigc::bind (mem_fun (this, &Session::remove_source), boost::weak_ptr<Source> (source)));
- set_dirty();
-
- SourceAdded (source); /* EMIT SIGNAL */
- } else {
- cerr << "\tNOT AUDIO FILE\n";
- }
+ }
}
void
save_state (_current_snapshot_name);
}
-
- SourceRemoved(source); /* EMIT SIGNAL */
}
boost::shared_ptr<Source>
} else {
snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav", spath.c_str(), cnt, legalized.c_str());
}
+
} else {
spath += '/';
if (cnt > limit) {
error << string_compose(_("There are already %1 recordings for %2, which I consider too many."), limit, name) << endmsg;
+ destroy ();
throw failed_constructor();
}
}
string foo = buf;
spath = discover_best_sound_dir ();
+ spath += '/';
string::size_type pos = foo.find_last_of ('/');
/* Playlist management */
-Playlist *
+boost::shared_ptr<Playlist>
Session::playlist_by_name (string name)
{
Glib::Mutex::Lock lm (playlist_lock);
return* i;
}
}
- return 0;
+
+ return boost::shared_ptr<Playlist>();
}
void
-Session::add_playlist (Playlist* playlist)
+Session::add_playlist (boost::shared_ptr<Playlist> playlist)
{
if (playlist->hidden()) {
return;
Glib::Mutex::Lock lm (playlist_lock);
if (find (playlists.begin(), playlists.end(), playlist) == playlists.end()) {
playlists.insert (playlists.begin(), playlist);
- // playlist->ref();
- playlist->InUse.connect (mem_fun (*this, &Session::track_playlist));
- playlist->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_playlist), playlist));
+ playlist->InUse.connect (sigc::bind (mem_fun (*this, &Session::track_playlist), boost::weak_ptr<Playlist>(playlist)));
+ playlist->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_playlist), boost::weak_ptr<Playlist>(playlist)));
}
}
}
void
-Session::track_playlist (Playlist* pl, bool inuse)
+Session::get_playlists (vector<boost::shared_ptr<Playlist> >& s)
{
+ {
+ Glib::Mutex::Lock lm (playlist_lock);
+ for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+ s.push_back (*i);
+ }
+ for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+ s.push_back (*i);
+ }
+ }
+}
+
+void
+Session::track_playlist (bool inuse, boost::weak_ptr<Playlist> wpl)
+{
+ boost::shared_ptr<Playlist> pl(wpl.lock());
+
+ if (!pl) {
+ return;
+ }
+
PlaylistList::iterator x;
+ if (pl->hidden()) {
+ /* its not supposed to be visible */
+ return;
+ }
+
{
Glib::Mutex::Lock lm (playlist_lock);
if (!inuse) {
- //cerr << "shifting playlist to unused: " << pl->name() << endl;
unused_playlists.insert (pl);
} else {
- //cerr << "shifting playlist to used: " << pl->name() << endl;
-
+
playlists.insert (pl);
if ((x = unused_playlists.find (pl)) != unused_playlists.end()) {
}
void
-Session::remove_playlist (Playlist* playlist)
+Session::remove_playlist (boost::weak_ptr<Playlist> weak_playlist)
{
if (_state_of_the_state & Deletion) {
return;
}
+ boost::shared_ptr<Playlist> playlist (weak_playlist.lock());
+
+ if (!playlist) {
+ return;
+ }
+
{
Glib::Mutex::Lock lm (playlist_lock);
- // cerr << "removing playlist: " << playlist->name() << endl;
PlaylistList::iterator i;
i = find (playlists.begin(), playlists.end(), playlist);
-
if (i != playlists.end()) {
playlists.erase (i);
}
return;
}
+ /* every track/bus asked for this to be handled but it was deferred because
+ we were connecting. do it now.
+ */
+
+ request_input_change_handling ();
+
resort_routes ();
/* force all diskstreams to update their capture offset values to
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.remove (port_insert);
+ 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 << _("programming error: unknown type of Insert deleted!") << endmsg;
+ fatal << string_compose (_("programming error: %1"),
+ X_("unknown type of Insert deleted!"))
+ << endmsg;
/*NOTREACHED*/
}
} else if ((send = dynamic_cast<Send *> (redirect)) != 0) {
- _sends.remove (send);
+ 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;
/*NOTREACHED*/
nframes_t
Session::available_capture_duration ()
{
- const double scale = 4096.0 / sizeof (Sample);
+ float sample_bytes_on_disk;
+
+ switch (Config->get_native_file_data_format()) {
+ case FormatFloat:
+ sample_bytes_on_disk = 4;
+ break;
+
+ case FormatInt24:
+ sample_bytes_on_disk = 3;
+ break;
+
+ default:
+ /* impossible, but keep some gcc versions happy */
+ fatal << string_compose (_("programming error: %1"),
+ X_("illegal native file data format"))
+ << endmsg;
+ /*NOTREACHED*/
+ }
+
+ double scale = 4096.0 / sample_bytes_on_disk;
if (_total_free_4k_blocks * scale > (double) max_frames) {
return max_frames;
allocate_pan_automation_buffers (current_block_size, howmany, false);
}
-string
-Session::next_send_name ()
+uint32_t
+Session::next_insert_id ()
{
- char buf[32];
- snprintf (buf, sizeof (buf), "send %" PRIu32, ++send_cnt);
- return buf;
+ /* this doesn't really loop forever. just think about it */
+
+ while (true) {
+ for (boost::dynamic_bitset<uint32_t>::size_type n = 0; n < insert_bitset.size(); ++n) {
+ if (!insert_bitset[n]) {
+ insert_bitset[n] = true;
+ cerr << "Returning " << n << " as insert ID\n";
+ return n;
+
+ }
+ }
+
+ /* none available, so resize and try again */
+
+ insert_bitset.resize (insert_bitset.size() + 16, false);
+ }
}
-string
-Session::next_insert_name ()
+uint32_t
+Session::next_send_id ()
{
- char buf[32];
- snprintf (buf, sizeof (buf), "insert %" PRIu32, ++insert_cnt);
- return buf;
+ /* this doesn't really loop forever. just think about it */
+
+ while (true) {
+ for (boost::dynamic_bitset<uint32_t>::size_type n = 0; n < send_bitset.size(); ++n) {
+ if (!send_bitset[n]) {
+ send_bitset[n] = true;
+ cerr << "Returning " << n << " as send ID\n";
+ return n;
+
+ }
+ }
+
+ /* none available, so resize and try again */
+
+ send_bitset.resize (send_bitset.size() + 16, false);
+ }
+}
+
+void
+Session::mark_send_id (uint32_t id)
+{
+ if (id >= send_bitset.size()) {
+ send_bitset.resize (id+16, false);
+ }
+ if (send_bitset[id]) {
+ warning << string_compose (_("send ID %1 appears to be in use already"), id) << endmsg;
+ }
+ send_bitset[id] = true;
+}
+
+void
+Session::mark_insert_id (uint32_t id)
+{
+ if (id >= insert_bitset.size()) {
+ insert_bitset.resize (id+16, false);
+ }
+ if (insert_bitset[id]) {
+ warning << string_compose (_("insert ID %1 appears to be in use already"), id) << endmsg;
+ }
+ insert_bitset[id] = true;
}
/* Named Selection management */
named_selections.insert (named_selections.begin(), named_selection);
}
+ for (list<boost::shared_ptr<Playlist> >::iterator i = named_selection->playlists.begin(); i != named_selection->playlists.end(); ++i) {
+ add_playlist (*i);
+ }
+
set_dirty();
- NamedSelectionAdded (); /* EMIT SIGNAL */
+ NamedSelectionAdded (); /* EMIT SIGNAL */
}
void
return true;
}
-int
-Session::cleanup_audio_file_source (boost::shared_ptr<AudioFileSource> fs)
-{
- return fs->move_to_trash (dead_sound_dir_name);
-}
-
uint32_t
Session::n_playlists () const
{
bool overwrite, vector<boost::shared_ptr<AudioSource> >& srcs, InterThreadInfo& itt)
{
int ret = -1;
- Playlist* playlist;
+ boost::shared_ptr<Playlist> playlist;
boost::shared_ptr<AudioFileSource> fsource;
uint32_t x;
char buf[PATH_MAX+1];
/* construct a region to represent the bounced material */
boost::shared_ptr<Region> aregion = RegionFactory::create (srcs, 0, srcs.front()->length(),
- region_name_from_path (srcs.front()->name()));
+ region_name_from_path (srcs.front()->name(), true));
ret = 0;
}
}
void
-Session::add_curve(Curve *curve)
+Session::add_automation_list(AutomationList *al)
{
- curves[curve->id()] = curve;
+ automation_lists[al->id()] = al;
}
-void
-Session::add_automation_list(AutomationList *al)
+nframes_t
+Session::compute_initial_length ()
{
- automation_lists[al->id()] = al;
+ return _engine.frame_rate() * 60 * 5;
}
+