You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
#ifndef __PART_H__
|
|
#define __PART_H__
|
|
|
|
#include <unordered_map>
|
|
#include <set>
|
|
|
|
#include "globals.h"
|
|
#include "voicemanager.h"
|
|
#include "voice.h"
|
|
#include "preset.h"
|
|
#include "dsp/frame.h"
|
|
|
|
class Channel {
|
|
public:
|
|
VoiceManager::channel_t number;
|
|
VoiceManager* voiceManager;
|
|
Voice::Settings settings;
|
|
|
|
Channel() : volume(1), pitchBend(0), modulation(0), lfoPhase(randPhase()) {}
|
|
|
|
void loadPreset(const Preset* preset);
|
|
|
|
void noteOn(int note, int vel);
|
|
void noteOff(int note);
|
|
void control(int cc, int val);
|
|
|
|
frame tick() {
|
|
frame out{0, 0};
|
|
float lfo = sin(lfoPhase);
|
|
Voice** voices = voiceManager->getChannelVoices(number);
|
|
for(Voice** voice = voices; *voice != NULL; ++voice) {
|
|
float voiceOut = (*voice)->tick(pitchBend + settings.lfoPitchMod * lfo, settings.lfoFltMod * lfo);
|
|
out.l += sinf((1 - (*voice)->pan) * (float) M_PI_2) * voiceOut;
|
|
out.r += sinf((*voice)->pan * (float) M_PI_2) * voiceOut;
|
|
}
|
|
out *= volume;
|
|
|
|
lfoPhase += settings.lfoStep;
|
|
if(lfoPhase >= (float) PIx2) {
|
|
lfoPhase -= PIx2;
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
private:
|
|
float volume;
|
|
float pitchBend;
|
|
float modulation;
|
|
|
|
float lfoPhase;
|
|
};
|
|
|
|
#endif |