Fix more broken whitespace.
[ardour.git] / libs / ardour / ardour / crossfade.h
1 /*
2     Copyright (C) 2000 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_overlap_h__
21 #define __ardour_overlap_h__
22
23 #include <vector>
24 #include <algorithm>
25 #include <boost/shared_ptr.hpp>
26
27
28 #include "pbd/undo.h"
29 #include "pbd/statefuldestructible.h"
30
31 #include "ardour/ardour.h"
32 #include "ardour/audioregion.h"
33 #include "ardour/crossfade_compare.h"
34 #include "evoral/Curve.hpp"
35
36 namespace ARDOUR {
37         namespace Properties {
38                 /* "active" is defined elsewhere but we use it with crossfade also */
39                 extern PBD::PropertyDescriptor<bool> active;
40                 extern PBD::PropertyDescriptor<bool> follow_overlap;
41         }
42
43 class Playlist;
44
45 class Crossfade : public ARDOUR::AudioRegion
46 {
47   public:
48
49         class NoCrossfadeHere: std::exception {
50         public:
51                 virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
52         };
53
54         /* constructor for "fixed" xfades at each end of an internal overlap */
55
56         Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out,
57                    framepos_t position,
58                    framecnt_t initial_length,
59                    AnchorPoint);
60
61         /* constructor for xfade between two regions that are overlapped in any way
62            except the "internal" case.
63         */
64
65         Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out, CrossfadeModel, bool active);
66
67
68         /* copy constructor to copy a crossfade with new regions. used (for example)
69            when a playlist copy is made
70         */
71         Crossfade (boost::shared_ptr<Crossfade>, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
72
73         /* the usual XML constructor */
74
75         Crossfade (const Playlist&, XMLNode const &);
76         virtual ~Crossfade();
77
78         static void make_property_quarks ();
79
80         bool operator== (const ARDOUR::Crossfade&);
81
82         XMLNode& get_state (void);
83         int set_state (const XMLNode&, int version);
84
85         boost::shared_ptr<ARDOUR::AudioRegion> in() const { return _in; }
86         boost::shared_ptr<ARDOUR::AudioRegion> out() const { return _out; }
87
88         framecnt_t read_at (Sample *buf, Sample *mixdown_buffer,
89                             float *gain_buffer, framepos_t position, framecnt_t cnt,
90                             uint32_t chan_n,
91                             framecnt_t read_frames = 0,
92                             framecnt_t skip_frames = 0) const;
93
94         bool refresh ();
95
96         uint32_t upper_layer () const {
97                 return std::max (_in->layer(), _out->layer());
98         }
99
100         uint32_t lower_layer () const {
101                 return std::min (_in->layer(), _out->layer());
102         }
103
104         bool involves (boost::shared_ptr<ARDOUR::AudioRegion> region) const {
105                 return _in == region || _out == region;
106         }
107
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);
110         }
111
112         framecnt_t overlap_length() const;
113
114         PBD::Signal1<void,boost::shared_ptr<Region> > Invalidated;
115
116         bool covers (framepos_t frame) const {
117                 return _position <= frame && frame < _position + _length;
118         }
119
120         OverlapType coverage (framepos_t start, framepos_t end) const;
121
122         static void set_buffer_size (framecnt_t);
123
124         bool active () const { return _active; }
125         void set_active (bool yn);
126
127         bool following_overlap() const { return _follow_overlap; }
128         bool can_follow_overlap() const;
129         void set_follow_overlap (bool yn);
130
131         AutomationList& fade_in() { return _fade_in; }
132         AutomationList& fade_out() { return _fade_out; }
133
134         framecnt_t set_xfade_length (framecnt_t);
135
136         bool is_dependent() const { return true; }
137         bool depends_on (boost::shared_ptr<Region> other) const {
138                 return other == _in || other == _out;
139         }
140
141         static framecnt_t short_xfade_length() { return _short_xfade_length; }
142         static void set_short_xfade_length (framecnt_t n);
143
144         /** emitted when the actual fade curves change, as opposed to one of the Stateful properties */
145         PBD::Signal0<void> FadesChanged;
146
147   private:
148         friend struct CrossfadeComparePtr;
149         friend class AudioPlaylist;
150
151         static framecnt_t _short_xfade_length;
152
153         boost::shared_ptr<ARDOUR::AudioRegion> _in;
154         boost::shared_ptr<ARDOUR::AudioRegion> _out;
155         PBD::Property<bool>  _active;
156         PBD::Property<bool>  _follow_overlap;
157         bool                 _in_update;
158         OverlapType           overlap_type;
159         AnchorPoint          _anchor_point;
160         bool                 _fixed;
161         int32_t               layer_relation;
162
163
164         mutable AutomationList _fade_in;
165         mutable AutomationList _fade_out;
166
167         static Sample* crossfade_buffer_out;
168         static Sample* crossfade_buffer_in;
169
170         void initialize ();
171         int  compute (boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>, CrossfadeModel);
172         bool update ();
173
174   protected:
175         framecnt_t read_raw_internal (Sample*, framepos_t, framecnt_t, int) const;
176 };
177
178
179 } // namespace ARDOUR
180
181 #endif /* __ardour_overlap_h__ */