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__
33 #include <sigc++/signal.h>
36 #include <pbd/stateful.h>
38 #include <ardour/ardour.h>
39 #include <ardour/crossfade_compare.h>
40 #include <ardour/location.h>
41 #include <ardour/state_manager.h>
42 #include <ardour/data_type.h>
49 class Playlist : public Stateful, public StateManager {
51 typedef list<Region*> RegionList;
53 Playlist (Session&, const XMLNode&, DataType type, bool hidden = false);
54 Playlist (Session&, string name, DataType type, bool hidden = false);
55 Playlist (const Playlist&, string name, bool hidden = false);
56 Playlist (const Playlist&, jack_nframes_t start, jack_nframes_t cnt, string name, bool hidden = false);
58 virtual void clear (bool with_delete = false, bool with_save = true);
59 virtual void dump () const;
60 virtual UndoAction get_memento() const = 0;
64 uint32_t refcnt() const { return _refcnt; }
66 const string& name() const { return _name; }
67 void set_name (const string& str);
69 const DataType& data_type() const { return _type; }
71 bool frozen() const { return _frozen; }
72 void set_frozen (bool yn);
74 bool hidden() const { return _hidden; }
76 jack_nframes_t get_maximum_extent () const;
77 layer_t top_layer() const;
79 EditMode get_edit_mode() const { return _edit_mode; }
80 void set_edit_mode (EditMode);
82 PBD::ID id() { return _id; }
83 /* Editing operations */
85 void add_region (const Region&, jack_nframes_t position, float times = 1, bool with_save = true);
86 void remove_region (Region *);
87 void get_equivalent_regions (const Region&, std::vector<Region*>&);
88 void get_region_list_equivalent_regions (const Region&, std::vector<Region*>&);
89 void replace_region (Region& old, Region& newr, jack_nframes_t pos);
90 void split_region (Region&, jack_nframes_t position);
91 void partition (jack_nframes_t start, jack_nframes_t end, bool just_top_level);
92 void duplicate (Region&, jack_nframes_t position, float times);
93 void nudge_after (jack_nframes_t start, jack_nframes_t distance, bool forwards);
95 Region* find_region (const PBD::ID&) const;
97 Playlist* cut (list<AudioRange>&, bool result_is_hidden = true);
98 Playlist* copy (list<AudioRange>&, bool result_is_hidden = true);
99 int paste (Playlist&, jack_nframes_t position, float times);
101 uint32_t read_data_count() { return _read_data_count; }
103 RegionList* regions_at (jack_nframes_t frame);
104 RegionList* regions_touched (jack_nframes_t start, jack_nframes_t end);
105 Region* top_region_at (jack_nframes_t frame);
107 Region* find_next_region (jack_nframes_t frame, RegionPoint point, int dir);
109 template<class T> void foreach_region (T *t, void (T::*func)(Region *, void *), void *arg);
110 template<class T> void foreach_region (T *t, void (T::*func)(Region *));
112 XMLNode& get_state ();
113 int set_state (const XMLNode&);
114 XMLNode& get_template ();
116 sigc::signal<void,Region *> RegionAdded;
117 sigc::signal<void,Region *> RegionRemoved;
118 sigc::signal<void,Playlist*,bool> InUse;
119 sigc::signal<void> Modified;
120 sigc::signal<void> NameChanged;
121 sigc::signal<void> LengthChanged;
122 sigc::signal<void> LayeringChanged;
123 sigc::signal<void,Playlist *> GoingAway;
124 sigc::signal<void> StatePushed;
126 static sigc::signal<void,Playlist*> PlaylistCreated;
128 static string bump_name (string old_name, Session&);
129 static string bump_name_once (string old_name);
134 void raise_region (Region&);
135 void lower_region (Region&);
136 void raise_region_to_top (Region&);
137 void lower_region_to_bottom (Region&);
139 uint32_t read_data_count() const { return _read_data_count; }
141 Session& session() { return _session; }
143 const PBD::ID& get_orig_diskstream_id () const { return _orig_diskstream_id; }
144 void set_orig_diskstream_id (const PBD::ID& did) { _orig_diskstream_id = did; }
146 /* destructive editing */
148 virtual bool destroy_region (Region *) = 0;
151 friend class Session;
152 virtual ~Playlist (); /* members of the public use unref() */
156 RegionLock (Playlist *pl, bool do_block_notify = true) : playlist (pl), block_notify (do_block_notify) {
157 playlist->region_lock.lock();
159 playlist->delay_notifications();
163 playlist->region_lock.unlock();
165 playlist->release_notifications ();
172 friend class RegionLock;
178 mutable gint block_notifications;
179 mutable gint ignore_state_changes;
180 mutable Glib::Mutex region_lock;
181 RegionList pending_removals;
182 RegionList pending_adds;
183 RegionList pending_bounds;
184 bool pending_modified;
187 string last_save_reason;
198 uint32_t _read_data_count;
199 PBD::ID _orig_diskstream_id;
200 uint64_t layer_op_counter;
201 jack_nframes_t freeze_length;
203 void init (bool hide);
205 bool holding_state () const {
206 return g_atomic_int_get (&block_notifications) != 0 ||
207 g_atomic_int_get (&ignore_state_changes) != 0;
210 /* prevent the compiler from ever generating these */
212 Playlist (const Playlist&);
213 Playlist (Playlist&);
215 void delay_notifications ();
216 void release_notifications ();
217 virtual void flush_notifications ();
219 void notify_region_removed (Region *);
220 void notify_region_added (Region *);
221 void notify_length_changed ();
222 void notify_layering_changed ();
223 void notify_modified ();
224 void notify_state_changed (Change);
226 void mark_session_dirty();
228 void region_changed_proxy (Change, Region*);
229 virtual bool region_changed (Change, Region*);
231 void region_bounds_changed (Change, Region *);
232 void region_deleted (Region *);
234 void sort_regions ();
236 void possibly_splice ();
237 void possibly_splice_unlocked();
239 void splice_locked ();
240 void splice_unlocked ();
243 virtual void finalize_split_region (Region *original, Region *left, Region *right) {}
245 virtual void check_dependents (Region& region, bool norefresh) {}
246 virtual void refresh_dependents (Region& region) {}
247 virtual void remove_dependents (Region& region) {}
249 virtual XMLNode& state (bool);
251 /* override state_manager::save_state so we can check in_set_state() */
253 void save_state (std::string why);
254 void maybe_save_state (std::string why);
256 void add_region_internal (Region *, jack_nframes_t position, bool delay_sort = false);
258 int remove_region_internal (Region *, bool delay_sort = false);
259 RegionList *find_regions_at (jack_nframes_t frame);
260 void copy_regions (RegionList&) const;
261 void partition_internal (jack_nframes_t start, jack_nframes_t end, bool cutting, RegionList& thawlist);
263 jack_nframes_t _get_maximum_extent() const;
265 Playlist* cut_copy (Playlist* (Playlist::*pmf)(jack_nframes_t, jack_nframes_t, bool),
266 list<AudioRange>& ranges, bool result_is_hidden);
267 Playlist *cut (jack_nframes_t start, jack_nframes_t cnt, bool result_is_hidden);
268 Playlist *copy (jack_nframes_t start, jack_nframes_t cnt, bool result_is_hidden);
271 int move_region_to_layer (layer_t, Region& r, int dir);
274 static Playlist* copyPlaylist (const Playlist&, jack_nframes_t start, jack_nframes_t length,
275 string name, bool result_is_hidden);
277 void unset_freeze_parent (Playlist*);
278 void unset_freeze_child (Playlist*);
280 void timestamp_layer_op (Region&);
285 } /* namespace ARDOUR */
287 #endif /* __ardour_playlist_h__ */