Added back manual triggering. Probably? Needs testing, esp. for conflicts with MIDI

This commit is contained in:
Oleksiy
2026-09-15 15:44:55 +03:00
parent 7f57145035
commit 0a17cda874

View File

@ -8,7 +8,6 @@
// todo: // todo:
// debug accent handling that overloads the filter // debug accent handling that overloads the filter
// bring back manual triggering (test conflicts with midi)
// add overdrive // add overdrive
#include <Mozzi.h> #include <Mozzi.h>
@ -108,11 +107,12 @@ IntMap kMapDrive( 0, 1023, 0, 400 );
Ead kEnvelope(MOZZI_CONTROL_RATE); Ead kEnvelope(MOZZI_CONTROL_RATE);
LowPassFilter lpfr; LowPassFilter lpfr;
Portamento <MOZZI_CONTROL_RATE> glide; Portamento <MOZZI_CONTROL_RATE> kGlide;
//Global variables //Global variables
byte gain; byte gain;
bool MIDINotePlaying; bool MIDINotePlaying;
bool MIDINoteFaded = true;
bool gateIsHigh = false; bool gateIsHigh = false;
Q16n16 noteFreq; Q16n16 noteFreq;
bool envSwitchVal; bool envSwitchVal;
@ -123,6 +123,7 @@ int driveAmount;
byte notePlaying; byte notePlaying;
bool accent = false; bool accent = false;
void MIDINoteOn(byte channel, byte note, byte velocity) { void MIDINoteOn(byte channel, byte note, byte velocity) {
notePlaying = note; notePlaying = note;
noteFreq = Q16n16_mtof((int) note); noteFreq = Q16n16_mtof((int) note);
@ -132,15 +133,16 @@ void MIDINoteOn(byte channel, byte note, byte velocity) {
} }
if (!MIDINotePlaying || !droneSwitchVal) { if (!MIDINotePlaying || !droneSwitchVal) {
glide.setTime(2); //4 at 256, 2 at 512 control rate to avoid portamento glitches caused by 0 kGlide.setTime(2); //4 at 256, 2 at 512 control rate to avoid portamento glitches caused by 0
} else { } else {
glide.setTime(GLIDE_TIME); kGlide.setTime(GLIDE_TIME);
} }
glide.start(note); kGlide.start(note);
if (!MIDINotePlaying || !droneSwitchVal) { if (!MIDINotePlaying || !droneSwitchVal) {
kEnvelope.start(); kEnvelope.start();
} }
MIDINotePlaying = true; MIDINotePlaying = true;
MIDINoteFaded = false;
digitalWrite(LED, LOW); digitalWrite(LED, LOW);
} }
@ -272,6 +274,18 @@ void updateControl(){
int envMod = kMapEnvMod(knob3Val); int envMod = kMapEnvMod(knob3Val);
driveAmount = kMapDrive(knob4Val); driveAmount = kMapDrive(knob4Val);
//Set pitch and play notes on trigger
if (MIDINoteFaded) {
noteFreq = mtof((float) kMapNote(CVInVal << 2) / pitchSubSteps);
digitalWrite(LED, !gateInVal);
if (gateInVal && !gateIsHigh) {
gateIsHigh = true;
kEnvelope.start();
} else if (!gateInVal && gateIsHigh) {
gateIsHigh = false;
}
}
//Update Envelope Settings //Update Envelope Settings
int attackTime = kMapAttack(knobAVal); int attackTime = kMapAttack(knobAVal);
int decayReleaseTime = kMapDecay(knobDRVal); int decayReleaseTime = kMapDecay(knobDRVal);
@ -283,12 +297,16 @@ void updateControl(){
//Set Oscilator Frequency //Set Oscilator Frequency
Q16n16 oscFreq; Q16n16 oscFreq;
oscFreq = glide.next(); oscFreq = kGlide.next();
aSquare.setFreq_Q16n16(oscFreq); aSquare.setFreq_Q16n16(oscFreq);
aSaw.setFreq_Q16n16(oscFreq); aSaw.setFreq_Q16n16(oscFreq);
int env = kEnvelope.next(); int env = kEnvelope.next();
if (!MIDINotePlaying && !MIDINoteFaded && env == 0) { //threshhold might need adjustment
MIDINoteFaded = true;
}
gain = accent? env * 2 : env; gain = accent? env * 2 : env;
lpfr.setCutoffFreqAndResonance(constrain(cutoff + (((long)env * envMod * cutoff)>>16), 0, 255), resonance); lpfr.setCutoffFreqAndResonance(constrain(cutoff + (((long)env * envMod * cutoff)>>16), 0, 255), resonance);