monitor section: make sip/afl/pfl buttons work, add rude solo, mono function, rearrange
[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 AudioRegion;
44 class Playlist;
45
46 class Crossfade : public ARDOUR::AudioRegion
47 {
48   public:
49
50         class NoCrossfadeHere: std::exception {
51         public:
52                 virtual const char *what() const throw() { return "no crossfade should be constructed here"; }
53         };
54
55         /* constructor for "fixed" xfades at each end of an internal overlap */
56
57         Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out,
58                    framepos_t position,
59                    framecnt_t initial_length,
60                    AnchorPoint);
61
62         /* constructor for xfade between two regions that are overlapped in any way
63            except the "internal" case.
64         */
65
66         Crossfade (boost::shared_ptr<ARDOUR::AudioRegion> in, boost::shared_ptr<ARDOUR::AudioRegion> out, CrossfadeModel, bool active);
67
68
69         /* copy constructor to copy a crossfade with new regions. used (for example)
70            when a playlist copy is made
71         */
72         Crossfade (boost::shared_ptr<Crossfade>, boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>);
73
74         /* the usual XML constructor */
75
76         Crossfade (const Playlist&, XMLNode&);
77         virtual ~Crossfade();
78
79         static void make_property_quarks ();
80
81         bool operator== (const ARDOUR::Crossfade&);
82
83         XMLNode& get_state (void);
84         int set_state (const XMLNode&, int version);
85
86         boost::shared_ptr<ARDOUR::AudioRegion> in() const { return _in; }
87         boost::shared_ptr<ARDOUR::AudioRegion> out() const { return _out; }
88
89         framecnt_t read_at (Sample *buf, Sample *mixdown_buffer,
90                             float *gain_buffer, framepos_t position, framecnt_t cnt,
91                             uint32_t chan_n,
92                             framecnt_t read_frames = 0,
93                             framecnt_t skip_frames = 0) const;
94
95         bool refresh ();
96
97         uint32_t upper_layer () const {
98                 return std::max (_in->layer(), _out->layer());
99         }
100
101         uint32_t lower_layer () const {
102                 return std::min (_in->layer(), _out->layer());
103         }
104
105         bool involves (boost::shared_ptr<ARDOUR::AudioRegion> region) const {
106                 return _in == region || _out == region;
107         }
108
109         bool involves (boost::shared_ptr<ARDOUR::AudioRegion> a, boost::shared_ptr<ARDOUR::AudioRegion> b) const {
110                 return (_in == a && _out == b) || (_in == b && _out == a);
111         }
112
113         framecnt_t overlap_length() const;
114
115         PBD::Signal1<void,boost::shared_ptr<Region> > Invalidated;
116
117         bool covers (framecnt_t frame) const {
118                 return _position <= frame && frame < _position + _length;
119         }
120
121         OverlapType coverage (framepos_t start, framepos_t end) const;
122
123         static void set_buffer_size (framecnt_t);
124
125         bool active () const { return _active; }
126         void set_active (bool yn);
127
128         bool following_overlap() const { return _follow_overlap; }
129         bool can_follow_overlap() const;
130         void set_follow_overlap (bool yn);
131
132         AutomationList& fade_in() { return _fade_in; }
133         AutomationList& fade_out() { return _fade_out; }
134
135         framecnt_t set_xfade_length (framecnt_t);
136
137         bool is_dependent() const { return true; }
138         bool depends_on (boost::shared_ptr<Region> other) const {
139                 return other == _in || other == _out;
140         }
141
142         static framecnt_t short_xfade_length() { return _short_xfade_length; }
143         static void set_short_xfade_length (framecnt_t n);
144
145   private:
146         friend struct CrossfadeComparePtr;
147         friend class AudioPlaylist;
148
149         static framecnt_t _short_xfade_length;
150
151         boost::shared_ptr<ARDOUR::AudioRegion> _in;
152         boost::shared_ptr<ARDOUR::AudioRegion> _out;
153         PBD::Property<bool>  _active;
154         PBD::Property<bool>  _follow_overlap;
155         bool                 _in_update;
156         OverlapType           overlap_type;
157         AnchorPoint          _anchor_point;
158         bool                 _fixed;
159         int32_t               layer_relation;
160
161
162         mutable AutomationList _fade_in;
163         mutable AutomationList _fade_out;
164
165         static Sample* crossfade_buffer_out;
166         static Sample* crossfade_buffer_in;
167
168         void initialize ();
169         int  compute (boost::shared_ptr<ARDOUR::AudioRegion>, boost::shared_ptr<ARDOUR::AudioRegion>, CrossfadeModel);
170         bool update ();
171
172   protected:
173         framecnt_t read_raw_internal (Sample*, framepos_t, framecnt_t, int) const;
174 };
175
176
177 } // namespace ARDOUR
178
179 #endif /* __ardour_overlap_h__ */