2 Copyright (C) 2000 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_overlap_h__
21 #define __ardour_overlap_h__
25 #include <boost/shared_ptr.hpp>
27 #include <sigc++/signal.h>
30 #include <pbd/statefuldestructible.h>
32 #include <ardour/ardour.h>
33 #include <ardour/audioregion.h>
34 #include <ardour/crossfade_compare.h>
35 #include <evoral/Curve.hpp>
42 class Crossfade : public ARDOUR::AudioRegion
46 class NoCrossfadeHere: std::exception {
48 virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
51 /* constructor for "fixed" xfades at each end of an internal overlap */
53 Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out,
55 nframes_t initial_length,
58 /* constructor for xfade between two regions that are overlapped in any way
59 except the "internal" case.
62 Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out, CrossfadeModel, bool active);
65 /* copy constructor to copy a crossfade with new regions. used (for example)
66 when a playlist copy is made
68 Crossfade (boost::shared_ptr<Crossfade>, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
70 /* the usual XML constructor */
72 Crossfade (const Playlist&, XMLNode&);
75 bool operator== (const ARDOUR::Crossfade&);
77 XMLNode& get_state (void);
78 int set_state (const XMLNode&);
80 boost::shared_ptr<ARDOUR::AudioRegion> in() const { return _in; }
81 boost::shared_ptr<ARDOUR::AudioRegion> out() const { return _out; }
83 nframes_t read_at (Sample *buf, Sample *mixdown_buffer,
84 float *gain_buffer, nframes_t position, nframes_t cnt,
86 nframes_t read_frames = 0,
87 nframes_t skip_frames = 0) const;
91 uint32_t upper_layer () const {
92 return std::max (_in->layer(), _out->layer());
95 uint32_t lower_layer () const {
96 return std::min (_in->layer(), _out->layer());
99 bool involves (boost::shared_ptr<ARDOUR::AudioRegion> region) const {
100 return _in == region || _out == region;
103 bool involves (boost::shared_ptr<ARDOUR::AudioRegion> a, boost::shared_ptr<ARDOUR::AudioRegion> b) const {
104 return (_in == a && _out == b) || (_in == b && _out == a);
107 nframes_t overlap_length() const;
111 sigc::signal<void,boost::shared_ptr<Region> > Invalidated;
112 sigc::signal<void,Change> StateChanged;
114 bool covers (nframes_t frame) const {
115 return _position <= frame && frame < _position + _length;
118 OverlapType coverage (nframes_t start, nframes_t end) const;
120 static void set_buffer_size (nframes_t);
122 bool active () const { return _active; }
123 void set_active (bool yn);
125 bool following_overlap() const { return _follow_overlap; }
126 bool can_follow_overlap() const;
127 void set_follow_overlap (bool yn);
129 AutomationList& fade_in() { return _fade_in; }
130 AutomationList& fade_out() { return _fade_out; }
132 nframes_t set_length (nframes_t);
134 bool is_dependent() const { return true; }
135 bool depends_on (boost::shared_ptr<Region> other) const {
136 return other == _in || other == _out;
139 static nframes_t short_xfade_length() { return _short_xfade_length; }
140 static void set_short_xfade_length (nframes_t n);
142 static Change ActiveChanged;
143 static Change FollowOverlapChanged;
146 friend struct CrossfadeComparePtr;
147 friend class AudioPlaylist;
149 static nframes_t _short_xfade_length;
151 boost::shared_ptr<ARDOUR::AudioRegion> _in;
152 boost::shared_ptr<ARDOUR::AudioRegion> _out;
155 OverlapType overlap_type;
156 AnchorPoint _anchor_point;
157 bool _follow_overlap;
159 int32_t layer_relation;
162 mutable AutomationList _fade_in;
163 mutable AutomationList _fade_out;
165 static Sample* crossfade_buffer_out;
166 static Sample* crossfade_buffer_in;
169 int compute (boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>, CrossfadeModel);
173 nframes_t read_raw_internal (Sample*, nframes_t, nframes_t) const;
177 } // namespace ARDOUR
179 #endif /* __ardour_overlap_h__ */