3 #ifndef SPECTMORPH_PROPERTY_HH 4 #define SPECTMORPH_PROPERTY_HH 18 virtual int min() = 0;
19 virtual int max() = 0;
20 virtual int get() = 0;
21 virtual void set (
int v) = 0;
23 virtual std::string label() = 0;
24 virtual std::string value_label() = 0;
27 template<
class MorphOp>
33 std::function<std::string (float)> m_custom_formatter;
35 std::function<float(const MorphOp&)> get_value;
36 std::function<void (MorphOp&, float)> set_value;
39 const std::string& label,
40 const std::string& format,
41 std::function<
float(
const MorphOp&)> get_value,
42 std::function<
void (MorphOp&,
float)> set_value) :
46 get_value (get_value),
50 int min() {
return 0; }
51 int max() {
return 1000; }
52 int get() {
return lrint (value2ui (get_value (morph_op)) * 1000); }
53 void set (
int v) { set_value (morph_op, ui2value (v / 1000.)); }
55 virtual double value2ui (
double value) = 0;
56 virtual double ui2value (
double ui) = 0;
58 std::string label() {
return m_label; }
63 if (m_custom_formatter)
64 return m_custom_formatter (get_value (morph_op));
66 return string_locale_printf (m_format.c_str(), get_value (morph_op));
70 set_custom_formatter (
const std::function<std::string (
float)>& formatter)
72 m_custom_formatter = formatter;
76 template<
class MorphOp>
84 const std::string& label,
85 const std::string& format,
89 std::function<
float(
const MorphOp&)> get_value,
90 std::function<
void (MorphOp&,
float)> set_value) :
92 m_min_value (min_value),
93 m_max_value (max_value),
100 return sm_xparam_inv ((v - m_min_value) / (m_max_value - m_min_value), m_slope);
105 return sm_xparam (ui, m_slope) * (m_max_value - m_min_value) + m_min_value;
109 template<
class MorphOp>
116 const std::string& label,
117 const std::string& format,
120 std::function<
float(
const MorphOp&)> get_value,
121 std::function<
void (MorphOp&,
float)> set_value) :
123 m_min_value (min_value),
124 m_max_value (max_value)
130 return (log (v) - log (m_min_value)) / (log (m_max_value) - log (m_min_value));
135 return exp (ui * (log (m_max_value) - log (m_min_value)) + log (m_min_value));
139 template<
class MorphOp>
146 const std::string& label,
147 const std::string& format,
150 std::function<
float(
const MorphOp&)> get_value,
151 std::function<
void (MorphOp&,
float)> set_value) :
153 m_min_value (min_value),
154 m_max_value (max_value)
160 return (v - m_min_value) / (m_max_value - m_min_value);
165 return ui * (m_max_value - m_min_value) + m_min_value;
Definition: smproperty.hh:140
Definition: smproperty.hh:77
Definition: smproperty.hh:15
Definition: smproperty.hh:110
Definition: smproperty.hh:28
Definition: smadsrenvelope.hh:8