2 * Module wrapper methods.
4 * Copyright (C) 2001-2007 Krzysztof Foltman
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include <calf/giface.h>
27 using namespace calf_utils
;
28 using namespace calf_plugins
;
30 float parameter_properties::from_01(double value01
) const
32 double value
= dsp::clip(value01
, 0., 1.);
33 switch(flags
& PF_SCALEMASK
)
35 case PF_SCALE_DEFAULT
:
39 value
= min
+ (max
- min
) * value01
;
42 value
= min
+ (max
- min
) * value01
* value01
;
45 value
= min
* pow(double(max
/ min
), value01
);
48 if (value01
< 0.00001)
51 float rmin
= std::max(1.0f
/ 1024.0f
, min
);
52 value
= rmin
* pow(double(max
/ rmin
), value01
);
55 case PF_SCALE_LOG_INF
:
57 if (value01
> (step
- 1.0) / step
)
58 value
= FAKE_INFINITY
;
60 value
= min
* pow(double(max
/ min
), value01
* step
/ (step
- 1.0));
63 switch(flags
& PF_TYPEMASK
)
70 value
= (int)(value
+ 0.5);
72 value
= (int)(value
- 0.5);
78 double parameter_properties::to_01(float value
) const
80 switch(flags
& PF_SCALEMASK
)
82 case PF_SCALE_DEFAULT
:
86 return double(value
- min
) / (max
- min
);
88 return sqrt(double(value
- min
) / (max
- min
));
91 return log((double)value
) / log((double)max
/ min
);
92 case PF_SCALE_LOG_INF
:
93 if (IS_FAKE_INFINITY(value
))
97 return (step
- 1.0) * log((double)value
) / (step
* log((double)max
/ min
));
99 if (value
< 1.0 / 1024.0) // new bottom limit - 60 dB
101 double rmin
= std::max(1.0f
/ 1024.0f
, min
);
103 return log((double)value
) / log(max
/ rmin
);
107 float parameter_properties::get_increment() const
109 float increment
= 0.01;
111 increment
= 1.0 / (step
- 1);
113 if (step
> 0 && step
< 1)
116 if ((flags
& PF_TYPEMASK
) != PF_FLOAT
)
117 increment
= 1.0 / (max
- min
);
121 int parameter_properties::get_char_count() const
123 if ((flags
& PF_SCALEMASK
) == PF_SCALE_PERC
)
125 if ((flags
& PF_SCALEMASK
) == PF_SCALE_GAIN
) {
128 sprintf(buf
, "%0.0f dB", 6.0 * log(min
) / log(2));
130 sprintf(buf
, "%0.0f dB", 6.0 * log(max
) / log(2));
131 len
= std::max(len
, strlen(buf
)) + 2;
134 return std::max(to_string(min
).length(), std::max(to_string(max
).length(), to_string(min
+ (max
-min
) * 0.987654).length()));
137 std::string
parameter_properties::to_string(float value
) const
140 if ((flags
& PF_SCALEMASK
) == PF_SCALE_PERC
) {
141 sprintf(buf
, "%0.f%%", 100.0 * value
);
144 if ((flags
& PF_SCALEMASK
) == PF_SCALE_GAIN
) {
145 if (value
< 1.0 / 1024.0) // new bottom limit - 60 dB
146 return "-inf dB"; // XXXKF change to utf-8 infinity
147 sprintf(buf
, "%0.1f dB", 6.0 * log(value
) / log(2));
150 switch(flags
& PF_TYPEMASK
)
162 if ((flags
& PF_SCALEMASK
) == PF_SCALE_LOG_INF
&& IS_FAKE_INFINITY(value
))
163 sprintf(buf
, "+inf"); // XXXKF change to utf-8 infinity
165 sprintf(buf
, "%g", value
);
167 switch(flags
& PF_UNITMASK
) {
168 case PF_UNIT_DB
: return string(buf
) + " dB";
169 case PF_UNIT_HZ
: return string(buf
) + " Hz";
170 case PF_UNIT_SEC
: return string(buf
) + " s";
171 case PF_UNIT_MSEC
: return string(buf
) + " ms";
172 case PF_UNIT_CENTS
: return string(buf
) + " ct";
173 case PF_UNIT_SEMITONES
: return string(buf
) + "#";
174 case PF_UNIT_BPM
: return string(buf
) + " bpm";
175 case PF_UNIT_RPM
: return string(buf
) + " rpm";
176 case PF_UNIT_DEG
: return string(buf
) + " deg";
179 static const char *notes
= "C C#D D#E F F#G G#A A#B ";
180 int note
= (int)value
;
181 if (note
< 0 || note
> 127)
183 return string(notes
+ 2 * (note
% 12), 2) + i2s(note
/ 12 - 2);
190 void calf_plugins::plugin_ctl_iface::clear_preset() {
191 int param_count
= get_param_count();
192 for (int i
=0; i
< param_count
; i
++)
194 parameter_properties
&pp
= *get_param_props(i
);
195 if ((pp
.flags
& PF_TYPEMASK
) == PF_STRING
)
197 configure(pp
.short_name
, pp
.choices
? pp
.choices
[0] : "");
200 set_param_value(i
, pp
.def_value
);
204 const char *calf_plugins::load_gui_xml(const std::string
&plugin_id
)
207 return strdup(calf_utils::load_file((std::string(PKGLIBDIR
) + "/gui-" + plugin_id
+ ".xml").c_str()).c_str());
209 catch(file_exception e
)
215 bool calf_plugins::check_for_message_context_ports(parameter_properties
*parameters
, int count
)
217 for (int i
= count
- 1; i
>= 0; i
--)
219 if (parameters
[i
].flags
& PF_PROP_MSGCONTEXT
)
225 bool calf_plugins::check_for_string_ports(parameter_properties
*parameters
, int count
)
227 for (int i
= count
- 1; i
>= 0; i
--)
229 if ((parameters
[i
].flags
& PF_TYPEMASK
) == PF_STRING
)
231 if ((parameters
[i
].flags
& PF_TYPEMASK
) < PF_STRING
)