ardour
region.h
Go to the documentation of this file.
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 namespace ARDOUR {
42 
43 namespace Properties {
51  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> external;
52  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> sync_marked;
53  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> left_of_split;
54  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> right_of_split;
55  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> hidden;
56  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> position_locked;
57  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> valid_transients;
69 };
70 
71 class Playlist;
72 class Filter;
73 class ExportSpecification;
74 class Progress;
75 
76 enum LIBARDOUR_API RegionEditState {
79  EditChangesID = 2
80 };
81 
82 
84  : public SessionObject
85  , public boost::enable_shared_from_this<Region>
86  , public Readable
87  , public Trimmable
88  , public Movable
89 {
90  public:
91  typedef std::vector<boost::shared_ptr<Source> > SourceList;
92 
93  static void make_property_quarks ();
94 
95  static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
96 
97  virtual ~Region();
98 
100  bool set_name (const std::string& str);
101 
102  const DataType& data_type () const { return _type; }
103 
104  AnalysisFeatureList transients () { return _transients; };
105 
112  framepos_t position () const { return _position; }
113  framepos_t start () const { return _start; }
114  framecnt_t length () const { return _length; }
115  layer_t layer () const { return _layer; }
116 
117  framecnt_t source_length(uint32_t n) const;
118  uint32_t max_source_level () const;
119 
120  /* these two are valid ONLY during a StateChanged signal handler */
121 
122  framepos_t last_position () const { return _last_position; }
123  framecnt_t last_length () const { return _last_length; }
124 
125  framepos_t ancestral_start () const { return _ancestral_start; }
126  framecnt_t ancestral_length () const { return _ancestral_length; }
127 
128  float stretch () const { return _stretch; }
129  float shift () const { return _shift; }
130 
131  void set_ancestral_data (framepos_t start, framecnt_t length, float stretch, float shift);
132 
133  frameoffset_t sync_offset (int& dir) const;
134  framepos_t sync_position () const;
135  framepos_t sync_point () const;
136 
137  framepos_t adjust_to_sync (framepos_t) const;
138 
139  /* first_frame() is an alias; last_frame() just hides some math */
140 
141  framepos_t first_frame () const { return _position; }
142  framepos_t last_frame () const { return _position + _length - 1; }
143 
147  framepos_t earliest_possible_position () const;
151  framepos_t latest_possible_frame () const;
152 
154  return Evoral::Range<framepos_t> (_last_position, _last_position + _last_length - 1);
155  }
156 
158  return Evoral::Range<framepos_t> (first_frame(), last_frame());
159  }
160 
161  bool hidden () const { return _hidden; }
162  bool muted () const { return _muted; }
163  bool opaque () const { return _opaque; }
164  bool locked () const { return _locked; }
165  bool position_locked () const { return _position_locked; }
166  bool video_locked () const { return _video_locked; }
167  bool valid_transients () const { return _valid_transients; }
168  bool automatic () const { return _automatic; }
169  bool whole_file () const { return _whole_file; }
170  bool captured () const { return !(_import || _external); }
171  bool can_move () const { return !_position_locked && !_locked; }
172  bool sync_marked () const { return _sync_marked; }
173  bool external () const { return _external; }
174  bool import () const { return _import; }
175 
176  Trimmable::CanTrim can_trim () const;
177 
178  PositionLockStyle position_lock_style () const { return _position_lock_style; }
179 
180  void set_position_lock_style (PositionLockStyle ps);
181  void recompute_position_from_lock_style ();
182 
183  void suspend_property_changes ();
184 
185  bool covers (framepos_t frame) const {
186  return first_frame() <= frame && frame <= last_frame();
187  }
188 
196  return Evoral::coverage (first_frame(), last_frame(), start, end);
197  }
198 
199  bool equivalent (boost::shared_ptr<const Region>) const;
200  bool size_equivalent (boost::shared_ptr<const Region>) const;
201  bool overlap_equivalent (boost::shared_ptr<const Region>) const;
202  bool region_list_equivalent (boost::shared_ptr<const Region>) const;
203  bool source_equivalent (boost::shared_ptr<const Region>) const;
204  bool any_source_equivalent (boost::shared_ptr<const Region>) const;
205  bool uses_source (boost::shared_ptr<const Source>) const;
206 
207  std::string source_string () const;
208 
209 
210  /* EDITING OPERATIONS */
211 
212  void set_length (framecnt_t);
213  void set_start (framepos_t);
214  void set_position (framepos_t);
215  void special_set_position (framepos_t);
216  virtual void update_after_tempo_map_change ();
217  void nudge_position (frameoffset_t);
218 
219  bool at_natural_position () const;
220  void move_to_natural_position ();
221 
222  void move_start (frameoffset_t distance);
223  void trim_front (framepos_t new_position);
224  void trim_end (framepos_t new_position);
225  void trim_to (framepos_t position, framecnt_t length);
226 
227  virtual void fade_range (framepos_t, framepos_t) {}
228 
229  void cut_front (framepos_t new_position);
230  void cut_end (framepos_t new_position);
231 
232  void set_layer (layer_t l); /* ONLY Playlist can call this */
233  void raise ();
234  void lower ();
235  void raise_to_top ();
236  void lower_to_bottom ();
237 
238  void set_sync_position (framepos_t n);
239  void clear_sync_position ();
240  void set_hidden (bool yn);
241  void set_muted (bool yn);
242  void set_whole_file (bool yn);
243  void set_automatic (bool yn);
244  void set_opaque (bool yn);
245  void set_locked (bool yn);
246  void set_video_locked (bool yn);
247  void set_position_locked (bool yn);
248 
249  int apply (Filter &, Progress* progress = 0);
250 
251  boost::shared_ptr<ARDOUR::Playlist> playlist () const { return _playlist.lock(); }
252  virtual void set_playlist (boost::weak_ptr<ARDOUR::Playlist>);
253 
254  void source_deleted (boost::weak_ptr<Source>);
255 
256  bool is_compound () const;
257 
258  boost::shared_ptr<Source> source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; }
259  uint32_t n_channels() const { return _sources.size(); }
260 
261  const SourceList& sources () const { return _sources; }
262  const SourceList& master_sources () const { return _master_sources; }
263 
264  std::vector<std::string> master_source_names();
265  void set_master_sources (const SourceList&);
266 
267  /* automation */
268 
270  control (const Evoral::Parameter& id, bool create=false) = 0;
271 
273  control (const Evoral::Parameter& id) const = 0;
274 
275  /* serialization */
276 
277  XMLNode& get_state ();
278  virtual XMLNode& state ();
279  virtual int set_state (const XMLNode&, int version);
280 
281  virtual boost::shared_ptr<Region> get_parent() const;
282 
283  uint64_t layering_index () const { return _layering_index; }
284  void set_layering_index (uint64_t when) { _layering_index = when; }
285 
286  virtual bool is_dependent() const { return false; }
287  virtual bool depends_on (boost::shared_ptr<Region> /*other*/) const { return false; }
288 
289  virtual void add_transient (framepos_t) {
290  // no transients, but its OK
291  }
292 
293  virtual int update_transient (framepos_t /* old_position */, framepos_t /* new_position */) {
294  // no transients, but its OK
295  return 0;
296  }
297 
298  virtual void remove_transient (framepos_t /* where */) {
299  // no transients, but its OK
300  }
301 
303  // no transients, but its OK
304  return 0;
305  }
306 
307  virtual int get_transients (AnalysisFeatureList&, bool force_new = false) {
308  (void) force_new;
309  // no transients, but its OK
310  return 0;
311  }
312 
313  virtual int adjust_transients (frameoffset_t /*delta*/) {
314  // no transients, but its OK
315  return 0;
316  }
317 
319  std::vector< boost::shared_ptr<Region> >&) const {
320  return 0;
321  }
322 
323  void invalidate_transients ();
324 
325  void drop_sources ();
326 
327  protected:
328  friend class RegionFactory;
329 
331  Region (const SourceList& srcs);
332 
335 
338 
340  Region (boost::shared_ptr<const Region>, const SourceList&);
341 
343  Region (Session& s, framepos_t start, framecnt_t length, const std::string& name, DataType);
344 
345  virtual bool can_trim_start_before_source_start () const {
346  return false;
347  }
348 
349  protected:
350 
351  void send_change (const PBD::PropertyChange&);
352  virtual int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
353  void post_set (const PBD::PropertyChange&);
354  virtual void set_position_internal (framepos_t pos, bool allow_bbt_recompute);
355  virtual void set_length_internal (framecnt_t);
356  virtual void set_start_internal (framecnt_t);
357 
359 
369 
370  SourceList _sources;
372  SourceList _master_sources;
373 
375 
377 
378  private:
379  void mid_thaw (const PBD::PropertyChange&);
380 
381  void trim_to_internal (framepos_t position, framecnt_t length);
382  void modify_front (framepos_t new_position, bool reset_fade);
383  void modify_end (framepos_t new_position, bool reset_fade);
384 
385  void maybe_uncopy ();
386  void first_edit ();
387 
388  bool verify_start (framepos_t);
389  bool verify_start_and_length (framepos_t, framecnt_t&);
390  bool verify_start_mutable (framepos_t&_start);
391  bool verify_length (framecnt_t&);
392 
393  virtual void recompute_at_start () = 0;
394  virtual void recompute_at_end () = 0;
395 
412 
415  mutable RegionEditState _first_edit;
416  Timecode::BBT_Time _bbt_time;
418 
419  void register_properties ();
420 
421  void use_sources (SourceList const &);
422 };
423 
424 } /* namespace ARDOUR */
425 
426 #endif /* __ardour_region_h__ */
AnalysisFeatureList _transients
Definition: region.h:374
PBD::Property< bool > _automatic
Definition: region.h:400
void set_layering_index(uint64_t when)
Definition: region.h:284
PBD::Property< bool > _muted
Definition: region.h:396
const SourceList & master_sources() const
Definition: region.h:262
virtual bool depends_on(boost::shared_ptr< Region >) const
Definition: region.h:287
PBD::Property< bool > _position_locked
Definition: region.h:405
PBD::Property< framepos_t > _ancestral_start
Definition: region.h:406
PBD::Property< bool > _external
Definition: region.h:403
Evoral::Range< framepos_t > last_range() const
Definition: region.h:153
LIBARDOUR_API PBD::PropertyDescriptor< layer_t > layer
Definition: region.cc:67
LIBARDOUR_API PBD::PropertyDescriptor< bool > hidden
Definition: route_group.h:50
framepos_t _last_position
Definition: region.h:414
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > ancestral_start
Definition: region.cc:68
EditChangesName
Definition: region.h:78
LIBARDOUR_API PBD::PropertyDescriptor< bool > video_locked
Definition: region.cc:52
bool covers(framepos_t frame) const
Definition: region.h:185
const SourceList & sources() const
Definition: region.h:261
EditChangesNothing
Definition: region.h:77
virtual bool is_dependent() const
Definition: region.h:286
bool valid_transients() const
Definition: region.h:167
layer_t _layer
Definition: region.h:417
virtual void fade_range(framepos_t, framepos_t)
Definition: region.h:227
bool whole_file() const
Definition: region.h:169
PBD::Property< bool > _whole_file
Definition: region.h:401
PBD::Property< framepos_t > _sync_position
Definition: region.h:368
boost::shared_ptr< Source > source(uint32_t n=0) const
Definition: region.h:258
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
bool external() const
Definition: region.h:173
PBD::Property< bool > _left_of_split
Definition: region.h:361
LIBARDOUR_API PBD::PropertyDescriptor< float > stretch
Definition: region.cc:70
bool can_move() const
Definition: region.h:171
PBD::Property< float > _stretch
Definition: region.h:408
framepos_t last_position() const
Definition: region.h:122
virtual int separate_by_channel(ARDOUR::Session &, std::vector< boost::shared_ptr< Region > > &) const
Definition: region.h:318
PBD::Property< bool > _valid_transients
Definition: region.h:363
PBD::Property< bool > _right_of_split
Definition: region.h:362
PBD::Property< bool > _locked
Definition: region.h:398
AnalysisFeatureList transients()
Definition: region.h:104
SourceList _master_sources
Definition: region.h:372
SourceList _sources
Definition: region.h:370
const DataType & data_type() const
Definition: region.h:102
LIBARDOUR_API PBD::PropertyDescriptor< bool > automatic
Definition: region.cc:53
PBD::Property< framepos_t > _start
Definition: region.h:364
int64_t framecnt_t
Definition: types.h:76
virtual bool can_trim_start_before_source_start() const
Definition: region.h:345
virtual int set_transients(AnalysisFeatureList &)
Definition: region.h:302
bool video_locked() const
Definition: region.h:166
RegionEditState _first_edit
Definition: region.h:415
PBD::Property< bool > _sync_marked
Definition: region.h:360
std::list< framepos_t > AnalysisFeatureList
Definition: types.h:530
framecnt_t ancestral_length() const
Definition: region.h:126
LIBARDOUR_API PBD::PropertyDescriptor< float > shift
Definition: region.cc:71
Definition: amp.h:29
bool position_locked() const
Definition: region.h:165
bool muted() const
Definition: region.h:162
LIBARDOUR_API PBD::PropertyDescriptor< bool > locked
Definition: region.cc:51
virtual void add_transient(framepos_t)
Definition: region.h:289
std::vector< boost::shared_ptr< Source > > SourceList
Definition: region.h:91
PBD::EnumProperty< PositionLockStyle > _position_lock_style
Definition: region.h:410
bool automatic() const
Definition: region.h:168
PBD::Property< bool > _opaque
Definition: region.h:397
Evoral::OverlapType coverage(framepos_t start, framepos_t end) const
Definition: region.h:195
LIBARDOUR_API PBD::PropertyDescriptor< bool > opaque
Definition: region.cc:50
uint32_t layer_t
Definition: types.h:59
LIBARDOUR_API void make_property_quarks()
int64_t framepos_t
Definition: types.h:66
LIBARDOUR_API PBD::PropertyDescriptor< bool > external
Definition: region.cc:56
LIBARDOUR_API PBD::PropertyDescriptor< bool > right_of_split
Definition: region.cc:59
int64_t frameoffset_t
Definition: types.h:71
virtual int adjust_transients(frameoffset_t)
Definition: region.h:313
layer_t layer() const
Definition: region.h:115
PositionLockStyle position_lock_style() const
Definition: region.h:178
framepos_t position() const
Definition: region.h:112
Timecode::BBT_Time _bbt_time
Definition: region.h:416
#define LIBARDOUR_API
LIBARDOUR_API PBD::PropertyDescriptor< uint64_t > layering_index
Definition: region.cc:73
virtual void remove_transient(framepos_t)
Definition: region.h:298
const char * name
bool locked() const
Definition: region.h:164
float shift() const
Definition: region.h:129
uint32_t n_channels() const
Definition: region.h:259
Definition: xml++.h:95
DataType _type
Definition: region.h:358
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > ancestral_length
Definition: region.cc:69
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > sync_position
Definition: region.cc:66
uint64_t layering_index() const
Definition: region.h:283
framecnt_t last_length() const
Definition: region.h:123
OverlapType coverage(T sa, T ea, T sb, T eb)
Definition: Range.hpp:40
OverlapType
Definition: Range.hpp:31
LIBARDOUR_API PBD::PropertyDescriptor< bool > sync_marked
Definition: region.cc:57
PBD::Property< float > _shift
Definition: region.h:409
#define lower
Definition: auto_spin.cc:29
bool opaque() const
Definition: region.h:163
framecnt_t length() const
Definition: region.h:114
Evoral::Range< framepos_t > range() const
Definition: region.h:157
bool captured() const
Definition: region.h:170
PositionLockStyle
Definition: types.h:553
framepos_t first_frame() const
Definition: region.h:141
virtual int update_transient(framepos_t, framepos_t)
Definition: region.h:293
PBD::Property< bool > _hidden
Definition: region.h:404
framepos_t start() const
Definition: region.h:113
virtual int get_transients(AnalysisFeatureList &, bool force_new=false)
Definition: region.h:307
framepos_t ancestral_start() const
Definition: region.h:125
LIBARDOUR_API PBD::PropertyDescriptor< PositionLockStyle > position_lock_style
Definition: region.cc:72
bool sync_marked() const
Definition: region.h:172
PBD::Property< framecnt_t > _ancestral_length
Definition: region.h:407
static PBD::Signal2< void, boost::shared_ptr< ARDOUR::Region >, const PBD::PropertyChange & > RegionPropertyChanged
Definition: region.h:95
LIBARDOUR_API PBD::PropertyDescriptor< bool > valid_transients
Definition: region.cc:62
PBD::Property< uint64_t > _layering_index
Definition: region.h:411
LIBARDOUR_API PBD::PropertyDescriptor< bool > muted
Definition: region.cc:49
LIBARDOUR_API PBD::PropertyDescriptor< bool > position_locked
Definition: region.cc:61
LIBARDOUR_API PBD::PropertyDescriptor< bool > whole_file
Definition: region.cc:54
PBD::Property< bool > _video_locked
Definition: region.h:399
float stretch() const
Definition: region.h:128
PBD::Property< bool > _import
Definition: region.h:402
LIBARDOUR_API PBD::PropertyDescriptor< bool > left_of_split
Definition: region.cc:58
framecnt_t _last_length
Definition: region.h:413
boost::shared_ptr< ARDOUR::Playlist > playlist() const
Definition: region.h:251
boost::weak_ptr< ARDOUR::Playlist > _playlist
Definition: region.h:376
PBD::Property< framepos_t > _position
Definition: region.h:366
PBD::Property< framecnt_t > _length
Definition: region.h:365
framepos_t last_frame() const
Definition: region.h:142
LIBARDOUR_API PBD::PropertyDescriptor< framecnt_t > length
Definition: region.cc:64
bool hidden() const
Definition: region.h:161