|
1 | 1 | #ifndef __PatchParameter_h__ |
2 | 2 | #define __PatchParameter_h__ |
3 | 3 |
|
4 | | - |
5 | | -#include "SmoothValue.h" |
6 | | - |
| 4 | +template<typename T> |
7 | 5 | class PatchParameter { |
8 | | -public: |
9 | | - virtual void update(uint16_t value){} |
10 | | -}; |
11 | | - |
12 | | -template<type T, type V> |
13 | | -class GenericParameter : public PatchParameter { |
14 | 6 | private: |
15 | | - PatchParameterId pid; |
16 | | - T min, max; |
17 | | - V value; |
| 7 | + int pid; |
| 8 | + T value; |
18 | 9 | public: |
19 | | - PatchParameter(){} |
20 | | - PatchParameter(PatchParameterId pid, T min, T max, V initialValue); |
21 | | - // called when requestParameter() returns to patch constructor |
22 | | - PatchParameter(const PatchParameter<T>& other); |
23 | | - void update(uint16_t value); |
24 | | - /* |
| 10 | + PatchParameter(); |
| 11 | + PatchParameter(int parameterId) : pid(parameterId){} |
| 12 | + /* assignment operator */ |
| 13 | + PatchParameter<T>& operator=( const PatchParameter<T>& other ); |
25 | 14 | void update(T newValue){ |
26 | 15 | value = newValue; |
27 | | - } */ |
28 | | - operator V(){ |
| 16 | + } |
| 17 | + T getValue(){ |
29 | 18 | return value; |
30 | 19 | } |
31 | | -}; |
32 | | - |
33 | | -template<type T, type V> |
34 | | -GenericParameter<T, V> Patch::requestParameter(const char* name, T min, T max, V defaultValue = V()){ |
35 | | - int pid = 0; |
36 | | - if(nextPid < 5){ |
37 | | - pid = nextPid++; |
38 | | - registerParameter(pid, name); |
| 20 | + operator T(){ |
| 21 | + return getValue(); |
39 | 22 | } |
40 | | - return GenericParameter<T, V>(PatchParameterId(pid), min, max, defaultValue); |
41 | | -} |
42 | | - |
43 | | -template<type T> |
44 | | -GenericParameter<T, SmoothValue<T>> Patch::requestParameter(const char* name, T min, T max, T defaultValue, T lambda){ |
45 | | - requestParameter(name, min, max, SmoothValue<T>(defaultValue, lambda)); |
46 | | -} |
47 | | - |
48 | | -// Patch { |
49 | | -// FloatParameter requestParameter(const char* name, float min, float max, float defaultValue); |
50 | | -// SmoothFloatParameter requestParameter(const char* name, float min, float max, float defaultValue, float lambda); // lambda between 0.5 and 0.99 - compensate for rate/blocksize |
51 | | -// IntParameter requestParameter(const char* name, int min, int max, int defaultValue); |
52 | | -// StiffIntParameter requestParameter(const char* name, int min, int max, int defaultValue, float delta); // delta between 0 and 1 for 0 to 4095 |
53 | | -// }; |
54 | | - |
55 | | -// exponentially averaged float parameter with hysteresis: |
56 | | -// won't work! |
57 | | -// StiffSmoothFloatParameter spread; spread = requestParameter("spread", 0.0, 1.0, 0.5, 0.9); // how to set stiff delta? |
58 | | -// should be GenericParameter<float, SmoothValue<StiffFloat>> but whole of stiff gets assigned to value of smooth |
59 | | -// typedef StiffSmoothFloatParameter GenericParameter<float, SmoothValue<StiffFloat>> |
60 | | - |
61 | | -// default in patch processor to StiffSmoothIntParameter |
62 | | - |
63 | | -typedef IntParameter GenericParameter<int, int>; |
64 | | -typedef StiffIntParameter GenericParameter<int, StiffInt>; |
65 | | -typedef SmoothIntParameter GenericParameter<int, SmoothInt>; |
66 | | -typedef FloatParameter GenericParameter<float, float; |
67 | | -typedef StiffFloatParameter GenericParameter<float, StiffFloat>; |
68 | | -typedef SmoothFloatParameter GenericParameter<float, SmoothFloat>; |
69 | | -//FloatParameter spread = requestParameter("Spread", 0.0, 1.0, 0.5); |
70 | | -//SmoothFloatParameter spread = requestParameter("Spread", 0.0, 1.0, SmoothFloat(0.9, 0.5)); |
71 | | -//SmoothFloatParameter spread = requestParameter("Spread", 0.0, 1.0, 0.5, 0.9); |
72 | | - |
73 | | -template<type T, type V> |
74 | | -GenericParameter<T,V>::GenericParameter<T,V>(PatchParameterId p, T mn, T mx, T v) |
75 | | -: pid(p), min(mn), max(mx), value(v) {} |
76 | | - |
77 | | -template<type T, type V> |
78 | | -GenericParameter(const GenericParameter<T,V>& other){ |
79 | | - // register for update callback in copy constructor |
80 | | - if(pid != NO_PID) |
81 | | - getCurrentPatchProcessor()->setPatchParameter(pid, this); |
82 | | -} |
83 | | - |
84 | | -template<V> |
85 | | -void GenericParameter<int,V>::update(uint16_t newValue){ |
86 | | - value = (newValue*(max-min)+min)/4095; |
87 | | -} |
| 23 | +}; |
88 | 24 |
|
89 | | -template<V> |
90 | | -void GenericParameter<float,V>::update(uint16_t value){ |
91 | | - value = newValue/4096.0f; |
92 | | - // should work for <float, float>, <float, SmoothFloat>, and <float, StiffFloat> |
93 | | -} |
| 25 | +typedef PatchParameter<float> FloatParameter; |
| 26 | +typedef PatchParameter<int> IntParameter; |
94 | 27 |
|
95 | 28 | #endif /* __PatchParameter_h__ */ |
0 commit comments