Basic monophonic

This commit is contained in:
Takeshi Yokemura 2021-05-18 23:57:43 +09:00
parent be1f0b4e3b
commit 0a5110c8d3
4 changed files with 34 additions and 1 deletions

View File

@ -218,6 +218,13 @@ void BaseVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSampl
}
}
void BaseVoice::changeNote (int midiNoteNumber, float velocity) {
noteNumber = midiNoteNumber;
ampByVelocityAndGain = * (settingRefs->gain) * velocity; // velocity value range is 0.0f-1.0f
}
void BaseVoice::calculateAngleDelta()
{
auto cyclesPerSecond = MidiMessage::getMidiNoteInHertz (noteNumber);

View File

@ -24,6 +24,8 @@ struct BaseVoice : public SynthesiserVoice
void pitchWheelMoved (int) override {}
void controllerMoved (int, int) override {}
void renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples) override;
void changeNote (int midiNoteNumber, float velocity);
virtual float voltageForAngle (double angle) = 0;
virtual void onFrameAdvanced() {};

View File

@ -9,13 +9,36 @@
*/
#include "CustomSynth.h"
#include "BaseVoice.h"
#include "PluginProcessor.h"
CustomSynth::CustomSynth(Magical8bitPlug2AudioProcessor& p) : processor(p) {}
void CustomSynth::noteOn(int midiChannel, int midiNoteNumber, float velocity) {
Synthesiser::noteOn(midiChannel, midiNoteNumber, velocity);
// Poly
if (!processor.settingRefs.isMonophonic()) {
Synthesiser::noteOn(midiChannel, midiNoteNumber, velocity);
return;
}
// Mono
auto voice = voices.getFirst();
if (voice == nullptr) {
return;
}
if (voice->isKeyDown()) {
((BaseVoice*)voice)->changeNote(midiNoteNumber, velocity);
} else {
Synthesiser::noteOn(midiChannel, midiNoteNumber, velocity);
}
}
void CustomSynth::noteOff(int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff) {
Synthesiser::noteOff(midiChannel, midiNoteNumber, velocity, allowTailOff);
}
void CustomSynth::allNotesOff (const int midiChannel, const bool allowTailOff) {
Synthesiser::allNotesOff(midiChannel, allowTailOff);
}

View File

@ -19,6 +19,7 @@ public:
void noteOn(int midiChannel, int midiNoteNumber, float velocity) override;
void noteOff(int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff) override;
void allNotesOff (const int midiChannel, const bool allowTailOff) override;
private:
Magical8bitPlug2AudioProcessor& processor;