Add menu to set frequency controls in beats, and half or double current value.
[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::VOID)
46                 , normal(parameter.normal())
47                 , lower(parameter.min())
48                 , upper(parameter.max())
49                 , step((upper - lower) / 100.0f)
50                 , smallstep((upper - lower) / 1000.0f)
51                 , largestep((upper - lower) / 10.0f)
52                 , integer_step(parameter.type() >= MidiCCAutomation &&
53                                parameter.type() <= MidiChannelPressureAutomation)
54                 , toggled(parameter.toggled())
55                 , logarithmic(false)
56                 , sr_dependent(false)
57                 , min_unbound(0)
58                 , max_unbound(0)
59                 , enumeration(false)
60         {
61                 if (parameter.type() == GainAutomation) {
62                         unit = DB;
63                 }
64         }
65
66         ParameterDescriptor()
67                 : key((uint32_t)-1)
68                 , datatype(Variant::VOID)
69                 , normal(0)
70                 , lower(0)
71                 , upper(0)
72                 , step(0)
73                 , smallstep(0)
74                 , largestep(0)
75                 , integer_step(false)
76                 , toggled(false)
77                 , logarithmic(false)
78                 , sr_dependent(false)
79                 , min_unbound(0)
80                 , max_unbound(0)
81                 , enumeration(false)
82         {}
83
84         /// Set step, smallstep, and largestep, based on current description
85         void update_steps() {
86                 if (unit == ParameterDescriptor::MIDI_NOTE) {
87                         step      = smallstep = 1;  // semitone
88                         largestep = 12;             // octave
89                 } else {
90                         const float delta = upper - lower;
91
92                         step      = delta / 1000.0f;
93                         smallstep = delta / 10000.0f;
94                         largestep = delta / 10.0f;
95
96                         if (integer_step) {
97                                 step      = rint(step);
98                                 largestep = rint(largestep);
99                                 // leave smallstep alone for fine tuning
100                         }
101                 }
102         }
103
104         std::string                    label;
105         std::string                    print_fmt;  ///< format string for pretty printing
106         boost::shared_ptr<ScalePoints> scale_points;
107         uint32_t                       key;  ///< for properties
108         Variant::Type                  datatype;  ///< for properties
109         Unit                           unit;
110         float                          normal;
111         float                          lower;  ///< for frequencies, this is in Hz (not a fraction of the sample rate)
112         float                          upper;  ///< for frequencies, this is in Hz (not a fraction of the sample rate)
113         float                          step;
114         float                          smallstep;
115         float                          largestep;
116         bool                           integer_step;
117         bool                           toggled;
118         bool                           logarithmic;
119         bool                           sr_dependent;
120         bool                           min_unbound;
121         bool                           max_unbound;
122         bool                           enumeration;
123 };
124
125 } // namespace ARDOUR
126
127 #endif // __ardour_parameter_descriptor_h__