2 Copyright (C) 2006 Paul Davis
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)
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
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.
19 #ifndef __ardour_amp_h__
20 #define __ardour_amp_h__
22 #include "ardour/dB.h"
23 #include "ardour/libardour_visibility.h"
24 #include "ardour/types.h"
25 #include "ardour/chan_count.h"
26 #include "ardour/processor.h"
27 #include "ardour/automation_control.h"
34 /** Applies a declick operation to all audio inputs, passing the same number of
35 * audio outputs, and passing through any other types unchanged.
37 class LIBARDOUR_API Amp : public Processor {
39 Amp(Session& s, std::string type = "amp");
41 std::string display_name () const { return _display_name; }
42 void set_display_name (const std::string& name) { _display_name = name; }
44 std::string type() const { return _type;}
46 bool visible () const;
48 bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
49 bool configure_io (ChanCount in, ChanCount out);
51 void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
53 bool apply_gain () const { return _apply_gain; }
54 void apply_gain (bool yn) { _apply_gain = yn; }
56 void set_gain_automation_buffer (gain_t *);
58 void setup_gain_automation (framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
60 bool apply_gain_automation() const { return _apply_gain_automation; }
61 void apply_gain_automation(bool yn) { _apply_gain_automation = yn; }
63 XMLNode& state (bool full);
64 int set_state (const XMLNode&, int version);
66 static gain_t apply_gain (BufferSet& bufs, framecnt_t sample_rate, framecnt_t nframes, gain_t initial, gain_t target, bool midi_amp = true);
67 static void apply_simple_gain(BufferSet& bufs, framecnt_t nframes, gain_t target, bool midi_amp = true);
69 static gain_t apply_gain (AudioBuffer& buf, framecnt_t sample_rate, framecnt_t nframes, gain_t initial, gain_t target);
70 static void apply_simple_gain(AudioBuffer& buf, framecnt_t nframes, gain_t target);
72 static void declick (BufferSet& bufs, framecnt_t nframes, int dir);
74 gain_t gain () const { return _gain_control->get_value(); }
76 void set_gain (gain_t g, void *src);
77 void inc_gain (gain_t delta, void *src);
79 static void update_meters();
83 struct GainControl : public AutomationControl {
84 GainControl (std::string name, Session& session, Amp* a, const Evoral::Parameter ¶m,
85 boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>() )
86 : AutomationControl (session, param, ParameterDescriptor(param), al, name)
88 set_flags (Controllable::Flag (flags() | Controllable::GainLike));
89 alist()->reset_default (1.0);
91 lower_db = accurate_coefficient_to_dB (_desc.lower);
92 range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
95 void set_value (double val);
96 void set_value_unchecked (double);
98 double internal_to_interface (double) const;
99 double interface_to_internal (double) const;
100 double internal_to_user (double) const;
101 double user_to_internal (double) const;
102 std::string get_user_string () const;
109 boost::shared_ptr<GainControl> gain_control() {
110 return _gain_control;
113 boost::shared_ptr<const GainControl> gain_control() const {
114 return _gain_control;
117 std::string value_as_string (boost::shared_ptr<AutomationControl>) const;
120 bool _denormal_protection;
122 bool _apply_gain_automation;
124 framepos_t _current_automation_frame;
126 std::string _display_name;
128 boost::shared_ptr<GainControl> _gain_control;
130 /** Buffer that we should use for gain automation */
131 gain_t* _gain_automation_buffer;
137 } // namespace ARDOUR
139 #endif // __ardour_amp_h__