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