Skip to content

Commit

Permalink
bound notes to supported frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidaudio committed Mar 13, 2021
1 parent 920f23a commit b29ab56
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void SquareOscilator::setDuty(DutyCycle duty)

void SquareOscilator::setEvent(MidiEvent event)
{
if (event.note < 36 || event.note > 108) {
setConstantVolume(0); // ignore it
return;
}
setConstantVolume(event.velocity);
set11BitPeriod(event.note);
}
Expand Down Expand Up @@ -184,6 +188,10 @@ void WaveOscillator::setWaveTable(uint8_t* samples)

void WaveOscillator::setEvent(MidiEvent event)
{
if (event.note < 36 || event.note > 120) {
setVelocity(0); // ignore it
return;
}
setVelocity(event.velocity);
set11BitPeriod(event.note);
}
Expand Down Expand Up @@ -308,8 +316,6 @@ void Synth::handleMIDIEvent(juce::MidiMessage msg)
for (OSCID i = 0; i < NUM_OSC; i++) {
if (!configs_[i].enabled) continue;
MidiEvent e = manager_.get(configs_[i].voice);
// NOTE: transposes can cause notes to wrap. I'm choosing to call this
// expected behavior.
e.note += configs_[i].transpose;
oscs_[i]->setEvent(e);
}
Expand Down

0 comments on commit b29ab56

Please sign in to comment.