#include <ardour/audioengine.h>
#include <ardour/configuration.h>
#include <ardour/session.h>
-#include <ardour/audio_diskstream.h>
#include <ardour/utils.h>
+#include <ardour/audio_diskstream.h>
#include <ardour/audioplaylist.h>
#include <ardour/audioregion.h>
#include <ardour/audiofilesource.h>
+#include <ardour/midi_diskstream.h>
+#include <ardour/midi_playlist.h>
+#include <ardour/midi_region.h>
+#include <ardour/smf_source.h>
#include <ardour/destructive_filesource.h>
#include <ardour/auditioner.h>
#include <ardour/recent_sessions.h>
#include <ardour/slave.h>
#include <ardour/tempo.h>
#include <ardour/audio_track.h>
+#include <ardour/midi_track.h>
#include <ardour/cycle_timer.h>
#include <ardour/named_selection.h>
#include <ardour/crossfade.h>
#include <ardour/playlist.h>
#include <ardour/click.h>
+#include <ardour/data_type.h>
#ifdef HAVE_LIBLO
#include <ardour/osc.h>
using namespace std;
using namespace ARDOUR;
-//using namespace sigc;
+using namespace PBD;
+using boost::shared_ptr;
const char* Session::_template_suffix = X_(".template");
const char* Session::_statefile_suffix = X_(".ardour");
sigc::signal<int> Session::AskAboutPendingState;
sigc::signal<void> Session::SMPTEOffsetChanged;
+sigc::signal<void> Session::SendFeedback;
+
int
Session::find_session (string str, string& path, string& snapshot, bool& isnew)
pending_events (2048),
//midi_requests (128), // the size of this should match the midi request pool size
_send_smpte_update (false),
+ routes (new RouteList),
+ auditioner ((Auditioner*) 0),
+ _click_io ((IO*) 0),
main_outs (0)
{
bool new_session;
_midi_port (default_midi_port),
pending_events (2048),
//midi_requests (16),
+ _send_smpte_update (false),
+ routes (new RouteList),
main_outs (0)
{
}
if (control_out_channels) {
- Route* r;
- r = new Route (*this, _("monitor"), -1, control_out_channels, -1, control_out_channels, Route::ControlOut);
+ shared_ptr<Route> r (new Route (*this, _("monitor"), -1, control_out_channels, -1, control_out_channels, Route::ControlOut));
add_route (r);
_control_out = r;
}
if (master_out_channels) {
- Route* r;
- r = new Route (*this, _("master"), -1, master_out_channels, -1, master_out_channels, Route::MasterOut);
+ shared_ptr<Route> r (new Route (*this, _("master"), -1, master_out_channels, -1, master_out_channels, Route::MasterOut));
add_route (r);
_master_out = r;
} else {
clear_clicks ();
- if (_click_io) {
- delete _click_io;
- }
-
-
- if (auditioner) {
- delete auditioner;
- }
-
for (vector<Sample*>::iterator i = _passthru_buffers.begin(); i != _passthru_buffers.end(); ++i) {
free(*i);
}
for (map<RunContext,char*>::iterator i = _conversion_buffers.begin(); i != _conversion_buffers.end(); ++i) {
delete [] (i->second);
}
+
+ AudioDiskstream::free_working_buffers();
#undef TRACK_DESTRUCTION
#ifdef TRACK_DESTRUCTION
tmp =i;
++tmp;
- delete (*i).second;
+ delete i->second;
i = tmp;
}
#ifdef TRACK_DESTRUCTION
- cerr << "delete routes\n";
+ cerr << "delete diskstreams\n";
#endif /* TRACK_DESTRUCTION */
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ) {
- RouteList::iterator tmp;
- tmp = i;
- ++tmp;
- delete *i;
- i = tmp;
- }
-
-#ifdef TRACK_DESTRUCTION
- cerr << "delete audio_diskstreams\n";
-#endif /* TRACK_DESTRUCTION */
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ) {
- AudioDiskstreamList::iterator tmp;
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ) {
+ DiskstreamList::iterator tmp;
tmp = i;
++tmp;
tmp = i;
++tmp;
- delete (*i).second;
+ delete i->second;
i = tmp;
}
}
void
-Session::set_worst_io_latencies (bool take_lock)
+Session::set_worst_io_latencies ()
{
_worst_output_latency = 0;
_worst_input_latency = 0;
return;
}
- if (take_lock) {
- route_lock.reader_lock ();
- }
+ boost::shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
_worst_output_latency = max (_worst_output_latency, (*i)->output_latency());
_worst_input_latency = max (_worst_input_latency, (*i)->input_latency());
}
-
- if (take_lock) {
- route_lock.reader_unlock ();
- }
}
void
/* every time we reconnect, recompute worst case output latencies */
- _engine.Running.connect (sigc::bind (mem_fun (*this, &Session::set_worst_io_latencies), true));
+ _engine.Running.connect (mem_fun (*this, &Session::set_worst_io_latencies));
if (synced_to_jack()) {
_engine.transport_stop ();
try {
XMLNode* child = 0;
- _click_io = new ClickIO (*this, "click", 0, 0, -1, -1);
+ _click_io.reset (new ClickIO (*this, "click", 0, 0, -1, -1));
if (state_tree && (child = find_named_node (*state_tree->root(), "Click")) != 0) {
/* default state for Click */
+ // FIXME: there's no JackPortIsAudio flag or anything like that, so this is _bad_.
+ // we need a get_nth_physical_audio_output or similar, but the existing one just
+ // deals with strings :/
+
first_physical_output = _engine.get_nth_physical_output (0);
-
+ cerr << "FIXME: click type" << endl;
+
if (first_physical_output.length()) {
if (_click_io->add_output_port (first_physical_output, this)) {
// relax, even though its an error
error << _("cannot setup Click I/O") << endmsg;
}
- set_worst_io_latencies (true);
+ set_worst_io_latencies ();
if (_clicking) {
ControlChanged (Clicking); /* EMIT SIGNAL */
*/
try {
- auditioner = new Auditioner (*this);
+ auditioner.reset (new Auditioner (*this));
}
catch (failed_constructor& err) {
_master_out->defer_pan_reset ();
while ((int) _master_out->n_inputs() < _master_out->input_maximum()) {
- if (_master_out->add_input_port ("", this)) {
+ if (_master_out->add_input_port ("", this, DataType::AUDIO)) {
error << _("cannot setup master inputs")
<< endmsg;
break;
}
n = 0;
while ((int) _master_out->n_outputs() < _master_out->output_maximum()) {
- if (_master_out->add_output_port (_engine.get_nth_physical_output (n), this)) {
+ if (_master_out->add_output_port (_engine.get_nth_physical_output (n), this, DataType::AUDIO)) {
error << _("cannot setup master outputs")
<< endmsg;
break;
}
void
-Session::diskstream_playlist_changed (AudioDiskstream* dstream)
+Session::diskstream_playlist_changed (Diskstream* dstream)
{
Playlist *playlist;
The rarity and short potential lock duration makes this "OK"
*/
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->record_enabled ()) {
//cerr << "switching to input = " << !auto_input << __FILE__ << __LINE__ << endl << endl;
(*i)->monitor_input (!auto_input);
{
if (transport_rolling()) {
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->record_enabled ()) {
//cerr << "switching to input = " << !auto_input << __FILE__ << __LINE__ << endl << endl;
(*i)->monitor_input (Config->get_use_hardware_monitoring() && !auto_input);
}
} else {
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->record_enabled ()) {
//cerr << "switching to input = " << !auto_input << __FILE__ << __LINE__ << endl << endl;
(*i)->monitor_input (Config->get_use_hardware_monitoring());
if (get_record_enabled() && get_punch_in()) {
/* capture start has been changed, so save new pending state */
save_state ("", true);
+ save_history();
}
}
}
else if (seamless_loop && !loop_changing) {
- // schedule a locate-roll to refill the audio_diskstreams at the
+ // schedule a locate-roll to refill the diskstreams at the
// previous loop end
loop_changing = true;
*/
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->record_enabled ()) {
(*i)->monitor_input (true);
}
*/
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->record_enabled ()) {
(*i)->monitor_input (false);
}
*/
Glib::RWLock::ReaderLock dsm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if (auto_input && (*i)->record_enabled ()) {
//cerr << "switching from input" << __FILE__ << __LINE__ << endl << endl;
(*i)->monitor_input (false);
*/
save_state ("", true);
+ save_history();
if (_transport_speed) {
if (!punch_in) {
*/
{
- Glib::RWLock::ReaderLock lm (route_lock);
Glib::RWLock::ReaderLock dsm (diskstream_lock);
vector<Sample*>::iterator i;
uint32_t np;
allocate_pan_automation_buffers (nframes, _npan_buffers, true);
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ boost::shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
(*i)->set_block_size (nframes);
}
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
(*i)->set_block_size (nframes);
}
- set_worst_io_latencies (false);
+ set_worst_io_latencies ();
}
}
}
struct RouteSorter {
- bool operator() (Route* r1, Route* r2) {
+ bool operator() (boost::shared_ptr<Route> r1, boost::shared_ptr<Route> r2) {
if (r1->fed_by.find (r2) != r1->fed_by.end()) {
return false;
} else if (r2->fed_by.find (r1) != r2->fed_by.end()) {
};
static void
-trace_terminal (Route* r1, Route* rbase)
+trace_terminal (shared_ptr<Route> r1, shared_ptr<Route> rbase)
{
- Route* r2;
+ shared_ptr<Route> r2;
if ((r1->fed_by.find (rbase) != r1->fed_by.end()) && (rbase->fed_by.find (r1) != rbase->fed_by.end())) {
info << string_compose(_("feedback loop setup between %1 and %2"), r1->name(), rbase->name()) << endmsg;
/* make a copy of the existing list of routes that feed r1 */
- set<Route *> existing = r1->fed_by;
+ set<shared_ptr<Route> > existing = r1->fed_by;
/* for each route that feeds r1, recurse, marking it as feeding
rbase as well.
*/
- for (set<Route *>::iterator i = existing.begin(); i != existing.end(); ++i) {
+ for (set<shared_ptr<Route> >::iterator i = existing.begin(); i != existing.end(); ++i) {
r2 =* i;
/* r2 is a route that feeds r1 which somehow feeds base. mark
}
void
-Session::resort_routes (void* src)
+Session::resort_routes ()
{
/* don't do anything here with signals emitted
by Routes while we are being destroyed.
return;
}
- /* Caller MUST hold the route_lock */
- RouteList::iterator i, j;
+ {
- for (i = routes.begin(); i != routes.end(); ++i) {
+ RCUWriter<RouteList> writer (routes);
+ shared_ptr<RouteList> r = writer.get_copy ();
+ resort_routes_using (r);
+ /* writer goes out of scope and forces update */
+ }
+}
+void
+Session::resort_routes_using (shared_ptr<RouteList> r)
+{
+ RouteList::iterator i, j;
+
+ for (i = r->begin(); i != r->end(); ++i) {
+
(*i)->fed_by.clear ();
- for (j = routes.begin(); j != routes.end(); ++j) {
-
+ for (j = r->begin(); j != r->end(); ++j) {
+
/* although routes can feed themselves, it will
cause an endless recursive descent if we
detect it. so don't bother checking for
self-feeding.
*/
-
+
if (*j == *i) {
continue;
}
-
+
if ((*j)->feeds (*i)) {
(*i)->fed_by.insert (*j);
}
}
}
- for (i = routes.begin(); i != routes.end(); ++i) {
+ for (i = r->begin(); i != r->end(); ++i) {
trace_terminal (*i, *i);
}
-
+
RouteSorter cmp;
- routes.sort (cmp);
-
+ r->sort (cmp);
+
#if 0
cerr << "finished route resort\n";
- for (i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
cerr << " " << (*i)->name() << " signal order = " << (*i)->order_key ("signal") << endl;
}
cerr << endl;
#endif
+
+}
+boost::shared_ptr<MidiTrack>
+Session::new_midi_track (TrackMode mode)
+{
+ char track_name[32];
+ uint32_t n = 0;
+ uint32_t channels_used = 0;
+ string port;
+
+ /* count existing midi tracks */
+
+ {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<MidiTrack*>((*i).get()) != 0) {
+ if (!(*i)->hidden()) {
+ n++;
+ channels_used += (*i)->n_inputs();
+ }
+ }
+ }
+ }
+
+ /* check for duplicate route names, since we might have pre-existing
+ routes with this name (e.g. create Midi1, Midi2, delete Midi1,
+ save, close,restart,add new route - first named route is now
+ Midi2)
+ */
+
+ do {
+ snprintf (track_name, sizeof(track_name), "Midi %" PRIu32, n+1);
+ if (route_by_name (track_name) == 0) {
+ break;
+ }
+ n++;
+
+ } while (n < (UINT_MAX-1));
+
+ try {
+ shared_ptr<MidiTrack> track (new MidiTrack (*this, track_name, Route::Flag (0), mode));
+
+ if (track->ensure_io (1, 1, false, this)) {
+ error << string_compose (_("cannot configure %1 in/%2 out configuration for new midi track"), track_name)
+ << endmsg;
+ }
+#if 0
+ if (nphysical_in) {
+ for (uint32_t x = 0; x < track->n_inputs() && x < nphysical_in; ++x) {
+
+ port = "";
+
+ if (input_auto_connect & AutoConnectPhysical) {
+ port = _engine.get_nth_physical_input ((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(); ++x) {
+
+ port = "";
+
+ if (nphysical_out && (output_auto_connect & AutoConnectPhysical)) {
+ port = _engine.get_nth_physical_output ((channels_used+x)%nphysical_out);
+ } else if (output_auto_connect & AutoConnectMaster) {
+ if (_master_out) {
+ port = _master_out->input (x%_master_out->n_inputs())->name();
+ }
+ }
+
+ if (port.length() && track->connect_output (track->output (x), port, this)) {
+ break;
+ }
+ }
+
+ if (_control_out) {
+ vector<string> cports;
+ uint32_t ni = _control_out->n_inputs();
+
+ for (n = 0; n < ni; ++n) {
+ cports.push_back (_control_out->input(n)->name());
+ }
+
+ track->set_control_outs (cports);
+ }
+#endif
+ track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes));
+
+ add_route (track);
+
+ track->set_remote_control_id (ntracks());
+ return track;
+ }
+
+ catch (failed_constructor &err) {
+ error << _("Session: could not create new midi track.") << endmsg;
+ return shared_ptr<MidiTrack> ((MidiTrack*) 0);
+ }
}
-AudioTrack*
+
+boost::shared_ptr<Route>
+Session::new_midi_route ()
+{
+ char bus_name[32];
+ uint32_t n = 0;
+ string port;
+
+ /* count existing midi busses */
+ {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<MidiTrack*>((*i).get()) == 0) {
+ if (!(*i)->hidden()) {
+ n++;
+ }
+ }
+ }
+ }
+
+ do {
+ snprintf (bus_name, sizeof(bus_name), "Bus %" PRIu32, n+1);
+ if (route_by_name (bus_name) == 0) {
+ break;
+ }
+ n++;
+
+ } while (n < (UINT_MAX-1));
+
+ try {
+ shared_ptr<Route> bus (new Route (*this, bus_name, -1, -1, -1, -1, Route::Flag(0), DataType::MIDI));
+
+ if (bus->ensure_io (1, 1, false, this)) {
+ error << (_("cannot configure 1 in/1 out configuration for new midi track"))
+ << endmsg;
+ }
+#if 0
+ for (uint32_t x = 0; x < bus->n_inputs(); ++x) {
+
+ port = "";
+
+ if (input_auto_connect & AutoConnectPhysical) {
+ port = _engine.get_nth_physical_input ((n+x)%n_physical_inputs);
+ }
+
+ if (port.length() && bus->connect_input (bus->input (x), port, this)) {
+ break;
+ }
+ }
+
+ for (uint32_t x = 0; x < bus->n_outputs(); ++x) {
+
+ port = "";
+
+ if (output_auto_connect & AutoConnectPhysical) {
+ port = _engine.get_nth_physical_input ((n+x)%n_physical_outputs);
+ } else if (output_auto_connect & AutoConnectMaster) {
+ if (_master_out) {
+ port = _master_out->input (x%_master_out->n_inputs())->name();
+ }
+ }
+
+ if (port.length() && bus->connect_output (bus->output (x), port, this)) {
+ break;
+ }
+ }
+#endif
+/*
+ if (_control_out) {
+ vector<string> cports;
+ uint32_t ni = _control_out->n_inputs();
+
+ for (uint32_t n = 0; n < ni; ++n) {
+ cports.push_back (_control_out->input(n)->name());
+ }
+ bus->set_control_outs (cports);
+ }
+*/
+ add_route (bus);
+ return bus;
+ }
+
+ catch (failed_constructor &err) {
+ error << _("Session: could not create new MIDI route.") << endmsg;
+ return shared_ptr<Route> ((Route*) 0);
+ }
+}
+
+
+shared_ptr<AudioTrack>
Session::new_audio_track (int input_channels, int output_channels, TrackMode mode)
{
- AudioTrack *track;
char track_name[32];
uint32_t n = 0;
uint32_t channels_used = 0;
/* count existing audio tracks */
{
- Glib::RWLock::ReaderLock lm (route_lock);
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
- if (dynamic_cast<AudioTrack*>(*i) != 0) {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<AudioTrack*>((*i).get()) != 0) {
if (!(*i)->hidden()) {
n++;
channels_used += (*i)->n_inputs();
}
try {
- track = new AudioTrack (*this, track_name, Route::Flag (0), mode);
+ shared_ptr<AudioTrack> track (new AudioTrack (*this, track_name, Route::Flag (0), mode));
if (track->ensure_io (input_channels, output_channels, false, this)) {
error << string_compose (_("cannot configure %1 in/%2 out configuration for new audio track"),
track->set_control_outs (cports);
}
- track->diskstream_changed.connect (mem_fun (this, &Session::resort_routes));
+ track->DiskstreamChanged.connect (mem_fun (this, &Session::resort_routes));
add_route (track);
track->set_remote_control_id (ntracks());
+ return track;
}
catch (failed_constructor &err) {
error << _("Session: could not create new audio track.") << endmsg;
- return 0;
+ return shared_ptr<AudioTrack> ((AudioTrack*) 0);
}
-
- return track;
}
-Route*
+shared_ptr<Route>
Session::new_audio_route (int input_channels, int output_channels)
{
- Route *bus;
char bus_name[32];
uint32_t n = 0;
string port;
/* count existing audio busses */
{
- Glib::RWLock::ReaderLock lm (route_lock);
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
- if (dynamic_cast<AudioTrack*>(*i) == 0) {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<AudioTrack*>((*i).get()) == 0) {
if (!(*i)->hidden()) {
n++;
}
} while (n < (UINT_MAX-1));
try {
- bus = new Route (*this, bus_name, -1, -1, -1, -1);
+ shared_ptr<Route> bus (new Route (*this, bus_name, -1, -1, -1, -1, Route::Flag(0), DataType::AUDIO));
if (bus->ensure_io (input_channels, output_channels, false, this)) {
error << string_compose (_("cannot configure %1 in/%2 out configuration for new audio track"),
}
add_route (bus);
+ return bus;
}
catch (failed_constructor &err) {
- error << _("Session: could not create new route.") << endmsg;
- return 0;
+ error << _("Session: could not create new audio route.") << endmsg;
+ return shared_ptr<Route> ((Route*) 0);
}
-
- return bus;
}
void
-Session::add_route (Route* route)
+Session::add_route (shared_ptr<Route> route)
{
{
- Glib::RWLock::WriterLock lm (route_lock);
- routes.push_front (route);
- resort_routes(0);
+ RCUWriter<RouteList> writer (routes);
+ shared_ptr<RouteList> r = writer.get_copy ();
+ r->push_front (route);
+ resort_routes_using (r);
}
route->solo_changed.connect (sigc::bind (mem_fun (*this, &Session::route_solo_changed), route));
}
void
-Session::add_diskstream (AudioDiskstream* dstream)
+Session::add_diskstream (Diskstream* dstream)
{
/* need to do this in case we're rolling at the time, to prevent false underruns */
- dstream->do_refill(0, 0, 0);
+ dstream->do_refill_with_alloc();
{
Glib::RWLock::WriterLock lm (diskstream_lock);
- audio_diskstreams.push_back (dstream);
+ diskstreams.push_back (dstream);
}
/* take a reference to the diskstream, preventing it from
set_dirty();
save_state (_current_snapshot_name);
+ save_history();
- AudioDiskstreamAdded (dstream); /* EMIT SIGNAL */
+ DiskstreamAdded (dstream); /* EMIT SIGNAL */
}
void
-Session::remove_route (Route& route)
+Session::remove_route (shared_ptr<Route> route)
{
{
- Glib::RWLock::WriterLock lm (route_lock);
- routes.remove (&route);
+ RCUWriter<RouteList> writer (routes);
+ shared_ptr<RouteList> rs = writer.get_copy ();
+ rs->remove (route);
/* deleting the master out seems like a dumb
idea, but its more of a UI policy issue
than our concern.
*/
- if (&route == _master_out) {
- _master_out = 0;
+ if (route == _master_out) {
+ _master_out = shared_ptr<Route> ((Route*) 0);
}
- if (&route == _control_out) {
- _control_out = 0;
+ if (route == _control_out) {
+ _control_out = shared_ptr<Route> ((Route*) 0);
/* cancel control outs for all routes */
vector<string> empty;
- for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
+ for (RouteList::iterator r = rs->begin(); r != rs->end(); ++r) {
(*r)->set_control_outs (empty);
}
}
update_route_solo_state ();
+
+ /* writer goes out of scope, forces route list update */
}
AudioTrack* at;
AudioDiskstream* ds = 0;
- if ((at = dynamic_cast<AudioTrack*>(&route)) != 0) {
- ds = &at->disk_stream();
+ if ((at = dynamic_cast<AudioTrack*>(route.get())) != 0) {
+ ds = &at->audio_diskstream();
}
if (ds) {
{
Glib::RWLock::WriterLock lm (diskstream_lock);
- audio_diskstreams.remove (ds);
+ diskstreams.remove (ds);
}
ds->unref ();
save_state (_current_snapshot_name);
- delete &route;
+ /* all shared ptrs to route should go out of scope here */
}
void
}
void
-Session::route_solo_changed (void* src, Route* route)
+Session::route_solo_changed (void* src, shared_ptr<Route> route)
{
if (solo_update_disabled) {
// We know already
return;
}
- Glib::RWLock::ReaderLock lm (route_lock);
bool is_track;
- is_track = (dynamic_cast<AudioTrack*>(route) != 0);
+ is_track = (dynamic_cast<AudioTrack*>(route.get()) != 0);
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
/* soloing a track mutes all other tracks, soloing a bus mutes all other busses */
/* don't mess with busses */
- if (dynamic_cast<AudioTrack*>(*i) == 0) {
+ if (dynamic_cast<AudioTrack*>((*i).get()) == 0) {
continue;
}
/* don't mess with tracks */
- if (dynamic_cast<AudioTrack*>(*i) != 0) {
+ if (dynamic_cast<AudioTrack*>((*i).get()) != 0) {
continue;
}
}
bool same_thing_soloed = false;
bool signal = false;
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->soloed()) {
something_soloed = true;
- if (dynamic_cast<AudioTrack*>(*i)) {
+ if (dynamic_cast<AudioTrack*>((*i).get())) {
if (is_track) {
same_thing_soloed = true;
break;
/* this is where we actually implement solo by changing
the solo mute setting of each track.
*/
-
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->soloed()) {
mute = true;
- if (dynamic_cast<AudioTrack*>(*i)) {
+ if (dynamic_cast<AudioTrack*>((*i).get())) {
is_track = true;
}
break;
/* nothing is soloed */
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
(*i)->set_solo_mute (false);
}
void
Session::modify_solo_mute (bool is_track, bool mute)
{
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if (is_track) {
/* only alter track solo mute */
- if (dynamic_cast<AudioTrack*>(*i)) {
+ if (dynamic_cast<AudioTrack*>((*i).get())) {
if ((*i)->soloed()) {
(*i)->set_solo_mute (!mute);
} else {
/* only alter bus solo mute */
- if (!dynamic_cast<AudioTrack*>(*i)) {
+ if (!dynamic_cast<AudioTrack*>((*i).get())) {
if ((*i)->soloed()) {
basis, but needs the global overview that only the session
has.
*/
- Glib::RWLock::ReaderLock lm (route_lock);
update_route_solo_state();
}
-Route *
+shared_ptr<Route>
Session::route_by_name (string name)
{
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->name() == name) {
- return* i;
+ return *i;
}
}
- return 0;
+ return shared_ptr<Route> ((Route*) 0);
}
-Route *
+shared_ptr<Route>
Session::route_by_remote_id (uint32_t id)
{
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->remote_control_id() == id) {
- return* i;
+ return *i;
}
}
- return 0;
+ return shared_ptr<Route> ((Route*) 0);
}
void
ensure atomicity.
*/
- for (AudioDiskstreamList::const_iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::const_iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
Playlist* pl = (*i)->playlist();
if ((me = pl->get_maximum_extent()) > max) {
max = me;
return max;
}
-AudioDiskstream *
+Diskstream *
Session::diskstream_by_name (string name)
{
Glib::RWLock::ReaderLock lm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->name() == name) {
return* i;
}
return 0;
}
-AudioDiskstream *
-Session::diskstream_by_id (id_t id)
+Diskstream *
+Session::diskstream_by_id (const PBD::ID& id)
{
Glib::RWLock::ReaderLock lm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if ((*i)->id() == id) {
return *i;
}
sbuf = buf;
for (i = audio_regions.begin(); i != audio_regions.end(); ++i) {
- if ((*i).second->name() == sbuf) {
+ if (i->second->name() == sbuf) {
break;
}
}
name_taken = false;
for (AudioRegionList::const_iterator i = audio_regions.begin(); i != audio_regions.end(); ++i) {
- if ((*i).second->name() == result) {
+ if (i->second->name() == result) {
name_taken = true;
break;
}
if (x == audio_regions.end()) {
- pair<AudioRegionList::key_type, AudioRegionList::mapped_type> entry;
-
+ pair<AudioRegionList::key_type,AudioRegionList::mapped_type> entry;
+
entry.first = region->id();
entry.second = ar;
AudioRegionList::iterator i;
AudioRegion* ar = 0;
bool removed = false;
-
+
{
Glib::Mutex::Lock lm (region_lock);
- if ((ar = dynamic_cast<AudioRegion*> (region)) != 0) {
+ if ((ar = dynamic_cast<AudioRegion*> (region)) != 0) {
if ((i = audio_regions.find (region->id())) != audio_regions.end()) {
audio_regions.erase (i);
removed = true;
- }
+ }
+
} else {
+
fatal << _("programming error: ")
<< X_("unknown region type passed to Session::remove_region()")
<< endmsg;
for (i = audio_regions.begin(); i != audio_regions.end(); ++i) {
- region = (*i).second;
+ region = i->second;
if (region->whole_file()) {
}
void
-Session::find_equivalent_playlist_regions (AudioRegion& region, vector<AudioRegion*>& result)
+Session::find_equivalent_playlist_regions (Region& region, vector<Region*>& result)
{
- for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) {
-
- AudioPlaylist* pl;
-
- if ((pl = dynamic_cast<AudioPlaylist*>(*i)) == 0) {
- continue;
- }
-
- pl->get_region_list_equivalent_regions (region, result);
- }
+ for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i)
+ (*i)->get_region_list_equivalent_regions (region, result);
}
int
Glib::RWLock::ReaderLock lm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
list<Region*>& l = (*i)->last_capture_regions();
if (!l.empty()) {
{
pair<AudioSourceList::key_type, AudioSourceList::mapped_type> entry;
- {
- Glib::Mutex::Lock lm (audio_source_lock);
+ {
+ Glib::Mutex::Lock lm (audio_source_lock);
entry.first = source->id();
entry.second = source;
audio_sources.insert (entry);
- }
+ }
source->GoingAway.connect (mem_fun (this, &Session::remove_source));
set_dirty();
if ((i = audio_sources.find (source->id())) != audio_sources.end()) {
audio_sources.erase (i);
- }
+ }
}
if (!_state_of_the_state & InCleanup) {
*/
save_state (_current_snapshot_name);
+ save_history();
}
SourceRemoved(source); /* EMIT SIGNAL */
}
Source *
-Session::get_source (ARDOUR::id_t id)
+Session::source_by_id (const PBD::ID& id)
{
Glib::Mutex::Lock lm (audio_source_lock);
AudioSourceList::iterator i;
Source* source = 0;
if ((i = audio_sources.find (id)) != audio_sources.end()) {
- source = (*i).second;
- }
-
- if (source) {
- return source;
+ source = i->second;
}
/* XXX search MIDI or other searches here */
- return 0;
+ return source;
}
string
the task here is to replace NAME with the new name.
*/
- /* find last slash */
-
string dir;
string suffix;
string::size_type slash;
string::size_type dash;
+ string::size_type postfix;
+
+ /* find last slash */
if ((slash = path.find_last_of ('/')) == string::npos) {
return "";
return "";
}
- suffix = path.substr (dash);
+ suffix = path.substr (dash+1);
+
+ // Suffix is now everything after the dash. Now we need to eliminate
+ // the nnnnn part, which is done by either finding a '%' or a '.'
+
+ postfix = suffix.find_last_of ("%");
+ if (postfix == string::npos) {
+ postfix = suffix.find_last_of ('.');
+ }
+
+ if (postfix != string::npos) {
+ suffix = suffix.substr (postfix);
+ } else {
+ error << "Logic error in Session::change_audio_path_by_name(), please report to the developers" << endl;
+ return "";
+ }
+
+ const uint32_t limit = 10000;
+ char buf[PATH_MAX+1];
+
+ for (uint32_t cnt = 1; cnt <= limit; ++cnt) {
+
+ snprintf (buf, sizeof(buf), "%s%s-%u%s", dir.c_str(), newname.c_str(), cnt, suffix.c_str());
+
+ if (access (buf, F_OK) != 0) {
+ path = buf;
+ break;
+ }
+ path = "";
+ }
+
+ if (path == "") {
+ error << "FATAL ERROR! Could not find a " << endl;
+ }
- path = dir;
- path += new_legalized;
- path += suffix;
}
return path;
*/
for (cnt = (destructive ? ++destructive_index : 1); cnt <= limit; ++cnt) {
-
+
vector<space_and_path>::iterator i;
uint32_t existing = 0;
-
+
for (i = session_dirs.begin(); i != session_dirs.end(); ++i) {
-
+
spath = (*i).path;
-
+
if (destructive) {
spath += tape_dir_name;
} else {
spath += sound_dir_name;
}
-
+
if (destructive) {
if (nchan < 2) {
snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav", spath.c_str(), cnt, legalized.c_str());
snprintf (buf, sizeof(buf), "%s/T%04d-%s.wav", spath.c_str(), cnt, legalized.c_str());
}
} else {
-
+
spath += '/';
spath += legalized;
-
+
if (nchan < 2) {
snprintf (buf, sizeof(buf), "%s-%u.wav", spath.c_str(), cnt);
} else if (nchan == 2) {
existing++;
}
}
-
+
if (existing == 0) {
break;
}
/* Playlist management */
-Playlist *
-Session::get_playlist (string name)
-{
- Playlist* ret = 0;
-
- if ((ret = playlist_by_name (name)) == 0) {
- ret = new AudioPlaylist (*this, name);
- }
-
- return ret;
-}
-
Playlist *
Session::playlist_by_name (string name)
{
}
void
-Session::audition_region (AudioRegion& r)
+Session::audition_region (Region& r)
{
- Event* ev = new Event (Event::Audition, Event::Add, Event::Immediate, 0, 0.0);
- ev->set_ptr (&r);
- queue_event (ev);
+ AudioRegion* ar = dynamic_cast<AudioRegion*>(&r);
+ if (ar) {
+ Event* ev = new Event (Event::Audition, Event::Add, Event::Immediate, 0, 0.0);
+ ev->set_ptr (ar);
+ queue_event (ev);
+ }
}
void
}
bool
-Session::RoutePublicOrderSorter::operator() (Route* a, Route* b)
+Session::RoutePublicOrderSorter::operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b)
{
return a->order_key(N_("signal")) < b->order_key(N_("signal"));
}
void
Session::set_all_solo (bool yn)
{
- {
- Glib::RWLock::ReaderLock lm (route_lock);
-
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
- if (!(*i)->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()) {
+ (*i)->set_solo (yn, this);
}
}
void
Session::set_all_mute (bool yn)
{
- {
- Glib::RWLock::ReaderLock lm (route_lock);
-
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
- if (!(*i)->hidden()) {
- (*i)->set_mute (yn, this);
- }
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if (!(*i)->hidden()) {
+ (*i)->set_mute (yn, this);
}
}
}
uint32_t
-Session::n_audio_diskstreams () const
+Session::n_diskstreams () const
{
Glib::RWLock::ReaderLock lm (diskstream_lock);
uint32_t n = 0;
- for (AudioDiskstreamList::const_iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::const_iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
if (!(*i)->hidden()) {
n++;
}
return n;
}
-void
-Session::foreach_audio_diskstream (void (AudioDiskstream::*func)(void))
-{
- Glib::RWLock::ReaderLock lm (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
- if (!(*i)->hidden()) {
- ((*i)->*func)();
- }
- }
-}
-
void
Session::graph_reordered ()
{
return;
}
- Glib::RWLock::WriterLock lm1 (route_lock);
Glib::RWLock::ReaderLock lm2 (diskstream_lock);
- resort_routes (0);
+ resort_routes ();
/* force all diskstreams to update their capture offset values to
reflect any changes in latencies within the graph.
*/
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
(*i)->set_capture_offset ();
}
}
void
Session::record_enable_change_all (bool yn)
{
- Glib::RWLock::ReaderLock lm1 (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
AudioTrack* at;
- if ((at = dynamic_cast<AudioTrack*>(*i)) != 0) {
+ if ((at = dynamic_cast<AudioTrack*>((*i).get())) != 0) {
at->set_record_enable (yn, this);
}
}
//RWLockMonitor lm1 (route_lock, true, __LINE__, __FILE__);
Glib::RWLock::ReaderLock lm2 (diskstream_lock);
- for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
+ for (DiskstreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
(*i)->reset_write_sources (false);
}
}
bool
Session::route_name_unique (string n) const
{
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->name() == n) {
return false;
}
_npan_buffers = howmany;
}
-void
-Session::add_instant_xml (XMLNode& node, const std::string& dir)
-{
- Stateful::add_instant_xml (node, dir);
- Config->add_instant_xml (node, get_user_ardour_path());
-}
-
int
Session::freeze (InterThreadInfo& itt)
{
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
AudioTrack *at;
- if ((at = dynamic_cast<AudioTrack*>(*i)) != 0) {
+ if ((at = dynamic_cast<AudioTrack*>((*i).get())) != 0) {
/* XXX this is wrong because itt.progress will keep returning to zero at the start
of every track.
*/
jack_nframes_t to_do;
vector<Sample*> buffers;
char * workbuf = 0;
- const jack_nframes_t chunk_size = (256 * 1024)/4;
+
+ // any bigger than this seems to cause stack overflows in called functions
+ const jack_nframes_t chunk_size = (128 * 1024)/4;
g_atomic_int_set (&processing_prohibited, 1);
/* call tree *MUST* hold route_lock */
- if ((playlist = track.disk_stream().playlist()) == 0) {
+ if ((playlist = track.diskstream().playlist()) == 0) {
goto out;
}
goto out;
}
- nchans = track.disk_stream().n_channels();
+ nchans = track.audio_diskstream().n_channels();
dir = discover_best_sound_dir ();
Session::ntracks () const
{
uint32_t n = 0;
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
- if (dynamic_cast<AudioTrack*> (*i)) {
+ for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<AudioTrack*> ((*i).get())) {
++n;
}
}
Session::nbusses () const
{
uint32_t n = 0;
- Glib::RWLock::ReaderLock lm (route_lock);
+ shared_ptr<RouteList> r = routes.reader ();
- for (RouteList::const_iterator i = routes.begin(); i != routes.end(); ++i) {
- if (dynamic_cast<AudioTrack*> (*i) == 0) {
+ for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
+ if (dynamic_cast<AudioTrack*> ((*i).get()) == 0) {
++n;
}
}