Moved modes to enum

This commit is contained in:
Oleksiy
2025-03-27 19:55:15 +02:00
parent cd29fedbfb
commit 4767c2942f
3 changed files with 52 additions and 50 deletions

View File

@ -23,8 +23,10 @@ uint8_t bpm = 130;
uint8_t bpmModulationChannel = 200; //0 - CV1, 1 - CV2, 255 - OFF
uint8_t bpmModulationRange = 0;
enum modes {Clock, Random, Sequencer, Swing, Gate};
struct channel {
uint8_t mode : 3; //mv: 7. 0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate
enum modes mode : 3; //mv: 7. 0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate
uint8_t subDiv : 5; //mv: 31
uint8_t random : 4; //mv: 15
uint8_t seqPattern : 5;
@ -238,7 +240,7 @@ void clock() {
if (bpmModulationRange != 0) {
calculateBPMTiming();
for (uint8_t i; i < 7; i++) {
if (channels[i].mode == 4) {
if (channels[i].mode == Gate) {
calculateGate(i);
}
}
@ -264,12 +266,12 @@ void clock() {
// pull low all outputs after set pulse length
for (uint8_t i = 0; i < 7; i++) {
if (channels[i].mode != 4 && tickCount >= PULSE_LENGTH) { //everything but gate mode
if (channels[i].mode != Gate && tickCount >= PULSE_LENGTH) { //everything but gate mode
digitalWrite(outsPins[i], LOW);
} else if (channels[i].mode == 4 && tickCount >= gateCountDown[i]) { //gate mode gateLengthTime[i] < pulsePeriod
} else if (channels[i].mode == Gate && tickCount >= gateCountDown[i]) { //gate mode gateLengthTime[i] < pulsePeriod
digitalWrite(outsPins[i], LOW);
gateCountDown[i] = gateLengthTime[i];
} else if (channels[i].mode == 4 && gateCountDown[i] > pulsePeriod && tickCount == 0) {
} else if (channels[i].mode == Gate && gateCountDown[i] > pulsePeriod && tickCount == 0) {
gateCountDown[i] = gateCountDown[i] - pulsePeriod;
}
}
@ -360,7 +362,7 @@ void sendTriggers() { //rename to onPulse or something
}
bool currentStepValue = bitRead(sequences[channels[i].seqPattern].sequence, currentStep[i]);
if (channels[i].mode == 2 && currentStepValue && !channels[i].isMute) {
if (channels[i].mode == Sequencer && currentStepValue && !channels[i].isMute) {
digitalWrite(outsPins[i], HIGH);
}
}
@ -373,7 +375,7 @@ void sendTriggers() { //rename to onPulse or something
} else {
sixteenthPulseCount = 0;
for (uint8_t i; i < 7; i++) {
if (channels[i].mode == 2 && currentStep[i] < sequences[channels[i].seqPattern].length) {
if (channels[i].mode == Sequencer && currentStep[i] < sequences[channels[i].seqPattern].length) {
currentStep[i] ++;
} else {
currentStep[i] = 0;
@ -390,7 +392,7 @@ void sendTriggers() { //rename to onPulse or something
channelPulseCount[i] = 0;
needPulseReset[i] = false;
}
if (channels[i].mode == 4) {
if (channels[i].mode == Gate) {
calculateGate(i);
}
}
@ -418,15 +420,15 @@ void sendTriggers() { //rename to onPulse or something
}
if (!channels[i].isMute) {
if ((channels[i].mode == 3 && channelPulseCount[i] == 0 && stepIsOdd == 0)
|| (channels[i].mode == 3 && channelPulseCount[i] == channels[i].swing && stepIsOdd == 1) //swing
if ((channels[i].mode == Swing && channelPulseCount[i] == 0 && stepIsOdd == 0)
|| (channels[i].mode == Swing && channelPulseCount[i] == channels[i].swing && stepIsOdd == 1) //swing
) {
digitalWrite(outsPins[i], HIGH);
}
if ((channels[i].mode == 0 && channelPulseCount[i] == channels[i].offset) //CLK with offset
|| (channels[i].mode == 1 && channelPulseCount[i] == 0 && (random(10) + 1) > randAmount) //RND
|| (channels[i].mode == 4 && channelPulseCount[i] == 0) //Gate
if ((channels[i].mode == Clock && channelPulseCount[i] == channels[i].offset) //CLK with offset
|| (channels[i].mode == Random && channelPulseCount[i] == 0 && (random(10) + 1) > randAmount) //RND
|| (channels[i].mode == Gate && channelPulseCount[i] == 0) //Gate
) {
digitalWrite(outsPins[i], HIGH);
}
@ -450,7 +452,7 @@ void calculateCycles() {
}
playingModes[i] = subDivs[channels[i].subDiv - mod]; //subtracting because the innitial array is backwards
if (channels[i].mode == 2 || channels[i].mode == 3) { //Sequencer and swing plays 1/16th
if (channels[i].mode == Sequencer || channels[i].mode == Swing) { //Sequencer and swing plays 1/16th
channelPulsesPerCycle[i] = (PPQN / 4) - 1;
} else if (playingModes[i] > 0) {
channelPulsesPerCycle[i] = (playingModes[i] * PPQN) - 1;