ardour
amp.h
Go to the documentation of this file.
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/dB.h"
24 #include "ardour/types.h"
25 #include "ardour/chan_count.h"
26 #include "ardour/processor.h"
28 
29 namespace ARDOUR {
30 
31 class BufferSet;
32 class IO;
33 
37 class LIBARDOUR_API Amp : public Processor {
38 public:
39  Amp(Session& s, std::string type = "amp");
40 
41  std::string display_name() const;
42 
43  bool visible () const;
44 
45  bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
46  bool configure_io (ChanCount in, ChanCount out);
47 
48  void run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool);
49 
50  bool apply_gain () const { return _apply_gain; }
51  void apply_gain (bool yn) { _apply_gain = yn; }
52 
53  void set_gain_automation_buffer (gain_t *);
54 
55  void setup_gain_automation (framepos_t start_frame, framepos_t end_frame, framecnt_t nframes);
56 
57  bool apply_gain_automation() const { return _apply_gain_automation; }
58  void apply_gain_automation(bool yn) { _apply_gain_automation = yn; }
59 
60  XMLNode& state (bool full);
61  int set_state (const XMLNode&, int version);
62 
63  static gain_t apply_gain (BufferSet& bufs, framecnt_t sample_rate, framecnt_t nframes, gain_t initial, gain_t target, bool midi_amp = true);
64  static void apply_simple_gain(BufferSet& bufs, framecnt_t nframes, gain_t target, bool midi_amp = true);
65 
66  static gain_t apply_gain (AudioBuffer& buf, framecnt_t sample_rate, framecnt_t nframes, gain_t initial, gain_t target);
67  static void apply_simple_gain(AudioBuffer& buf, framecnt_t nframes, gain_t target);
68 
69  static void declick (BufferSet& bufs, framecnt_t nframes, int dir);
70 
71  gain_t gain () const { return _gain_control->get_value(); }
72 
73  void set_gain (gain_t g, void *src);
74  void inc_gain (gain_t delta, void *src);
75 
76  static void update_meters();
77 
78  /* automation */
79 
80  struct GainControl : public AutomationControl {
81  GainControl (std::string name, Session& session, Amp* a, const Evoral::Parameter &param,
83  : AutomationControl (session, param, ParameterDescriptor(param), al, name)
84  , _amp (a) {
85  set_flags (Controllable::Flag (flags() | Controllable::GainLike));
86  alist()->reset_default (1.0);
87 
88  lower_db = accurate_coefficient_to_dB (_desc.lower);
89  range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
90  }
91 
92  void set_value (double val);
93 
94  double internal_to_interface (double) const;
95  double interface_to_internal (double) const;
96  double internal_to_user (double) const;
97  double user_to_internal (double) const;
98  std::string get_user_string () const;
99 
101  double lower_db;
102  double range_db;
103  };
104 
106  return _gain_control;
107  }
108 
110  return _gain_control;
111  }
112 
114 
115 private:
121 
123 
126  std::string _type;
127  bool _midi_amp;
128 };
129 
130 
131 } // namespace ARDOUR
132 
133 #endif // __ardour_amp_h__
void apply_gain(bool yn)
Definition: amp.h:51
bool _apply_gain
Definition: amp.h:117
bool _denormal_protection
Definition: amp.h:116
bool _apply_gain_automation
Definition: amp.h:118
boost::shared_ptr< GainControl > _gain_control
Definition: amp.h:122
bool apply_gain_automation() const
Definition: amp.h:57
gain_t * _gain_automation_buffer
Definition: amp.h:125
bool apply_gain() const
Definition: amp.h:50
std::string value_as_string(const ARDOUR::ParameterDescriptor &desc, double v)
gain_t gain() const
Definition: amp.h:71
uint32_t pframes_t
Definition: types.h:61
float gain_t
Definition: types.h:58
static float accurate_coefficient_to_dB(float coeff)
Definition: dB.h:38
GainControl(std::string name, Session &session, Amp *a, const Evoral::Parameter &param, boost::shared_ptr< AutomationList > al=boost::shared_ptr< AutomationList >())
Definition: amp.h:81
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
int64_t framepos_t
Definition: types.h:66
framepos_t _current_automation_frame
Definition: amp.h:120
#define LIBARDOUR_API
float _current_gain
Definition: amp.h:119
const char * name
boost::shared_ptr< GainControl > gain_control()
Definition: amp.h:105
Definition: xml++.h:95
bool _midi_amp
Definition: amp.h:127
std::string _type
Definition: amp.h:126
void apply_gain_automation(bool yn)
Definition: amp.h:58
Definition: io.h:67
boost::shared_ptr< const GainControl > gain_control() const
Definition: amp.h:109