-
Notifications
You must be signed in to change notification settings - Fork 1
/
VoiceManager.h
80 lines (76 loc) · 2.43 KB
/
VoiceManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "Voice.h"
#include <functional>
class VoiceManager
{
public:
void onNoteOn(int noteNumber, int velocity);
void onNoteOff(int noteNumber, int velocity);
double nextSample();
void setSampleRate(double sampleRate) {
EnvelopeGenerator::setSampleRate(sampleRate);
for (int i = 0; i < NumberOfVoices; i++) {
Voice& voice = voices[i];
voice.mOscillatorOne.setSampleRate(sampleRate);
voice.mOscillatorTwo.setSampleRate(sampleRate);
}
mLFO.setSampleRate(sampleRate);
}
inline void setLFOMode(Oscillator::OscillatorMode mode) { mLFO.setMode(mode); }
inline void setLFOFrequency(double frequency) { mLFO.setFrequency(frequency); }
typedef std::tr1::function<void(Voice&)> VoiceChangerFunction;
inline void changeAllVoices(VoiceChangerFunction changer) {
for (int i = 0; i < NumberOfVoices; i++) {
changer(voices[i]);
}
}
//Functions to change a single voice:
static void setVolumeEnvelopeStageValue(Voice& voice, EnvelopeGenerator::EnvelopeStage stage, double value) {
voice.mVolumeEnvelope.setStageValue(stage, value);
}
static void setFilterEnvelopeStageValue(Voice& voice, EnvelopeGenerator::EnvelopeStage stage, double value) {
voice.mFilterEnvelope.setStageValue(stage, value);
}
static void setOscillatorMode(Voice& voice, int oscillatorNumber, Oscillator::OscillatorMode mode) {
switch (oscillatorNumber) {
case 1:
voice.mOscillatorOne.setMode(mode);
break;
case 2:
voice.mOscillatorTwo.setMode(mode);
break;
}
}
static void setOscillatorPitchMod(Voice& voice, int oscillatorNumber, double amount) {
switch (oscillatorNumber) {
case 1:
voice.setOscillatorOnePitchAmount(amount);
break;
case 2:
voice.setOscillatorTwoPitchAmount(amount);
break;
}
}
static void setOscillatorMix(Voice& voice, double value) {
voice.setOscillatorMix(value);
}
static void setFilterCutoff(Voice& voice, double cutoff) {
voice.mFilter.setCutoff(cutoff);
}
static void setFilterResonance(Voice& voice, double resonance) {
voice.mFilter.setResonance(resonance);
}
static void setFilterMode(Voice& voice, Filter::FilterMode mode) {
voice.mFilter.setFilterMode(mode);
}
static void setFilterEnvAmount(Voice& voice, double amount) {
voice.setFilterEnvelopeAmount(amount);
}
static void setFilterLFOAmount(Voice& voice, double amount) {
voice.setFilterLFOAmount(amount);
}
private:
static const int NumberOfVoices = 64;
Voice voices[NumberOfVoices];
Oscillator mLFO;
Voice* findFreeVoice();
};