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>
26 #include <boost/utility.hpp>
29 #include "pbd/signals.h"
31 #include "ardour/ardour.h"
32 #include "ardour/data_type.h"
33 #include "ardour/automatable.h"
34 #include "ardour/readable.h"
35 #include "ardour/session_object.h"
42 namespace Properties {
43 extern PBD::PropertyDescriptor<bool> muted;
44 extern PBD::PropertyDescriptor<bool> opaque;
45 extern PBD::PropertyDescriptor<bool> locked;
46 extern PBD::PropertyDescriptor<bool> automatic;
47 extern PBD::PropertyDescriptor<bool> whole_file;
48 extern PBD::PropertyDescriptor<bool> import;
49 extern PBD::PropertyDescriptor<bool> external;
50 extern PBD::PropertyDescriptor<bool> sync_marked;
51 extern PBD::PropertyDescriptor<bool> left_of_split;
52 extern PBD::PropertyDescriptor<bool> right_of_split;
53 extern PBD::PropertyDescriptor<bool> hidden;
54 extern PBD::PropertyDescriptor<bool> position_locked;
55 extern PBD::PropertyDescriptor<framepos_t> start;
56 extern PBD::PropertyDescriptor<framecnt_t> length;
57 extern PBD::PropertyDescriptor<framepos_t> position;
58 extern PBD::PropertyDescriptor<framecnt_t> sync_position;
59 extern PBD::PropertyDescriptor<layer_t> layer;
60 extern PBD::PropertyDescriptor<framepos_t> ancestral_start;
61 extern PBD::PropertyDescriptor<framecnt_t> ancestral_length;
62 extern PBD::PropertyDescriptor<float> stretch;
63 extern PBD::PropertyDescriptor<float> shift;
68 class ExportSpecification;
70 enum RegionEditState {
71 EditChangesNothing = 0,
78 : public SessionObject
79 , public boost::enable_shared_from_this<Region>
83 typedef std::vector<boost::shared_ptr<Source> > SourceList;
85 static void make_property_quarks ();
87 enum PositionLockStyle {
92 static PBD::PropertyChange FadeChanged;
93 static PBD::PropertyChange SyncOffsetChanged;
94 static PBD::PropertyChange MuteChanged;
95 static PBD::PropertyChange OpacityChanged;
96 static PBD::PropertyChange LockChanged;
97 static PBD::PropertyChange LayerChanged;
98 static PBD::PropertyChange HiddenChanged;
100 PBD::Signal1<void,PBD::PropertyChange> StateChanged;
101 static PBD::Signal1<void,boost::shared_ptr<ARDOUR::Region> > RegionPropertyChanged;
103 void unlock_property_changes () { _no_property_changes = false; }
104 void block_property_changes () { _no_property_changes = true; }
108 /** Note: changing the name of a Region does not constitute an edit */
109 bool set_name (const std::string& str);
111 const DataType& data_type() const { return _type; }
113 /** How the region parameters play together:
115 * POSITION: first frame of the region along the timeline
116 * START: first frame of the region within its source(s)
117 * LENGTH: number of frames the region represents
119 sframes_t position () const { return _position; }
120 sframes_t start () const { return _start; }
121 framecnt_t length() const { return _length; }
122 layer_t layer () const { return _layer; }
124 framecnt_t source_length(uint32_t n) const;
126 /* these two are valid ONLY during a StateChanged signal handler */
128 sframes_t last_position() const { return _last_position; }
129 framecnt_t last_length() const { return _last_length; }
131 sframes_t ancestral_start () const { return _ancestral_start; }
132 framecnt_t ancestral_length () const { return _ancestral_length; }
133 float stretch() const { return _stretch; }
134 float shift() const { return _shift; }
136 void set_ancestral_data (nframes64_t start, nframes64_t length, float stretch, float shift);
138 frameoffset_t sync_offset(int& dir) const;
139 framepos_t sync_position() const;
140 framepos_t sync_point () const;
142 framepos_t adjust_to_sync (framepos_t) const;
144 /* first_frame() is an alias; last_frame() just hides some math */
146 framepos_t first_frame() const { return _position; }
147 framepos_t last_frame() const { return _position + _length - 1; }
149 bool hidden() const { return _hidden; }
150 bool muted() const { return _muted; }
151 bool opaque () const { return _opaque; }
152 bool locked() const { return _locked; }
153 bool position_locked() const { return _position_locked; }
154 bool automatic() const { return _automatic; }
155 bool whole_file() const { return _whole_file; }
156 bool captured() const { return !(_import || _external); }
157 bool can_move() const { return !_position_locked; }
158 bool sync_marked() const { return _sync_marked; }
159 bool external() const { return _external; }
160 bool import() const { return _import; }
162 PositionLockStyle positional_lock_style() const { return _positional_lock_style; }
163 void set_position_lock_style (PositionLockStyle ps);
164 void recompute_position_from_lock_style ();
169 bool covers (framepos_t frame) const {
170 return first_frame() <= frame && frame <= last_frame();
173 OverlapType coverage (framepos_t start, framepos_t end) const {
174 return ARDOUR::coverage (first_frame(), last_frame(), start, end);
177 bool equivalent (boost::shared_ptr<const Region>) const;
178 bool size_equivalent (boost::shared_ptr<const Region>) const;
179 bool overlap_equivalent (boost::shared_ptr<const Region>) const;
180 bool region_list_equivalent (boost::shared_ptr<const Region>) const;
181 bool source_equivalent (boost::shared_ptr<const Region>) const;
182 bool uses_source (boost::shared_ptr<const Source>) const;
184 /* EDITING OPERATIONS */
186 void set_length (framecnt_t, void *src);
187 void set_start (framepos_t, void *src);
188 void set_position (framepos_t, void *src);
189 void set_position_on_top (framepos_t, void *src);
190 void special_set_position (framepos_t);
191 void update_position_after_tempo_map_change ();
192 void nudge_position (frameoffset_t, void *src);
194 bool at_natural_position () const;
195 void move_to_natural_position (void *src);
197 void trim_start (framepos_t new_position, void *src);
198 void trim_front (framepos_t new_position, void *src);
199 void trim_end (framepos_t new_position, void *src);
200 void trim_to (framepos_t position, framecnt_t length, void *src);
202 void set_layer (layer_t l); /* ONLY Playlist can call this */
205 void raise_to_top ();
206 void lower_to_bottom ();
208 void set_sync_position (framepos_t n);
209 void clear_sync_position ();
210 void set_hidden (bool yn);
211 void set_muted (bool yn);
212 void set_whole_file (bool yn);
213 void set_automatic (bool yn);
214 void set_opaque (bool yn);
215 void set_locked (bool yn);
216 void set_position_locked (bool yn);
220 virtual uint64_t read_data_count() const { return _read_data_count; }
222 boost::shared_ptr<ARDOUR::Playlist> playlist() const { return _playlist.lock(); }
223 virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
225 void source_deleted (boost::weak_ptr<Source>);
227 boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
228 uint32_t n_channels() const { return _sources.size(); }
230 const SourceList& sources() const { return _sources; }
231 const SourceList& master_sources() const { return _master_sources; }
233 std::vector<std::string> master_source_names();
234 void set_master_sources (const SourceList&);
238 virtual boost::shared_ptr<Evoral::Control>
239 control(const Evoral::Parameter& id, bool create=false) = 0;
241 virtual boost::shared_ptr<const Evoral::Control>
242 control(const Evoral::Parameter& id) const = 0;
246 XMLNode& get_state ();
247 virtual XMLNode& state (bool);
248 virtual int set_state (const XMLNode&, int version);
250 virtual boost::shared_ptr<Region> get_parent() const;
252 uint64_t last_layer_op() const { return _last_layer_op; }
253 void set_last_layer_op (uint64_t when);
255 virtual bool is_dependent() const { return false; }
256 virtual bool depends_on (boost::shared_ptr<Region> /*other*/) const { return false; }
258 virtual int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&) = 0;
260 virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
262 // no transients, but its OK
266 virtual int separate_by_channel (ARDOUR::Session&,
267 std::vector< boost::shared_ptr<Region> >&) const {
271 void invalidate_transients ();
273 void set_pending_explicit_relayer (bool p) {
274 _pending_explicit_relayer = p;
277 bool pending_explicit_relayer () const {
278 return _pending_explicit_relayer;
282 friend class RegionFactory;
284 /** Construct a region from a single source */
285 Region (boost::shared_ptr<Source> src);
286 /** Construct a region from multiple sources*/
287 Region (const SourceList& srcs);
288 /** Construct a region from another region, at an offset within that region */
289 Region (boost::shared_ptr<const Region>, frameoffset_t start_offset = 0, bool start_relative = true);
290 /** Construct a region as a copy of another region, but with different sources */
291 Region (boost::shared_ptr<const Region>, const SourceList&);
292 /** normal Region copy constructor */
293 Region (boost::shared_ptr<const Region>);
295 /** Construct a region from 1 source and XML state */
296 Region (boost::shared_ptr<Source> src, const XMLNode&);
297 /** Construct a region from multiple sources and XML state */
298 Region (const SourceList& srcs, const XMLNode&);
300 /** Constructor for derived types only */
301 Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
304 void send_change (PBD::PropertyChange);
306 void trim_to_internal (framepos_t position, framecnt_t length, void *src);
307 virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
309 void maybe_uncopy ();
312 bool verify_start (framepos_t);
313 bool verify_start_and_length (framepos_t, framecnt_t&);
314 bool verify_start_mutable (framepos_t&_start);
315 bool verify_length (framecnt_t);
317 virtual void recompute_at_start () = 0;
318 virtual void recompute_at_end () = 0;
321 bool _no_property_changes;
323 PBD::Property<bool> _muted;
324 PBD::Property<bool> _opaque;
325 PBD::Property<bool> _locked;
326 PBD::Property<bool> _automatic;
327 PBD::Property<bool> _whole_file;
328 PBD::Property<bool> _import;
329 PBD::Property<bool> _external;
330 PBD::Property<bool> _sync_marked;
331 PBD::Property<bool> _left_of_split;
332 PBD::Property<bool> _right_of_split;
333 PBD::Property<bool> _hidden;
334 PBD::Property<bool> _position_locked;
335 PBD::Property<framepos_t> _start;
336 PBD::Property<framecnt_t> _length;
337 PBD::Property<framepos_t> _position;
338 PBD::Property<framepos_t> _sync_position;
339 PBD::Property<layer_t> _layer;
340 PBD::Property<framepos_t> _ancestral_start;
341 PBD::Property<framecnt_t> _ancestral_length;
342 PBD::Property<float> _stretch;
343 PBD::Property<float> _shift;
345 framecnt_t _last_length;
346 framepos_t _last_position;
347 PositionLockStyle _positional_lock_style;
348 mutable RegionEditState _first_edit;
351 AnalysisFeatureList _transients;
352 bool _valid_transients;
353 mutable uint64_t _read_data_count; ///< modified in read()
354 PBD::PropertyChange _pending_changed;
355 uint64_t _last_layer_op; ///< timestamp
358 /** Used when timefx are applied, so we can always use the original source */
359 SourceList _master_sources;
361 /** true if this region has had its layer explicitly set since the playlist last relayered */
362 bool _pending_explicit_relayer;
364 boost::weak_ptr<ARDOUR::Playlist> _playlist;
366 virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
368 PBD::PropertyChange set_property (const PBD::PropertyBase&);
369 void register_properties ();
372 void use_sources (SourceList const &);
375 } /* namespace ARDOUR */
377 #endif /* __ardour_region_h__ */