working on new clock

This commit is contained in:
--global
2023-05-07 20:37:20 +03:00
parent b954f0a28b
commit a4225751e5

View File

@ -45,14 +45,15 @@ channel channels[6] = { //array of channel settings
int outsClocksCounts[6];
int playingModes[6]; //actual channel modes array updated from channels each beat
int clockCount = 0;
int pulseCount = 0;
int pulsePeriod;
bool isPlaying = 0;
int needToResetChannel;
bool isPlaying = false;
bool beatCounted = false;
bool pulseCounted = false;
unsigned int tickCount = 0;
unsigned int pulseCount = 0;
unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
bool externalPulseCounted = true;
unsigned long lastExtPulseTime;
@ -127,7 +128,7 @@ void setup() {
updateScreen();
updateTiming();
FlexiTimer2::set(1, 1.0/1000, clock); // 1.0/1000 = 1ms period
FlexiTimer2::set(1, 1.0/1000, clock); // 1.0/1000 = 1ms period. If other than 1ms updateTiming() might need tweaking
FlexiTimer2::start();
}
@ -139,20 +140,30 @@ void clock() {
if (isPlaying) {
// Action on each pulse
if (clockCount == 0 && !pulseCounted) {
if (tickCount == 0 && !pulseCounted) {
sendTriggers();
pulseCounted = true;
}
//modulation
for (int i = 0; i<6; i++) {
int mod;
if (!channels[i].modulationChannel) {
mod = a1Input;
//this part gets the Pulse and Ticks ticking
//it's placed after the triggers to avoid problems on the start (when pulseCount==0)
if (tickCount < pulsePeriod) {
tickCount++;
} else {
mod = a2Input;
tickCount = 0;
if (pulseCount < PPQN) {
pulseCount++;
beatCounted = false; //reset pulse and beat count AFTER the pulse is incremented
pulseCounted = false;
} else {
pulseCount = 0; //Beat happens here
}
mod = map (mod, 0, 1023, 0, channels[i].modulationRange);
playingModes[i] = clockModes[channels[i].mode - mod]; //subtrackting because the innitiall array is backwards
}
}
}
void sendTriggers() {
//divider
if (pulseCount == 0 && !beatCounted) {
for (int i = 0; i<6; i++) {
@ -188,58 +199,6 @@ void clock() {
}
}
}
pulseCounted = true;
}
switch (masterClockMode) {
case 0: //internal
if (clockCount == 0) {
pulseCount++;
beatCounted = false;
pulseCounted = false;
}
break;
case 1: //external 24ppqn
if (externalPulseCounted == false) {
pulseCount++;
externalPulseCounted = true;
beatCounted = false;
pulseCounted = false;
}
break;
case 2: //external beat
if (externalPulseCounted == false) {
externalPulseCounted = true;
clockCount == 0;
lastExtPulseTime = newExtPulseTime;
newExtPulseTime = millis();
if (lastExtPulseTime) {
updateTiming();
}
}
if (clockCount == 0) {
pulseCount++;
beatCounted = false;
pulseCounted = false;
}
break;
}
if (clockCount < pulsePeriod) {
clockCount++;
} else {
clockCount = 0;
}
if (pulseCount >= PPQN) {
pulseCount = 0;
}
// pull low all outputs after set pulse length
if (clockCount >= PULSE_LENGTH) {
for (int i = 0; i<6; i++) {
digitalWrite(outsPins[i], LOW);
}
}
}
}
void externalClock() {
@ -328,7 +287,6 @@ void checkInputs() {
} else if (channels[displayTab-1].mode > (sizeof(clockModes)/sizeof(int)) - 1) {
channels[displayTab-1].mode = (sizeof(clockModes)/sizeof(int)) - 1;
}
needToResetChannel = displayTab-1;
} else if (displayTab != 0 && insideTab == 1) { //random
channels[displayTab-1].random = channels[displayTab-1].random + change;
if (channels[displayTab-1].random > 9 || channels[displayTab-1].random < 0) {