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/movable.h"
35 #include "ardour/readable.h"
36 #include "ardour/session_object.h"
37 #include "ardour/trimmable.h"
44 namespace Properties {
45 extern PBD::PropertyDescriptor<bool> muted;
46 extern PBD::PropertyDescriptor<bool> opaque;
47 extern PBD::PropertyDescriptor<bool> locked;
48 extern PBD::PropertyDescriptor<bool> automatic;
49 extern PBD::PropertyDescriptor<bool> whole_file;
50 extern PBD::PropertyDescriptor<bool> import;
51 extern PBD::PropertyDescriptor<bool> external;
52 extern PBD::PropertyDescriptor<bool> sync_marked;
53 extern PBD::PropertyDescriptor<bool> left_of_split;
54 extern PBD::PropertyDescriptor<bool> right_of_split;
55 extern PBD::PropertyDescriptor<bool> hidden;
56 extern PBD::PropertyDescriptor<bool> position_locked;
57 extern PBD::PropertyDescriptor<bool> valid_transients;
58 extern PBD::PropertyDescriptor<framepos_t> start;
59 extern PBD::PropertyDescriptor<framecnt_t> length;
60 extern PBD::PropertyDescriptor<framepos_t> position;
61 extern PBD::PropertyDescriptor<framecnt_t> sync_position;
62 extern PBD::PropertyDescriptor<layer_t> layer;
63 extern PBD::PropertyDescriptor<framepos_t> ancestral_start;
64 extern PBD::PropertyDescriptor<framecnt_t> ancestral_length;
65 extern PBD::PropertyDescriptor<float> stretch;
66 extern PBD::PropertyDescriptor<float> shift;
67 extern PBD::PropertyDescriptor<PositionLockStyle> position_lock_style;
72 class ExportSpecification;
75 enum RegionEditState {
76 EditChangesNothing = 0,
83 : public SessionObject
84 , public boost::enable_shared_from_this<Region>
90 typedef std::vector<boost::shared_ptr<Source> > SourceList;
92 static void make_property_quarks ();
94 static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
98 /** Note: changing the name of a Region does not constitute an edit */
99 bool set_name (const std::string& str);
101 const DataType& data_type() const { return _type; }
103 AnalysisFeatureList transients () { return _transients; };
105 /** How the region parameters play together:
107 * POSITION: first frame of the region along the timeline
108 * START: first frame of the region within its source(s)
109 * LENGTH: number of frames the region represents
111 framepos_t position () const { return _position; }
112 framepos_t start () const { return _start; }
113 framecnt_t length() const { return _length; }
114 layer_t layer () const { return _layer; }
116 framecnt_t source_length(uint32_t n) const;
118 /* these two are valid ONLY during a StateChanged signal handler */
120 framepos_t last_position() const { return _last_position; }
121 framecnt_t last_length() const { return _last_length; }
123 framepos_t ancestral_start () const { return _ancestral_start; }
124 framecnt_t ancestral_length () const { return _ancestral_length; }
125 float stretch() const { return _stretch; }
126 float shift() const { return _shift; }
128 void set_ancestral_data (framepos_t start, framepos_t length, float stretch, float shift);
130 frameoffset_t sync_offset(int& dir) const;
131 framepos_t sync_position() const;
132 framepos_t sync_point () const;
134 framepos_t adjust_to_sync (framepos_t) const;
136 /* first_frame() is an alias; last_frame() just hides some math */
138 framepos_t first_frame() const { return _position; }
139 framepos_t last_frame() const { return _position + _length - 1; }
141 bool hidden() const { return _hidden; }
142 bool muted() const { return _muted; }
143 bool opaque () const { return _opaque; }
144 bool locked() const { return _locked; }
145 bool position_locked() const { return _position_locked; }
146 bool valid_transients() const { return _valid_transients; }
147 bool automatic() const { return _automatic; }
148 bool whole_file() const { return _whole_file; }
149 bool captured() const { return !(_import || _external); }
150 bool can_move() const { return !_position_locked; }
151 bool sync_marked() const { return _sync_marked; }
152 bool external() const { return _external; }
153 bool import() const { return _import; }
155 Trimmable::CanTrim can_trim() const;
157 PositionLockStyle position_lock_style() const { return _position_lock_style; }
158 void set_position_lock_style (PositionLockStyle ps);
159 void recompute_position_from_lock_style ();
161 void suspend_property_changes ();
163 bool covers (framepos_t frame) const {
164 return first_frame() <= frame && frame <= last_frame();
167 OverlapType coverage (framepos_t start, framepos_t end) const {
168 return ARDOUR::coverage (first_frame(), last_frame(), start, end);
171 bool equivalent (boost::shared_ptr<const Region>) const;
172 bool size_equivalent (boost::shared_ptr<const Region>) const;
173 bool overlap_equivalent (boost::shared_ptr<const Region>) const;
174 bool region_list_equivalent (boost::shared_ptr<const Region>) const;
175 bool source_equivalent (boost::shared_ptr<const Region>) const;
176 bool uses_source (boost::shared_ptr<const Source>) const;
178 /* EDITING OPERATIONS */
180 void set_length (framecnt_t, void *src);
181 void set_start (framepos_t, void *src);
182 void set_position (framepos_t, void *src);
183 void set_position_on_top (framepos_t, void *src);
184 void special_set_position (framepos_t);
185 void update_position_after_tempo_map_change ();
186 void nudge_position (frameoffset_t, void *src);
188 bool at_natural_position () const;
189 void move_to_natural_position (void *src);
191 void trim_start (framepos_t new_position, void *src);
192 void trim_front (framepos_t new_position, void *src);
193 void trim_end (framepos_t new_position, void *src);
194 void trim_to (framepos_t position, framecnt_t length, void *src);
196 void cut_front (nframes_t new_position, void *src);
197 void cut_end (nframes_t new_position, void *src);
199 void set_layer (layer_t l); /* ONLY Playlist can call this */
202 void raise_to_top ();
203 void lower_to_bottom ();
205 void set_sync_position (framepos_t n);
206 void clear_sync_position ();
207 void set_hidden (bool yn);
208 void set_muted (bool yn);
209 void set_whole_file (bool yn);
210 void set_automatic (bool yn);
211 void set_opaque (bool yn);
212 void set_locked (bool yn);
213 void set_position_locked (bool yn);
215 int apply (Filter &, Progress* progress = 0);
217 virtual uint64_t read_data_count() const { return _read_data_count; }
219 boost::shared_ptr<ARDOUR::Playlist> playlist() const { return _playlist.lock(); }
220 virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
222 void source_deleted (boost::weak_ptr<Source>);
224 boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
225 uint32_t n_channels() const { return _sources.size(); }
227 const SourceList& sources() const { return _sources; }
228 const SourceList& master_sources() const { return _master_sources; }
230 std::vector<std::string> master_source_names();
231 void set_master_sources (const SourceList&);
235 virtual boost::shared_ptr<Evoral::Control>
236 control(const Evoral::Parameter& id, bool create=false) = 0;
238 virtual boost::shared_ptr<const Evoral::Control>
239 control(const Evoral::Parameter& id) const = 0;
243 XMLNode& get_state ();
244 virtual XMLNode& state ();
245 virtual int set_state (const XMLNode&, int version);
247 virtual boost::shared_ptr<Region> get_parent() const;
249 uint64_t last_layer_op() const { return _last_layer_op; }
250 void set_last_layer_op (uint64_t when);
252 virtual bool is_dependent() const { return false; }
253 virtual bool depends_on (boost::shared_ptr<Region> /*other*/) const { return false; }
255 virtual int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&) = 0;
257 virtual void add_transient (framepos_t) {
258 // no transients, but its OK
261 virtual int update_transient (framepos_t /* old_position */, framepos_t /* new_position */) {
262 // no transients, but its OK
266 virtual void remove_transient (framepos_t /* where */) {
267 // no transients, but its OK
270 virtual int set_transients (AnalysisFeatureList&) {
271 // no transients, but its OK
275 virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
277 // no transients, but its OK
281 virtual int adjust_transients (framepos_t /*delta*/) {
282 // no transients, but its OK
286 virtual int separate_by_channel (ARDOUR::Session&,
287 std::vector< boost::shared_ptr<Region> >&) const {
291 void invalidate_transients ();
293 void set_pending_explicit_relayer (bool p) {
294 _pending_explicit_relayer = p;
297 bool pending_explicit_relayer () const {
298 return _pending_explicit_relayer;
301 void drop_sources ();
304 friend class RegionFactory;
306 /** Construct a region from multiple sources*/
307 Region (const SourceList& srcs);
308 /** Construct a region from another region, at an offset within that region */
309 Region (boost::shared_ptr<const Region>, frameoffset_t start_offset = 0, bool start_relative = true);
310 /** Construct a region as a copy of another region, but with different sources */
311 Region (boost::shared_ptr<const Region>, const SourceList&);
312 /** normal Region copy constructor */
313 Region (boost::shared_ptr<const Region>);
315 /** Constructor for derived types only */
316 Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
319 void send_change (const PBD::PropertyChange&);
320 void mid_thaw (const PBD::PropertyChange&);
322 void trim_to_internal (framepos_t position, framecnt_t length, void *src);
323 virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
324 void modify_front (nframes_t new_position, bool reset_fade, void* src);
325 void modify_end (nframes_t new_position, bool reset_fade, void* src);
327 void maybe_uncopy ();
330 bool verify_start (framepos_t);
331 bool verify_start_and_length (framepos_t, framecnt_t&);
332 bool verify_start_mutable (framepos_t&_start);
333 bool verify_length (framecnt_t);
335 virtual void recompute_at_start () = 0;
336 virtual void recompute_at_end () = 0;
340 PBD::Property<bool> _muted;
341 PBD::Property<bool> _opaque;
342 PBD::Property<bool> _locked;
343 PBD::Property<bool> _automatic;
344 PBD::Property<bool> _whole_file;
345 PBD::Property<bool> _import;
346 PBD::Property<bool> _external;
347 PBD::Property<bool> _sync_marked;
348 PBD::Property<bool> _left_of_split;
349 PBD::Property<bool> _right_of_split;
350 PBD::Property<bool> _hidden;
351 PBD::Property<bool> _position_locked;
352 PBD::Property<bool> _valid_transients;
353 PBD::Property<framepos_t> _start;
354 PBD::Property<framecnt_t> _length;
355 PBD::Property<framepos_t> _position;
356 /** Sync position relative to the start of our file */
357 PBD::Property<framepos_t> _sync_position;
358 PBD::Property<layer_t> _layer;
359 PBD::Property<framepos_t> _ancestral_start;
360 PBD::Property<framecnt_t> _ancestral_length;
361 PBD::Property<float> _stretch;
362 PBD::Property<float> _shift;
363 PBD::EnumProperty<PositionLockStyle> _position_lock_style;
365 framecnt_t _last_length;
366 framepos_t _last_position;
367 mutable RegionEditState _first_edit;
369 AnalysisFeatureList _transients;
371 mutable uint64_t _read_data_count; ///< modified in read()
372 uint64_t _last_layer_op; ///< timestamp
374 /** Used when timefx are applied, so we can always use the original source */
375 SourceList _master_sources;
377 /** true if this region has had its layer explicitly set since the playlist last relayered */
378 bool _pending_explicit_relayer;
380 boost::weak_ptr<ARDOUR::Playlist> _playlist;
382 virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
384 void register_properties ();
387 void use_sources (SourceList const &);
390 } /* namespace ARDOUR */
392 #endif /* __ardour_region_h__ */