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.
21 #ifndef __ardour_audio_region_h__
22 #define __ardour_audio_region_h__
26 #include <pbd/fastlog.h>
29 #include <ardour/ardour.h>
30 #include <ardour/region.h>
31 #include <ardour/gain.h>
32 #include <ardour/logcurve.h>
33 #include <ardour/export.h>
45 struct AudioRegionState : public RegionState
47 AudioRegionState (std::string why);
52 gain_t _scale_amplitude;
53 uint32_t _fade_in_disabled;
54 uint32_t _fade_out_disabled;
57 class AudioRegion : public Region
60 static Change FadeInChanged;
61 static Change FadeOutChanged;
62 static Change FadeInActiveChanged;
63 static Change FadeOutActiveChanged;
64 static Change EnvelopeActiveChanged;
65 static Change ScaleAmplitudeChanged;
66 static Change EnvelopeChanged;
70 bool speed_mismatch (float) const;
72 boost::shared_ptr<AudioSource> audio_source (uint32_t n=0) const;
74 void set_scale_amplitude (gain_t);
75 gain_t scale_amplitude() const { return _scale_amplitude; }
77 void normalize_to (float target_in_dB = 0.0f);
79 bool envelope_active () const { return _flags & Region::EnvelopeActive; }
80 bool fade_in_active () const { return _flags & Region::FadeIn; }
81 bool fade_out_active () const { return _flags & Region::FadeOut; }
83 Curve& fade_in() { return _fade_in; }
84 Curve& fade_out() { return _fade_out; }
85 Curve& envelope() { return _envelope; }
87 jack_nframes_t read_peaks (PeakData *buf, jack_nframes_t npeaks,
88 jack_nframes_t offset, jack_nframes_t cnt,
89 uint32_t chan_n=0, double samples_per_unit= 1.0) const;
91 virtual jack_nframes_t read_at (Sample *buf, Sample *mixdown_buf,
92 float *gain_buf, jack_nframes_t position, jack_nframes_t cnt,
94 jack_nframes_t read_frames = 0,
95 jack_nframes_t skip_frames = 0) const;
97 jack_nframes_t master_read_at (Sample *buf, Sample *mixdown_buf, float *gain_buf,
98 jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n=0) const;
100 XMLNode& state (bool);
101 int set_state (const XMLNode&);
103 static void set_default_fade (float steepness, jack_nframes_t len);
113 void set_fade_in_active (bool yn);
114 void set_fade_in_shape (FadeShape);
115 void set_fade_in_length (jack_nframes_t);
116 void set_fade_in (FadeShape, jack_nframes_t);
118 void set_fade_out_active (bool yn);
119 void set_fade_out_shape (FadeShape);
120 void set_fade_out_length (jack_nframes_t);
121 void set_fade_out (FadeShape, jack_nframes_t);
123 void set_envelope_active (bool yn);
125 int separate_by_channel (ARDOUR::Session&, vector<AudioRegion*>&) const;
127 UndoAction get_memento() const;
131 int apply (AudioFilter&);
135 int exportme (ARDOUR::Session&, ARDOUR::AudioExportSpecification&);
137 /* xfade/fade interactions */
139 void suspend_fade_in ();
140 void suspend_fade_out ();
141 void resume_fade_in ();
142 void resume_fade_out ();
145 friend class RegionFactory;
147 AudioRegion (boost::shared_ptr<AudioSource>, jack_nframes_t start, jack_nframes_t length);
148 AudioRegion (boost::shared_ptr<AudioSource>, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
149 AudioRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
150 AudioRegion (boost::shared_ptr<const AudioRegion>, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags);
151 AudioRegion (boost::shared_ptr<const AudioRegion>);
152 AudioRegion (boost::shared_ptr<AudioSource>, const XMLNode&);
153 AudioRegion (SourceList &, const XMLNode&);
156 void set_default_fades ();
157 void set_default_fade_in ();
158 void set_default_fade_out ();
159 void set_default_envelope ();
161 StateManager::State* state_factory (std::string why) const;
162 Change restore_state (StateManager::State&);
164 void recompute_gain_at_end ();
165 void recompute_gain_at_start ();
167 jack_nframes_t _read_at (const SourceList&, Sample *buf, Sample *mixdown_buffer,
168 float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt,
170 jack_nframes_t read_frames = 0,
171 jack_nframes_t skip_frames = 0) const;
173 void recompute_at_start ();
174 void recompute_at_end ();
176 void envelope_changed (Change);
177 void source_offset_changed ();
179 mutable Curve _fade_in;
180 FadeShape _fade_in_shape;
181 mutable Curve _fade_out;
182 FadeShape _fade_out_shape;
183 mutable Curve _envelope;
184 gain_t _scale_amplitude;
185 uint32_t _fade_in_disabled;
186 uint32_t _fade_out_disabled;
189 } /* namespace ARDOUR */
191 /* access from C objects */
194 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);
195 uint32_t region_length_from_c (void *arg);
196 uint32_t sourcefile_length_from_c (void *arg, double);
199 #endif /* __ardour_audio_region_h__ */