2 Copyright (C) 2014 Paul Davis
3 Author: David Robillard
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "ardour/value_as_string.h"
26 value_as_string(const Evoral::ParameterDescriptor& desc,
31 if (desc.scale_points) {
32 // Check if value is on a scale point
33 for (Evoral::ScalePoints::const_iterator i = desc.scale_points->begin();
34 i != desc.scale_points->end();
37 return i->first; // Found it, return scale point label
42 // Value is not a scale point, print it normally
43 if (desc.unit == Evoral::ParameterDescriptor::MIDI_NOTE) {
44 if (v >= 0 && v <= 127) {
45 const int num = rint(v);
46 static const char names[12][3] = {
47 "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
49 snprintf(buf, sizeof(buf), "%s %d", names[num % 12], (num / 12) - 2);
51 // Odd, invalid range, just print the number
52 snprintf(buf, sizeof(buf), "%.0f", v);
54 } else if (!desc.print_fmt.empty()) {
55 snprintf(buf, sizeof(buf), desc.print_fmt.c_str(), v);
56 } else if (desc.integer_step) {
57 snprintf(buf, sizeof(buf), "%d", (int)v);
59 snprintf(buf, sizeof(buf), "%.3f", v);
61 if (desc.print_fmt.empty() && desc.unit == Evoral::ParameterDescriptor::DB) {
62 // TODO: Move proper dB printing from AutomationLine here
63 return std::string(buf) + " dB";
69 value_as_string(const Evoral::ParameterDescriptor& desc,
70 const Evoral::Variant& val)
72 // Only numeric support, for now
73 return value_as_string(desc, val.to_double());