25 |
|
|
26 |
#include "global.h" |
#include "global.h" |
27 |
|
|
28 |
|
/** |
29 |
|
* Handles modulation parameters and events for the current audio fragment. |
30 |
|
* |
31 |
|
* TODO: class should better be renamed to 'EventSystem' or even better: most of the attributes here could be moved into the engine and everything left would just be class Event (thus -> event.h and event.cpp), but that can wait until we restructe the source tree for multi engine support |
32 |
|
*/ |
33 |
class ModulationSystem { |
class ModulationSystem { |
34 |
public: |
public: |
35 |
enum destination_t { |
enum destination_t { |
36 |
destination_vca, ///< Volume level |
destination_vca, ///< Volume level |
37 |
|
destination_vco, ///< Pitch depth |
38 |
destination_count ///< Total number of modulation sources (this has to stay the last element in the enum) |
destination_count ///< Total number of modulation sources (this has to stay the last element in the enum) |
39 |
}; |
}; |
40 |
enum source_t { |
typedef uint32_t real_time_t; ///< We read the processor's cycle count register as an reference for the real time. These are of course only abstract values with arbitrary time entity, but that's not a problem as we calculate relatively. |
41 |
source_eg1, ///< Envelope Generator 1 |
enum event_type_t { |
42 |
source_count ///< Total number of modulation sources (this has to stay the last element in the enum) |
event_type_note_on, |
43 |
|
event_type_note_off, |
44 |
|
event_type_pitchbend, |
45 |
|
event_type_control_change |
46 |
|
}; |
47 |
|
class Event { |
48 |
|
public: |
49 |
|
event_type_t Type; |
50 |
|
union { |
51 |
|
uint8_t Key; ///< MIDI key number for note-on and note-off events. |
52 |
|
uint8_t Controller; ///< MIDI controller number for control change events. |
53 |
|
}; |
54 |
|
union { |
55 |
|
uint8_t Velocity; ///< Trigger or release velocity for note-on or note-off events. |
56 |
|
uint8_t Value; ///< Value for control change events. |
57 |
|
}; |
58 |
|
int16_t Pitch; ///< Pitch value for pitchbend events. |
59 |
|
|
60 |
|
Event() { |
61 |
|
TimeStamp = ModulationSystem::CreateTimeStamp(); |
62 |
|
iFragmentPos = -1; |
63 |
|
}; |
64 |
|
uint FragmentPos() { |
65 |
|
if (iFragmentPos >= 0) return (uint) iFragmentPos; |
66 |
|
return (uint) (iFragmentPos = ModulationSystem::ToFragmentPos(TimeStamp)); |
67 |
|
}; |
68 |
|
private: |
69 |
|
real_time_t TimeStamp; ///< Time stamp of the event's occurence. |
70 |
|
int iFragmentPos; ///< Position in the current fragment this event refers to. |
71 |
}; |
}; |
72 |
|
|
73 |
static float** pDestinationParameter; |
static float** pDestinationParameter; |
|
//static bool DestinationParameterModified; |
|
74 |
|
|
75 |
static void Initialize(uint SampleRate, uint MaxSamplesPerCycle); |
static void Initialize(uint SampleRate, uint MaxSamplesPerCycle); |
76 |
static void Close(); |
static void Close(); |
77 |
static void ResetDestinationParameter(ModulationSystem::destination_t dst, float val); |
static void ResetDestinationParameter(ModulationSystem::destination_t dst, float val); |
78 |
static inline uint GetMaxSamplesPerCycle() { return uiMaxSamplesPerCycle; }; |
static void UpdateFragmentTime(); |
79 |
static inline uint GetSampleRate() { return uiSampleRate; }; |
static real_time_t CreateTimeStamp(); |
80 |
|
static inline uint MaxSamplesPerCycle() { return uiMaxSamplesPerCycle; }; |
81 |
|
static inline uint SampleRate() { return uiSampleRate; }; |
82 |
|
static inline uint ToFragmentPos(real_time_t time_stamp) { |
83 |
|
return uint ((time_stamp - FragmentTime.begin) * FragmentTime.sample_ratio); |
84 |
|
}; |
85 |
protected: |
protected: |
86 |
static uint uiMaxSamplesPerCycle; |
static uint uiMaxSamplesPerCycle; |
87 |
static uint uiSampleRate; |
static uint uiSampleRate; |
88 |
|
static struct __FragmentTime__ { |
89 |
|
real_time_t begin; ///< Real time stamp of the beginning of this audio fragment cycle. |
90 |
|
real_time_t end; ///< Real time stamp of the end of this audio fragment cycle. |
91 |
|
float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle) |
92 |
|
} FragmentTime; |
93 |
}; |
}; |
94 |
|
|
95 |
#endif // __MODULATION_SYSTEM_H__ |
#endif // __MODULATION_SYSTEM_H__ |