Fix range of pan controls.
[ardour.git] / libs / ardour / parameter_descriptor.cc
1 /*
2     Copyright (C) 2014 Paul Davis
3     Author: David Robillard
4
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)
8     any later version.
9
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
13     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     675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "ardour/amp.h"
21 #include "ardour/parameter_descriptor.h"
22 #include "ardour/types.h"
23
24 namespace ARDOUR {
25
26 ParameterDescriptor::ParameterDescriptor(const Evoral::Parameter& parameter)
27         : Evoral::ParameterDescriptor()
28         , key((uint32_t)-1)
29         , datatype(Variant::NOTHING)
30         , unit(NONE)
31         , step(0)
32         , smallstep(0)
33         , largestep(0)
34         , integer_step(parameter.type() >= MidiCCAutomation &&
35                        parameter.type() <= MidiChannelPressureAutomation)
36         , logarithmic(false)
37         , sr_dependent(false)
38         , min_unbound(0)
39         , max_unbound(0)
40         , enumeration(false)
41 {
42         if (parameter.type() == GainAutomation) {
43                 unit = DB;
44         }
45
46         switch((AutomationType)parameter.type()) {
47         case GainAutomation:
48                 upper  = Amp::max_gain_coefficient;
49                 normal = 1.0f;
50                 break;
51         case PanAzimuthAutomation:
52                 normal = 0.5f; // there really is no _normal but this works for stereo, sort of
53                 upper  = 1.0f;
54                 break;
55         case PanWidthAutomation:
56                 lower  = -1.0;
57                 upper  = 1.0;
58                 normal = 0.0f;
59                 break;
60         case RecEnableAutomation:
61                 lower  = 0.0;
62                 upper  = 1.0;
63                 toggled = true;
64                 break;
65         case PluginAutomation:
66         case FadeInAutomation:
67         case FadeOutAutomation:
68         case EnvelopeAutomation:
69                 upper  = 2.0f;
70                 normal = 1.0f;
71                 break;
72         case SoloAutomation:
73         case MuteAutomation:
74                 upper  = 1.0f;
75                 normal = 0.0f;
76                 toggled = true;
77                 break;
78         case MidiCCAutomation:
79         case MidiPgmChangeAutomation:
80         case MidiChannelPressureAutomation:
81                 lower  = 0.0;
82                 normal = 0.0;
83                 upper  = 127.0;
84                 break;
85         case MidiPitchBenderAutomation:
86                 lower  = 0.0;
87                 normal = 8192.0;
88                 upper  = 16383.0;
89                 break;
90         default:
91                 break;
92         }
93
94         update_steps();
95 }
96
97 ParameterDescriptor::ParameterDescriptor()
98         : Evoral::ParameterDescriptor()
99         , key((uint32_t)-1)
100         , datatype(Variant::NOTHING)
101         , unit(NONE)
102         , step(0)
103         , smallstep(0)
104         , largestep(0)
105         , integer_step(false)
106         , logarithmic(false)
107         , sr_dependent(false)
108         , min_unbound(0)
109         , max_unbound(0)
110         , enumeration(false)
111 {}
112
113 void
114 ParameterDescriptor::update_steps()
115 {
116         if (unit == ParameterDescriptor::MIDI_NOTE) {
117                 step      = smallstep = 1;  // semitone
118                 largestep = 12;             // octave
119         } else if (integer_step) {
120                 const float delta = upper - lower;
121
122                 smallstep = delta / 10000.0f;
123                 step      = delta / 1000.0f;
124                 largestep = delta / 40.0f;
125
126                 smallstep = std::max(1.0, rint(smallstep));
127                 step      = std::max(1.0, rint(step));
128                 largestep = std::max(1.0, rint(largestep));
129         }
130         /* else: leave all others as default '0'
131          * in that case the UI (eg. AutomationController::create)
132          * uses internal_to_interface() to map the value
133          * to an appropriate interface range
134          */
135 }
136
137 } // namespace ARDOUR