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:
// debug accent handling that overloads the filter
// bring back manual triggering (test conflicts with midi)
// add overdrive
#include <Mozzi.h>
@ -108,11 +107,12 @@ IntMap kMapDrive( 0, 1023, 0, 400 );
Ead kEnvelope(MOZZI_CONTROL_RATE);
LowPassFilter lpfr;
Portamento <MOZZI_CONTROL_RATE> glide;
Portamento <MOZZI_CONTROL_RATE> kGlide;
//Global variables
byte gain;
bool MIDINotePlaying;
bool MIDINoteFaded = true;
bool gateIsHigh = false;
Q16n16 noteFreq;
bool envSwitchVal;
@ -123,6 +123,7 @@ int driveAmount;
byte notePlaying;
bool accent = false;
void MIDINoteOn(byte channel, byte note, byte velocity) {
notePlaying = note;
noteFreq = Q16n16_mtof((int) note);
@ -132,15 +133,16 @@ void MIDINoteOn(byte channel, byte note, byte velocity) {
}
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 {
glide.setTime(GLIDE_TIME);
kGlide.setTime(GLIDE_TIME);
}
glide.start(note);
kGlide.start(note);
if (!MIDINotePlaying || !droneSwitchVal) {
kEnvelope.start();
}
MIDINotePlaying = true;
MIDINoteFaded = false;
digitalWrite(LED, LOW);
}
@ -272,6 +274,18 @@ void updateControl(){
int envMod = kMapEnvMod(knob3Val);
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
int attackTime = kMapAttack(knobAVal);
int decayReleaseTime = kMapDecay(knobDRVal);
@ -283,12 +297,16 @@ void updateControl(){
//Set Oscilator Frequency
Q16n16 oscFreq;
oscFreq = glide.next();
oscFreq = kGlide.next();
aSquare.setFreq_Q16n16(oscFreq);
aSaw.setFreq_Q16n16(oscFreq);
int env = kEnvelope.next();
if (!MIDINotePlaying && !MIDINoteFaded && env == 0) { //threshhold might need adjustment
MIDINoteFaded = true;
}
gain = accent? env * 2 : env;
lpfr.setCutoffFreqAndResonance(constrain(cutoff + (((long)env * envMod * cutoff)>>16), 0, 255), resonance);
@ -298,7 +316,7 @@ void updateControl(){
AudioOutput updateAudio(){
long signal;
if(envSwitchVal) {
signal = (aSquare.next() * 3) >> 2; // tricky way to set 0.75 gain to ~ match saw level
signal = (aSquare.next() * 3) >> 2; //tricky way to set 0.75 gain to ~ match saw level
} else {
signal = aSaw.next();
}