Merge branch 'master' into cairocanvas
[ardour.git] / libs / ardour / ardour / amp.h
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_amp_h__
20 #define __ardour_amp_h__
21
22 #include "ardour/libardour_visibility.h"
23 #include "ardour/types.h"
24 #include "ardour/chan_count.h"
25 #include "ardour/processor.h"
26 #include "ardour/automation_control.h"
27
28 namespace ARDOUR {
29
30 class BufferSet;
31 class IO;
32
33 /** Applies a declick operation to all audio inputs, passing the same number of
34  * audio outputs, and passing through any other types unchanged.
35  */
36 class LIBARDOUR_API Amp : public Processor {
37 public:
38         Amp(Session& s);
39
40         std::string display_name() const;
41
42         bool visible () const;
43
44         bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
45         bool configure_io (ChanCount in, ChanCount out);
46
47         void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
48
49         bool apply_gain () const  { return _apply_gain; }
50         void apply_gain (bool yn) { _apply_gain = yn; }
51
52         void set_gain_automation_buffer (gain_t *);
53
54         void setup_gain_automation (framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
55
56         bool apply_gain_automation() const  { return _apply_gain_automation; }
57         void apply_gain_automation(bool yn) { _apply_gain_automation = yn; }
58
59         XMLNode& state (bool full);
60         int set_state (const XMLNode&, int version);
61
62         static void apply_gain (BufferSet& bufs, framecnt_t nframes, gain_t initial, gain_t target);
63         static void apply_simple_gain(BufferSet& bufs, framecnt_t nframes, gain_t target);
64
65         static void apply_gain (AudioBuffer& buf, framecnt_t nframes, gain_t initial, gain_t target);
66         static void apply_simple_gain(AudioBuffer& buf, framecnt_t nframes, gain_t target);
67
68         static void declick (BufferSet& bufs, framecnt_t nframes, int dir);
69
70         gain_t         gain () const { return _gain_control->get_value(); }
71
72         void           set_gain (gain_t g, void *src);
73         void           inc_gain (gain_t delta, void *src);
74
75         static void update_meters();
76
77         /* automation */
78
79         struct GainControl : public AutomationControl {
80                 GainControl (std::string name, Session& session, Amp* a, const Evoral::Parameter &param,
81                                 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>() )
82                         : AutomationControl (session, param, al, name)
83                         , _amp (a) {
84                         set_flags (Controllable::Flag (flags() | Controllable::GainLike));
85                         alist()->reset_default (1.0);
86                 }
87
88                 void set_value (double val);
89
90                 double internal_to_interface (double) const;
91                 double interface_to_internal (double) const;
92                 double internal_to_user (double) const;
93
94                 Amp* _amp;
95         };
96
97         boost::shared_ptr<GainControl> gain_control() {
98                 return _gain_control;
99         }
100
101         boost::shared_ptr<const GainControl> gain_control() const {
102                 return _gain_control;
103         }
104
105         std::string value_as_string (boost::shared_ptr<AutomationControl>) const;
106
107         static const float max_gain_coefficient;
108
109 private:
110         bool   _denormal_protection;
111         bool   _apply_gain;
112         bool   _apply_gain_automation;
113         float  _current_gain;
114
115         boost::shared_ptr<GainControl> _gain_control;
116
117         /** Buffer that we should use for gain automation */
118         gain_t* _gain_automation_buffer;
119 };
120
121
122 } // namespace ARDOUR
123
124 #endif // __ardour_amp_h__