fixed unwanted offset bug

This commit is contained in:
--global
2023-05-08 00:04:32 +03:00
parent a4225751e5
commit 5ddfb5e266

View File

@ -48,7 +48,6 @@ int playingModes[6]; //actual channel modes array updated from channels each bea
int pulsePeriod; int pulsePeriod;
bool isPlaying = false; bool isPlaying = false;
bool beatCounted = false;
bool pulseCounted = false; bool pulseCounted = false;
unsigned int tickCount = 0; unsigned int tickCount = 0;
@ -123,7 +122,7 @@ void setup() {
display.setTextColor(SSD1306_WHITE); display.setTextColor(SSD1306_WHITE);
display.println(F("V:0.1a")); //Version display.println(F("V:0.1a")); //Version
display.display(); display.display();
delay(1200); delay(800);
updateScreen(); updateScreen();
updateTiming(); updateTiming();
@ -151,23 +150,36 @@ void clock() {
tickCount++; tickCount++;
} else { } else {
tickCount = 0; tickCount = 0;
if (pulseCount < PPQN) { if (pulseCount < (PPQN-1)) { //-1 is here to avoid extra IF to reset to 0
pulseCount++; pulseCount++;
beatCounted = false; //reset pulse and beat count AFTER the pulse is incremented
pulseCounted = false;
} else { } else {
pulseCount = 0; //Beat happens here pulseCount = 0;
} }
} }
//pulse and beat count reset
if (tickCount == 0) {
pulseCounted = false;
}
// pull low all outputs after set pulse length
if (tickCount >= PULSE_LENGTH) {
for (int i = 0; i<6; i++) {
digitalWrite(outsPins[i], LOW);
}
}
} }
} }
void sendTriggers() { void sendTriggers() {
//divider //divider
if (pulseCount == 0 && !beatCounted) { if (pulseCount == 0) {
for (int i = 0; i<6; i++) { for (int i = 0; i<6; i++) {
playingModes[i] = clockModes[channels[i].mode]; //updated here to prevent sync problems for multipliers if (playingModes[i] != clockModes[channels[i].mode]) { //switching modes on the beat and resetting channel clock
playingModes[i] = clockModes[channels[i].mode];
outsClocksCounts[i] = 0;
}
if (playingModes[i] > 0) { if (playingModes[i] > 0) {
if (outsClocksCounts[i] == 0) { //Pulse on 0 if (outsClocksCounts[i] == 0) { //Pulse on 0
if (channels[i].random == 0 || random(10) > channels[i].random) { if (channels[i].random == 0 || random(10) > channels[i].random) {
@ -181,7 +193,6 @@ void sendTriggers() {
} }
} }
} }
beatCounted = true;
} }
//multiplier //multiplier
@ -192,7 +203,7 @@ void sendTriggers() {
digitalWrite(outsPins[i], HIGH); digitalWrite(outsPins[i], HIGH);
} }
} }
if (outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) { if (playingModes[i] < 0 && outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) { //multiplier
outsClocksCounts[i]++; outsClocksCounts[i]++;
} else { } else {
outsClocksCounts[i] = 0; outsClocksCounts[i] = 0;