Ardour  8.12
audioregion.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __ardour_audio_region_h__
24 #define __ardour_audio_region_h__
25 
26 #include <atomic>
27 #include <vector>
28 #include <list>
29 
30 #include "pbd/fastlog.h"
31 #include "pbd/undo.h"
32 
33 #include "ardour/ardour.h"
34 #include "ardour/automatable.h"
35 #include "ardour/automation_list.h"
36 #include "ardour/buffer_set.h"
38 #include "ardour/logcurve.h"
39 #include "ardour/region.h"
40 
41 class XMLNode;
43 class PlaylistReadTest;
44 
45 namespace ARDOUR {
46 
47 namespace Properties {
60 }
61 
62 class Playlist;
63 class Session;
64 class Filter;
65 class AudioSource;
66 class RegionFxPlugin;
67 class PlugInsertBase;
68 
70 {
71  public:
72  static void make_property_quarks ();
73 
75 
76  void copy_settings (std::shared_ptr<const AudioRegion>);
77 
78  bool source_equivalent (std::shared_ptr<const Region>) const;
79 
80  bool speed_mismatch (float) const;
81 
82  std::shared_ptr<AudioSource> audio_source (uint32_t n=0) const;
83 
85  gain_t scale_amplitude() const { return _scale_amplitude; }
86 
87  void normalize (float, float target_in_dB = 0.0f);
88 
92  double maximum_amplitude (PBD::Progress* p = 0) const;
93 
97  double rms (PBD::Progress* p = 0) const;
98 
99  bool loudness (float& tp, float& i, float& s, float& m, PBD::Progress* p = 0) const;
100 
101  bool envelope_active () const { return _envelope_active; }
102  bool fade_in_active () const { return _fade_in_active; }
103  bool fade_out_active () const { return _fade_out_active; }
104  bool fade_before_fx () const { return _fade_before_fx; }
105 
106  std::shared_ptr<AutomationList> fade_in() { return _fade_in.val (); }
107  std::shared_ptr<AutomationList> inverse_fade_in() { return _inverse_fade_in.val (); }
108  std::shared_ptr<AutomationList> fade_out() { return _fade_out.val (); }
109  std::shared_ptr<AutomationList> inverse_fade_out() { return _inverse_fade_out.val (); }
110  std::shared_ptr<AutomationList> envelope() { return _envelope.val (); }
111 
113 
115  samplecnt_t offset, samplecnt_t cnt,
116  uint32_t chan_n=0, double samples_per_pixel = 1.0) const;
117 
118  /* AudioReadable interface */
119 
120  samplecnt_t read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const;
121  samplecnt_t readable_length_samples() const { return length_samples(); }
122  uint32_t n_channels() const { return _sources.size(); }
123 
125  Sample* mixdown_buf,
126  gain_t* gain_buf,
128  samplecnt_t cnt,
129  uint32_t chan_n = 0) const;
130 
133  samplecnt_t cnt,
134  uint32_t chan_n=0) const;
135 
137 
138  XMLNode& state () const;
140  int set_state (const XMLNode&, int version);
141 
143 
144  bool fade_in_is_default () const;
145  bool fade_out_is_default () const;
146 
147  void set_fade_in_active (bool yn);
151  void set_fade_in (std::shared_ptr<AutomationList>);
152 
153  void set_fade_out_active (bool yn);
157  void set_fade_out (std::shared_ptr<AutomationList>);
158 
161 
163 
164  void set_envelope_active (bool yn);
166 
167  void set_fade_before_fx (bool yn);
168 
169  int separate_by_channel (std::vector<std::shared_ptr<Region> >&) const;
170 
171  bool remove_plugin (std::shared_ptr<RegionFxPlugin>);
173 
174  timecnt_t tail () const;
175 
176  /* automation */
177 
178  std::shared_ptr<Evoral::Control>
179  control(const Evoral::Parameter& id, bool create=false) {
180  return _automatable.control(id, create);
181  }
182 
183  virtual std::shared_ptr<const Evoral::Control>
184  control(const Evoral::Parameter& id) const {
185  return _automatable.control(id);
186  }
187 
188  /* export */
189 
190  bool do_export (std::string const&) const;
191 
192  /* xfade/fade interactions */
193 
196  void resume_fade_in ();
198 
204  void update_transient (samplepos_t old_position, samplepos_t new_position);
205 
207 
208  private:
209  friend class RegionFactory;
210 
211  AudioRegion (std::shared_ptr<AudioSource>);
213  AudioRegion (std::shared_ptr<const AudioRegion>);
214  AudioRegion (std::shared_ptr<const AudioRegion>, timecnt_t const & offset);
215  AudioRegion (std::shared_ptr<const AudioRegion>, const SourceList&);
217 
218  private:
219  friend class ::AudioRegionReadTest;
220  friend class ::PlaylistReadTest;
221 
223 
232 
235 
236  void init ();
238 
241 
243 
246 
254 
255 
264 
265  std::shared_ptr<ARDOUR::Region> get_single_other_xfade_region (bool start) const;
266 
268  void fx_latency_changed (bool no_emit);
269  void fx_tail_changed (bool no_emit);
270  void copy_plugin_state (std::shared_ptr<const AudioRegion>);
271 
274  mutable bool _fx_latent_read;
275 
276  mutable Glib::Threads::Mutex _cache_lock;
281  mutable std::atomic<bool> _invalidated;
282 
283  protected:
284  /* default constructor for derived (compound) types */
285 
286  AudioRegion (Session& s, timepos_t const &, timecnt_t const &, std::string name);
287 
288  bool _add_plugin (std::shared_ptr<RegionFxPlugin>, std::shared_ptr<RegionFxPlugin>, bool);
289 
290  int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
293 };
294 
295 } /* namespace ARDOUR */
296 
297 /* access from C objects */
298 
299 extern "C" {
300  LIBARDOUR_API int region_read_peaks_from_c (void *arg, uint32_t npeaks, uint32_t start, uint32_t length, intptr_t data, uint32_t n_chan, double samples_per_unit);
301  LIBARDOUR_API uint32_t region_length_from_c (void *arg);
302  LIBARDOUR_API uint32_t sourcefile_length_from_c (void *arg, double);
303 }
304 
305 #endif /* __ardour_audio_region_h__ */
uint32_t region_length_from_c(void *arg)
uint32_t sourcefile_length_from_c(void *arg, double)
int region_read_peaks_from_c(void *arg, uint32_t npeaks, uint32_t start, uint32_t length, intptr_t data, uint32_t n_chan, double samples_per_unit)
bool fade_before_fx() const
Definition: audioregion.h:104
timecnt_t tail() const
AutomationListProperty _inverse_fade_in
Definition: audioregion.h:257
Automatable _automatable
Definition: audioregion.h:261
PBD::Property< bool > _default_fade_out
Definition: audioregion.h:226
std::shared_ptr< AutomationList > fade_in()
Definition: audioregion.h:106
samplecnt_t read_from_sources(SourceList const &, samplecnt_t, Sample *, samplepos_t, samplecnt_t, uint32_t) const
bool _add_plugin(std::shared_ptr< RegionFxPlugin >, std::shared_ptr< RegionFxPlugin >, bool)
AudioRegion(SourceList &)
void set_fade_out(FadeShape, samplecnt_t)
void normalize(float, float target_in_dB=0.0f)
BufferSet _readcache
Definition: audioregion.h:277
samplecnt_t readable_length_samples() const
Definition: audioregion.h:121
bool fade_out_active() const
Definition: audioregion.h:103
virtual std::shared_ptr< const Evoral::Control > control(const Evoral::Parameter &id) const
Definition: audioregion.h:184
void set_fade_in(FadeShape, samplecnt_t)
uint32_t n_channels() const
Definition: audioregion.h:122
uint32_t _fade_out_suspended
Definition: audioregion.h:263
AudioRegion(const SourceList &)
samplepos_t _cache_start
Definition: audioregion.h:278
void send_change(const PBD::PropertyChange &)
int separate_by_channel(std::vector< std::shared_ptr< Region > > &) const
bool loudness(float &tp, float &i, float &s, float &m, PBD::Progress *p=0) const
void fx_tail_changed(bool no_emit)
std::shared_ptr< AutomationList > envelope()
Definition: audioregion.h:110
std::shared_ptr< AudioSource > audio_source(uint32_t n=0) const
pframes_t _fx_block_size
Definition: audioregion.h:273
AudioRegion(std::shared_ptr< const AudioRegion >)
void fade_range(samplepos_t, samplepos_t)
void source_offset_changed()
double rms(PBD::Progress *p=0) const
PBD::Property< bool > _fade_in_active
Definition: audioregion.h:227
void add_transient(samplepos_t where)
samplecnt_t _cache_tail
Definition: audioregion.h:280
bool fade_in_is_default() const
int set_state(const XMLNode &, int version)
AutomationListProperty _inverse_fade_out
Definition: audioregion.h:259
XMLNode & state() const
void copy_plugin_state(std::shared_ptr< const AudioRegion >)
PBD::Property< bool > _envelope_active
Definition: audioregion.h:224
void recompute_gain_at_end()
double maximum_amplitude(PBD::Progress *p=0) const
PBD::Property< gain_t > _scale_amplitude
Definition: audioregion.h:231
samplepos_t _fx_pos
Definition: audioregion.h:272
void reorder_plugins(RegionFxList const &)
void recompute_gain_at_start()
bool fade_in_active() const
Definition: audioregion.h:102
bool fade_out_is_default() const
bool source_equivalent(std::shared_ptr< const Region >) const
void update_transient(samplepos_t old_position, samplepos_t new_position)
void set_fade_out_active(bool yn)
bool speed_mismatch(float) const
XMLNode & get_basic_state() const
void set_fade_in_length(samplecnt_t)
void set_fade_before_fx(bool yn)
void connect_to_header_position_offset_changed()
void set_fade_out(std::shared_ptr< AutomationList >)
AutomationListProperty _fade_in
Definition: audioregion.h:256
PBD::Property< bool > _default_fade_in
Definition: audioregion.h:225
gain_t scale_amplitude() const
Definition: audioregion.h:85
AudioRegion(std::shared_ptr< AudioSource >)
bool do_export(std::string const &) const
std::shared_ptr< AutomationList > inverse_fade_in()
Definition: audioregion.h:107
AutomationListProperty _fade_out
Definition: audioregion.h:258
samplecnt_t verify_xfade_bounds(samplecnt_t, bool start)
void get_transients(AnalysisFeatureList &)
AudioIntervalResult find_silence(Sample, samplecnt_t, samplecnt_t, InterThreadInfo &) const
int _set_state(const XMLNode &, int version, PBD::PropertyChange &what_changed, bool send_signal)
std::atomic< bool > _invalidated
Definition: audioregion.h:281
PBD::Property< bool > _fade_before_fx
Definition: audioregion.h:229
samplepos_t _cache_end
Definition: audioregion.h:279
std::shared_ptr< ARDOUR::Region > get_single_other_xfade_region(bool start) const
void set_onsets(AnalysisFeatureList &)
bool remove_plugin(std::shared_ptr< RegionFxPlugin >)
AutomationListProperty _envelope
Definition: audioregion.h:260
void set_fade_out_shape(FadeShape)
void set_fade_out_length(samplecnt_t)
std::shared_ptr< AutomationList > fade_out()
Definition: audioregion.h:108
std::shared_ptr< Evoral::Control > control(const Evoral::Parameter &id, bool create=false)
Definition: audioregion.h:179
AudioRegion(Session &s, timepos_t const &, timecnt_t const &, std::string name)
AudioRegion(std::shared_ptr< const AudioRegion >, const SourceList &)
void remove_transient(samplepos_t where)
Temporal::Range body_range() const
void connect_to_analysis_changed()
samplecnt_t read_raw_internal(Sample *, samplepos_t, samplecnt_t, int channel) const
PBD::Property< bool > _fade_out_active
Definition: audioregion.h:228
samplecnt_t master_read_at(Sample *buf, samplepos_t position, samplecnt_t cnt, uint32_t chan_n=0) const
void set_fade_in_active(bool yn)
void set_fade_in_shape(FadeShape)
std::shared_ptr< AutomationList > inverse_fade_out()
Definition: audioregion.h:109
void set_envelope_active(bool yn)
virtual samplecnt_t read_peaks(PeakData *buf, samplecnt_t npeaks, samplecnt_t offset, samplecnt_t cnt, uint32_t chan_n=0, double samples_per_pixel=1.0) const
samplecnt_t read(Sample *, samplepos_t pos, samplecnt_t cnt, int channel) const
AudioRegion(std::shared_ptr< const AudioRegion >, timecnt_t const &offset)
samplecnt_t read_at(Sample *buf, Sample *mixdown_buf, gain_t *gain_buf, samplepos_t position, samplecnt_t cnt, uint32_t chan_n=0) const
bool envelope_active() const
Definition: audioregion.h:101
void fx_latency_changed(bool no_emit)
Glib::Threads::Mutex _cache_lock
Definition: audioregion.h:276
static void make_property_quarks()
void post_set(const PBD::PropertyChange &)
void set_fade_in(std::shared_ptr< AutomationList >)
void set_scale_amplitude(gain_t)
void copy_settings(std::shared_ptr< const AudioRegion >)
uint32_t _fade_in_suspended
Definition: audioregion.h:262
void apply_region_fx(BufferSet &, samplepos_t, samplepos_t, samplecnt_t)
std::list< std::shared_ptr< RegionFxPlugin > > RegionFxList
std::vector< std::shared_ptr< Source > > SourceList
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< std::shared_ptr< AutomationList > > envelope
PBD::PropertyDescriptor< std::shared_ptr< AutomationList > > fade_out
PBD::PropertyDescriptor< bool > envelope_active
PBD::PropertyDescriptor< bool > fade_out_active
PBD::PropertyDescriptor< bool > default_fade_in
PBD::PropertyDescriptor< std::shared_ptr< AutomationList > > inverse_fade_out
PBD::PropertyDescriptor< timecnt_t > length
PBD::PropertyDescriptor< bool > fade_in_active
PBD::PropertyDescriptor< float > scale_amplitude
PBD::PropertyDescriptor< bool > fade_before_fx
PBD::PropertyDescriptor< timepos_t > start
PBD::PropertyDescriptor< std::shared_ptr< AutomationList > > fade_in
PBD::PropertyDescriptor< bool > default_fade_out
PBD::PropertyDescriptor< std::shared_ptr< AutomationList > > inverse_fade_in
std::list< std::pair< sampleoffset_t, sampleoffset_t > > AudioIntervalResult
std::list< samplepos_t > AnalysisFeatureList
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t
DebugBits Properties