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 "pbd/natsort.h" 24 #include "ardour/types.h" 25 #include "ardour/variant.h" 26 27 #include "evoral/Parameter.h" 28 #include "evoral/ParameterDescriptor.h" 29 30 namespace ARDOUR { 31 32 struct CompareNumericallyLess { operatorCompareNumericallyLess33 bool operator() (std::string const& a, std::string const& b) const { 34 return PBD::numerically_less (a.c_str(), b.c_str()); 35 } 36 }; 37 38 typedef std::map<const std::string, const float, CompareNumericallyLess> ScalePoints; 39 40 /** Descriptor of a parameter or control. 41 * 42 * Essentially a union of LADSPA, VST and LV2 info. 43 */ 44 struct LIBARDOUR_API ParameterDescriptor : public Evoral::ParameterDescriptor 45 { 46 enum Unit { 47 NONE, ///< No unit 48 DB, ///< Decibels 49 MIDI_NOTE, ///< MIDI note number 50 HZ, ///< Frequency in Hertz 51 }; 52 53 static std::string midi_note_name (uint8_t, bool translate=true); 54 55 /** Dual of midi_note_name, convert a note name into its midi note number. */ 56 typedef std::map<std::string, uint8_t> NameNumMap; 57 static std::string normalize_note_name(const std::string& name); 58 static NameNumMap build_midi_name2num(); 59 static uint8_t midi_note_num (const std::string& name); 60 61 ParameterDescriptor(const Evoral::Parameter& parameter); 62 63 ParameterDescriptor(); 64 65 /** control-value to normalized [0..1] range 66 * 67 * Convert given AutomationType from lower/upper range to [0..1] 68 * interface value, using settings from Evoral::ParameterDescriptor. 69 * 70 * default for AutomationControl::internal_to_interface (); 71 * 72 * @param v the control-value to convert 73 * @param rotary set to true if the GUI control is a rotary knob 74 * @return interface value in range 0..1 75 */ 76 float to_interface (float v, bool rotary = false) const; 77 78 /** normalized [0..1] to control-value range 79 * 80 * Convert [0..1] to the control's range of this AutomationType 81 * using settings from Evoral::ParameterDescriptor. 82 * 83 * default for AutomationControl::interface_to_internal (); 84 * 85 * @param v the value in range 0..1 to on convert 86 * @param rotary set to true if the GUI control is a rotary knob 87 * @return control-value in range lower..upper 88 */ 89 float from_interface (float v, bool rotary = false) const; 90 91 bool is_linear () const; 92 float compute_delta (float from, float to) const; 93 float apply_delta (float value, float delta) const; 94 95 /* find the closest scale-point, return the internal value of 96 * the prev/next scale-point (no wrap-around) 97 * 98 * If the given parameter is not en enum, the given val is returned. 99 * 100 * @param val internal (not interface) value 101 * @param prev if true, step to prev scale-point, otherwise next 102 * @return internal value, suitable for set_value() 103 */ 104 float step_enum (float val, bool prev) const; 105 106 /** Set step, smallstep, and largestep, based on current description. */ 107 void update_steps(); 108 109 std::string label; 110 std::string print_fmt; ///< format string for pretty printing 111 boost::shared_ptr<ScalePoints> scale_points; 112 uint32_t key; ///< for properties 113 Variant::Type datatype; ///< for properties 114 AutomationType type; 115 Unit unit; 116 float step; 117 float smallstep; 118 float largestep; 119 bool integer_step; 120 bool sr_dependent; 121 bool enumeration; 122 bool inline_ctrl; 123 uint32_t display_priority; ///< higher is more important http://lv2plug.in/ns/ext/port-props#displayPriority 124 }; 125 126 } // namespace ARDOUR 127 128 #endif // __ardour_parameter_descriptor_h__ 129