2 Copyright (C) 2006-2016 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.
21 #include "pbd/convert.h"
22 #include "pbd/strsplit.h"
24 #include "evoral/Curve.hpp"
26 #include "ardour/dB.h"
27 #include "ardour/gain_control.h"
28 #include "ardour/session.h"
29 #include "ardour/vca.h"
30 #include "ardour/vca_manager.h"
34 using namespace ARDOUR;
37 GainControl::GainControl (Session& session, const Evoral::Parameter ¶m, boost::shared_ptr<AutomationList> al)
38 : SlavableAutomationControl (session, param, ParameterDescriptor(param),
39 al ? al : boost::shared_ptr<AutomationList> (new AutomationList (param)),
40 param.type() == GainAutomation ? X_("gaincontrol") : X_("trimcontrol"),
41 Controllable::GainLike)
43 alist()->reset_default (1.0);
45 lower_db = accurate_coefficient_to_dB (_desc.lower);
46 range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
50 GainControl::internal_to_interface (double v) const
52 if (_desc.type == GainAutomation) {
53 return gain_to_slider_position (v);
55 return (accurate_coefficient_to_dB (v) - lower_db) / range_db;
60 GainControl::interface_to_internal (double v) const
62 if (_desc.type == GainAutomation) {
63 return slider_position_to_gain (v);
65 return dB_to_coefficient (lower_db + v * range_db);
70 GainControl::internal_to_user (double v) const
72 return accurate_coefficient_to_dB (v);
76 GainControl::user_to_internal (double u) const
78 return dB_to_coefficient (u);
82 GainControl::get_user_string () const
84 char theBuf[32]; sprintf( theBuf, _("%3.1f dB"), accurate_coefficient_to_dB (get_value()));
85 return std::string(theBuf);
89 GainControl::inc_gain (gain_t factor)
91 /* To be used ONLY when doing group-relative gain adjustment, from
92 * ControlGroup::set_group_values().
95 const float desired_gain = get_value ();
97 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
98 // really?! what's the idea here?
99 actually_set_value (0.000001f + (0.000001f * factor), Controllable::ForGroup);
101 actually_set_value (desired_gain + (desired_gain * factor), Controllable::ForGroup);
106 GainControl::post_add_master (boost::shared_ptr<AutomationControl> m)
108 if (m->get_value() == 0) {
109 /* master is at -inf, which forces this ctrl to -inf on assignment */
110 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
115 GainControl::get_masters_curve_locked (framepos_t start, framepos_t end, float* vec, framecnt_t veclen) const
117 if (_masters.empty()) {
118 return list()->curve().rt_safe_get_vector (start, end, vec, veclen);
120 for (framecnt_t i = 0; i < veclen; ++i) {
123 return SlavableAutomationControl::masters_curve_multiply (start, end, vec, veclen);