54bd9defe240c9a43af4afa94ab72fd4a21f6f6b
[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/types.h"
23 #include "ardour/chan_count.h"
24 #include "ardour/processor.h"
25 #include "ardour/automation_control.h"
26
27 namespace ARDOUR {
28
29 class BufferSet;
30 class IO;
31 class MuteMaster;
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 Amp : public Processor {
37 public:
38         Amp(Session& s, boost::shared_ptr<MuteMaster> m);
39
40         std::string display_name() const;
41
42         bool visible () const;
43
44         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const;
45         bool configure_io (ChanCount in, ChanCount out);
46
47         void run (BufferSet& bufs, sframes_t start_frame, sframes_t end_frame, nframes_t nframes, bool);
48
49         bool apply_gain() const  { return _apply_gain; }
50         void apply_gain(bool yn) { _apply_gain = yn; }
51
52         void setup_gain_automation (sframes_t start_frame, sframes_t end_frame, nframes_t nframes);
53
54         bool apply_gain_automation() const  { return _apply_gain_automation; }
55         void apply_gain_automation(bool yn) { _apply_gain_automation = yn; }
56
57         XMLNode& state (bool full);
58         int set_state (const XMLNode&, int version);
59
60         static void apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t target);
61         static void apply_simple_gain(BufferSet& bufs, nframes_t nframes, gain_t target);
62
63         gain_t         gain () const { return _gain_control->user_float(); }
64
65         virtual void   set_gain (gain_t g, void *src);
66         void           inc_gain (gain_t delta, void *src);
67
68         static void update_meters();
69
70         /* automation */
71
72         struct GainControl : public AutomationControl {
73                 GainControl (std::string name, Session& session, Amp* a, const Evoral::Parameter &param,
74                                 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>() )
75                         : AutomationControl (session, param, al, name)
76                         , _amp (a) {
77                         set_flags (Controllable::Flag (flags() | Controllable::GainLike));
78                 }
79
80                 void set_value (float val);
81                 float get_value (void) const;
82
83                 Amp* _amp;
84         };
85
86         boost::shared_ptr<GainControl> gain_control() {
87                 return _gain_control;
88         }
89
90         boost::shared_ptr<const GainControl> gain_control() const {
91                 return _gain_control;
92         }
93
94 private:
95         bool   _denormal_protection;
96         bool   _apply_gain;
97         bool   _apply_gain_automation;
98         float  _current_gain;
99
100         boost::shared_ptr<GainControl> _gain_control;
101         boost::shared_ptr<MuteMaster>  _mute_master;
102 };
103
104
105 } // namespace ARDOUR
106
107 #endif // __ardour_amp_h__