865ad9ed3961bd7a0afe70945f1c84830ab89ba3
[ardour.git] / libs / ardour / ardour / session_playlists.h
1 /*
2     Copyright (C) 2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_session_playlists_h__
21 #define __ardour_session_playlists_h__
22
23 #include <set>
24 #include <vector>
25 #include <string>
26 #include <glibmm/threads.h>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/function.hpp>
29
30 #include "pbd/signals.h"
31
32 class XMLNode;
33
34 namespace PBD {
35         class ID;
36 }
37
38 namespace ARDOUR {
39
40 class Playlist;
41 class Region;
42 class Source;
43 class Session;
44 class Crossfade;
45 class Track;
46
47 class LIBARDOUR_API SessionPlaylists : public PBD::ScopedConnectionList
48 {
49 public:
50         ~SessionPlaylists ();
51
52         boost::shared_ptr<Playlist> by_name (std::string name);
53         boost::shared_ptr<Playlist> by_id (const PBD::ID&);
54         uint32_t source_use_count (boost::shared_ptr<const Source> src) const;
55         uint32_t region_use_count (boost::shared_ptr<Region> region) const;
56         template<class T> void foreach (T *obj, void (T::*func)(boost::shared_ptr<Playlist>));
57         void foreach (boost::function<void(boost::shared_ptr<const Playlist>)> functor, bool incl_unused = true);
58         void get (std::vector<boost::shared_ptr<Playlist> >&) const;
59         void unassigned (std::list<boost::shared_ptr<Playlist> > & list);
60         void destroy_region (boost::shared_ptr<Region>);
61         boost::shared_ptr<Crossfade> find_crossfade (const PBD::ID &);
62         void sync_all_regions_with_regions ();
63         std::vector<boost::shared_ptr<Playlist> > playlists_for_track (boost::shared_ptr<Track>) const;
64         std::vector<boost::shared_ptr<Playlist> > get_used () const;
65         std::vector<boost::shared_ptr<Playlist> > get_unused () const;
66         uint32_t n_playlists() const;
67
68 private:
69         friend class Session;
70
71         bool add (boost::shared_ptr<Playlist>);
72         void remove (boost::shared_ptr<Playlist>);
73         void remove_weak (boost::weak_ptr<Playlist>);
74         void track (bool, boost::weak_ptr<Playlist>);
75         void update_tracking ();
76
77         void find_equivalent_playlist_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >& result);
78         void update_after_tempo_map_change ();
79         void add_state (XMLNode*, bool save_template, bool include_unused);
80         bool maybe_delete_unused (boost::function<int(boost::shared_ptr<Playlist>)>);
81         int load (Session &, const XMLNode&);
82         int load_unused (Session &, const XMLNode&);
83         boost::shared_ptr<Playlist> XMLPlaylistFactory (Session &, const XMLNode&);
84
85         mutable Glib::Threads::Mutex lock;
86         typedef std::set<boost::shared_ptr<Playlist> > List;
87         List playlists;
88         List unused_playlists;
89 };
90
91 }
92
93 #endif