ardour
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
libs
ardour
ardour
value_as_string.h
Go to the documentation of this file.
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
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
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19
*/
20
21
#ifndef __ardour_value_as_string_h__
22
#define __ardour_value_as_string_h__
23
24
#include <stddef.h>
25
26
#include "
ardour/parameter_descriptor.h
"
27
28
namespace
ARDOUR
{
29
30
inline
std::string
31
value_as_string
(
const
ARDOUR::ParameterDescriptor
& desc,
32
double
v)
33
{
34
char
buf[32];
35
36
if
(desc.
scale_points
) {
37
// Check if value is on a scale point
38
for
(ARDOUR::ScalePoints::const_iterator i = desc.
scale_points
->begin();
39
i != desc.
scale_points
->end();
40
++i) {
41
if
(i->second == v) {
42
return
i->first;
// Found it, return scale point label
43
}
44
}
45
}
46
47
// Value is not a scale point, print it normally
48
if
(desc.
unit
==
ARDOUR::ParameterDescriptor::MIDI_NOTE
) {
49
if
(v >= 0 && v <= 127) {
50
const
int
num = rint(v);
51
static
const
char
names[12][3] = {
52
"C"
,
"C#"
,
"D"
,
"D#"
,
"E"
,
"F"
,
"F#"
,
"G"
,
"G#"
,
"A"
,
"A#"
,
"B"
53
};
54
snprintf(buf,
sizeof
(buf),
"%s %d"
, names[num % 12], (num / 12) - 2);
55
}
else
{
56
// Odd, invalid range, just print the number
57
snprintf(buf,
sizeof
(buf),
"%.0f"
, v);
58
}
59
}
else
if
(!desc.
print_fmt
.empty()) {
60
snprintf(buf,
sizeof
(buf), desc.
print_fmt
.c_str(), v);
61
}
else
if
(desc.
integer_step
) {
62
snprintf(buf,
sizeof
(buf),
"%d"
, (
int
)v);
63
}
else
{
64
snprintf(buf,
sizeof
(buf),
"%.3f"
, v);
65
}
66
if
(desc.
print_fmt
.empty() && desc.
unit
==
ARDOUR::ParameterDescriptor::DB
) {
67
// TODO: Move proper dB printing from AutomationLine here
68
return
std::string(buf) +
" dB"
;
69
}
70
return
buf;
71
}
72
73
inline
std::string
74
value_as_string
(
const
ARDOUR::ParameterDescriptor
& desc,
75
const
ARDOUR::Variant
& val)
76
{
77
// Only numeric support, for now
78
return
value_as_string
(desc, val.
to_double
());
79
}
80
81
}
// namespace ARDOUR
82
83
#endif
/* __ardour_value_as_string_h__ */
ARDOUR::ParameterDescriptor
Definition:
parameter_descriptor.h:36
ARDOUR::value_as_string
std::string value_as_string(const ARDOUR::ParameterDescriptor &desc, double v)
Definition:
value_as_string.h:31
ARDOUR::ParameterDescriptor::unit
Unit unit
Definition:
parameter_descriptor.h:58
ARDOUR::Variant::to_double
double to_double() const
Definition:
variant.h:106
ARDOUR::ParameterDescriptor::DB
Decibels.
Definition:
parameter_descriptor.h:40
ARDOUR::ParameterDescriptor::integer_step
bool integer_step
Definition:
parameter_descriptor.h:62
ARDOUR
Definition:
amp.h:29
ARDOUR::ParameterDescriptor::print_fmt
std::string print_fmt
format string for pretty printing
Definition:
parameter_descriptor.h:53
ARDOUR::ParameterDescriptor::MIDI_NOTE
MIDI note number.
Definition:
parameter_descriptor.h:41
parameter_descriptor.h
ARDOUR::ParameterDescriptor::scale_points
boost::shared_ptr< ScalePoints > scale_points
Definition:
parameter_descriptor.h:54
ARDOUR::Variant
Definition:
variant.h:36
Generated on Sun May 24 2015 12:15:05 for ardour by
1.8.8