49 |
*/ |
*/ |
50 |
class NoteBase { |
class NoteBase { |
51 |
public: |
public: |
52 |
|
enum class ValueScope : unsigned char { |
53 |
|
RELATIVE = (unsigned char) Event::ValueScope::RELATIVE, |
54 |
|
FINAL_NORM = (unsigned char) Event::ValueScope::FINAL_NORM, |
55 |
|
FINAL_NATIVE = (unsigned char) Event::ValueScope::FINAL_NATIVE, |
56 |
|
}; |
57 |
|
|
58 |
|
/** |
59 |
|
* General purpose note parameter value which might be both either in |
60 |
|
* normalized value range (0..1) or in a native unit (i.e. seconds, Hz) |
61 |
|
* depending on member variable @c Scope. |
62 |
|
*/ |
63 |
|
struct Param { |
64 |
|
float Value; |
65 |
|
ValueScope Scope; |
66 |
|
|
67 |
|
Param() { |
68 |
|
Value = 1.f; |
69 |
|
Scope = ValueScope::RELATIVE; |
70 |
|
} |
71 |
|
|
72 |
|
bool isFinal() const { |
73 |
|
return Scope == ValueScope::FINAL_NORM || |
74 |
|
Scope == ValueScope::FINAL_NATIVE; |
75 |
|
} |
76 |
|
|
77 |
|
template<typename T> |
78 |
|
inline void applyTo(T& dst) { |
79 |
|
if (isFinal()) |
80 |
|
dst = Value; |
81 |
|
else |
82 |
|
dst *= Value; |
83 |
|
} |
84 |
|
}; |
85 |
|
|
86 |
|
/** |
87 |
|
* Parameter value being in normalized value range (0..1). |
88 |
|
*/ |
89 |
|
struct Norm { |
90 |
|
float Value; |
91 |
|
bool Final; |
92 |
|
|
93 |
|
Norm() { |
94 |
|
Value = 1.f; |
95 |
|
Final = false; |
96 |
|
} |
97 |
|
|
98 |
|
template<typename T> |
99 |
|
inline void applyTo(T& dst) { |
100 |
|
if (Final) |
101 |
|
dst = Value; |
102 |
|
else |
103 |
|
dst *= Value; |
104 |
|
} |
105 |
|
}; |
106 |
|
|
107 |
|
/** |
108 |
|
* Parameter value being in signed normalized value range (-1..+1). |
109 |
|
*/ |
110 |
|
struct SNorm { |
111 |
|
float Value; |
112 |
|
bool Final; |
113 |
|
int64_t Sources; ///< Might be used for calculating an average pan value in differential way: amount of times the @c Value had been changed and shall be calculated relatively upon. |
114 |
|
|
115 |
|
SNorm() { |
116 |
|
Value = 0.f; |
117 |
|
Final = false; |
118 |
|
Sources = 0; |
119 |
|
} |
120 |
|
}; |
121 |
|
|
122 |
int hostKey; ///< Key on which this is @c Note is allocated on. This is usually the note-on event's note number, however in case of a child note this will rather be the parent note's key instead! |
int hostKey; ///< Key on which this is @c Note is allocated on. This is usually the note-on event's note number, however in case of a child note this will rather be the parent note's key instead! |
123 |
note_id_t parentNoteID; ///< If not null: unique ID of the parent note of this note (see comments of field @c pChildNotes). |
note_id_t parentNoteID; ///< If not null: unique ID of the parent note of this note (see comments of field @c pChildNotes). |
124 |
RTList<note_id_t>* pChildNotes; ///< Note ID list of "child" notes of this note. These are special notes that must be released once this note gets released. |
RTList<note_id_t>* pChildNotes; ///< Note ID list of "child" notes of this note. These are special notes that must be released once this note gets released. |
127 |
sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched. |
sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched. |
128 |
/// Optional synthesis parameters that might be overridden (by calling real-time instrument script functions like change_vol(), change_pitch(), etc.). |
/// Optional synthesis parameters that might be overridden (by calling real-time instrument script functions like change_vol(), change_pitch(), etc.). |
129 |
struct _Override { |
struct _Override { |
130 |
float Volume; ///< as linear amplification ratio (1.0 being neutral) |
Norm Volume; ///< as linear amplification ratio (1.0 being neutral) |
131 |
float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume. |
float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume. |
132 |
float Pitch; ///< as linear frequency ratio (1.0 being neutral) |
Norm Pitch; ///< as linear frequency ratio (1.0 being neutral) |
133 |
float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch. |
float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch. |
134 |
float Pan; ///< between -1.0 (most left) and +1.0 (most right) and 0.0 being neutral. |
SNorm Pan; ///< between -1.0 (most left) and +1.0 (most right) and 0.0 being neutral. |
135 |
float PanTime; ///< Transition duration (in seconds) for changes to @c Pan. |
float PanTime; ///< Transition duration (in seconds) for changes to @c Pan. |
136 |
int64_t PanSources; ///< Might be used for calculating an average pan value in differential way: amount of times the Pan value had been changed and shall be calculated relatively upon. |
Param Cutoff; ///< between 0.0 and 1.0 |
137 |
float Cutoff; ///< between 0.0 and 1.0 |
Norm Resonance; ///< between 0.0 and 1.0 |
138 |
float Resonance; ///< between 0.0 and 1.0 |
Param Attack; ///< between 0.0 and 1.0 |
139 |
float Attack; ///< between 0.0 and 1.0 |
Param Decay; ///< between 0.0 and 1.0 |
140 |
float Decay; ///< between 0.0 and 1.0 |
Norm Sustain; ///< between 0.0 and 1.0 |
141 |
float Sustain; ///< between 0.0 and 1.0 |
Param Release; ///< between 0.0 and 1.0 |
142 |
float Release; ///< between 0.0 and 1.0 |
Param CutoffAttack; ///< between 0.0 and 1.0 |
143 |
float CutoffAttack; ///< between 0.0 and 1.0 |
Param CutoffDecay; ///< between 0.0 and 1.0 |
144 |
float CutoffDecay; ///< between 0.0 and 1.0 |
Norm CutoffSustain;///< between 0.0 and 1.0 |
145 |
float CutoffSustain;///< between 0.0 and 1.0 |
Param CutoffRelease;///< between 0.0 and 1.0 |
146 |
float CutoffRelease;///< between 0.0 and 1.0 |
Norm AmpLFODepth; ///< between 0.0 and 1.0 |
147 |
float AmpLFODepth; ///< between 0.0 and 1.0 |
Param AmpLFOFreq; ///< between 0.0 and 1.0 |
148 |
float AmpLFOFreq; ///< between 0.0 and 1.0 |
Norm CutoffLFODepth;///< between 0.0 and 1.0 |
149 |
float CutoffLFODepth;///< between 0.0 and 1.0 |
Param CutoffLFOFreq; ///< between 0.0 and 1.0 |
150 |
float CutoffLFOFreq; ///< between 0.0 and 1.0 |
Norm PitchLFODepth; ///< between 0.0 and 1.0 |
151 |
float PitchLFODepth; ///< between 0.0 and 1.0 |
Param PitchLFOFreq; ///< between 0.0 and 1.0 |
|
float PitchLFOFreq; ///< between 0.0 and 1.0 |
|
152 |
fade_curve_t VolumeCurve; |
fade_curve_t VolumeCurve; |
153 |
fade_curve_t PitchCurve; |
fade_curve_t PitchCurve; |
154 |
fade_curve_t PanCurve; |
fade_curve_t PanCurve; |
163 |
} Gig; |
} Gig; |
164 |
} Format; |
} Format; |
165 |
vmint userPar[4]; ///< Used only for real-time instrument script functions set_event_par() and get_event_par() to store script author's user specific data ($EVENT_PAR_0 to $EVENT_PAR_3). |
vmint userPar[4]; ///< Used only for real-time instrument script functions set_event_par() and get_event_par() to store script author's user specific data ($EVENT_PAR_0 to $EVENT_PAR_3). |
166 |
|
|
167 |
|
inline |
168 |
|
void apply(RTList<Event>::Iterator& itEvent, Param _Override::*noteParam) { |
169 |
|
const Event::ValueScope& scope = itEvent->Param.NoteSynthParam.Scope; |
170 |
|
switch (scope) { |
171 |
|
case Event::ValueScope::SELF_RELATIVE: |
172 |
|
if ((this->Override.*noteParam).Scope == ValueScope::FINAL_NATIVE) |
173 |
|
(this->Override.*noteParam) = Param(); |
174 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
175 |
|
((this->Override.*noteParam).Value *= itEvent->Param.NoteSynthParam.Delta); |
176 |
|
(this->Override.*noteParam).Scope = ValueScope::RELATIVE; |
177 |
|
break; |
178 |
|
case Event::ValueScope::RELATIVE: |
179 |
|
(this->Override.*noteParam).Value = |
180 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
181 |
|
itEvent->Param.NoteSynthParam.Delta; |
182 |
|
(this->Override.*noteParam).Scope = ValueScope::RELATIVE; |
183 |
|
break; |
184 |
|
case Event::ValueScope::FINAL_SELF_RELATIVE: |
185 |
|
if ((this->Override.*noteParam).Scope == ValueScope::FINAL_NATIVE) |
186 |
|
(this->Override.*noteParam) = Param(); |
187 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
188 |
|
((this->Override.*noteParam).Value *= itEvent->Param.NoteSynthParam.Delta); |
189 |
|
(this->Override.*noteParam).Scope = ValueScope::FINAL_NORM; |
190 |
|
break; |
191 |
|
case Event::ValueScope::FINAL_NORM: |
192 |
|
(this->Override.*noteParam).Value = |
193 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
194 |
|
itEvent->Param.NoteSynthParam.Delta; |
195 |
|
(this->Override.*noteParam).Scope = ValueScope::FINAL_NORM; |
196 |
|
break; |
197 |
|
case Event::ValueScope::FINAL_NATIVE: |
198 |
|
(this->Override.*noteParam).Value = |
199 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
200 |
|
itEvent->Param.NoteSynthParam.Delta; |
201 |
|
(this->Override.*noteParam).Scope = ValueScope::FINAL_NATIVE; |
202 |
|
break; |
203 |
|
} |
204 |
|
} |
205 |
|
|
206 |
|
inline |
207 |
|
void apply(RTList<Event>::Iterator& itEvent, Norm _Override::*noteParam) { |
208 |
|
const Event::ValueScope& scope = itEvent->Param.NoteSynthParam.Scope; |
209 |
|
switch (scope) { |
210 |
|
case Event::ValueScope::SELF_RELATIVE: |
211 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
212 |
|
((this->Override.*noteParam).Value *= itEvent->Param.NoteSynthParam.Delta); |
213 |
|
(this->Override.*noteParam).Final = false; |
214 |
|
break; |
215 |
|
case Event::ValueScope::RELATIVE: |
216 |
|
(this->Override.*noteParam).Value = |
217 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
218 |
|
itEvent->Param.NoteSynthParam.Delta; |
219 |
|
(this->Override.*noteParam).Final = false; |
220 |
|
break; |
221 |
|
case Event::ValueScope::FINAL_SELF_RELATIVE: |
222 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
223 |
|
((this->Override.*noteParam).Value *= itEvent->Param.NoteSynthParam.Delta); |
224 |
|
(this->Override.*noteParam).Final = true; |
225 |
|
break; |
226 |
|
case Event::ValueScope::FINAL_NORM: |
227 |
|
(this->Override.*noteParam).Value = |
228 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
229 |
|
itEvent->Param.NoteSynthParam.Delta; |
230 |
|
(this->Override.*noteParam).Final = true; |
231 |
|
break; |
232 |
|
case Event::ValueScope::FINAL_NATIVE: |
233 |
|
dmsg(1,("BUG: Attempt to assign a value in native unit to a Note parameter being in normalized value range only!\n")); |
234 |
|
break; |
235 |
|
} |
236 |
|
} |
237 |
|
|
238 |
|
inline |
239 |
|
void apply(RTList<Event>::Iterator& itEvent, SNorm _Override::*noteParam) { |
240 |
|
const Event::ValueScope& scope = itEvent->Param.NoteSynthParam.Scope; |
241 |
|
switch (scope) { |
242 |
|
case Event::ValueScope::SELF_RELATIVE: |
243 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
244 |
|
(this->Override.*noteParam).Value = RTMath::RelativeSummedAvg( |
245 |
|
(this->Override.*noteParam).Value, |
246 |
|
itEvent->Param.NoteSynthParam.Delta, |
247 |
|
++(this->Override.*noteParam).Sources |
248 |
|
); |
249 |
|
(this->Override.*noteParam).Final = false; |
250 |
|
break; |
251 |
|
case Event::ValueScope::RELATIVE: |
252 |
|
(this->Override.*noteParam).Value = |
253 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
254 |
|
itEvent->Param.NoteSynthParam.Delta; |
255 |
|
(this->Override.*noteParam).Sources = 1; |
256 |
|
(this->Override.*noteParam).Final = false; |
257 |
|
break; |
258 |
|
case Event::ValueScope::FINAL_SELF_RELATIVE: |
259 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
260 |
|
(this->Override.*noteParam).Value = RTMath::RelativeSummedAvg( |
261 |
|
(this->Override.*noteParam).Value, |
262 |
|
itEvent->Param.NoteSynthParam.Delta, |
263 |
|
++(this->Override.*noteParam).Sources |
264 |
|
); |
265 |
|
(this->Override.*noteParam).Final = true; |
266 |
|
break; |
267 |
|
case Event::ValueScope::FINAL_NORM: |
268 |
|
(this->Override.*noteParam).Value = |
269 |
|
itEvent->Param.NoteSynthParam.AbsValue = |
270 |
|
itEvent->Param.NoteSynthParam.Delta; |
271 |
|
(this->Override.*noteParam).Sources = 1; |
272 |
|
(this->Override.*noteParam).Final = true; |
273 |
|
break; |
274 |
|
case Event::ValueScope::FINAL_NATIVE: |
275 |
|
dmsg(1,("BUG: Attempt to assign a value in native unit to a Note parameter being in signed normalized value range only!\n")); |
276 |
|
break; |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
|
inline static ValueScope scopeBy_FinalUnit(bool bFinal, bool bNativeUnit) { |
281 |
|
if (!bFinal) return ValueScope::RELATIVE; |
282 |
|
return (bNativeUnit) ? ValueScope::FINAL_NATIVE : ValueScope::FINAL_NORM; |
283 |
|
} |
284 |
protected: |
protected: |
285 |
NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) { |
NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) { |
286 |
Override.Volume = 1.f; |
Override.Volume = Norm(); |
287 |
Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S; |
Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S; |
288 |
Override.Pitch = 1.f; |
Override.Pitch = Norm(); |
289 |
Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S; |
Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S; |
290 |
Override.Pan = 0.f; |
Override.Pan = SNorm(); |
291 |
Override.PanTime = DEFAULT_NOTE_PAN_TIME_S; |
Override.PanTime = DEFAULT_NOTE_PAN_TIME_S; |
292 |
Override.PanSources = 0; |
Override.Cutoff = Param(); |
293 |
Override.Cutoff = 1.f; |
Override.Resonance = Norm(); |
294 |
Override.Resonance = 1.f; |
Override.Attack = Param(); |
295 |
Override.Attack = 1.f; |
Override.Decay = Param(); |
296 |
Override.Decay = 1.f; |
Override.Sustain = Norm(); |
297 |
Override.Sustain = 1.f; |
Override.Release = Param(); |
298 |
Override.Release = 1.f; |
Override.CutoffAttack = Param(); |
299 |
Override.CutoffAttack = 1.f; |
Override.CutoffDecay = Param(); |
300 |
Override.CutoffDecay = 1.f; |
Override.CutoffSustain = Norm(); |
301 |
Override.CutoffSustain = 1.f; |
Override.CutoffRelease = Param(); |
302 |
Override.CutoffRelease = 1.f; |
Override.AmpLFODepth = Norm(); |
303 |
Override.AmpLFODepth = 1.f; |
Override.AmpLFOFreq = Param(); |
304 |
Override.AmpLFOFreq = 1.f; |
Override.CutoffLFODepth = Norm(); |
305 |
Override.CutoffLFODepth = 1.f; |
Override.CutoffLFOFreq = Param(); |
306 |
Override.CutoffLFOFreq = 1.f; |
Override.PitchLFODepth = Norm(); |
307 |
Override.PitchLFODepth = 1.f; |
Override.PitchLFOFreq = Param(); |
|
Override.PitchLFOFreq = 1.f; |
|
308 |
Override.VolumeCurve = DEFAULT_FADE_CURVE; |
Override.VolumeCurve = DEFAULT_FADE_CURVE; |
309 |
Override.PitchCurve = DEFAULT_FADE_CURVE; |
Override.PitchCurve = DEFAULT_FADE_CURVE; |
310 |
Override.PanCurve = DEFAULT_FADE_CURVE; |
Override.PanCurve = DEFAULT_FADE_CURVE; |
369 |
pChildNotes->clear(); |
pChildNotes->clear(); |
370 |
cause = Event(); |
cause = Event(); |
371 |
eventID = 0; |
eventID = 0; |
372 |
Override.Volume = 1.f; |
Override.Volume = Norm(); |
373 |
Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S; |
Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S; |
374 |
Override.Pitch = 1.f; |
Override.Pitch = Norm(); |
375 |
Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S; |
Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S; |
376 |
Override.Pan = 0.f; |
Override.Pan = SNorm(); |
377 |
Override.PanTime = DEFAULT_NOTE_PAN_TIME_S; |
Override.PanTime = DEFAULT_NOTE_PAN_TIME_S; |
378 |
Override.PanSources = 0; |
Override.Cutoff = Param(); |
379 |
Override.Cutoff = 1.f; |
Override.Resonance = Norm(); |
380 |
Override.Resonance = 1.f; |
Override.Attack = Param(); |
381 |
Override.Attack = 1.f; |
Override.Decay = Param(); |
382 |
Override.Decay = 1.f; |
Override.Sustain = Norm(); |
383 |
Override.Sustain = 1.f; |
Override.Release = Param(); |
384 |
Override.Release = 1.f; |
Override.CutoffAttack = Param(); |
385 |
Override.CutoffAttack = 1.f; |
Override.CutoffDecay = Param(); |
386 |
Override.CutoffDecay = 1.f; |
Override.CutoffSustain = Norm(); |
387 |
Override.CutoffSustain = 1.f; |
Override.CutoffRelease = Param(); |
388 |
Override.CutoffRelease = 1.f; |
Override.AmpLFODepth = Norm(); |
389 |
Override.AmpLFODepth = 1.f; |
Override.AmpLFOFreq = Param(); |
390 |
Override.AmpLFOFreq = 1.f; |
Override.CutoffLFODepth = Norm(); |
391 |
Override.CutoffLFODepth = 1.f; |
Override.CutoffLFOFreq = Param(); |
392 |
Override.CutoffLFOFreq = 1.f; |
Override.PitchLFODepth = Norm(); |
393 |
Override.PitchLFODepth = 1.f; |
Override.PitchLFOFreq = Param(); |
|
Override.PitchLFOFreq = 1.f; |
|
394 |
Override.VolumeCurve = DEFAULT_FADE_CURVE; |
Override.VolumeCurve = DEFAULT_FADE_CURVE; |
395 |
Override.PitchCurve = DEFAULT_FADE_CURVE; |
Override.PitchCurve = DEFAULT_FADE_CURVE; |
396 |
Override.PanCurve = DEFAULT_FADE_CURVE; |
Override.PanCurve = DEFAULT_FADE_CURVE; |