Ardour  9.10
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  void copy_plugin_state (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 
112  Evoral::ControlList& waveform_envelope () { return _waveform_envelope; }
113  uint64_t envelope_timestamp () { return _envelope_timestamp; }
114  void set_waveform_envelope_enabled (bool state);
115 
117 
119  samplecnt_t offset, samplecnt_t cnt,
120  uint32_t chan_n=0, double samples_per_pixel = 1.0) const;
121 
123  samplecnt_t offset, samplecnt_t cnt) const;
124 
125  /* AudioReadable interface */
126 
127  samplecnt_t read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const;
128  samplecnt_t readable_length_samples() const { return length_samples(); }
129  uint32_t n_channels() const { return _sources.size(); }
130 
132  Sample* mixdown_buf,
133  gain_t* gain_buf,
135  samplecnt_t cnt,
136  uint32_t chan_n = 0) const;
137 
140  samplecnt_t cnt,
141  uint32_t chan_n=0) const;
142 
144 
145  XMLNode& state () const;
147  int set_state (const XMLNode&, int version);
148 
150 
151  bool fade_in_is_default () const;
152  bool fade_out_is_default () const;
155 
156  void set_fade_in_active (bool yn);
160  void set_fade_in (std::shared_ptr<AutomationList>);
161 
162  void set_fade_out_active (bool yn);
166  void set_fade_out (std::shared_ptr<AutomationList>);
167 
170 
172 
173  void set_envelope_active (bool yn);
175 
176  void set_fade_before_fx (bool yn);
177 
179 
180  int separate_by_channel (std::vector<std::shared_ptr<Region> >&) const;
181 
182  bool remove_plugin (std::shared_ptr<RegionFxPlugin>);
184 
185  timecnt_t tail () const;
186 
187  /* automation */
188 
189  std::shared_ptr<Evoral::Control>
190  control(const Evoral::Parameter& id, bool create=false) {
191  return _automatable.control(id, create);
192  }
193 
194  virtual std::shared_ptr<const Evoral::Control>
195  control(const Evoral::Parameter& id) const {
196  return _automatable.control(id);
197  }
198 
199  /* export */
200 
201  bool do_export (std::string const&) const;
202 
203  /* xfade/fade interactions */
204 
207  void resume_fade_in ();
209 
215  void update_transient (samplepos_t old_position, samplepos_t new_position);
216 
218 
219  private:
220  friend class RegionFactory;
221 
222  AudioRegion (std::shared_ptr<AudioSource>);
224  AudioRegion (std::shared_ptr<const AudioRegion>);
225  AudioRegion (std::shared_ptr<const AudioRegion>, timecnt_t const & offset);
226  AudioRegion (std::shared_ptr<const AudioRegion>, const SourceList&);
228 
229  private:
230  friend class ::AudioRegionReadTest;
231  friend class ::PlaylistReadTest;
232 
234 
243 
246 
247  void init ();
249 
252 
254 
257 
265 
266 
275 
276  /* waveform_envelope is a copy of _envelope's ControlList:
277  * when drawing waveforms it is faster to use this instead of
278  * waiting for a read lock on the region that might be held by the butler
279  * (especially if the read cache duration is high)
280  */
285 
286  std::shared_ptr<ARDOUR::Region> get_single_other_xfade_region (bool start) const;
287 
289  void fx_latency_changed (bool no_emit);
290  void fx_tail_changed (bool no_emit);
291 
294  mutable bool _fx_latent_read;
295 
302  mutable std::atomic<bool> _invalidated;
303 
304  protected:
305  /* default constructor for derived (compound) types */
306 
307  AudioRegion (Session& s, timepos_t const &, timecnt_t const &, std::string name);
308 
309  bool _add_plugin (std::shared_ptr<RegionFxPlugin>, std::shared_ptr<RegionFxPlugin>, bool);
310 
311  int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
314 };
315 
316 } /* namespace ARDOUR */
317 
318 /* access from C objects */
319 
320 extern "C" {
321  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);
322  LIBARDOUR_API uint32_t region_length_from_c (void *arg);
323  LIBARDOUR_API uint32_t sourcefile_length_from_c (void *arg, double);
324 }
325 
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)
void read_waveform_envelope(gain_t *buf, samplecnt_t npoints, samplecnt_t offset, samplecnt_t cnt) const
bool fade_before_fx() const
Definition: audioregion.h:104
timecnt_t tail() const
AutomationListProperty _inverse_fade_in
Definition: audioregion.h:268
Automatable _automatable
Definition: audioregion.h:272
PBD::Property< bool > _default_fade_out
Definition: audioregion.h:237
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:298
samplecnt_t readable_length_samples() const
Definition: audioregion.h:128
bool fade_out_active() const
Definition: audioregion.h:103
uint64_t _envelope_timestamp
Definition: audioregion.h:282
virtual std::shared_ptr< const Evoral::Control > control(const Evoral::Parameter &id) const
Definition: audioregion.h:195
void set_fade_in(FadeShape, samplecnt_t)
Temporal::timepos_t fade_in_length()
uint32_t n_channels() const
Definition: audioregion.h:129
uint32_t _fade_out_suspended
Definition: audioregion.h:274
AudioRegion(const SourceList &)
samplepos_t _cache_start
Definition: audioregion.h:299
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:293
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:238
void add_transient(samplepos_t where)
samplecnt_t _cache_tail
Definition: audioregion.h:301
bool fade_in_is_default() const
int set_state(const XMLNode &, int version)
AutomationListProperty _inverse_fade_out
Definition: audioregion.h:270
Evoral::ControlList _waveform_envelope
Definition: audioregion.h:281
XMLNode & state() const
void copy_plugin_state(std::shared_ptr< const AudioRegion >)
PBD::Property< bool > _envelope_active
Definition: audioregion.h:235
void recompute_gain_at_end()
double maximum_amplitude(PBD::Progress *p=0) const
PBD::Property< gain_t > _scale_amplitude
Definition: audioregion.h:242
samplepos_t _fx_pos
Definition: audioregion.h:292
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
PBD::Mutex _cache_lock
Definition: audioregion.h:297
void update_transient(samplepos_t old_position, samplepos_t new_position)
void set_fade_out_active(bool yn)
bool speed_mismatch(float) const
void move_automation_to_new_start()
XMLNode & get_basic_state() const
PBD::Mutex _read_lock
Definition: audioregion.h:296
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:267
PBD::Property< bool > _default_fade_in
Definition: audioregion.h:236
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:269
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:302
PBD::Property< bool > _fade_before_fx
Definition: audioregion.h:240
samplepos_t _cache_end
Definition: audioregion.h:300
uint64_t envelope_timestamp()
Definition: audioregion.h:113
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:271
PBD::Mutex _waveform_lock
Definition: audioregion.h:284
void set_fade_out_shape(FadeShape)
void set_fade_out_length(samplecnt_t)
Temporal::timepos_t fade_out_length()
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:190
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:239
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_waveform_envelope_enabled(bool state)
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)
static void make_property_quarks()
bool _waveform_envelope_enabled
Definition: audioregion.h:283
void post_set(const PBD::PropertyChange &)
void set_fade_in(std::shared_ptr< AutomationList >)
void set_scale_amplitude(gain_t)
Evoral::ControlList & waveform_envelope()
Definition: audioregion.h:112
void copy_settings(std::shared_ptr< const AudioRegion >)
uint32_t _fade_in_suspended
Definition: audioregion.h:273
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