No-op: whitespace.
[ardour.git] / libs / ardour / ardour / region.h
1 /*
2     Copyright (C) 2000-2001 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_region_h__
21 #define __ardour_region_h__
22
23 #include <vector>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/enable_shared_from_this.hpp>
26 #include <boost/utility.hpp>
27
28 #include "pbd/undo.h"
29 #include "pbd/signals.h"
30
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"
38
39 class XMLNode;
40
41
42 namespace ARDOUR {
43
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;
68 };
69
70 class Playlist;
71 class Filter;
72 class ExportSpecification;
73 class Progress; 
74
75 enum RegionEditState {
76         EditChangesNothing = 0,
77         EditChangesName    = 1,
78         EditChangesID      = 2
79 };
80
81
82 class Region
83         : public SessionObject
84         , public boost::enable_shared_from_this<Region>
85         , public Readable
86         , public Trimmable
87         , public Movable
88 {
89   public:
90         typedef std::vector<boost::shared_ptr<Source> > SourceList;
91
92         static void make_property_quarks ();
93         
94         static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
95
96         virtual ~Region();
97         
98         /** Note: changing the name of a Region does not constitute an edit */
99         bool set_name (const std::string& str);
100
101         const DataType& data_type () const { return _type; }
102         
103         AnalysisFeatureList transients () { return _transients; };
104
105         /** How the region parameters play together:
106          *   
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
110          */
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; }
115
116         framecnt_t source_length(uint32_t n) const;
117
118         /* these two are valid ONLY during a StateChanged signal handler */
119
120         framepos_t last_position () const { return _last_position; }
121         framecnt_t last_length ()   const { return _last_length; }
122
123         framepos_t ancestral_start ()  const { return _ancestral_start; }
124         framecnt_t ancestral_length () const { return _ancestral_length; }
125         
126         float stretch () const { return _stretch; }
127         float shift ()   const { return _shift; }
128
129         void set_ancestral_data (framepos_t start, framepos_t length, float stretch, float shift);
130
131         frameoffset_t sync_offset (int& dir) const;
132         framepos_t sync_position () const;
133         framepos_t sync_point () const;
134         
135         framepos_t adjust_to_sync (framepos_t) const;
136
137         /* first_frame() is an alias; last_frame() just hides some math */
138
139         framepos_t first_frame () const { return _position; }
140         framepos_t last_frame ()  const { return _position + _length - 1; }
141
142         bool hidden ()           const { return _hidden; }
143         bool muted ()            const { return _muted; }
144         bool opaque ()           const { return _opaque; }
145         bool locked ()           const { return _locked; }
146         bool position_locked ()  const { return _position_locked; }
147         bool valid_transients () const { return _valid_transients; }
148         bool automatic ()        const { return _automatic; }
149         bool whole_file ()       const { return _whole_file; }
150         bool captured ()         const { return !(_import || _external); }
151         bool can_move ()         const { return !_position_locked; }
152         bool sync_marked ()      const { return _sync_marked; }
153         bool external ()         const { return _external; }
154         bool import ()           const { return _import; }
155         
156         Trimmable::CanTrim can_trim () const;
157
158         PositionLockStyle position_lock_style () const { return _position_lock_style; }
159         
160         void set_position_lock_style (PositionLockStyle ps);
161         void recompute_position_from_lock_style ();
162
163         void suspend_property_changes ();
164
165         bool covers (framepos_t frame) const {
166                 return first_frame() <= frame && frame <= last_frame();
167         }
168
169         OverlapType coverage (framepos_t start, framepos_t end) const {
170                 return ARDOUR::coverage (first_frame(), last_frame(), start, end);
171         }
172
173         bool equivalent (boost::shared_ptr<const Region>) const;
174         bool size_equivalent (boost::shared_ptr<const Region>) const;
175         bool overlap_equivalent (boost::shared_ptr<const Region>) const;
176         bool region_list_equivalent (boost::shared_ptr<const Region>) const;
177         bool source_equivalent (boost::shared_ptr<const Region>) const;
178         bool uses_source (boost::shared_ptr<const Source>) const;
179         
180         std::string source_string () const;
181
182
183         /* EDITING OPERATIONS */
184
185         void set_length (framecnt_t, void *src);
186         void set_start (framepos_t, void *src);
187         void set_position (framepos_t, void *src);
188         void set_position_on_top (framepos_t, void *src);
189         void special_set_position (framepos_t);
190         void update_position_after_tempo_map_change ();
191         void nudge_position (frameoffset_t, void *src);
192
193         bool at_natural_position () const;
194         void move_to_natural_position (void *src);
195
196         void trim_start (framepos_t new_position, void *src);
197         void trim_front (framepos_t new_position, void *src);
198         void trim_end (framepos_t new_position, void *src);
199         void trim_to (framepos_t position, framecnt_t length, void *src);
200
201         void cut_front (framepos_t new_position, void *src);
202         void cut_end (framepos_t new_position, void *src);
203
204         void set_layer (layer_t l); /* ONLY Playlist can call this */
205         void raise ();
206         void lower ();
207         void raise_to_top ();
208         void lower_to_bottom ();
209
210         void set_sync_position (framepos_t n);
211         void clear_sync_position ();
212         void set_hidden (bool yn);
213         void set_muted (bool yn);
214         void set_whole_file (bool yn);
215         void set_automatic (bool yn);
216         void set_opaque (bool yn);
217         void set_locked (bool yn);
218         void set_position_locked (bool yn);
219
220         int apply (Filter &, Progress* progress = 0);
221
222         virtual uint64_t read_data_count () const { return _read_data_count; }
223
224         boost::shared_ptr<ARDOUR::Playlist> playlist () const { return _playlist.lock(); }
225         virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
226
227         void source_deleted (boost::weak_ptr<Source>);
228
229         boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
230         uint32_t n_channels() const { return _sources.size(); }
231
232         const SourceList& sources ()        const { return _sources; }
233         const SourceList& master_sources () const { return _master_sources; }
234
235         std::vector<std::string> master_source_names();
236         void set_master_sources (const SourceList&);
237
238         /* automation */
239
240         virtual boost::shared_ptr<Evoral::Control>
241         control (const Evoral::Parameter& id, bool create=false) = 0;
242
243         virtual boost::shared_ptr<const Evoral::Control>
244         control (const Evoral::Parameter& id) const = 0;
245
246         /* serialization */
247
248         XMLNode&         get_state ();
249         virtual XMLNode& state ();
250         virtual int      set_state (const XMLNode&, int version);
251
252         virtual boost::shared_ptr<Region> get_parent() const;
253
254         uint64_t last_layer_op() const { return _last_layer_op; }
255         void set_last_layer_op (uint64_t when);
256
257         virtual bool is_dependent() const { return false; }
258         virtual bool depends_on (boost::shared_ptr<Region> /*other*/) const { return false; }
259
260         virtual int exportme (ARDOUR::Session&, ARDOUR::ExportSpecification&) = 0;
261
262         virtual void add_transient (framepos_t) {
263                 // no transients, but its OK
264         }
265
266         virtual int update_transient (framepos_t /* old_position */, framepos_t /* new_position */) {
267                 // no transients, but its OK
268                 return 0;
269         }
270
271         virtual void remove_transient (framepos_t /* where */) {
272                 // no transients, but its OK
273         }
274
275         virtual int set_transients (AnalysisFeatureList&) {
276                 // no transients, but its OK
277                 return 0;
278         }
279
280         virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
281                 (void) force_new;
282                 // no transients, but its OK
283                 return 0;
284         }
285
286         virtual int adjust_transients (framepos_t /*delta*/) {
287                 // no transients, but its OK
288                 return 0;
289         }
290
291         virtual int separate_by_channel (ARDOUR::Session&,
292                         std::vector< boost::shared_ptr<Region> >&) const {
293                 return 0;
294         }
295
296         void invalidate_transients ();
297
298         void set_pending_explicit_relayer (bool p) {
299                 _pending_explicit_relayer = p;
300         }
301
302         bool pending_explicit_relayer () const {
303                 return _pending_explicit_relayer;
304         }
305
306         void drop_sources ();
307
308   protected:
309         friend class RegionFactory;
310
311         /** Construct a region from multiple sources*/
312         Region (const SourceList& srcs);
313
314         /** Construct a region from another region */
315         Region (boost::shared_ptr<const Region>);
316
317         /** Construct a region from another region, at an offset within that region */
318         Region (boost::shared_ptr<const Region>, frameoffset_t start_offset);
319         
320         /** Construct a region as a copy of another region, but with different sources */
321         Region (boost::shared_ptr<const Region>, const SourceList&);
322
323         /** Constructor for derived types only */
324         Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
325
326         virtual bool can_trim_start_before_source_start () const {
327                 return false;
328         }
329
330   protected:
331         void send_change (const PBD::PropertyChange&);
332         void mid_thaw (const PBD::PropertyChange&);
333
334         void trim_to_internal (framepos_t position, framecnt_t length, void *src);
335         virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
336         virtual void set_length_internal (framepos_t pos);
337         void modify_front (framepos_t new_position, bool reset_fade, void* src);
338         void modify_end (framepos_t new_position, bool reset_fade, void* src);
339
340         void maybe_uncopy ();
341         void first_edit ();
342
343         bool verify_start (framepos_t);
344         bool verify_start_and_length (framepos_t, framecnt_t&);
345         bool verify_start_mutable (framepos_t&_start);
346         bool verify_length (framecnt_t);
347
348         virtual void recompute_at_start () = 0;
349         virtual void recompute_at_end () = 0;
350         
351         DataType _type;
352
353         PBD::Property<bool>        _muted;
354         PBD::Property<bool>        _opaque;
355         PBD::Property<bool>        _locked;
356         PBD::Property<bool>        _automatic;
357         PBD::Property<bool>        _whole_file;
358         PBD::Property<bool>        _import;
359         PBD::Property<bool>        _external;
360         PBD::Property<bool>        _sync_marked;
361         PBD::Property<bool>        _left_of_split;
362         PBD::Property<bool>        _right_of_split;
363         PBD::Property<bool>        _hidden;
364         PBD::Property<bool>        _position_locked;
365         PBD::Property<bool>        _valid_transients;
366         PBD::Property<framepos_t>  _start;
367         PBD::Property<framecnt_t>  _length;
368         PBD::Property<framepos_t>  _position;
369         /** Sync position relative to the start of our file */
370         PBD::Property<framepos_t>  _sync_position;
371         PBD::Property<layer_t>     _layer;
372         PBD::Property<framepos_t>  _ancestral_start;
373         PBD::Property<framecnt_t>  _ancestral_length;
374         PBD::Property<float>       _stretch;
375         PBD::Property<float>       _shift;
376         PBD::EnumProperty<PositionLockStyle> _position_lock_style;
377
378         framecnt_t              _last_length;
379         framepos_t              _last_position;
380         mutable RegionEditState _first_edit;
381         Timecode::BBT_Time      _bbt_time;
382         AnalysisFeatureList     _transients;
383         
384         mutable uint64_t        _read_data_count;  ///< modified in read()
385         uint64_t                _last_layer_op;  ///< timestamp
386         SourceList              _sources;
387         /** Used when timefx are applied, so we can always use the original source */
388         SourceList              _master_sources;
389
390         /** true if this region has had its layer explicitly set since the playlist last relayered */
391         bool                    _pending_explicit_relayer;
392
393         boost::weak_ptr<ARDOUR::Playlist> _playlist;
394
395         virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
396
397         void register_properties ();
398
399 protected:
400         void use_sources (SourceList const &);
401 };
402
403 } /* namespace ARDOUR */
404
405 #endif /* __ardour_region_h__ */