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<bool> valid_transients;
56 extern PBD::PropertyDescriptor<framepos_t> start;
57 extern PBD::PropertyDescriptor<framecnt_t> length;
58 extern PBD::PropertyDescriptor<framepos_t> position;
59 extern PBD::PropertyDescriptor<framecnt_t> sync_position;
60 extern PBD::PropertyDescriptor<layer_t> layer;
61 extern PBD::PropertyDescriptor<framepos_t> ancestral_start;
62 extern PBD::PropertyDescriptor<framecnt_t> ancestral_length;
63 extern PBD::PropertyDescriptor<float> stretch;
64 extern PBD::PropertyDescriptor<float> shift;
65 extern PBD::PropertyDescriptor<PositionLockStyle> position_lock_style;
70 class ExportSpecification;
72 enum RegionEditState {
73 EditChangesNothing = 0,
80 : public SessionObject
81 , public boost::enable_shared_from_this<Region>
85 typedef std::vector<boost::shared_ptr<Source> > SourceList;
87 static void make_property_quarks ();
89 static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
91 PBD::PropertyList* property_factory (const XMLNode&) const;
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 AnalysisFeatureList transients () { return _transients; };
102 /** How the region parameters play together:
104 * POSITION: first frame of the region along the timeline
105 * START: first frame of the region within its source(s)
106 * LENGTH: number of frames the region represents
108 sframes_t position () const { return _position; }
109 sframes_t start () const { return _start; }
110 framecnt_t length() const { return _length; }
111 layer_t layer () const { return _layer; }
113 framecnt_t source_length(uint32_t n) const;
115 /* these two are valid ONLY during a StateChanged signal handler */
117 sframes_t last_position() const { return _last_position; }
118 framecnt_t last_length() const { return _last_length; }
120 sframes_t ancestral_start () const { return _ancestral_start; }
121 framecnt_t ancestral_length () const { return _ancestral_length; }
122 float stretch() const { return _stretch; }
123 float shift() const { return _shift; }
125 void set_ancestral_data (nframes64_t start, nframes64_t length, float stretch, float shift);
127 frameoffset_t sync_offset(int& dir) const;
128 framepos_t sync_position() const;
129 framepos_t sync_point () const;
131 framepos_t adjust_to_sync (framepos_t) const;
133 /* first_frame() is an alias; last_frame() just hides some math */
135 framepos_t first_frame() const { return _position; }
136 framepos_t last_frame() const { return _position + _length - 1; }
138 bool hidden() const { return _hidden; }
139 bool muted() const { return _muted; }
140 bool opaque () const { return _opaque; }
141 bool locked() const { return _locked; }
142 bool position_locked() const { return _position_locked; }
143 bool valid_transients() const { return _valid_transients; }
144 bool automatic() const { return _automatic; }
145 bool whole_file() const { return _whole_file; }
146 bool captured() const { return !(_import || _external); }
147 bool can_move() const { return !_position_locked; }
148 bool sync_marked() const { return _sync_marked; }
149 bool external() const { return _external; }
150 bool import() const { return _import; }
152 PositionLockStyle position_lock_style() const { return _position_lock_style; }
153 void set_position_lock_style (PositionLockStyle ps);
154 void recompute_position_from_lock_style ();
156 void suspend_property_changes ();
158 bool covers (framepos_t frame) const {
159 return first_frame() <= frame && frame <= last_frame();
162 OverlapType coverage (framepos_t start, framepos_t end) const {
163 return ARDOUR::coverage (first_frame(), last_frame(), start, end);
166 bool equivalent (boost::shared_ptr<const Region>) const;
167 bool size_equivalent (boost::shared_ptr<const Region>) const;
168 bool overlap_equivalent (boost::shared_ptr<const Region>) const;
169 bool region_list_equivalent (boost::shared_ptr<const Region>) const;
170 bool source_equivalent (boost::shared_ptr<const Region>) const;
171 bool uses_source (boost::shared_ptr<const Source>) const;
173 /* EDITING OPERATIONS */
175 void set_length (framecnt_t, void *src);
176 void set_start (framepos_t, void *src);
177 void set_position (framepos_t, void *src);
178 void set_position_on_top (framepos_t, void *src);
179 void special_set_position (framepos_t);
180 void update_position_after_tempo_map_change ();
181 void nudge_position (frameoffset_t, void *src);
183 bool at_natural_position () const;
184 void move_to_natural_position (void *src);
186 void trim_start (framepos_t new_position, void *src);
187 void trim_front (framepos_t new_position, void *src);
188 void trim_end (framepos_t new_position, void *src);
189 void trim_to (framepos_t position, framecnt_t length, void *src);
191 void cut_front (nframes_t new_position, void *src);
192 void cut_end (nframes_t new_position, void *src);
194 void set_layer (layer_t l); /* ONLY Playlist can call this */
197 void raise_to_top ();
198 void lower_to_bottom ();
200 void set_sync_position (framepos_t n);
201 void clear_sync_position ();
202 void set_hidden (bool yn);
203 void set_muted (bool yn);
204 void set_whole_file (bool yn);
205 void set_automatic (bool yn);
206 void set_opaque (bool yn);
207 void set_locked (bool yn);
208 void set_position_locked (bool yn);
212 virtual uint64_t read_data_count() const { return _read_data_count; }
214 boost::shared_ptr<ARDOUR::Playlist> playlist() const { return _playlist.lock(); }
215 virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
217 void source_deleted (boost::weak_ptr<Source>);
219 boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
220 uint32_t n_channels() const { return _sources.size(); }
222 const SourceList& sources() const { return _sources; }
223 const SourceList& master_sources() const { return _master_sources; }
225 std::vector<std::string> master_source_names();
226 void set_master_sources (const SourceList&);
230 virtual boost::shared_ptr<Evoral::Control>
231 control(const Evoral::Parameter& id, bool create=false) = 0;
233 virtual boost::shared_ptr<const Evoral::Control>
234 control(const Evoral::Parameter& id) const = 0;
238 XMLNode& get_state ();
239 virtual XMLNode& state (bool);
240 virtual int set_state (const XMLNode&, int version);
242 virtual boost::shared_ptr<Region> get_parent() const;
244 uint64_t last_layer_op() const { return _last_layer_op; }
245 void set_last_layer_op (uint64_t when);
247 virtual bool is_dependent() const { return false; }
248 virtual bool depends_on (boost::shared_ptr<Region> /*other*/) const { return false; }
250 virtual int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&) = 0;
252 virtual void add_transient (nframes64_t where) {
253 // no transients, but its OK
256 virtual int update_transient (nframes64_t old_position, nframes64_t new_position) {
257 // no transients, but its OK
261 virtual void remove_transient (nframes64_t where) {
262 // no transients, but its OK
265 virtual int set_transients (AnalysisFeatureList&) {
266 // no transients, but its OK
270 virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
272 // no transients, but its OK
276 virtual int adjust_transients (nframes64_t delta) {
277 // no transients, but its OK
281 virtual int separate_by_channel (ARDOUR::Session&,
282 std::vector< boost::shared_ptr<Region> >&) const {
286 void invalidate_transients ();
288 void set_pending_explicit_relayer (bool p) {
289 _pending_explicit_relayer = p;
292 bool pending_explicit_relayer () const {
293 return _pending_explicit_relayer;
296 void drop_sources ();
299 friend class RegionFactory;
301 /** Construct a region from multiple sources*/
302 Region (const SourceList& srcs);
303 /** Construct a region from another region, at an offset within that region */
304 Region (boost::shared_ptr<const Region>, frameoffset_t start_offset = 0, bool start_relative = true);
305 /** Construct a region as a copy of another region, but with different sources */
306 Region (boost::shared_ptr<const Region>, const SourceList&);
307 /** normal Region copy constructor */
308 Region (boost::shared_ptr<const Region>);
310 /** Constructor for derived types only */
311 Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
314 void send_change (const PBD::PropertyChange&);
315 void mid_thaw (const PBD::PropertyChange&);
317 void trim_to_internal (framepos_t position, framecnt_t length, void *src);
318 virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
319 void modify_front (nframes_t new_position, bool reset_fade, void* src);
320 void modify_end (nframes_t new_position, bool reset_fade, void* src);
322 void maybe_uncopy ();
325 bool verify_start (framepos_t);
326 bool verify_start_and_length (framepos_t, framecnt_t&);
327 bool verify_start_mutable (framepos_t&_start);
328 bool verify_length (framecnt_t);
330 virtual void recompute_at_start () = 0;
331 virtual void recompute_at_end () = 0;
335 PBD::Property<bool> _muted;
336 PBD::Property<bool> _opaque;
337 PBD::Property<bool> _locked;
338 PBD::Property<bool> _automatic;
339 PBD::Property<bool> _whole_file;
340 PBD::Property<bool> _import;
341 PBD::Property<bool> _external;
342 PBD::Property<bool> _sync_marked;
343 PBD::Property<bool> _left_of_split;
344 PBD::Property<bool> _right_of_split;
345 PBD::Property<bool> _hidden;
346 PBD::Property<bool> _position_locked;
347 PBD::Property<bool> _valid_transients;
348 PBD::Property<framepos_t> _start;
349 PBD::Property<framecnt_t> _length;
350 PBD::Property<framepos_t> _position;
351 PBD::Property<framepos_t> _sync_position;
352 PBD::Property<layer_t> _layer;
353 PBD::Property<framepos_t> _ancestral_start;
354 PBD::Property<framecnt_t> _ancestral_length;
355 PBD::Property<float> _stretch;
356 PBD::Property<float> _shift;
357 PBD::EnumProperty<PositionLockStyle> _position_lock_style;
359 framecnt_t _last_length;
360 framepos_t _last_position;
361 mutable RegionEditState _first_edit;
363 AnalysisFeatureList _transients;
365 mutable uint64_t _read_data_count; ///< modified in read()
366 uint64_t _last_layer_op; ///< timestamp
368 /** Used when timefx are applied, so we can always use the original source */
369 SourceList _master_sources;
371 /** true if this region has had its layer explicitly set since the playlist last relayered */
372 bool _pending_explicit_relayer;
374 boost::weak_ptr<ARDOUR::Playlist> _playlist;
376 virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
378 void register_properties ();
381 void use_sources (SourceList const &);
384 } /* namespace ARDOUR */
386 #endif /* __ardour_region_h__ */