if a complete refill is called for, DiskReader cannot internal seek
[ardour.git] / libs / ardour / gain_control.cc
1 /*
2  * Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <cmath>
21
22 #include "pbd/convert.h"
23 #include "pbd/strsplit.h"
24
25 #include "evoral/Curve.hpp"
26
27 #include "ardour/dB.h"
28 #include "ardour/gain_control.h"
29 #include "ardour/session.h"
30 #include "ardour/vca.h"
31 #include "ardour/vca_manager.h"
32
33 #include "pbd/i18n.h"
34
35 using namespace ARDOUR;
36 using namespace std;
37
38 GainControl::GainControl (Session& session, const Evoral::Parameter &param, boost::shared_ptr<AutomationList> al)
39         : SlavableAutomationControl (session, param, ParameterDescriptor(param),
40                                      al ? al : boost::shared_ptr<AutomationList> (new AutomationList (param)),
41                                      param.type() == GainAutomation ? X_("gaincontrol") : X_("trimcontrol"),
42                                      Controllable::GainLike)
43 {
44 }
45
46 void
47 GainControl::inc_gain (gain_t factor)
48 {
49         /* To be used ONLY when doing group-relative gain adjustment, from
50          * ControlGroup::set_group_values().
51          */
52
53         const float desired_gain = get_value ();
54
55         if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
56                 // really?! what's the idea here?
57                 actually_set_value (0.000001f + (0.000001f * factor), Controllable::ForGroup);
58         } else {
59                 actually_set_value (desired_gain + (desired_gain * factor), Controllable::ForGroup);
60         }
61 }
62
63 void
64 GainControl::post_add_master (boost::shared_ptr<AutomationControl> m)
65 {
66         if (m->get_value() == 0) {
67                 /* master is at -inf, which forces this ctrl to -inf on assignment */
68                 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
69         }
70 }
71
72 bool
73 GainControl::get_masters_curve_locked (samplepos_t start, samplepos_t end, float* vec, samplecnt_t veclen) const
74 {
75         if (_masters.empty()) {
76                 return list()->curve().rt_safe_get_vector (start, end, vec, veclen);
77         }
78         for (samplecnt_t i = 0; i < veclen; ++i) {
79                 vec[i] = 1.f;
80         }
81         return SlavableAutomationControl::masters_curve_multiply (start, end, vec, veclen);
82 }