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.
19 #include "ardour/dB.h"
20 #include "ardour/gain_control.h"
21 #include "ardour/session.h"
25 using namespace ARDOUR;
28 GainControl::GainControl (Session& session, const Evoral::Parameter ¶m, boost::shared_ptr<AutomationList> al)
29 : AutomationControl (session, param, ParameterDescriptor(param),
30 al ? al : boost::shared_ptr<AutomationList> (new AutomationList (param)),
31 param.type() == GainAutomation ? X_("gaincontrol") : X_("trimcontrol")) {
33 alist()->reset_default (1.0);
35 lower_db = accurate_coefficient_to_dB (_desc.lower);
36 range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db;
40 GainControl::get_value() const
43 return AutomationControl::get_value();
45 return AutomationControl::get_value() * _master->get_value();
49 GainControl::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
52 _set_value (val, group_override);
57 GainControl::set_value_unchecked (double val)
59 /* used only automation playback */
60 _set_value (val, Controllable::NoGroup);
64 GainControl::_set_value (double val, Controllable::GroupControlDisposition group_override)
66 AutomationControl::set_value (std::max (std::min (val, (double)_desc.upper), (double)_desc.lower), group_override);
67 _session.set_dirty ();
71 GainControl::internal_to_interface (double v) const
73 if (_desc.type == GainAutomation) {
74 return gain_to_slider_position (v);
76 return (accurate_coefficient_to_dB (v) - lower_db) / range_db;
81 GainControl::interface_to_internal (double v) const
83 if (_desc.type == GainAutomation) {
84 return slider_position_to_gain (v);
86 return dB_to_coefficient (lower_db + v * range_db);
91 GainControl::internal_to_user (double v) const
93 return accurate_coefficient_to_dB (v);
97 GainControl::user_to_internal (double u) const
99 return dB_to_coefficient (u);
103 GainControl::get_user_string () const
105 char theBuf[32]; sprintf( theBuf, _("%3.1f dB"), accurate_coefficient_to_dB (get_value()));
106 return std::string(theBuf);
110 GainControl::set_master (boost::shared_ptr<GainControl> m)
112 double old_master_val;
115 old_master_val = _master->get_value();
117 old_master_val = 1.0;
122 double new_master_val;
125 new_master_val = _master->get_value();
127 new_master_val = 1.0;
130 if (old_master_val != new_master_val) {
131 Changed(); /* EMIT SIGNAL */