Invert Pan-Azimuth (up means left)
[ardour.git] / libs / ardour / ardour / parameter_descriptor.h
1 /*
2  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2014 David Robillard <d@drobilla.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License 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  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef __ardour_parameter_descriptor_h__
21 #define __ardour_parameter_descriptor_h__
22
23 #include "ardour/types.h"
24 #include "ardour/variant.h"
25
26 #include "evoral/Parameter.hpp"
27 #include "evoral/ParameterDescriptor.hpp"
28
29 namespace ARDOUR {
30
31 typedef std::map<const std::string, const float> ScalePoints;
32
33 /** Descriptor of a parameter or control.
34  *
35  * Essentially a union of LADSPA, VST and LV2 info.
36  */
37 struct LIBARDOUR_API ParameterDescriptor : public Evoral::ParameterDescriptor
38 {
39         enum Unit {
40                 NONE,       ///< No unit
41                 DB,         ///< Decibels
42                 MIDI_NOTE,  ///< MIDI note number
43                 HZ,         ///< Frequency in Hertz
44         };
45
46         static std::string midi_note_name (uint8_t, bool translate=true);
47
48         /** Dual of midi_note_name, convert a note name into its midi note number. */
49         typedef std::map<std::string, uint8_t> NameNumMap;
50         static std::string normalize_note_name(const std::string& name);
51         static NameNumMap build_midi_name2num();
52         static uint8_t midi_note_num (const std::string& name);
53
54         ParameterDescriptor(const Evoral::Parameter& parameter);
55
56         ParameterDescriptor();
57
58         /** control-value to normalized [0..1] range
59          *
60          * Convert given AutomationType from lower/upper range to [0..1]
61          * interface value, using settings from Evoral::ParameterDescriptor.
62          *
63          * default for AutomationControl::internal_to_interface ();
64          *
65          * @param v the control-value to convert
66          * @param rotary set to true if the GUI control is a rotary knob
67          * @return interface value in range 0..1
68          */
69         float to_interface (float v, bool rotary = false) const;
70
71         /** normalized [0..1] to control-value range
72          *
73          * Convert [0..1] to the control's range of this AutomationType
74          * using settings from Evoral::ParameterDescriptor.
75          *
76          * default for AutomationControl::interface_to_internal ();
77          *
78          * @param v the value in range 0..1 to on convert
79          * @param rotary set to true if the GUI control is a rotary knob
80          * @return control-value in range lower..upper
81          */
82         float from_interface (float v, bool rotary = false) const;
83
84         bool  is_linear () const;
85         float compute_delta (float from, float to) const;
86         float apply_delta (float value, float delta) const;
87
88         /* find the closest scale-point, return the internal value of
89          * the prev/next scale-point (no wrap-around)
90          *
91          * If the given parameter is not en enum, the given val is returned.
92          *
93          * @param val internal (not interface) value
94          * @param prev if true, step to prev scale-point, otherwise next
95          * @return internal value, suitable for set_value()
96          */
97         float step_enum (float val, bool prev) const;
98
99         /** Set step, smallstep, and largestep, based on current description. */
100         void update_steps();
101
102         std::string                    label;
103         std::string                    print_fmt;  ///< format string for pretty printing
104         boost::shared_ptr<ScalePoints> scale_points;
105         uint32_t                       key;  ///< for properties
106         Variant::Type                  datatype;  ///< for properties
107         AutomationType                 type;
108         Unit                           unit;
109         float                          step;
110         float                          smallstep;
111         float                          largestep;
112         bool                           integer_step;
113         bool                           sr_dependent;
114         bool                           enumeration;
115 };
116
117 } // namespace ARDOUR
118
119 #endif // __ardour_parameter_descriptor_h__