3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2017 Christian Schoenebeck * |
* Copyright (C) 2005 - 2019 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
31 |
#include "../EngineChannel.h" |
#include "../EngineChannel.h" |
32 |
#include "../../scriptvm/common.h" |
#include "../../scriptvm/common.h" |
33 |
|
|
34 |
|
// On Windows RELATIVE might be defined as macro in wingdi.h, which would |
35 |
|
// cause a compiler error of the same token used in this header file below. |
36 |
|
// So we undefine that macro here for now (if present). |
37 |
|
#ifdef RELATIVE |
38 |
|
# warning Preprocessor conflict detected: Macro RELATIVE was declared by system headers; undefining it here. |
39 |
|
# undef RELATIVE |
40 |
|
#endif |
41 |
|
|
42 |
namespace LinuxSampler { |
namespace LinuxSampler { |
43 |
|
|
44 |
// just symbol prototyping |
// just symbol prototyping |
186 |
synth_param_pitch_time, |
synth_param_pitch_time, |
187 |
synth_param_pitch_curve, |
synth_param_pitch_curve, |
188 |
synth_param_pan, |
synth_param_pan, |
189 |
|
synth_param_pan_time, |
190 |
|
synth_param_pan_curve, |
191 |
synth_param_cutoff, |
synth_param_cutoff, |
192 |
synth_param_resonance, |
synth_param_resonance, |
193 |
synth_param_attack, |
synth_param_attack, |
194 |
synth_param_decay, |
synth_param_decay, |
195 |
synth_param_sustain, |
synth_param_sustain, |
196 |
synth_param_release, |
synth_param_release, |
197 |
|
synth_param_cutoff_attack, |
198 |
|
synth_param_cutoff_decay, |
199 |
|
synth_param_cutoff_sustain, |
200 |
|
synth_param_cutoff_release, |
201 |
synth_param_amp_lfo_depth, |
synth_param_amp_lfo_depth, |
202 |
synth_param_amp_lfo_freq, |
synth_param_amp_lfo_freq, |
203 |
|
synth_param_cutoff_lfo_depth, |
204 |
|
synth_param_cutoff_lfo_freq, |
205 |
synth_param_pitch_lfo_depth, |
synth_param_pitch_lfo_depth, |
206 |
synth_param_pitch_lfo_freq, |
synth_param_pitch_lfo_freq, |
207 |
}; |
}; |
208 |
|
enum class ValueScope : unsigned char { |
209 |
|
/** |
210 |
|
* The new synthesis parameter value should be applied |
211 |
|
* relatively to itself (as normalized value range), and then |
212 |
|
* applied relatively against other sources (i.e. LFOs, EGs) |
213 |
|
* for the same synthesis parameter. |
214 |
|
*/ |
215 |
|
SELF_RELATIVE = 1, |
216 |
|
/** |
217 |
|
* The new synthesis paramater value of itself should be |
218 |
|
* replaced, and then applied relatively to other sources |
219 |
|
* (i.e. LFOs, EGs) for the same synthesis parameter. |
220 |
|
*/ |
221 |
|
RELATIVE = 0, //IMPORANT: must remain 0 because of the union structure below which would otherwise i.e. assign invalid pointers/IDs to Param.Note structure in Init() |
222 |
|
/** |
223 |
|
* The new synthesis parameter value should be applied |
224 |
|
* relatively to itself (as normalized value range), and then |
225 |
|
* applied directly (as normalized value range) as final value |
226 |
|
* of this synthesis chain, thus all other sources (i.e. LFOs, |
227 |
|
* EGs) should entirely be ignored. |
228 |
|
*/ |
229 |
|
FINAL_SELF_RELATIVE = 2, |
230 |
|
/** |
231 |
|
* The new synthesis parameter value of itself should be |
232 |
|
* replaced, and then applied directly (as normalized value |
233 |
|
* range) as final value of this synthesis chain, thus all other |
234 |
|
* sources (i.e. LFOs, EGs) should entirely be ignored. |
235 |
|
*/ |
236 |
|
FINAL_NORM = 3, |
237 |
|
/** |
238 |
|
* Same as @c FINAL_NORM, but this one is already in the native |
239 |
|
* unit (i.e. seconds, Hz) of this synthesis parameter. |
240 |
|
*/ |
241 |
|
FINAL_NATIVE = 4, |
242 |
|
}; |
243 |
union { |
union { |
244 |
/// Note-on and note-off event specifics |
/// Note-on and note-off event specifics |
245 |
struct _Note { |
struct _Note { |
284 |
note_id_t NoteID; ///< ID of Note whose voices shall be modified. |
note_id_t NoteID; ///< ID of Note whose voices shall be modified. |
285 |
synth_param_t Type; ///< Synthesis parameter which is to be changed. |
synth_param_t Type; ///< Synthesis parameter which is to be changed. |
286 |
float Delta; ///< The value change that should be applied against the note's current synthesis parameter value. |
float Delta; ///< The value change that should be applied against the note's current synthesis parameter value. |
|
bool Relative; ///< Whether @c Delta should be applied relatively against the note's current synthesis parameter value (false means the paramter's current value is simply replaced by Delta). |
|
287 |
float AbsValue; ///< New current absolute value of synthesis parameter (that is after @c Delta being applied). |
float AbsValue; ///< New current absolute value of synthesis parameter (that is after @c Delta being applied). |
288 |
|
ValueScope Scope; ///< How @c Delta should be applied against @c AbsValue, and how @c AbsValue should then actually be applied to the synthesis chain. |
289 |
|
|
290 |
|
inline bool isFinal() const { return Scope >= ValueScope::FINAL_SELF_RELATIVE; } |
291 |
} NoteSynthParam; |
} NoteSynthParam; |
292 |
} Param; |
} Param; |
293 |
EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message). |
EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message). |
294 |
MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages) |
MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages) |
295 |
|
|
296 |
inline void Init() { |
inline void Init() { |
297 |
|
//FIXME: probably we should memset() zero entire structure here, due to potential union initialization conflicts (see comment on ValueScope::RELATIVE) |
298 |
Param.Note.ID = 0; |
Param.Note.ID = 0; |
299 |
Param.Note.ParentNoteID = 0; |
Param.Note.ParentNoteID = 0; |
300 |
Param.NoteSynthParam.NoteID = 0; |
Param.NoteSynthParam.NoteID = 0; |
301 |
|
Param.NoteSynthParam.Scope = ValueScope::RELATIVE; |
302 |
} |
} |
303 |
inline int32_t FragmentPos() { |
inline int32_t FragmentPos() { |
304 |
if (iFragmentPos >= 0) return iFragmentPos; |
if (iFragmentPos >= 0) return iFragmentPos; |
316 |
inline sched_time_t SchedTime() { |
inline sched_time_t SchedTime() { |
317 |
return pEventGenerator->schedTimeAtCurrentFragmentStart() + FragmentPos(); |
return pEventGenerator->schedTimeAtCurrentFragmentStart() + FragmentPos(); |
318 |
} |
} |
319 |
|
inline static ValueScope scopeBy_FinalRelativeUnit(bool bFinal, bool bRelative, bool bNativeUnit) { |
320 |
|
if (!bFinal && bRelative) |
321 |
|
return ValueScope::SELF_RELATIVE; |
322 |
|
if (!bFinal) |
323 |
|
return ValueScope::RELATIVE; |
324 |
|
if (bRelative) |
325 |
|
return ValueScope::FINAL_SELF_RELATIVE; |
326 |
|
if (bNativeUnit) |
327 |
|
return ValueScope::FINAL_NATIVE; |
328 |
|
return ValueScope::FINAL_NORM; |
329 |
|
} |
330 |
protected: |
protected: |
331 |
typedef EventGenerator::time_stamp_t time_stamp_t; |
typedef EventGenerator::time_stamp_t time_stamp_t; |
332 |
Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time); |
Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time); |