diff options
author | Carl Hetherington <carl@carlh.net> | 2009-12-03 21:52:10 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2009-12-03 21:52:10 +0000 |
commit | ee9455af40adaaf48010784330f457f471b2546e (patch) | |
tree | 187facb02c3a19b350ae9e3c3308d532331dfbd3 | |
parent | 03c74e45a871f2e09fb1ee855f830c94d1cdb163 (diff) |
Move some (most) playlist-related code and data into a separate object
(SessionPlaylists). Main point being to ensure that, when a Session
is destroyed (especially as a result of its constructor throwing an
exception) SessionPlaylists::track is disconnected from its signal
at the same time as the list of playlists is destroyed. Otherwise
problems abound.
git-svn-id: svn://localhost/ardour2/branches/3.0@6270 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/editor.cc | 6 | ||||
-rw-r--r-- | gtk2_ardour/playlist_selector.cc | 4 | ||||
-rw-r--r-- | gtk2_ardour/route_time_axis.cc | 8 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 32 | ||||
-rw-r--r-- | libs/ardour/ardour/session_playlist.h | 9 | ||||
-rw-r--r-- | libs/ardour/audio_diskstream.cc | 4 | ||||
-rw-r--r-- | libs/ardour/audio_playlist_importer.cc | 2 | ||||
-rw-r--r-- | libs/ardour/audio_track.cc | 4 | ||||
-rw-r--r-- | libs/ardour/midi_diskstream.cc | 2 | ||||
-rw-r--r-- | libs/ardour/midi_track.cc | 2 | ||||
-rw-r--r-- | libs/ardour/named_selection.cc | 2 | ||||
-rw-r--r-- | libs/ardour/playlist.cc | 2 | ||||
-rw-r--r-- | libs/ardour/session.cc | 192 | ||||
-rw-r--r-- | libs/ardour/session_command.cc | 2 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 134 | ||||
-rw-r--r-- | libs/ardour/wscript | 1 |
16 files changed, 47 insertions, 359 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 445044f65c..b7dd21f535 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -4026,7 +4026,7 @@ Editor::new_playlists (TimeAxisView* v) { begin_reversible_command (_("new playlists")); vector<boost::shared_ptr<ARDOUR::Playlist> > playlists; - session->get_playlists(playlists); + session->playlists.get (playlists); mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v, RouteGroup::Edit); commit_reversible_command (); } @@ -4042,7 +4042,7 @@ Editor::copy_playlists (TimeAxisView* v) { begin_reversible_command (_("copy playlists")); vector<boost::shared_ptr<ARDOUR::Playlist> > playlists; - session->get_playlists(playlists); + session->playlists.get (playlists); mapover_tracks (bind (mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v, RouteGroup::Edit); commit_reversible_command (); } @@ -4057,7 +4057,7 @@ Editor::clear_playlists (TimeAxisView* v) { begin_reversible_command (_("clear playlists")); vector<boost::shared_ptr<ARDOUR::Playlist> > playlists; - session->get_playlists(playlists); + session->playlists.get (playlists); mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v, RouteGroup::Edit); commit_reversible_command (); } diff --git a/gtk2_ardour/playlist_selector.cc b/gtk2_ardour/playlist_selector.cc index ca40951e8b..82541cd7fb 100644 --- a/gtk2_ardour/playlist_selector.cc +++ b/gtk2_ardour/playlist_selector.cc @@ -112,7 +112,7 @@ PlaylistSelector::show_for (RouteUI* ruix) model->clear (); - session->foreach_playlist (this, &PlaylistSelector::add_playlist_to_map); + session->playlists.foreach (this, &PlaylistSelector::add_playlist_to_map); this_ds = rui->get_diskstream(); @@ -180,7 +180,7 @@ PlaylistSelector::show_for (RouteUI* ruix) // Add unassigned (imported) playlists to the list list<boost::shared_ptr<Playlist> > unassigned; - session->unassigned_playlists (unassigned); + session->playlists.unassigned (unassigned); TreeModel::Row row; TreeModel::Row* selected_row = 0; diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 08e9ac11ce..a644ef5e9e 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1037,7 +1037,7 @@ RouteTimeAxisView::use_copy_playlist (bool prompt, vector<boost::shared_ptr<Play name = resolve_new_group_playlist_name(name, playlists_before_op); } - while (_session.playlist_by_name(name)) { + while (_session.playlists.by_name(name)) { name = Playlist::bump_name (name, _session); } @@ -1089,7 +1089,7 @@ RouteTimeAxisView::use_new_playlist (bool prompt, vector<boost::shared_ptr<Playl name = resolve_new_group_playlist_name(name,playlists_before_op); } - while (_session.playlist_by_name(name)) { + while (_session.playlists.by_name(name)) { name = Playlist::bump_name (name, _session); } @@ -1497,7 +1497,7 @@ RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu) boost::shared_ptr<Diskstream> ds = get_diskstream(); RadioMenuItem::Group playlist_group; - _session.get_playlists (playlists); + _session.playlists.get (playlists); for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) { @@ -1585,7 +1585,7 @@ RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl) continue; } - boost::shared_ptr<Playlist> ipl = session().playlist_by_name(playlist_name); + boost::shared_ptr<Playlist> ipl = session().playlists.by_name(playlist_name); if (!ipl) { // No playlist for this track for this take yet, make it track->diskstream()->use_new_playlist(); diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 449bbc790d..1260e3e997 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -56,6 +56,7 @@ #include "ardour/location.h" #include "ardour/timecode.h" #include "ardour/interpolation.h" +#include "ardour/session_playlists.h" class XMLTree; class XMLNode; @@ -615,8 +616,6 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable boost::shared_ptr<Region> find_whole_file_parent (boost::shared_ptr<Region const>); - void find_equivalent_playlist_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >& result); - boost::shared_ptr<Region> XMLRegionFactory (const XMLNode&, bool full); boost::shared_ptr<AudioRegion> XMLAudioRegionFactory (const XMLNode&, bool full); boost::shared_ptr<MidiRegion> XMLMidiRegionFactory (const XMLNode&, bool full); @@ -641,8 +640,6 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable void add_source (boost::shared_ptr<Source>); void remove_source (boost::weak_ptr<Source>); - uint32_t source_use_count (boost::shared_ptr<const Source> src) const; - int cleanup_sources (CleanupReport&); int cleanup_trash_sources (CleanupReport&); @@ -655,7 +652,7 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable 0 for "yes, delete this playlist", 1 for "no, don't delete this playlist". */ - sigc::signal<int,boost::shared_ptr<ARDOUR::Playlist> > AskAboutPlaylistDeletion; + sigc::signal<int,boost::shared_ptr<Playlist> > AskAboutPlaylistDeletion; /** handlers should return 0 for "ignore the rate mismatch", !0 for "do not use this session" @@ -673,18 +670,7 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable boost::shared_ptr<Source> source_by_id (const PBD::ID&); boost::shared_ptr<Source> source_by_path_and_channel (const Glib::ustring&, uint16_t); - /* playlist management */ - - boost::shared_ptr<Playlist> playlist_by_name (std::string name); - void unassigned_playlists (std::list<boost::shared_ptr<Playlist> > & list); void add_playlist (boost::shared_ptr<Playlist>, bool unused = false); - sigc::signal<void,boost::shared_ptr<Playlist> > PlaylistAdded; - sigc::signal<void,boost::shared_ptr<Playlist> > PlaylistRemoved; - - uint32_t n_playlists() const; - - template<class T> void foreach_playlist (T *obj, void (T::*func)(boost::shared_ptr<Playlist>)); - void get_playlists (std::vector<boost::shared_ptr<Playlist> >&); /* named selections */ @@ -994,6 +980,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable SlaveState slave_state() const { return _slave_state; } + SessionPlaylists playlists; + protected: friend class AudioEngine; void set_block_size (nframes_t nframes); @@ -1496,19 +1484,7 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable /* PLAYLISTS */ - mutable Glib::Mutex playlist_lock; - typedef std::set<boost::shared_ptr<Playlist> > PlaylistList; - PlaylistList playlists; - PlaylistList unused_playlists; - - int load_playlists (const XMLNode&); - int load_unused_playlists (const XMLNode&); void remove_playlist (boost::weak_ptr<Playlist>); - void track_playlist (bool, boost::weak_ptr<Playlist>); - - boost::shared_ptr<Playlist> playlist_factory (std::string name); - boost::shared_ptr<Playlist> XMLPlaylistFactory (const XMLNode&); - void playlist_length_changed (); void diskstream_playlist_changed (boost::weak_ptr<Diskstream>); diff --git a/libs/ardour/ardour/session_playlist.h b/libs/ardour/ardour/session_playlist.h index f924fe4bbc..7f5d1e89ce 100644 --- a/libs/ardour/ardour/session_playlist.h +++ b/libs/ardour/ardour/session_playlist.h @@ -22,19 +22,20 @@ #include "ardour/session.h" #include "ardour/playlist.h" +#include "ardour/session_playlists.h" namespace ARDOUR { template<class T> void -Session::foreach_playlist (T *obj, void (T::*func)(boost::shared_ptr<Playlist>)) +SessionPlaylists::foreach (T *obj, void (T::*func)(boost::shared_ptr<Playlist>)) { - Glib::Mutex::Lock lm (playlist_lock); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); i++) { + Glib::Mutex::Lock lm (lock); + for (List::iterator i = playlists.begin(); i != playlists.end(); i++) { if (!(*i)->hidden()) { (obj->*func) (*i); } } - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); i++) { + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); i++) { if (!(*i)->hidden()) { (obj->*func) (*i); } diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 6c96f5c598..e72f6d0ef6 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -257,7 +257,7 @@ AudioDiskstream::find_and_use_playlist (const string& name) { boost::shared_ptr<AudioPlaylist> playlist; - if ((playlist = boost::dynamic_pointer_cast<AudioPlaylist> (_session.playlist_by_name (name))) == 0) { + if ((playlist = boost::dynamic_pointer_cast<AudioPlaylist> (_session.playlists.by_name (name))) == 0) { playlist = boost::dynamic_pointer_cast<AudioPlaylist> (PlaylistFactory::create (DataType::AUDIO, _session, name)); } @@ -2312,7 +2312,7 @@ AudioDiskstream::can_become_destructive (bool& requires_bounce) const assert (afirst); - if (_session.source_use_count (afirst->source()) > 1) { + if (_session.playlists.source_use_count (afirst->source()) > 1) { requires_bounce = true; return false; } diff --git a/libs/ardour/audio_playlist_importer.cc b/libs/ardour/audio_playlist_importer.cc index d97e95195f..81ad169989 100644 --- a/libs/ardour/audio_playlist_importer.cc +++ b/libs/ardour/audio_playlist_importer.cc @@ -168,7 +168,7 @@ bool AudioPlaylistImporter::_prepare_move () { // Rename - while (session.playlist_by_name (name) || !handler.check_name (name)) { + while (session.playlists.by_name (name) || !handler.check_name (name)) { std::pair<bool, string> rename_pair = Rename (_("A playlist with this name already exists, please rename it."), name); if (!rename_pair.first) { return false; diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 383eb982b1..a7f795ba8e 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -391,7 +391,7 @@ AudioTrack::set_state_part_two () _freeze_record.processor_info.clear (); if ((prop = fnode->property (X_("playlist"))) != 0) { - boost::shared_ptr<Playlist> pl = _session.playlist_by_name (prop->value()); + boost::shared_ptr<Playlist> pl = _session.playlists.by_name (prop->value()); if (pl) { _freeze_record.playlist = boost::dynamic_pointer_cast<AudioPlaylist> (pl); } else { @@ -718,7 +718,7 @@ AudioTrack::freeze (InterThreadInfo& itt) candidate = string_compose ("<F%2>%1", _freeze_record.playlist->name(), n); - if (_session.playlist_by_name (candidate) == 0) { + if (_session.playlists.by_name (candidate) == 0) { new_playlist_name = candidate; break; } diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index f06b00ae00..3712e74676 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -220,7 +220,7 @@ MidiDiskstream::find_and_use_playlist (const string& name) { boost::shared_ptr<MidiPlaylist> playlist; - if ((playlist = boost::dynamic_pointer_cast<MidiPlaylist> (_session.playlist_by_name (name))) == 0) { + if ((playlist = boost::dynamic_pointer_cast<MidiPlaylist> (_session.playlists.by_name (name))) == 0) { playlist = boost::dynamic_pointer_cast<MidiPlaylist> (PlaylistFactory::create (DataType::MIDI, _session, name)); } diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 5cafe9c81d..2aac811e65 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -323,7 +323,7 @@ MidiTrack::set_state_part_two () _freeze_record.processor_info.clear (); if ((prop = fnode->property (X_("playlist"))) != 0) { - boost::shared_ptr<Playlist> pl = _session.playlist_by_name (prop->value()); + boost::shared_ptr<Playlist> pl = _session.playlists.by_name (prop->value()); if (pl) { _freeze_record.playlist = boost::dynamic_pointer_cast<MidiPlaylist> (pl); } else { diff --git a/libs/ardour/named_selection.cc b/libs/ardour/named_selection.cc index 0c6b3699b6..56e4252ab9 100644 --- a/libs/ardour/named_selection.cc +++ b/libs/ardour/named_selection.cc @@ -82,7 +82,7 @@ NamedSelection::NamedSelection (Session& session, const XMLNode& node) plnode = *niter; if ((property = plnode->property ("name")) != 0) { - if ((playlist = session.playlist_by_name (property->value())) != 0) { + if ((playlist = session.playlists.by_name (property->value())) != 0) { playlist->use(); playlists.push_back (playlist); } else { diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index bcc4c6061d..e3d1831470 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -1967,7 +1967,7 @@ Playlist::bump_name (string name, Session &session) do { newname = bump_name_once (newname); - } while (session.playlist_by_name (newname)!=NULL); + } while (session.playlists.by_name (newname)!=NULL); return newname; } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index b32f758ce8..82ca9eee98 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -86,6 +86,7 @@ #include "ardour/session_directory.h" #include "ardour/session_directory.h" #include "ardour/session_metadata.h" +#include "ardour/session_playlists.h" #include "ardour/slave.h" #include "ardour/smf_source.h" #include "ardour/source_factory.h" @@ -400,36 +401,6 @@ Session::destroy () i = tmp; } - DEBUG_TRACE (DEBUG::Destruction, "delete used playlists\n"); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ) { - PlaylistList::iterator tmp; - - tmp = i; - ++tmp; - - DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for used playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); - (*i)->drop_references (); - - - i = tmp; - } - - DEBUG_TRACE (DEBUG::Destruction, "delete unused playlists\n"); - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ) { - PlaylistList::iterator tmp; - - tmp = i; - ++tmp; - - DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for unused playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); - (*i)->drop_references (); - - i = tmp; - } - - playlists.clear (); - unused_playlists.clear (); - DEBUG_TRACE (DEBUG::Destruction, "delete regions\n"); for (RegionList::iterator i = regions.begin(); i != regions.end(); ) { RegionList::iterator tmp; @@ -2939,13 +2910,6 @@ Session::find_whole_file_parent (boost::shared_ptr<Region const> child) return boost::shared_ptr<Region> (); } -void -Session::find_equivalent_playlist_regions (boost::shared_ptr<Region> region, vector<boost::shared_ptr<Region> >& result) -{ - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) - (*i)->get_region_list_equivalent_regions (region, result); -} - int Session::destroy_region (boost::shared_ptr<Region> region) { @@ -3071,23 +3035,6 @@ Session::remove_source (boost::weak_ptr<Source> src) } } -/** Return the number of playlists (not regions) that contain @a src */ -uint32_t -Session::source_use_count (boost::shared_ptr<const Source> src) const -{ - uint32_t count = 0; - for (PlaylistList::const_iterator p = playlists.begin(); p != playlists.end(); ++p) { - for (Playlist::RegionList::const_iterator r = (*p)->region_list().begin(); - r != (*p)->region_list().end(); ++r) { - if ((*r)->uses_source(src)) { - ++count; - break; - } - } - } - return count; -} - boost::shared_ptr<Source> Session::source_by_id (const PBD::ID& id) { @@ -3429,42 +3376,6 @@ Session::create_midi_source_for_session (MidiDiskstream& ds) } -/* Playlist management */ - -boost::shared_ptr<Playlist> -Session::playlist_by_name (string name) -{ - Glib::Mutex::Lock lm (playlist_lock); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) { - if ((*i)->name() == name) { - return* i; - } - } - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { - if ((*i)->name() == name) { - return* i; - } - } - - return boost::shared_ptr<Playlist>(); -} - -void -Session::unassigned_playlists (std::list<boost::shared_ptr<Playlist> > & list) -{ - Glib::Mutex::Lock lm (playlist_lock); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) { - if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) { - list.push_back (*i); - } - } - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { - if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) { - list.push_back (*i); - } - } -} - void Session::add_playlist (boost::shared_ptr<Playlist> playlist, bool unused) { @@ -3472,13 +3383,9 @@ Session::add_playlist (boost::shared_ptr<Playlist> playlist, bool unused) return; } - { - Glib::Mutex::Lock lm (playlist_lock); - if (find (playlists.begin(), playlists.end(), playlist) == playlists.end()) { - playlists.insert (playlists.begin(), 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))); - } + bool existing = playlists.add (playlist); + if (!existing) { + playlist->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_playlist), boost::weak_ptr<Playlist>(playlist))); } if (unused) { @@ -3486,61 +3393,6 @@ Session::add_playlist (boost::shared_ptr<Playlist> playlist, bool unused) } set_dirty(); - - PlaylistAdded (playlist); /* EMIT SIGNAL */ -} - -void -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) { - - unused_playlists.insert (pl); - - if ((x = playlists.find (pl)) != playlists.end()) { - playlists.erase (x); - } - - - } else { - - playlists.insert (pl); - - if ((x = unused_playlists.find (pl)) != unused_playlists.end()) { - unused_playlists.erase (x); - } - } - } } void @@ -3556,26 +3408,9 @@ Session::remove_playlist (boost::weak_ptr<Playlist> weak_playlist) return; } - { - Glib::Mutex::Lock lm (playlist_lock); - - PlaylistList::iterator i; - - i = find (playlists.begin(), playlists.end(), playlist); - if (i != playlists.end()) { - playlists.erase (i); - } - - i = find (unused_playlists.begin(), unused_playlists.end(), playlist); - if (i != unused_playlists.end()) { - unused_playlists.erase (i); - } - - } + playlists.remove (playlist); set_dirty(); - - PlaylistRemoved (playlist); /* EMIT SIGNAL */ } void @@ -3907,13 +3742,7 @@ Session::tempo_map_changed (Change) { clear_clicks (); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) { - (*i)->update_after_tempo_map_change (); - } - - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { - (*i)->update_after_tempo_map_change (); - } + playlists.update_after_tempo_map_change (); set_dirty (); } @@ -4134,13 +3963,6 @@ Session::route_name_internal (string n) const return false; } -uint32_t -Session::n_playlists () const -{ - Glib::Mutex::Lock lm (playlist_lock); - return playlists.size(); -} - void Session::allocate_pan_automation_buffers (nframes_t nframes, uint32_t howmany, bool force) { @@ -4556,5 +4378,3 @@ Session::get_routes_with_regions_at (nframes64_t const p) const return rl; } - - diff --git a/libs/ardour/session_command.cc b/libs/ardour/session_command.cc index d5de62b142..c078e2cadf 100644 --- a/libs/ardour/session_command.cc +++ b/libs/ardour/session_command.cc @@ -99,7 +99,7 @@ Session::memento_command_factory(XMLNode *n) } else if (obj_T == typeid (TempoMap).name()) { return new MementoCommand<TempoMap>(*_tempo_map, before, after); } else if (obj_T == typeid (Playlist).name() || obj_T == typeid (AudioPlaylist).name() || obj_T == typeid (MidiPlaylist).name()) { - if (boost::shared_ptr<Playlist> pl = playlist_by_name(child->property("name")->value())) { + if (boost::shared_ptr<Playlist> pl = playlists.by_name(child->property("name")->value())) { return new MementoCommand<Playlist>(*(pl.get()), before, after); } } else if (obj_T == typeid (Route).name() || obj_T == typeid (AudioTrack).name() || obj_T == typeid(MidiTrack).name()) { diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index e2df46c83a..55cf473683 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -89,7 +89,6 @@ #include "ardour/midi_source.h" #include "ardour/midi_track.h" #include "ardour/named_selection.h" -#include "ardour/playlist_factory.h" #include "ardour/processor.h" #include "ardour/region_factory.h" #include "ardour/route_group.h" @@ -98,6 +97,7 @@ #include "ardour/session_directory.h" #include "ardour/session_metadata.h" #include "ardour/session_state_utils.h" +#include "ardour/session_playlists.h" #include "ardour/session_utils.h" #include "ardour/silentfilesource.h" #include "ardour/slave.h" @@ -112,6 +112,7 @@ #include "ardour/utils.h" #include "ardour/utils.h" #include "ardour/version.h" +#include "ardour/playlist_factory.h" #include "control_protocol/control_protocol.h" @@ -1061,39 +1062,13 @@ Session::state(bool full_state) } } + playlists.add_state (node, full_state); child = node->add_child ("RouteGroups"); for (list<RouteGroup *>::iterator i = _route_groups.begin(); i != _route_groups.end(); ++i) { child->add_child_nocopy ((*i)->get_state()); } - child = node->add_child ("Playlists"); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) { - if (!(*i)->hidden()) { - if (!(*i)->empty()) { - if (full_state) { - child->add_child_nocopy ((*i)->get_state()); - } else { - child->add_child_nocopy ((*i)->get_template()); - } - } - } - } - - child = node->add_child ("UnusedPlaylists"); - for (PlaylistList::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { - if (!(*i)->hidden()) { - if (!(*i)->empty()) { - if (full_state) { - child->add_child_nocopy ((*i)->get_state()); - } else { - child->add_child_nocopy ((*i)->get_template()); - } - } - } - } - - if (_click_io) { child = node->add_child ("Click"); child->add_child_nocopy (_click_io->state (full_state)); @@ -1271,13 +1246,13 @@ Session::set_state (const XMLNode& node, int version) if ((child = find_named_node (node, "Playlists")) == 0) { error << _("Session: XML state has no playlists section") << endmsg; goto out; - } else if (load_playlists (*child)) { + } else if (playlists.load (*this, *child)) { goto out; } if ((child = find_named_node (node, "UnusedPlaylists")) == 0) { // this is OK - } else if (load_unused_playlists (*child)) { + } else if (playlists.load_unused (*this, *child)) { goto out; } @@ -1960,65 +1935,6 @@ Session::get_best_session_directory_for_new_source () } int -Session::load_playlists (const XMLNode& node) -{ - XMLNodeList nlist; - XMLNodeConstIterator niter; - boost::shared_ptr<Playlist> playlist; - - nlist = node.children(); - - set_dirty(); - - for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - - if ((playlist = XMLPlaylistFactory (**niter)) == 0) { - error << _("Session: cannot create Playlist from XML description.") << endmsg; - } - } - - return 0; -} - -int -Session::load_unused_playlists (const XMLNode& node) -{ - XMLNodeList nlist; - XMLNodeConstIterator niter; - boost::shared_ptr<Playlist> playlist; - - nlist = node.children(); - - set_dirty(); - - for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - - if ((playlist = XMLPlaylistFactory (**niter)) == 0) { - error << _("Session: cannot create Playlist from XML description.") << endmsg; - continue; - } - - // now manually untrack it - - track_playlist (false, boost::weak_ptr<Playlist> (playlist)); - } - - return 0; -} - -boost::shared_ptr<Playlist> -Session::XMLPlaylistFactory (const XMLNode& node) -{ - try { - return PlaylistFactory::create (*this, node); - } - - catch (failed_constructor& err) { - return boost::shared_ptr<Playlist>(); - } -} - -int Session::load_named_selections (const XMLNode& node) { XMLNodeList nlist; @@ -2450,7 +2366,6 @@ Session::cleanup_sources (CleanupReport& rep) // FIXME: needs adaptation to midi vector<boost::shared_ptr<Source> > dead_sources; - vector<boost::shared_ptr<Playlist> > playlists_tbd; PathScanner scanner; string sound_path; vector<space_and_path>::iterator i; @@ -2464,38 +2379,13 @@ Session::cleanup_sources (CleanupReport& rep) _state_of_the_state = (StateOfTheState) (_state_of_the_state | InCleanup); - /* step 1: consider deleting all unused playlists */ - - for (PlaylistList::iterator x = unused_playlists.begin(); x != unused_playlists.end(); ++x) { - int status; - - status = AskAboutPlaylistDeletion (*x); - - switch (status) { - case -1: - ret = 0; - goto out; - break; - - case 0: - playlists_tbd.push_back (*x); - break; - - default: - /* leave it alone */ - break; - } - } - - /* now delete any that were marked for deletion */ - - for (vector<boost::shared_ptr<Playlist> >::iterator x = playlists_tbd.begin(); x != playlists_tbd.end(); ++x) { - (*x)->drop_references (); + + if (playlists.maybe_delete_unused (AskAboutPlaylistDeletion)) { + ret = 0; + goto out; } - playlists_tbd.clear (); - /* step 2: find all un-used sources */ rep.paths.clear (); @@ -2512,7 +2402,7 @@ Session::cleanup_sources (CleanupReport& rep) capture files. */ - if (!source_use_count(i->second) && i->second->length(i->second->timeline_position()) > 0) { + if (!playlists.source_use_count(i->second) && i->second->length(i->second->timeline_position()) > 0) { dead_sources.push_back (i->second); i->second->GoingAway(); } @@ -3078,9 +2968,9 @@ Session::config_changed (std::string p, bool ours) } else if (p == "edit-mode") { - Glib::Mutex::Lock lm (playlist_lock); + Glib::Mutex::Lock lm (playlists.lock); - for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) { + for (SessionPlaylists::List::iterator i = playlists.playlists.begin(); i != playlists.playlists.end(); ++i) { (*i)->set_edit_mode (Config->get_edit_mode ()); } diff --git a/libs/ardour/wscript b/libs/ardour/wscript index bf850ebeab..22d86ffd3c 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -164,6 +164,7 @@ libardour_sources = [ 'session_export.cc', 'session_metadata.cc', 'session_midi.cc', + 'session_playlists.cc', 'session_process.cc', 'session_state.cc', 'session_state_utils.cc', |