2 Copyright (C) 2000 Paul Davis
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.
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.
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.
20 #ifndef __ardour_playlist_h__
21 #define __ardour_playlist_h__
27 #include <boost/shared_ptr.hpp>
28 #include <boost/enable_shared_from_this.hpp>
34 #include <sigc++/signal.h>
37 #include <pbd/stateful.h>
38 #include <pbd/statefuldestructible.h>
40 #include <ardour/ardour.h>
41 #include <ardour/crossfade_compare.h>
42 #include <ardour/location.h>
49 class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_from_this<Playlist> {
51 typedef list<boost::shared_ptr<Region> > RegionList;
53 Playlist (Session&, const XMLNode&, bool hidden = false);
54 Playlist (Session&, string name, bool hidden = false);
55 Playlist (boost::shared_ptr<const Playlist>, string name, bool hidden = false);
56 Playlist (boost::shared_ptr<const Playlist>, nframes_t start, nframes_t cnt, string name, bool hidden = false);
60 void set_region_ownership ();
62 virtual void clear (bool with_signals=true);
63 virtual void dump () const;
67 bool used () const { return _refcnt != 0; }
69 std::string name() const { return _name; }
70 void set_name (std::string str);
72 bool frozen() const { return _frozen; }
73 void set_frozen (bool yn);
75 bool hidden() const { return _hidden; }
77 uint32_t n_regions() const;
78 nframes_t get_maximum_extent () const;
79 layer_t top_layer() const;
81 EditMode get_edit_mode() const { return _edit_mode; }
82 void set_edit_mode (EditMode);
84 /* Editing operations */
86 void add_region (boost::shared_ptr<Region>, nframes_t position, float times = 1);
87 void remove_region (boost::shared_ptr<Region>);
88 void get_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
89 void get_region_list_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
90 void replace_region (boost::shared_ptr<Region> old, boost::shared_ptr<Region> newr, nframes_t pos);
91 void split_region (boost::shared_ptr<Region>, nframes_t position);
92 void partition (nframes_t start, nframes_t end, bool just_top_level);
93 void duplicate (boost::shared_ptr<Region>, nframes_t position, float times);
94 void nudge_after (nframes_t start, nframes_t distance, bool forwards);
96 boost::shared_ptr<Playlist> cut (list<AudioRange>&, bool result_is_hidden = true);
97 boost::shared_ptr<Playlist> copy (list<AudioRange>&, bool result_is_hidden = true);
98 int paste (boost::shared_ptr<Playlist>, nframes_t position, float times);
100 RegionList* regions_at (nframes_t frame);
101 RegionList* regions_touched (nframes_t start, nframes_t end);
102 boost::shared_ptr<Region> find_region (const PBD::ID&) const;
103 boost::shared_ptr<Region> top_region_at (nframes_t frame);
104 boost::shared_ptr<Region> find_next_region (nframes_t frame, RegionPoint point, int dir);
106 template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>, void *), void *arg);
107 template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>));
109 XMLNode& get_state ();
110 int set_state (const XMLNode&);
111 XMLNode& get_template ();
113 sigc::signal<void,bool> InUse;
114 sigc::signal<void> Modified;
115 sigc::signal<void> NameChanged;
116 sigc::signal<void> LengthChanged;
117 sigc::signal<void> LayeringChanged;
119 static string bump_name (string old_name, Session&);
120 static string bump_name_once (string old_name);
125 void raise_region (boost::shared_ptr<Region>);
126 void lower_region (boost::shared_ptr<Region>);
127 void raise_region_to_top (boost::shared_ptr<Region>);
128 void lower_region_to_bottom (boost::shared_ptr<Region>);
130 uint32_t read_data_count() const { return _read_data_count; }
132 Session& session() { return _session; }
134 const PBD::ID& get_orig_diskstream_id () const { return _orig_diskstream_id; }
135 void set_orig_diskstream_id (const PBD::ID& did) { _orig_diskstream_id = did; }
137 /* destructive editing */
139 virtual bool destroy_region (boost::shared_ptr<Region>) = 0;
141 /* special case function used by UI selection objects, which have playlists that actually own the regions
145 void drop_regions ();
148 friend class Session;
152 RegionLock (Playlist *pl, bool do_block_notify = true) : playlist (pl), block_notify (do_block_notify) {
153 playlist->region_lock.lock();
155 playlist->delay_notifications();
159 playlist->region_lock.unlock();
161 playlist->release_notifications ();
168 friend class RegionLock;
170 RegionList regions; /* the current list of regions in the playlist */
171 std::set<boost::shared_ptr<Region> > all_regions; /* all regions ever added to this playlist */
174 mutable gint block_notifications;
175 mutable gint ignore_state_changes;
176 mutable Glib::Mutex region_lock;
177 std::set<boost::shared_ptr<Region> > pending_adds;
178 std::set<boost::shared_ptr<Region> > pending_removes;
179 RegionList pending_bounds;
180 bool pending_modified;
183 string last_save_reason;
184 uint32_t in_set_state;
185 bool first_set_state;
195 uint32_t _read_data_count;
196 PBD::ID _orig_diskstream_id;
197 uint64_t layer_op_counter;
198 nframes_t freeze_length;
200 void init (bool hide);
202 bool holding_state () const {
203 return g_atomic_int_get (&block_notifications) != 0 ||
204 g_atomic_int_get (&ignore_state_changes) != 0;
207 /* prevent the compiler from ever generating these */
209 Playlist (const Playlist&);
210 Playlist (Playlist&);
212 void delay_notifications ();
213 void release_notifications ();
214 virtual void flush_notifications ();
216 void notify_region_removed (boost::shared_ptr<Region>);
217 void notify_region_added (boost::shared_ptr<Region>);
218 void notify_length_changed ();
219 void notify_layering_changed ();
220 void notify_modified ();
221 void notify_state_changed (Change);
223 void mark_session_dirty();
225 void region_changed_proxy (Change, boost::weak_ptr<Region>);
226 virtual bool region_changed (Change, boost::shared_ptr<Region>);
228 void region_bounds_changed (Change, boost::shared_ptr<Region>);
229 void region_deleted (boost::shared_ptr<Region>);
231 void sort_regions ();
233 void possibly_splice ();
234 void possibly_splice_unlocked();
236 void splice_locked ();
237 void splice_unlocked ();
240 virtual void finalize_split_region (boost::shared_ptr<Region> original, boost::shared_ptr<Region> left, boost::shared_ptr<Region> right) {}
242 virtual void check_dependents (boost::shared_ptr<Region> region, bool norefresh) {}
243 virtual void refresh_dependents (boost::shared_ptr<Region> region) {}
244 virtual void remove_dependents (boost::shared_ptr<Region> region) {}
246 virtual XMLNode& state (bool);
248 boost::shared_ptr<Region> region_by_id (PBD::ID);
250 void add_region_internal (boost::shared_ptr<Region>, nframes_t position);
252 int remove_region_internal (boost::shared_ptr<Region>);
253 RegionList *find_regions_at (nframes_t frame);
254 void copy_regions (RegionList&) const;
255 void partition_internal (nframes_t start, nframes_t end, bool cutting, RegionList& thawlist);
257 nframes_t _get_maximum_extent() const;
259 boost::shared_ptr<Playlist> cut_copy (boost::shared_ptr<Playlist> (Playlist::*pmf)(nframes_t, nframes_t, bool),
260 list<AudioRange>& ranges, bool result_is_hidden);
261 boost::shared_ptr<Playlist> cut (nframes_t start, nframes_t cnt, bool result_is_hidden);
262 boost::shared_ptr<Playlist> copy (nframes_t start, nframes_t cnt, bool result_is_hidden);
265 int move_region_to_layer (layer_t, boost::shared_ptr<Region> r, int dir);
268 void unset_freeze_parent (Playlist*);
269 void unset_freeze_child (Playlist*);
271 void timestamp_layer_op (boost::shared_ptr<Region>);
274 } /* namespace ARDOUR */
276 #endif /* __ardour_playlist_h__ */