2 Copyright (C) 2000-2001 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_region_h__
21 #define __ardour_region_h__
24 #include <boost/shared_ptr.hpp>
25 #include <boost/enable_shared_from_this.hpp>
29 #include <ardour/ardour.h>
30 #include <ardour/data_type.h>
31 #include <ardour/automatable.h>
32 #include <ardour/readable.h>
41 enum RegionEditState {
42 EditChangesNothing = 0,
47 class Region : public Automatable, public boost::enable_shared_from_this<Region>, public Readable
50 typedef std::vector<boost::shared_ptr<Source> > SourceList;
57 DefaultFadeOut = 0x10,
68 RightOfSplit = 0x8000,
70 DoNotSaveState = 0x20000,
71 PositionLocked = 0x40000,
73 range_guarantoor = USHRT_MAX
76 enum PositionLockStyle {
81 static const Flag DefaultFlags = Flag (Opaque|DefaultFadeIn|DefaultFadeOut|FadeIn|FadeOut);
83 static Change FadeChanged;
84 static Change SyncOffsetChanged;
85 static Change MuteChanged;
86 static Change OpacityChanged;
87 static Change LockChanged;
88 static Change LayerChanged;
89 static Change HiddenChanged;
91 sigc::signal<void,Change> StateChanged;
95 /** Note: changing the name of a Region does not constitute an edit */
96 bool set_name (const std::string& str);
98 const DataType& data_type() const { return _type; }
100 nframes_t position () const { return _position; }
101 nframes_t start () const { return _start; }
102 nframes_t length() const { return _length; }
103 layer_t layer () const { return _layer; }
105 /* these two are valid ONLY during a StateChanged signal handler */
107 nframes_t last_position() const { return _last_position; }
108 nframes_t last_length() const { return _last_length; }
110 nframes64_t ancestral_start () const { return _ancestral_start; }
111 nframes64_t ancestral_length () const { return _ancestral_length; }
112 float stretch() const { return _stretch; }
113 float shift() const { return _shift; }
115 void set_ancestral_data (nframes64_t start, nframes64_t length, float stretch, float shift);
117 nframes_t sync_offset(int& dir) const;
118 nframes_t sync_position() const;
120 nframes_t adjust_to_sync (nframes_t);
122 /* first_frame() is an alias; last_frame() just hides some math */
124 nframes_t first_frame() const { return _position; }
125 nframes_t last_frame() const { return _position + _length - 1; }
127 Flag flags() const { return _flags; }
128 bool hidden() const { return _flags & Hidden; }
129 bool muted() const { return _flags & Muted; }
130 bool opaque () const { return _flags & Opaque; }
131 bool locked() const { return _flags & Locked; }
132 bool position_locked() const { return _flags & PositionLocked; }
133 bool automatic() const { return _flags & Automatic; }
134 bool whole_file() const { return _flags & WholeFile ; }
135 bool captured() const { return !(_flags & (Region::Flag (Region::Import|Region::External))); }
136 bool can_move() const { return !(_flags & (Locked|PositionLocked)); }
138 PositionLockStyle positional_lock_style() const { return _positional_lock_style; }
139 void set_position_lock_style (PositionLockStyle ps);
141 virtual bool should_save_state () const { return !(_flags & DoNotSaveState); };
144 void thaw (const string& why);
146 bool covers (nframes_t frame) const {
147 return first_frame() <= frame && frame <= last_frame();
150 OverlapType coverage (nframes_t start, nframes_t end) const {
151 return ARDOUR::coverage (first_frame(), last_frame(), start, end);
154 bool equivalent (boost::shared_ptr<const Region>) const;
155 bool size_equivalent (boost::shared_ptr<const Region>) const;
156 bool overlap_equivalent (boost::shared_ptr<const Region>) const;
157 bool region_list_equivalent (boost::shared_ptr<const Region>) const;
158 bool source_equivalent (boost::shared_ptr<const Region>) const;
160 /* EDITING OPERATIONS */
162 void set_length (nframes_t, void *src);
163 void set_start (nframes_t, void *src);
164 void set_position (nframes_t, void *src);
165 void set_position_on_top (nframes_t, void *src);
166 void special_set_position (nframes_t);
167 void update_position_after_tempo_map_change ();
168 void nudge_position (nframes64_t, void *src);
170 bool at_natural_position () const;
171 void move_to_natural_position (void *src);
173 void trim_start (nframes_t new_position, void *src);
174 void trim_front (nframes_t new_position, void *src);
175 void trim_end (nframes_t new_position, void *src);
176 void trim_to (nframes_t position, nframes_t length, void *src);
178 void set_layer (layer_t l); /* ONLY Playlist can call this */
181 void raise_to_top ();
182 void lower_to_bottom ();
184 void set_sync_position (nframes_t n);
185 void clear_sync_position ();
186 void set_hidden (bool yn);
187 void set_muted (bool yn);
188 void set_opaque (bool yn);
189 void set_locked (bool yn);
190 void set_position_locked (bool yn);
194 virtual uint32_t read_data_count() const { return _read_data_count; }
196 boost::shared_ptr<ARDOUR::Playlist> playlist() const { return _playlist.lock(); }
197 virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
199 void source_deleted (boost::shared_ptr<Source>);
201 boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
202 uint32_t n_channels() const { return _sources.size(); }
204 const SourceList& sources() const { return _sources; }
205 const SourceList& master_sources() const { return _master_sources; }
207 std::vector<string> master_source_names();
208 void set_master_sources (SourceList&);
212 XMLNode& get_state ();
213 virtual XMLNode& state (bool);
214 virtual int set_state (const XMLNode&);
215 virtual int set_live_state (const XMLNode&, Change&, bool send);
217 virtual boost::shared_ptr<Region> get_parent() const;
219 uint64_t last_layer_op() const { return _last_layer_op; }
220 void set_last_layer_op (uint64_t when);
222 virtual bool is_dependent() const { return false; }
223 virtual bool depends_on (boost::shared_ptr<Region> other) const { return false; }
225 virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
226 // no transients, but its OK
230 void invalidate_transients ();
233 friend class RegionFactory;
235 Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length,
236 const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags);
237 Region (const SourceList& srcs, nframes_t start, nframes_t length,
238 const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags);
240 Region (boost::shared_ptr<const Region>, nframes_t start, nframes_t length, const string& name, layer_t = 0, Flag flags = DefaultFlags);
241 Region (boost::shared_ptr<const Region>);
242 Region (boost::shared_ptr<Source> src, const XMLNode&);
243 Region (const SourceList& srcs, const XMLNode&);
245 Region (Session& s, nframes_t start, nframes_t length, const string& name, DataType, layer_t = 0, Flag flags = DefaultFlags);
248 XMLNode& get_short_state (); /* used only by Session */
250 void send_change (Change);
252 void trim_to_internal (nframes_t position, nframes_t length, void *src);
253 void set_position_internal (nframes_t pos, bool allow_bbt_recompute);
255 bool copied() const { return _flags & Copied; }
256 void maybe_uncopy ();
259 bool verify_start (nframes_t);
260 bool verify_start_and_length (nframes_t, nframes_t&);
261 bool verify_start_mutable (nframes_t&_start);
262 bool verify_length (nframes_t);
264 virtual void recompute_at_start () = 0;
265 virtual void recompute_at_end () = 0;
271 nframes_t _last_length;
273 nframes_t _last_position;
274 PositionLockStyle _positional_lock_style;
275 nframes_t _sync_position;
277 mutable RegionEditState _first_edit;
279 nframes64_t _ancestral_start;
280 nframes64_t _ancestral_length;
284 AnalysisFeatureList _transients;
285 bool _valid_transients;
286 mutable uint32_t _read_data_count; ///< modified in read()
287 Change _pending_changed;
288 uint64_t _last_layer_op; ///< timestamp
291 /** Used when timefx are applied, so we can always use the original source */
292 SourceList _master_sources;
294 boost::weak_ptr<ARDOUR::Playlist> _playlist;
297 } /* namespace ARDOUR */
299 #endif /* __ardour_region_h__ */