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"
37 class AudioRegionReadTest;
38 class PlaylistReadTest;
42 namespace Properties {
43 LIBARDOUR_API extern PBD::PropertyDescriptor<bool> envelope_active;
44 LIBARDOUR_API extern PBD::PropertyDescriptor<bool> default_fade_in;
45 LIBARDOUR_API extern PBD::PropertyDescriptor<bool> default_fade_out;
46 LIBARDOUR_API extern PBD::PropertyDescriptor<bool> fade_in_active;
47 LIBARDOUR_API extern PBD::PropertyDescriptor<bool> fade_out_active;
48 LIBARDOUR_API extern PBD::PropertyDescriptor<float> scale_amplitude;
49 LIBARDOUR_API extern PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > fade_in;
50 LIBARDOUR_API extern PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > inverse_fade_in;
51 LIBARDOUR_API extern PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > fade_out;
52 LIBARDOUR_API extern PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > inverse_fade_out;
53 LIBARDOUR_API extern PBD::PropertyDescriptor<boost::shared_ptr<AutomationList> > envelope;
62 class LIBARDOUR_API AudioRegion : public Region
65 static void make_property_quarks ();
69 void copy_settings (boost::shared_ptr<const AudioRegion>);
71 bool source_equivalent (boost::shared_ptr<const Region>) const;
73 bool speed_mismatch (float) const;
75 boost::shared_ptr<AudioSource> audio_source (uint32_t n=0) const;
77 void set_scale_amplitude (gain_t);
78 gain_t scale_amplitude() const { return _scale_amplitude; }
80 void normalize (float, float target_in_dB = 0.0f);
81 double maximum_amplitude (Progress* p = 0) const;
83 bool envelope_active () const { return _envelope_active; }
84 bool fade_in_active () const { return _fade_in_active; }
85 bool fade_out_active () const { return _fade_out_active; }
87 boost::shared_ptr<AutomationList> fade_in() { return _fade_in.val (); }
88 boost::shared_ptr<AutomationList> inverse_fade_in() { return _inverse_fade_in.val (); }
89 boost::shared_ptr<AutomationList> fade_out() { return _fade_out.val (); }
90 boost::shared_ptr<AutomationList> inverse_fade_out() { return _inverse_fade_out.val (); }
91 boost::shared_ptr<AutomationList> envelope() { return _envelope.val (); }
93 Evoral::Range<framepos_t> body_range () const;
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 frames_per_pixel = 1.0) const;
99 /* Readable interface */
101 virtual framecnt_t read (Sample*, framepos_t pos, framecnt_t cnt, int channel) const;
102 virtual framecnt_t readable_length() const { return length(); }
104 virtual framecnt_t read_at (Sample *buf, Sample *mixdown_buf, float *gain_buf,
107 uint32_t chan_n = 0) const;
109 virtual framecnt_t master_read_at (Sample *buf, Sample *mixdown_buf, float *gain_buf,
110 framepos_t position, framecnt_t cnt, uint32_t chan_n=0) const;
112 virtual framecnt_t read_raw_internal (Sample*, framepos_t, framecnt_t, int channel) const;
115 XMLNode& get_basic_state ();
116 int set_state (const XMLNode&, int version);
118 bool fade_in_is_default () const;
119 bool fade_out_is_default () const;
121 void set_fade_in_active (bool yn);
122 void set_fade_in_shape (FadeShape);
123 void set_fade_in_length (framecnt_t);
124 void set_fade_in (FadeShape, framecnt_t);
125 void set_fade_in (boost::shared_ptr<AutomationList>);
127 void set_fade_out_active (bool yn);
128 void set_fade_out_shape (FadeShape);
129 void set_fade_out_length (framecnt_t);
130 void set_fade_out (FadeShape, framecnt_t);
131 void set_fade_out (boost::shared_ptr<AutomationList>);
133 void set_default_fade_in ();
134 void set_default_fade_out ();
136 framecnt_t verify_xfade_bounds (framecnt_t, bool start);
138 void set_envelope_active (bool yn);
139 void set_default_envelope ();
141 int separate_by_channel (ARDOUR::Session&, std::vector<boost::shared_ptr<Region> >&) const;
145 boost::shared_ptr<Evoral::Control>
146 control(const Evoral::Parameter& id, bool create=false) {
147 return _automatable.control(id, create);
150 virtual boost::shared_ptr<const Evoral::Control>
151 control(const Evoral::Parameter& id) const {
152 return _automatable.control(id);
155 /* xfade/fade interactions */
157 void suspend_fade_in ();
158 void suspend_fade_out ();
159 void resume_fade_in ();
160 void resume_fade_out ();
162 void add_transient (framepos_t where);
163 void remove_transient (framepos_t where);
164 int set_transients (AnalysisFeatureList&);
165 int get_transients (AnalysisFeatureList&, bool force_new = false);
166 int update_transient (framepos_t old_position, framepos_t new_position);
167 int adjust_transients (frameoffset_t delta);
169 AudioIntervalResult find_silence (Sample, framecnt_t, InterThreadInfo&) const;
172 friend class RegionFactory;
174 AudioRegion (boost::shared_ptr<AudioSource>);
175 AudioRegion (const SourceList &);
176 AudioRegion (boost::shared_ptr<const AudioRegion>);
177 AudioRegion (boost::shared_ptr<const AudioRegion>, frameoffset_t offset);
178 AudioRegion (boost::shared_ptr<const AudioRegion>, const SourceList&);
179 AudioRegion (SourceList &);
182 friend class ::AudioRegionReadTest;
183 friend class ::PlaylistReadTest;
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 ();
199 void recompute_gain_at_end ();
200 void recompute_gain_at_start ();
202 framecnt_t read_from_sources (SourceList const &, framecnt_t, Sample *, framepos_t, framecnt_t, uint32_t) const;
204 void recompute_at_start ();
205 void recompute_at_end ();
207 void envelope_changed ();
208 void fade_in_changed ();
209 void fade_out_changed ();
210 void source_offset_changed ();
211 void listen_to_my_curves ();
212 void connect_to_analysis_changed ();
213 void connect_to_header_position_offset_changed ();
216 AutomationListProperty _fade_in;
217 AutomationListProperty _inverse_fade_in;
218 AutomationListProperty _fade_out;
219 AutomationListProperty _inverse_fade_out;
220 AutomationListProperty _envelope;
221 Automatable _automatable;
222 uint32_t _fade_in_suspended;
223 uint32_t _fade_out_suspended;
225 boost::shared_ptr<ARDOUR::Region> get_single_other_xfade_region (bool start) const;
228 /* default constructor for derived (compound) types */
230 AudioRegion (Session& s, framepos_t, framecnt_t, std::string name);
232 int _set_state (const XMLNode&, int version, PBD::PropertyChange& what_changed, bool send_signal);
235 } /* namespace ARDOUR */
237 /* access from C objects */
240 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);
241 LIBARDOUR_API uint32_t region_length_from_c (void *arg);
242 LIBARDOUR_API uint32_t sourcefile_length_from_c (void *arg, double);
245 #endif /* __ardour_audio_region_h__ */