Redesign Session+Route Template Meta Script API
[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/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         float to_interface (float) const;
66
67         /** normalized [0..1] to control-value range
68          *
69          * Convert [0..1] to the control's range of this AutomationType
70          * using settings from Evoral::ParameterDescriptor.
71          *
72          * default for AutomationControl::interface_to_internal ();
73          */
74         float from_interface (float) const;
75
76         bool  is_linear () const;
77         float compute_delta (float from, float to) const;
78         float apply_delta (float value, float delta) const;
79
80         /* find the closest scale-point, return the internal value of
81          * the prev/next scale-point (no wrap-around)
82          *
83          * If the given parameter is not en enum, the given val is returned.
84          *
85          * @param val internal (not interface) value
86          * @param prev if true, step to prev scale-point, otherwise next
87          * @return internal value, suitable for set_value()
88          */
89         float step_enum (float val, bool prev) const;
90
91         /** Set step, smallstep, and largestep, based on current description. */
92         void update_steps();
93
94         std::string                    label;
95         std::string                    print_fmt;  ///< format string for pretty printing
96         boost::shared_ptr<ScalePoints> scale_points;
97         uint32_t                       key;  ///< for properties
98         Variant::Type                  datatype;  ///< for properties
99         AutomationType                 type;
100         Unit                           unit;
101         float                          step;
102         float                          smallstep;
103         float                          largestep;
104         bool                           integer_step;
105         bool                           sr_dependent;
106         bool                           enumeration;
107 };
108
109 } // namespace ARDOUR
110
111 #endif // __ardour_parameter_descriptor_h__