2 Copyright (C) 2014 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "ardour/amp.h"
21 #include "ardour/dB.h"
22 #include "ardour/parameter_descriptor.h"
23 #include "ardour/rc_configuration.h"
24 #include "ardour/types.h"
25 #include "ardour/utils.h"
29 ParameterDescriptor::ParameterDescriptor(const Evoral::Parameter& parameter)
30 : Evoral::ParameterDescriptor()
32 , datatype(Variant::NOTHING)
33 , type((AutomationType)parameter.type())
38 , integer_step(parameter.type() >= MidiCCAutomation &&
39 parameter.type() <= MidiChannelPressureAutomation)
46 switch((AutomationType)parameter.type()) {
48 upper = Config->get_max_gain();
51 case PanAzimuthAutomation:
52 normal = 0.5f; // there really is no _normal but this works for stereo, sort of
55 case PanWidthAutomation:
60 case RecEnableAutomation:
65 case PluginAutomation:
66 case FadeInAutomation:
67 case FadeOutAutomation:
68 case EnvelopeAutomation:
78 case MidiCCAutomation:
79 case MidiPgmChangeAutomation:
80 case MidiChannelPressureAutomation:
85 case MidiPitchBenderAutomation:
97 ParameterDescriptor::ParameterDescriptor()
98 : Evoral::ParameterDescriptor()
100 , datatype(Variant::NOTHING)
105 , integer_step(false)
107 , sr_dependent(false)
114 ParameterDescriptor::update_steps()
116 if (unit == ParameterDescriptor::MIDI_NOTE) {
117 step = smallstep = 1; // semitone
118 largestep = 12; // octave
119 } else if (type == GainAutomation) {
120 /* dB_coeff_step gives a step normalized for [0, max_gain]. This is
121 like "slider position", so we convert from "slider position" to gain
122 to have the correct unit here. */
123 largestep = slider_position_to_gain(dB_coeff_step(upper));
124 step = slider_position_to_gain(largestep / 10.0);
127 const float delta = upper - lower;
129 /* 30 happens to be the total number of steps for a fader with default
130 max gain of 2.0 (6 dB), so we use 30 here too for consistency. */
131 step = smallstep = (delta / 300.0f);
132 largestep = (delta / 30.0f);
135 /* Steps are linear, but we map them with pow like values (in
136 internal_to_interface). Thus, they are applied exponentially,
137 which means too few steps. So, divide to get roughly the
138 desired number of steps (30). This is not mathematically
139 precise but seems to be about right for the controls I tried.
140 If you're reading this, you've probably found a case where that
141 isn't true, and somebody needs to sit down with a piece of paper
142 and actually do the math. */
143 smallstep = smallstep / logf(30.0f);
144 step = step / logf(30.0f);
145 largestep = largestep / logf(30.0f);
146 } else if (integer_step) {
147 smallstep = std::max(1.0, rint(smallstep));
148 step = std::max(1.0, rint(step));
149 largestep = std::max(1.0, rint(largestep));
154 } // namespace ARDOUR