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.
21 #ifndef __ardour_overlap_h__
22 #define __ardour_overlap_h__
27 #include <sigc++/signal.h>
31 #include <ardour/ardour.h>
32 #include <ardour/curve.h>
33 #include <ardour/audioregion.h>
34 #include <ardour/state_manager.h>
35 #include <ardour/crossfade_compare.h>
42 struct CrossfadeState : public StateManager::State {
43 CrossfadeState (std::string reason) : StateManager::State (reason) {}
45 UndoAction fade_in_memento;
46 UndoAction fade_out_memento;
47 jack_nframes_t position;
48 jack_nframes_t length;
49 AnchorPoint anchor_point;
54 class Crossfade : public Stateful, public StateManager
58 class NoCrossfadeHere: std::exception {
60 virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
63 /* constructor for "fixed" xfades at each end of an internal overlap */
65 Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out,
66 jack_nframes_t position,
67 jack_nframes_t initial_length,
70 /* constructor for xfade between two regions that are overlapped in any way
71 except the "internal" case.
74 Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, CrossfadeModel, bool active);
76 /* the usual XML constructor */
78 Crossfade (const ARDOUR::Playlist&, XMLNode&);
81 bool operator== (const ARDOUR::Crossfade&);
83 XMLNode& get_state (void);
84 int set_state (const XMLNode&);
86 ARDOUR::AudioRegion& in() const { return *_in; }
87 ARDOUR::AudioRegion& out() const { return *_out; }
89 jack_nframes_t read_at (Sample *buf, Sample *mixdown_buffer,
90 float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt,
92 jack_nframes_t read_frames = 0,
93 jack_nframes_t skip_frames = 0);
97 uint32_t upper_layer () const {
98 return std::max (_in->layer(), _out->layer());
101 uint32_t lower_layer () const {
102 return std::min (_in->layer(), _out->layer());
105 bool involves (ARDOUR::AudioRegion& region) const {
106 return _in == ®ion || _out == ®ion;
109 bool involves (ARDOUR::AudioRegion& a, ARDOUR::AudioRegion& b) const {
110 return (_in == &a && _out == &b) || (_in == &b && _out == &a);
113 jack_nframes_t length() const { return _length; }
114 jack_nframes_t overlap_length() const;
115 jack_nframes_t position() const { return _position; }
117 sigc::signal<void,Crossfade*> Invalidated;
118 sigc::signal<void> GoingAway;
120 bool covers (jack_nframes_t frame) const {
121 return _position <= frame && frame < _position + _length;
124 OverlapType coverage (jack_nframes_t start, jack_nframes_t end) const;
126 UndoAction get_memento() const;
128 static void set_buffer_size (jack_nframes_t);
130 bool active () const { return _active; }
131 void set_active (bool yn);
133 bool following_overlap() const { return _follow_overlap; }
134 bool can_follow_overlap() const;
135 void set_follow_overlap (bool yn);
137 Curve& fade_in() { return _fade_in; }
138 Curve& fade_out() { return _fade_out; }
140 jack_nframes_t set_length (jack_nframes_t);
142 static jack_nframes_t short_xfade_length() { return _short_xfade_length; }
143 static void set_short_xfade_length (jack_nframes_t n);
145 static Change ActiveChanged;
148 friend struct CrossfadeComparePtr;
150 static jack_nframes_t _short_xfade_length;
152 ARDOUR::AudioRegion* _in;
153 ARDOUR::AudioRegion* _out;
156 OverlapType overlap_type;
157 jack_nframes_t _length;
158 jack_nframes_t _position;
159 AnchorPoint _anchor_point;
160 bool _follow_overlap;
165 static Sample* crossfade_buffer_out;
166 static Sample* crossfade_buffer_in;
168 void initialize (bool savestate=true);
169 int compute (ARDOUR::AudioRegion&, ARDOUR::AudioRegion&, CrossfadeModel);
170 bool update (bool force);
172 StateManager::State* state_factory (std::string why) const;
173 Change restore_state (StateManager::State&);
175 void member_changed (ARDOUR::Change);
180 } // namespace ARDOUR
182 #endif /* __ardour_overlap_h__ */