Fix a tiny memory-leak when calling vfork
[ardour.git] / libs / ardour / gain_control.cc
1 /*
2     Copyright (C) 2006-2016 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 #include <cmath>
20
21 #include "pbd/convert.h"
22 #include "pbd/strsplit.h"
23
24 #include "evoral/Curve.hpp"
25
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"
31
32 #include "pbd/i18n.h"
33
34 using namespace ARDOUR;
35 using namespace std;
36
37 GainControl::GainControl (Session& session, const Evoral::Parameter &param, 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)
42 {
43 }
44
45 void
46 GainControl::inc_gain (gain_t factor)
47 {
48         /* To be used ONLY when doing group-relative gain adjustment, from
49          * ControlGroup::set_group_values().
50          */
51
52         const float desired_gain = get_value ();
53
54         if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
55                 // really?! what's the idea here?
56                 actually_set_value (0.000001f + (0.000001f * factor), Controllable::ForGroup);
57         } else {
58                 actually_set_value (desired_gain + (desired_gain * factor), Controllable::ForGroup);
59         }
60 }
61
62 void
63 GainControl::post_add_master (boost::shared_ptr<AutomationControl> m)
64 {
65         if (m->get_value() == 0) {
66                 /* master is at -inf, which forces this ctrl to -inf on assignment */
67                 Changed (false, Controllable::NoGroup); /* EMIT SIGNAL */
68         }
69 }
70
71 bool
72 GainControl::get_masters_curve_locked (samplepos_t start, samplepos_t end, float* vec, samplecnt_t veclen) const
73 {
74         if (_masters.empty()) {
75                 return list()->curve().rt_safe_get_vector (start, end, vec, veclen);
76         }
77         for (samplecnt_t i = 0; i < veclen; ++i) {
78                 vec[i] = 1.f;
79         }
80         return SlavableAutomationControl::masters_curve_multiply (start, end, vec, veclen);
81 }