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.
21 #ifndef __ardour_playlist_h__
22 #define __ardour_playlist_h__
28 #include <boost/shared_ptr.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>
43 #include <ardour/state_manager.h>
50 class Playlist : public StateManager, public PBD::StatefulDestructible {
52 typedef list<boost::shared_ptr<Region> > RegionList;
54 Playlist (Session&, const XMLNode&, bool hidden = false);
55 Playlist (Session&, string name, bool hidden = false);
56 Playlist (const Playlist&, string name, bool hidden = false);
57 Playlist (const Playlist&, nframes_t start, nframes_t cnt, string name, bool hidden = false);
59 virtual void clear (bool with_save = true);
60 virtual void dump () const;
61 virtual UndoAction get_memento() const = 0;
65 uint32_t refcnt() const { return _refcnt; }
67 const string& name() const { return _name; }
68 void set_name (const string& str);
70 bool frozen() const { return _frozen; }
71 void set_frozen (bool yn);
73 bool hidden() const { return _hidden; }
75 nframes_t get_maximum_extent () const;
76 layer_t top_layer() const;
78 EditMode get_edit_mode() const { return _edit_mode; }
79 void set_edit_mode (EditMode);
81 /* Editing operations */
83 void add_region (boost::shared_ptr<Region>, nframes_t position, float times = 1, bool with_save = true);
84 void remove_region (boost::shared_ptr<Region>);
85 void get_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
86 void get_region_list_equivalent_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >&);
87 void replace_region (boost::shared_ptr<Region> old, boost::shared_ptr<Region> newr, nframes_t pos);
88 void split_region (boost::shared_ptr<Region>, nframes_t position);
89 void partition (nframes_t start, nframes_t end, bool just_top_level);
90 void duplicate (boost::shared_ptr<Region>, nframes_t position, float times);
91 void nudge_after (nframes_t start, nframes_t distance, bool forwards);
93 boost::shared_ptr<Region> find_region (const PBD::ID&) const;
95 Playlist* cut (list<AudioRange>&, bool result_is_hidden = true);
96 Playlist* copy (list<AudioRange>&, bool result_is_hidden = true);
97 int paste (Playlist&, nframes_t position, float times);
99 uint32_t read_data_count() { return _read_data_count; }
101 RegionList* regions_at (nframes_t frame);
102 RegionList* regions_touched (nframes_t start, nframes_t end);
103 boost::shared_ptr<Region> top_region_at (nframes_t frame);
105 boost::shared_ptr<Region> find_next_region (nframes_t frame, RegionPoint point, int dir);
107 template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>, void *), void *arg);
108 template<class T> void foreach_region (T *t, void (T::*func)(boost::shared_ptr<Region>));
110 XMLNode& get_state ();
111 int set_state (const XMLNode&);
112 XMLNode& get_template ();
114 sigc::signal<void,boost::shared_ptr<Region> > RegionAdded;
115 sigc::signal<void,boost::shared_ptr<Region> > RegionRemoved;
116 sigc::signal<void,Playlist*,bool> InUse;
117 sigc::signal<void> Modified;
118 sigc::signal<void> NameChanged;
119 sigc::signal<void> LengthChanged;
120 sigc::signal<void> LayeringChanged;
121 sigc::signal<void> StatePushed;
123 static sigc::signal<void,Playlist*> PlaylistCreated;
125 static string bump_name (string old_name, Session&);
126 static string bump_name_once (string old_name);
131 void raise_region (boost::shared_ptr<Region>);
132 void lower_region (boost::shared_ptr<Region>);
133 void raise_region_to_top (boost::shared_ptr<Region>);
134 void lower_region_to_bottom (boost::shared_ptr<Region>);
136 uint32_t read_data_count() const { return _read_data_count; }
138 Session& session() { return _session; }
140 const PBD::ID& get_orig_diskstream_id () const { return _orig_diskstream_id; }
141 void set_orig_diskstream_id (const PBD::ID& did) { _orig_diskstream_id = did; }
143 /* destructive editing */
145 virtual bool destroy_region (boost::shared_ptr<Region>) = 0;
148 friend class Session;
149 virtual ~Playlist (); /* members of the public use unref() */
153 RegionLock (Playlist *pl, bool do_block_notify = true) : playlist (pl), block_notify (do_block_notify) {
154 playlist->region_lock.lock();
156 playlist->delay_notifications();
160 playlist->region_lock.unlock();
162 playlist->release_notifications ();
169 friend class RegionLock;
174 mutable gint block_notifications;
175 mutable gint ignore_state_changes;
176 mutable Glib::Mutex region_lock;
177 RegionList pending_removals;
178 RegionList pending_adds;
179 RegionList pending_bounds;
180 bool pending_modified;
183 string last_save_reason;
194 uint32_t _read_data_count;
195 PBD::ID _orig_diskstream_id;
196 uint64_t layer_op_counter;
197 nframes_t freeze_length;
199 void init (bool hide);
201 bool holding_state () const {
202 return g_atomic_int_get (&block_notifications) != 0 ||
203 g_atomic_int_get (&ignore_state_changes) != 0;
206 /* prevent the compiler from ever generating these */
208 Playlist (const Playlist&);
209 Playlist (Playlist&);
211 void delay_notifications ();
212 void release_notifications ();
213 virtual void flush_notifications ();
215 void notify_region_removed (boost::shared_ptr<Region>);
216 void notify_region_added (boost::shared_ptr<Region>);
217 void notify_length_changed ();
218 void notify_layering_changed ();
219 void notify_modified ();
220 void notify_state_changed (Change);
222 void mark_session_dirty();
224 void region_changed_proxy (Change, boost::shared_ptr<Region>);
225 virtual bool region_changed (Change, boost::shared_ptr<Region>);
227 void region_bounds_changed (Change, boost::shared_ptr<Region>);
228 void region_deleted (boost::shared_ptr<Region>);
230 void sort_regions ();
232 void possibly_splice ();
233 void possibly_splice_unlocked();
235 void splice_locked ();
236 void splice_unlocked ();
239 virtual void finalize_split_region (boost::shared_ptr<Region> original, boost::shared_ptr<Region> left, boost::shared_ptr<Region> right) {}
241 virtual void check_dependents (boost::shared_ptr<Region> region, bool norefresh) {}
242 virtual void refresh_dependents (boost::shared_ptr<Region> region) {}
243 virtual void remove_dependents (boost::shared_ptr<Region> region) {}
245 virtual XMLNode& state (bool);
247 /* override state_manager::save_state so we can check in_set_state() */
249 void save_state (std::string why);
250 void maybe_save_state (std::string why);
252 void add_region_internal (boost::shared_ptr<Region>, nframes_t position, bool delay_sort = false);
254 int remove_region_internal (boost::shared_ptr<Region>, bool delay_sort = false);
255 RegionList *find_regions_at (nframes_t frame);
256 void copy_regions (RegionList&) const;
257 void partition_internal (nframes_t start, nframes_t end, bool cutting, RegionList& thawlist);
259 nframes_t _get_maximum_extent() const;
261 Playlist* cut_copy (Playlist* (Playlist::*pmf)(nframes_t, nframes_t, bool),
262 list<AudioRange>& ranges, bool result_is_hidden);
263 Playlist *cut (nframes_t start, nframes_t cnt, bool result_is_hidden);
264 Playlist *copy (nframes_t start, nframes_t cnt, bool result_is_hidden);
267 int move_region_to_layer (layer_t, boost::shared_ptr<Region> r, int dir);
270 static Playlist* copyPlaylist (const Playlist&, nframes_t start, nframes_t length,
271 string name, bool result_is_hidden);
273 void unset_freeze_parent (Playlist*);
274 void unset_freeze_child (Playlist*);
276 void timestamp_layer_op (boost::shared_ptr<Region>);
279 } /* namespace ARDOUR */
281 #endif /* __ardour_playlist_h__ */