Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
24 
25 #include <atomic>
26 #include <vector>
27 #include <list>
28 
29 #include "pbd/fastlog.h"
30 #include "pbd/undo.h"
31 
32 #include "ardour/ardour.h"
33 #include "ardour/automatable.h"
34 #include "ardour/automation_list.h"
35 #include "ardour/buffer_set.h"
37 #include "ardour/logcurve.h"
38 #include "ardour/region.h"
39 
40 class XMLNode;
42 class PlaylistReadTest;
43 
44 namespace ARDOUR {
45 
46 namespace Properties {
59 }
60 
61 class Playlist;
62 class Session;
63 class Filter;
64 class AudioSource;
65 class RegionFxPlugin;
66 class PlugInsertBase;
67 
69 {
70  public:
71  static void make_property_quarks ();
72 
74 
75  void copy_settings (std::shared_ptr<const AudioRegion>);
76 
77  bool source_equivalent (std::shared_ptr<const Region>) const;
78 
79  bool speed_mismatch (float) const;
80 
81  std::shared_ptr<AudioSource> audio_source (uint32_t n=0) const;
82 
84  gain_t scale_amplitude() const { return _scale_amplitude; }
85 
86  void normalize (float, float target_in_dB = 0.0f);
87 
91  double maximum_amplitude (PBD::Progress* p = 0) const;
92 
96  double rms (PBD::Progress* p = 0) const;
97 
98  bool loudness (float& tp, float& i, float& s, float& m, PBD::Progress* p = 0) const;
99 
100  bool envelope_active () const { return _envelope_active; }
101  bool fade_in_active () const { return _fade_in_active; }
102  bool fade_out_active () const { return _fade_out_active; }
103  bool fade_before_fx () const { return _fade_before_fx; }
104 
105  std::shared_ptr<AutomationList> fade_in() { return _fade_in.val (); }
106  std::shared_ptr<AutomationList> inverse_fade_in() { return _inverse_fade_in.val (); }
107  std::shared_ptr<AutomationList> fade_out() { return _fade_out.val (); }
108  std::shared_ptr<AutomationList> inverse_fade_out() { return _inverse_fade_out.val (); }
109  std::shared_ptr<AutomationList> envelope() { return _envelope.val (); }
110 
112 
114  samplecnt_t offset, samplecnt_t cnt,
115  uint32_t chan_n=0, double samples_per_pixel = 1.0) const;
116 
117  /* AudioReadable interface */
118 
119  samplecnt_t read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const;
120  samplecnt_t readable_length_samples() const { return length_samples(); }
121  uint32_t n_channels() const { return _sources.size(); }
122 
124  Sample* mixdown_buf,
125  gain_t* gain_buf,
127  samplecnt_t cnt,
128  uint32_t chan_n = 0) const;
129 
132  samplecnt_t cnt,
133  uint32_t chan_n=0) const;
134 
136 
137  XMLNode& state () const;
139  int set_state (const XMLNode&, int version);
140 
142 
143  bool fade_in_is_default () const;
144  bool fade_out_is_default () const;
145 
146  void set_fade_in_active (bool yn);
150  void set_fade_in (std::shared_ptr<AutomationList>);
151 
152  void set_fade_out_active (bool yn);
156  void set_fade_out (std::shared_ptr<AutomationList>);
157 
160 
162 
163  void set_envelope_active (bool yn);
165 
166  void set_fade_before_fx (bool yn);
167 
168  int separate_by_channel (std::vector<std::shared_ptr<Region> >&) const;
169 
170  bool remove_plugin (std::shared_ptr<RegionFxPlugin>);
172 
173  timecnt_t tail () const;
174 
175  /* automation */
176 
177  std::shared_ptr<Evoral::Control>
178  control(const Evoral::Parameter& id, bool create=false) {
179  return _automatable.control(id, create);
180  }
181 
182  virtual std::shared_ptr<const Evoral::Control>
183  control(const Evoral::Parameter& id) const {
184  return _automatable.control(id);
185  }
186 
187  /* export */
188 
189  bool do_export (std::string const&) const;
190 
191  /* xfade/fade interactions */
192 
195  void resume_fade_in ();
197 
203  void update_transient (samplepos_t old_position, samplepos_t new_position);
204 
206 
207  private:
208  friend class RegionFactory;
209 
210  AudioRegion (std::shared_ptr<AudioSource>);
212  AudioRegion (std::shared_ptr<const AudioRegion>);
213  AudioRegion (std::shared_ptr<const AudioRegion>, timecnt_t const & offset);
214  AudioRegion (std::shared_ptr<const AudioRegion>, const SourceList&);
216 
217  private:
218  friend class ::AudioRegionReadTest;
219  friend class ::PlaylistReadTest;
220 
222 
231 
234 
235  void init ();
237 
240 
242 
245 
253 
254 
263 
264  std::shared_ptr<ARDOUR::Region> get_single_other_xfade_region (bool start) const;
265 
267  void fx_latency_changed (bool no_emit);
268  void fx_tail_changed (bool no_emit);
269  void copy_plugin_state (std::shared_ptr<const AudioRegion>);
270 
273  mutable bool _fx_latent_read;
274 
275  mutable Glib::Threads::Mutex _cache_lock;
280  mutable std::atomic<bool> _invalidated;
281 
282  protected:
283  /* default constructor for derived (compound) types */
284 
285  AudioRegion (Session& s, timepos_t const &, timecnt_t const &, std::string name);
286 
287  bool _add_plugin (std::shared_ptr<RegionFxPlugin>, std::shared_ptr<RegionFxPlugin>, bool);
288 
289  int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
291 };
292 
293 } /* namespace ARDOUR */
294 
295 /* access from C objects */
296 
297 extern "C" {
298  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);
299  LIBARDOUR_API uint32_t region_length_from_c (void *arg);
300  LIBARDOUR_API uint32_t sourcefile_length_from_c (void *arg, double);
301 }
302 
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:103
timecnt_t tail() const
AutomationListProperty _inverse_fade_in
Definition: audioregion.h:256
Automatable _automatable
Definition: audioregion.h:260
PBD::Property< bool > _default_fade_out
Definition: audioregion.h:225
std::shared_ptr< AutomationList > fade_in()
Definition: audioregion.h:105
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:276
samplecnt_t readable_length_samples() const
Definition: audioregion.h:120
bool fade_out_active() const
Definition: audioregion.h:102
virtual std::shared_ptr< const Evoral::Control > control(const Evoral::Parameter &id) const
Definition: audioregion.h:183
void set_fade_in(FadeShape, samplecnt_t)
uint32_t n_channels() const
Definition: audioregion.h:121
uint32_t _fade_out_suspended
Definition: audioregion.h:262
AudioRegion(const SourceList &)
samplepos_t _cache_start
Definition: audioregion.h:277
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:109
std::shared_ptr< AudioSource > audio_source(uint32_t n=0) const
pframes_t _fx_block_size
Definition: audioregion.h:272
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:226
void add_transient(samplepos_t where)
samplecnt_t _cache_tail
Definition: audioregion.h:279
bool fade_in_is_default() const
int set_state(const XMLNode &, int version)
AutomationListProperty _inverse_fade_out
Definition: audioregion.h:258
XMLNode & state() const
void copy_plugin_state(std::shared_ptr< const AudioRegion >)
PBD::Property< bool > _envelope_active
Definition: audioregion.h:223
void recompute_gain_at_end()
double maximum_amplitude(PBD::Progress *p=0) const
PBD::Property< gain_t > _scale_amplitude
Definition: audioregion.h:230
samplepos_t _fx_pos
Definition: audioregion.h:271
void reorder_plugins(RegionFxList const &)
void recompute_gain_at_start()
bool fade_in_active() const
Definition: audioregion.h:101
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:255
PBD::Property< bool > _default_fade_in
Definition: audioregion.h:224
gain_t scale_amplitude() const
Definition: audioregion.h:84
AudioRegion(std::shared_ptr< AudioSource >)
bool do_export(std::string const &) const
std::shared_ptr< AutomationList > inverse_fade_in()
Definition: audioregion.h:106
AutomationListProperty _fade_out
Definition: audioregion.h:257
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:280
PBD::Property< bool > _fade_before_fx
Definition: audioregion.h:228
samplepos_t _cache_end
Definition: audioregion.h:278
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:259
void set_fade_out_shape(FadeShape)
void set_fade_out_length(samplecnt_t)
std::shared_ptr< AutomationList > fade_out()
Definition: audioregion.h:107
std::shared_ptr< Evoral::Control > control(const Evoral::Parameter &id, bool create=false)
Definition: audioregion.h:178
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:227
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:108
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:100
void fx_latency_changed(bool no_emit)
Glib::Threads::Mutex _cache_lock
Definition: audioregion.h:275
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:261
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