2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
20 #ifndef __ardour_audio_region_h__
21 #define __ardour_audio_region_h__
26 #include "pbd/fastlog.h"
29 #include "ardour/ardour.h"
30 #include "ardour/automatable.h"
31 #include "ardour/automation_list.h"
32 #include "ardour/interthread_info.h"
33 #include "ardour/logcurve.h"
34 #include "ardour/region.h"
41 namespace Properties {
42 extern PBD::PropertyDescriptor<bool> envelope_active;
43 extern PBD::PropertyDescriptor<bool> default_fade_in;
44 extern PBD::PropertyDescriptor<bool> default_fade_out;
45 extern PBD::PropertyDescriptor<bool> fade_in_active;
46 extern PBD::PropertyDescriptor<bool> fade_out_active;
47 extern PBD::PropertyDescriptor<float> scale_amplitude;
49 /* the envelope and fades are not scalar items and so
50 currently (2010/02) are not stored using Property.
51 However, these descriptors enable us to notify
52 about changes to them via PropertyChange.
55 extern PBD::PropertyDescriptor<bool> envelope;
56 extern PBD::PropertyDescriptor<bool> fade_in;
57 extern PBD::PropertyDescriptor<bool> fade_out;
66 class AudioRegion : public Region
69 static void make_property_quarks ();
73 void copy_settings (boost::shared_ptr<const AudioRegion>);
75 bool source_equivalent (boost::shared_ptr<const Region>) const;
77 bool speed_mismatch (float) const;
79 boost::shared_ptr<AudioSource> audio_source (uint32_t n=0) const;
81 void set_scale_amplitude (gain_t);
82 gain_t scale_amplitude() const { return _scale_amplitude; }
84 void normalize (float, float target_in_dB = 0.0f);
85 double maximum_amplitude (Progress* p = 0) const;
87 bool envelope_active () const { return _envelope_active; }
88 bool fade_in_active () const { return _fade_in_active; }
89 bool fade_out_active () const { return _fade_out_active; }
91 boost::shared_ptr<AutomationList> fade_in() { return _fade_in; }
92 boost::shared_ptr<AutomationList> fade_out() { return _fade_out; }
93 boost::shared_ptr<AutomationList> envelope() { return _envelope; }
95 virtual framecnt_t read_peaks (PeakData *buf, framecnt_t npeaks,
96 framecnt_t offset, framecnt_t cnt,
97 uint32_t chan_n=0, double samples_per_unit= 1.0) const;
99 /* Readable interface */
103 ReadOpsOwnAutomation = 0x1,
104 ReadOpsOwnScaling = 0x2,
108 virtual framecnt_t read (Sample*, framepos_t pos, framecnt_t cnt, int channel) const;
109 virtual framecnt_t readable_length() const { return length(); }
111 virtual framecnt_t read_at (Sample *buf, Sample *mixdown_buf, float *gain_buf,
114 uint32_t chan_n = 0) const;
116 virtual framecnt_t master_read_at (Sample *buf, Sample *mixdown_buf, float *gain_buf,
117 framepos_t position, framecnt_t cnt, uint32_t chan_n=0) const;
119 virtual framecnt_t read_raw_internal (Sample*, framepos_t, framecnt_t, int channel) const;
122 int set_state (const XMLNode&, int version);
124 static void set_default_fade (float steepness, framecnt_t len);
125 bool fade_in_is_default () const;
126 bool fade_out_is_default () const;
128 void set_fade_in_active (bool yn);
129 void set_fade_in_shape (FadeShape);
130 void set_fade_in_length (framecnt_t);
131 void set_fade_in (FadeShape, framecnt_t);
132 void set_fade_in (boost::shared_ptr<AutomationList>);
134 void set_fade_out_active (bool yn);
135 void set_fade_out_shape (FadeShape);
136 void set_fade_out_length (framecnt_t);
137 void set_fade_out (FadeShape, framecnt_t);
138 void set_fade_out (boost::shared_ptr<AutomationList>);
140 void set_envelope_active (bool yn);
141 void set_default_envelope ();
143 int separate_by_channel (ARDOUR::Session&, std::vector<boost::shared_ptr<Region> >&) const;
147 boost::shared_ptr<Evoral::Control>
148 control(const Evoral::Parameter& id, bool create=false) {
149 return _automatable.control(id, create);
152 virtual boost::shared_ptr<const Evoral::Control>
153 control(const Evoral::Parameter& id) const {
154 return _automatable.control(id);
157 /* xfade/fade interactions */
159 void suspend_fade_in ();
160 void suspend_fade_out ();
161 void resume_fade_in ();
162 void resume_fade_out ();
164 void add_transient (framepos_t where);
165 void remove_transient (framepos_t where);
166 int set_transients (AnalysisFeatureList&);
167 int get_transients (AnalysisFeatureList&, bool force_new = false);
168 int update_transient (framepos_t old_position, framepos_t new_position);
169 int adjust_transients (framepos_t delta);
171 AudioIntervalResult find_silence (Sample, framecnt_t, InterThreadInfo&) const;
174 friend class RegionFactory;
175 friend class Crossfade;
177 AudioRegion (boost::shared_ptr<AudioSource>);
178 AudioRegion (const SourceList &);
179 AudioRegion (boost::shared_ptr<const AudioRegion>);
180 AudioRegion (boost::shared_ptr<const AudioRegion>, frameoffset_t offset);
181 AudioRegion (boost::shared_ptr<const AudioRegion>, const SourceList&);
182 AudioRegion (SourceList &);
185 PBD::Property<bool> _envelope_active;
186 PBD::Property<bool> _default_fade_in;
187 PBD::Property<bool> _default_fade_out;
188 PBD::Property<bool> _fade_in_active;
189 PBD::Property<bool> _fade_out_active;
190 /** linear gain to apply to the whole region */
191 PBD::Property<gain_t> _scale_amplitude;
193 void register_properties ();
194 void post_set (const PBD::PropertyChange&);
197 void set_default_fades ();
198 void set_default_fade_in ();
199 void set_default_fade_out ();
201 void recompute_gain_at_end ();
202 void recompute_gain_at_start ();
204 framecnt_t _read_at (const SourceList&, framecnt_t limit,
205 Sample *buf, Sample *mixdown_buffer, float *gain_buffer,
206 framepos_t position, framecnt_t cnt,
208 ReadOps readops = ReadOps (~0)) const;
210 void recompute_at_start ();
211 void recompute_at_end ();
213 void envelope_changed ();
214 void fade_in_changed ();
215 void fade_out_changed ();
216 void source_offset_changed ();
217 void listen_to_my_curves ();
218 void connect_to_analysis_changed ();
219 void connect_to_header_position_offset_changed ();
221 Automatable _automatable;
223 boost::shared_ptr<AutomationList> _fade_in;
224 boost::shared_ptr<AutomationList> _fade_out;
225 boost::shared_ptr<AutomationList> _envelope;
226 uint32_t _fade_in_suspended;
227 uint32_t _fade_out_suspended;
230 /* default constructor for derived (compound) types */
232 AudioRegion (Session& s, framepos_t, framecnt_t, std::string name);
234 int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
237 } /* namespace ARDOUR */
239 /* access from C objects */
242 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);
243 uint32_t region_length_from_c (void *arg);
244 uint32_t sourcefile_length_from_c (void *arg, double);
247 #endif /* __ardour_audio_region_h__ */