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>
29 #include "pbd/statefuldestructible.h"
31 #include "ardour/ardour.h"
32 #include "ardour/audioregion.h"
33 #include "evoral/Curve.hpp"
36 namespace Properties {
37 /* "active" is defined elsewhere but we use it with crossfade also */
38 extern PBD::PropertyDescriptor<bool> active;
39 extern PBD::PropertyDescriptor<bool> follow_overlap;
50 class Crossfade : public ARDOUR::AudioRegion
54 class NoCrossfadeHere: std::exception {
56 virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
59 /* constructor for "fixed" xfades at each end of an internal overlap */
61 Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out,
62 framecnt_t initial_length,
65 /* constructor for xfade between two regions that are overlapped in any way
66 except the "internal" case.
69 Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out, CrossfadeModel, bool active);
72 /* copy constructor to copy a crossfade with new regions. used (for example)
73 when a playlist copy is made
75 Crossfade (boost::shared_ptr<Crossfade>, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
77 /* the usual XML constructor */
79 Crossfade (const Playlist&, XMLNode const &);
82 static void make_property_quarks ();
84 XMLNode& get_state (void);
85 int set_state (const XMLNode&, int version);
87 boost::shared_ptr<ARDOUR::AudioRegion> in() const { return _in; }
88 boost::shared_ptr<ARDOUR::AudioRegion> out() const { return _out; }
90 framecnt_t read_at (Sample *buf, Sample *mixdown_buffer,
91 float *gain_buffer, framepos_t position, framecnt_t cnt,
92 uint32_t chan_n) const;
96 uint32_t upper_layer () const {
97 return std::max (_in->layer(), _out->layer());
100 uint32_t lower_layer () const {
101 return std::min (_in->layer(), _out->layer());
104 bool involves (boost::shared_ptr<ARDOUR::AudioRegion> region) const {
105 return _in == region || _out == region;
108 bool involves (boost::shared_ptr<ARDOUR::AudioRegion> a, boost::shared_ptr<ARDOUR::AudioRegion> b) const {
109 return (_in == a && _out == b) || (_in == b && _out == a);
112 framecnt_t overlap_length() const;
114 PBD::Signal1<void,boost::shared_ptr<Region> > Invalidated;
116 OverlapType coverage (framepos_t start, framepos_t end) const;
118 static void set_buffer_size (framecnt_t);
120 bool active () const { return _active; }
121 void set_active (bool yn);
123 bool following_overlap() const { return _follow_overlap; }
124 bool can_follow_overlap() const;
125 void set_follow_overlap (bool yn);
127 AutomationList& fade_in() { return _fade_in; }
128 AutomationList& fade_out() { return _fade_out; }
130 framecnt_t set_xfade_length (framecnt_t);
132 bool is_dependent() const { return true; }
133 bool depends_on (boost::shared_ptr<Region> other) const {
134 return other == _in || other == _out;
137 static framecnt_t short_xfade_length() { return _short_xfade_length; }
138 static void set_short_xfade_length (framecnt_t n);
140 /** emitted when the actual fade curves change, as opposed to one of the Stateful properties */
141 PBD::Signal0<void> FadesChanged;
144 friend struct CrossfadeComparePtr;
145 friend class AudioPlaylist;
147 static framecnt_t _short_xfade_length;
149 boost::shared_ptr<ARDOUR::AudioRegion> _in;
150 boost::shared_ptr<ARDOUR::AudioRegion> _out;
151 PBD::Property<bool> _active;
152 PBD::Property<bool> _follow_overlap;
154 OverlapType overlap_type;
155 AnchorPoint _anchor_point;
157 int32_t layer_relation;
160 mutable AutomationList _fade_in;
161 mutable AutomationList _fade_out;
163 static Sample* crossfade_buffer_out;
164 static Sample* crossfade_buffer_in;
167 void register_properties ();
168 int compute (boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>, CrossfadeModel);
171 bool operator== (const ARDOUR::Crossfade&);
174 framecnt_t read_raw_internal (Sample*, framepos_t, framecnt_t, int) const;
178 } // namespace ARDOUR
180 #endif /* __ardour_overlap_h__ */