Just rename problematic Variant::VOID type.
[ardour.git] / libs / ardour / ardour / parameter_descriptor.h
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 #ifndef __ardour_parameter_descriptor_h__
21 #define __ardour_parameter_descriptor_h__
22
23 #include "ardour/variant.h"
24 #include "evoral/Parameter.hpp"
25
26 namespace ARDOUR {
27
28 typedef std::map<const std::string, const float> ScalePoints;
29
30 /** Descriptor of a parameter or control.
31  *
32  * Essentially a union of LADSPA, VST and LV2 info.
33  */
34 struct ParameterDescriptor
35 {
36         enum Unit {
37                 NONE,       ///< No unit
38                 DB,         ///< Decibels
39                 MIDI_NOTE,  ///< MIDI note number
40                 HZ,         ///< Frequency in Hertz
41         };
42
43         ParameterDescriptor(const Evoral::Parameter& parameter)
44                 : key((uint32_t)-1)
45                 , datatype(Variant::NOTHING)
46                 , unit(NONE)
47                 , normal(parameter.normal())
48                 , lower(parameter.min())
49                 , upper(parameter.max())
50                 , step((upper - lower) / 100.0f)
51                 , smallstep((upper - lower) / 1000.0f)
52                 , largestep((upper - lower) / 10.0f)
53                 , integer_step(parameter.type() >= MidiCCAutomation &&
54                                parameter.type() <= MidiChannelPressureAutomation)
55                 , toggled(parameter.toggled())
56                 , logarithmic(false)
57                 , sr_dependent(false)
58                 , min_unbound(0)
59                 , max_unbound(0)
60                 , enumeration(false)
61         {
62                 if (parameter.type() == GainAutomation) {
63                         unit = DB;
64                 }
65         }
66
67         ParameterDescriptor()
68                 : key((uint32_t)-1)
69                 , datatype(Variant::NOTHING)
70                 , unit(NONE)
71                 , normal(0)
72                 , lower(0)
73                 , upper(0)
74                 , step(0)
75                 , smallstep(0)
76                 , largestep(0)
77                 , integer_step(false)
78                 , toggled(false)
79                 , logarithmic(false)
80                 , sr_dependent(false)
81                 , min_unbound(0)
82                 , max_unbound(0)
83                 , enumeration(false)
84         {}
85
86         /// Set step, smallstep, and largestep, based on current description
87         void update_steps() {
88                 if (unit == ParameterDescriptor::MIDI_NOTE) {
89                         step      = smallstep = 1;  // semitone
90                         largestep = 12;             // octave
91                 } else {
92                         const float delta = upper - lower;
93
94                         step      = delta / 1000.0f;
95                         smallstep = delta / 10000.0f;
96                         largestep = delta / 10.0f;
97
98                         if (integer_step) {
99                                 step      = rint(step);
100                                 largestep = rint(largestep);
101                                 // leave smallstep alone for fine tuning
102                         }
103                 }
104         }
105
106         std::string                    label;
107         std::string                    print_fmt;  ///< format string for pretty printing
108         boost::shared_ptr<ScalePoints> scale_points;
109         uint32_t                       key;  ///< for properties
110         Variant::Type                  datatype;  ///< for properties
111         Unit                           unit;
112         float                          normal;
113         float                          lower;  ///< for frequencies, this is in Hz (not a fraction of the sample rate)
114         float                          upper;  ///< for frequencies, this is in Hz (not a fraction of the sample rate)
115         float                          step;
116         float                          smallstep;
117         float                          largestep;
118         bool                           integer_step;
119         bool                           toggled;
120         bool                           logarithmic;
121         bool                           sr_dependent;
122         bool                           min_unbound;
123         bool                           max_unbound;
124         bool                           enumeration;
125 };
126
127 } // namespace ARDOUR
128
129 #endif // __ardour_parameter_descriptor_h__