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__
31 #include <sigc++/signal.h>
32 #include <pbd/atomic.h>
35 #include <ardour/ardour.h>
36 #include <ardour/crossfade_compare.h>
37 #include <ardour/location.h>
38 #include <ardour/stateful.h>
39 #include <ardour/source.h>
40 #include <ardour/state_manager.h>
47 class Playlist : public Stateful, public StateManager {
49 typedef list<Region*> RegionList;
51 Playlist (Session&, const XMLNode&, bool hidden = false);
52 Playlist (Session&, string name, bool hidden = false);
53 Playlist (const Playlist&, string name, bool hidden = false);
54 Playlist (const Playlist&, jack_nframes_t start, jack_nframes_t cnt, string name, bool hidden = false);
56 virtual jack_nframes_t read (Sample *dst, Sample *mixdown, float *gain_buffer, char * workbuf, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0) = 0;
57 virtual void clear (bool with_delete = false, bool with_save = true);
58 virtual void dump () const;
59 virtual UndoAction get_memento() const = 0;
63 uint32_t refcnt() const { return _refcnt; }
65 const string& name() const { return _name; }
66 void set_name (const string& str);
68 bool frozen() const { return _frozen; }
69 void set_frozen (bool yn);
71 bool hidden() const { return _hidden; }
73 jack_nframes_t get_maximum_extent () const;
74 layer_t top_layer() const;
76 EditMode get_edit_mode() const { return _edit_mode; }
77 void set_edit_mode (EditMode);
79 /* Editing operations */
81 void add_region (const Region&, jack_nframes_t position, float times = 1, bool with_save = true);
82 void remove_region (Region *);
83 void replace_region (Region& old, Region& newr, jack_nframes_t pos);
84 void split_region (Region&, jack_nframes_t position);
85 void partition (jack_nframes_t start, jack_nframes_t end, bool just_top_level);
86 void duplicate (Region&, jack_nframes_t position, float times);
87 void nudge_after (jack_nframes_t start, jack_nframes_t distance, bool forwards);
89 Region* find_region (id_t) const;
91 Playlist* cut (list<AudioRange>&, bool result_is_hidden = true);
92 Playlist* copy (list<AudioRange>&, bool result_is_hidden = true);
93 int paste (Playlist&, jack_nframes_t position, float times);
95 uint32_t read_data_count() { return _read_data_count; }
97 RegionList* regions_at (jack_nframes_t frame);
98 RegionList* regions_touched (jack_nframes_t start, jack_nframes_t end);
99 Region* top_region_at (jack_nframes_t frame);
101 Region* find_next_region (jack_nframes_t frame, RegionPoint point, int dir);
103 template<class T> void foreach_region (T *t, void (T::*func)(Region *, void *), void *arg);
104 template<class T> void foreach_region (T *t, void (T::*func)(Region *));
106 XMLNode& get_state ();
107 int set_state (const XMLNode&);
108 XMLNode& get_template ();
110 sigc::signal<void,Region *> RegionAdded;
111 sigc::signal<void,Region *> RegionRemoved;
113 sigc::signal<void,Playlist*,bool> InUse;
114 sigc::signal<void> Modified;
115 sigc::signal<void> NameChanged;
116 sigc::signal<void> LengthChanged;
117 sigc::signal<void> LayeringChanged;
118 sigc::signal<void,Playlist *> GoingAway;
119 sigc::signal<void> StatePushed;
121 static sigc::signal<void,Playlist*> PlaylistCreated;
123 static string bump_name (string old_name, Session&);
124 static string bump_name_once (string old_name);
129 void raise_region (Region&);
130 void lower_region (Region&);
131 void raise_region_to_top (Region&);
132 void lower_region_to_bottom (Region&);
134 uint32_t read_data_count() const { return _read_data_count; }
136 Session& session() { return _session; }
138 id_t get_orig_diskstream_id () const { return _orig_diskstream_id; }
139 void set_orig_diskstream_id (id_t did) { _orig_diskstream_id = did; }
141 /* destructive editing */
143 virtual bool destroy_region (Region *) = 0;
146 friend class Session;
147 virtual ~Playlist (); /* members of the public use unref() */
151 RegionLock (Playlist *pl, bool do_block_notify = true) : playlist (pl), block_notify (do_block_notify) {
152 playlist->region_lock.lock();
154 playlist->delay_notifications();
158 playlist->region_lock.unlock();
160 playlist->release_notifications ();
167 friend class RegionLock;
172 atomic_t block_notifications;
173 atomic_t ignore_state_changes;
174 mutable PBD::NonBlockingLock region_lock;
175 RegionList pending_removals;
176 RegionList pending_adds;
177 RegionList pending_bounds;
178 bool pending_modified;
181 string last_save_reason;
192 uint32_t _read_data_count;
193 id_t _orig_diskstream_id;
194 uint64_t layer_op_counter;
195 jack_nframes_t freeze_length;
197 void init (bool hide);
199 bool holding_state () const {
200 return atomic_read (&block_notifications) != 0 ||
201 atomic_read (&ignore_state_changes) != 0;
204 /* prevent the compiler from ever generating these */
206 Playlist (const Playlist&);
207 Playlist (Playlist&);
209 void delay_notifications ();
210 void release_notifications ();
211 virtual void flush_notifications ();
213 void notify_region_removed (Region *);
214 void notify_region_added (Region *);
215 void notify_length_changed ();
216 void notify_layering_changed ();
217 void notify_modified ();
218 void notify_state_changed (Change);
220 void mark_session_dirty();
222 void region_changed_proxy (Change, Region*);
223 virtual bool region_changed (Change, Region*);
225 void region_bounds_changed (Change, Region *);
226 void region_deleted (Region *);
228 void sort_regions ();
230 void possibly_splice ();
231 void possibly_splice_unlocked();
233 void splice_locked ();
234 void splice_unlocked ();
236 virtual void check_dependents (Region& region, bool norefresh) {}
237 virtual void refresh_dependents (Region& region) {}
238 virtual void remove_dependents (Region& region) {}
240 virtual XMLNode& state (bool);
242 /* override state_manager::save_state so we can check in_set_state() */
244 void save_state (std::string why);
245 void maybe_save_state (std::string why);
247 void add_region_internal (Region *, jack_nframes_t position, bool delay_sort = false);
249 int remove_region_internal (Region *, bool delay_sort = false);
250 RegionList *find_regions_at (jack_nframes_t frame);
251 void copy_regions (RegionList&) const;
252 void partition_internal (jack_nframes_t start, jack_nframes_t end, bool cutting, RegionList& thawlist);
254 jack_nframes_t _get_maximum_extent() const;
256 Playlist* cut_copy (Playlist* (Playlist::*pmf)(jack_nframes_t, jack_nframes_t, bool),
257 list<AudioRange>& ranges, bool result_is_hidden);
258 Playlist *cut (jack_nframes_t start, jack_nframes_t cnt, bool result_is_hidden);
259 Playlist *copy (jack_nframes_t start, jack_nframes_t cnt, bool result_is_hidden);
262 int move_region_to_layer (layer_t, Region& r, int dir);
265 static Playlist* copyPlaylist (const Playlist&, jack_nframes_t start, jack_nframes_t length,
266 string name, bool result_is_hidden);
268 void unset_freeze_parent (Playlist*);
269 void unset_freeze_child (Playlist*);
271 void timestamp_layer_op (Region&);
274 } /* namespace ARDOUR */
276 #endif /* __ardour_playlist_h__ */