2 Copyright (C) 2000-2001 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/source.h>
31 #include <ardour/gain.h>
32 #include <ardour/region.h>
33 #include <ardour/export.h>
44 struct AudioRegionState : public RegionState
46 AudioRegionState (std::string why);
51 gain_t _scale_amplitude;
52 uint32_t _fade_in_disabled;
53 uint32_t _fade_out_disabled;
56 class AudioRegion : public Region
59 typedef vector<Source *> SourceList;
61 static Change FadeInChanged;
62 static Change FadeOutChanged;
63 static Change FadeInActiveChanged;
64 static Change FadeOutActiveChanged;
65 static Change EnvelopeActiveChanged;
66 static Change ScaleAmplitudeChanged;
67 static Change EnvelopeChanged;
69 AudioRegion (Source&, jack_nframes_t start, jack_nframes_t length, bool announce = true);
70 AudioRegion (Source&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
71 AudioRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
72 AudioRegion (const AudioRegion&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true);
73 AudioRegion (const AudioRegion&);
74 AudioRegion (Source&, const XMLNode&);
75 AudioRegion (SourceList &, const XMLNode&);
78 bool region_list_equivalent (const AudioRegion&) const ;
79 bool source_equivalent (const AudioRegion&) const;
80 bool equivalent (const AudioRegion&) const;
81 bool size_equivalent (const AudioRegion&) const;
82 bool overlap_equivalent (const AudioRegion&) const;
84 bool speed_mismatch (float) const;
87 void unlock_sources ();
88 Source& source (uint32_t n=0) const { if (n < sources.size()) return *sources[n]; else return *sources[0]; }
90 void set_scale_amplitude (gain_t);
91 gain_t scale_amplitude() const { return _scale_amplitude; }
93 void normalize_to (float target_in_dB = 0.0f);
95 uint32_t n_channels() { return sources.size(); }
96 vector<string> master_source_names();
98 bool envelope_active () const { return _flags & Region::EnvelopeActive; }
99 bool fade_in_active () const { return _flags & Region::FadeIn; }
100 bool fade_out_active () const { return _flags & Region::FadeOut; }
101 bool captured() const { return !(_flags & (Region::Flag (Region::Import|Region::External))); }
103 Curve& fade_in() { return _fade_in; }
104 Curve& fade_out() { return _fade_out; }
105 Curve& envelope() { return _envelope; }
107 jack_nframes_t read_peaks (PeakData *buf, jack_nframes_t npeaks, jack_nframes_t offset, jack_nframes_t cnt, uint32_t chan_n=0, double samples_per_unit= 1.0) const;
109 virtual jack_nframes_t read_at (Sample *buf, Sample *mixdown_buffer,
110 float *gain_buffer, char * workbuf, jack_nframes_t position, jack_nframes_t cnt,
112 jack_nframes_t read_frames = 0,
113 jack_nframes_t skip_frames = 0) const;
115 jack_nframes_t master_read_at (Sample *buf, Sample *mixdown_buffer,
116 float *gain_buffer, char * workbuf, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n=0) const;
119 XMLNode& state (bool);
120 XMLNode& get_state ();
121 int set_state (const XMLNode&);
123 static void set_default_fade (float steepness, jack_nframes_t len);
134 void set_fade_in_active (bool yn);
135 void set_fade_in_shape (FadeShape);
136 void set_fade_in_length (jack_nframes_t);
137 void set_fade_in (FadeShape, jack_nframes_t);
139 void set_fade_out_active (bool yn);
140 void set_fade_out_shape (FadeShape);
141 void set_fade_out_length (jack_nframes_t);
142 void set_fade_out (FadeShape, jack_nframes_t);
144 void set_envelope_active (bool yn);
146 int separate_by_channel (ARDOUR::Session&, vector<AudioRegion*>&) const;
148 uint32_t read_data_count() const { return _read_data_count; }
150 ARDOUR::Playlist* playlist() const { return _playlist; }
152 UndoAction get_memento() const;
156 int apply (AudioFilter&);
160 int exportme (ARDOUR::Session&, ARDOUR::AudioExportSpecification&);
162 Region* get_parent();
164 /* xfade/fade interactions */
166 void suspend_fade_in ();
167 void suspend_fade_out ();
168 void resume_fade_in ();
169 void resume_fade_out ();
172 friend class Playlist;
176 SourceList master_sources; /* used when timefx are applied, so
177 we can always use the original
180 mutable Curve _fade_in;
181 FadeShape _fade_in_shape;
182 mutable Curve _fade_out;
183 FadeShape _fade_out_shape;
184 mutable Curve _envelope;
185 gain_t _scale_amplitude;
186 uint32_t _fade_in_disabled;
187 uint32_t _fade_out_disabled;
189 void set_default_fades ();
190 void set_default_fade_in ();
191 void set_default_fade_out ();
192 void set_default_envelope ();
194 StateManager::State* state_factory (std::string why) const;
195 Change restore_state (StateManager::State&);
197 void recompute_gain_at_end ();
198 void recompute_gain_at_start ();
200 bool copied() const { return _flags & Copied; }
201 void maybe_uncopy ();
202 void rename_after_first_edit ();
204 jack_nframes_t _read_at (const SourceList&, Sample *buf, Sample *mixdown_buffer,
205 float *gain_buffer, char * workbuf, jack_nframes_t position, jack_nframes_t cnt,
207 jack_nframes_t read_frames = 0,
208 jack_nframes_t skip_frames = 0) const;
210 bool verify_start (jack_nframes_t position);
211 bool verify_length (jack_nframes_t position);
212 bool verify_start_mutable (jack_nframes_t& start);
213 bool verify_start_and_length (jack_nframes_t start, jack_nframes_t length);
214 void recompute_at_start ();
215 void recompute_at_end ();
217 void envelope_changed (Change);
219 void source_deleted (Source*);
222 } /* namespace ARDOUR */
224 /* access from C objects */
227 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);
228 uint32_t region_length_from_c (void *arg);
229 uint32_t sourcefile_length_from_c (void *arg, double);
232 #endif /* __ardour_audio_region_h__ */