working on new clock
This commit is contained in:
@ -45,14 +45,15 @@ channel channels[6] = { //array of channel settings
|
|||||||
int outsClocksCounts[6];
|
int outsClocksCounts[6];
|
||||||
int playingModes[6]; //actual channel modes array updated from channels each beat
|
int playingModes[6]; //actual channel modes array updated from channels each beat
|
||||||
|
|
||||||
int clockCount = 0;
|
|
||||||
int pulseCount = 0;
|
|
||||||
int pulsePeriod;
|
int pulsePeriod;
|
||||||
bool isPlaying = 0;
|
bool isPlaying = false;
|
||||||
int needToResetChannel;
|
|
||||||
bool beatCounted = false;
|
bool beatCounted = false;
|
||||||
bool pulseCounted = false;
|
bool pulseCounted = false;
|
||||||
|
|
||||||
|
unsigned int tickCount = 0;
|
||||||
|
unsigned int pulseCount = 0;
|
||||||
|
|
||||||
unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
|
unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
|
||||||
bool externalPulseCounted = true;
|
bool externalPulseCounted = true;
|
||||||
unsigned long lastExtPulseTime;
|
unsigned long lastExtPulseTime;
|
||||||
@ -127,7 +128,7 @@ void setup() {
|
|||||||
updateScreen();
|
updateScreen();
|
||||||
updateTiming();
|
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();
|
FlexiTimer2::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,106 +140,64 @@ void clock() {
|
|||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
|
|
||||||
// Action on each pulse
|
// Action on each pulse
|
||||||
if (clockCount == 0 && !pulseCounted) {
|
if (tickCount == 0 && !pulseCounted) {
|
||||||
|
sendTriggers();
|
||||||
//modulation
|
|
||||||
for (int i = 0; i<6; i++) {
|
|
||||||
int mod;
|
|
||||||
if (!channels[i].modulationChannel) {
|
|
||||||
mod = a1Input;
|
|
||||||
} else {
|
|
||||||
mod = a2Input;
|
|
||||||
}
|
|
||||||
mod = map (mod, 0, 1023, 0, channels[i].modulationRange);
|
|
||||||
playingModes[i] = clockModes[channels[i].mode - mod]; //subtrackting because the innitiall array is backwards
|
|
||||||
}
|
|
||||||
|
|
||||||
//divider
|
|
||||||
if (pulseCount == 0 && !beatCounted) {
|
|
||||||
for (int i = 0; i<6; i++) {
|
|
||||||
playingModes[i] = clockModes[channels[i].mode]; //updated here to prevent sync problems for multipliers
|
|
||||||
if (playingModes[i] > 0) {
|
|
||||||
if (outsClocksCounts[i] == 0) { //Pulse on 0
|
|
||||||
if (channels[i].random == 0 || random(10) > channels[i].random) {
|
|
||||||
digitalWrite(outsPins[i], HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (outsClocksCounts[i] < (playingModes[i] - 1)) {
|
|
||||||
outsClocksCounts[i]++;
|
|
||||||
} else {
|
|
||||||
outsClocksCounts[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
beatCounted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//multiplier
|
|
||||||
for (int i = 0; i<6; i++) {
|
|
||||||
if (playingModes[i] < 0) {
|
|
||||||
if (outsClocksCounts[i] == 0) { //Pulse on 0
|
|
||||||
if (channels[i].random == 0 || random(10) > channels[i].random) { //random
|
|
||||||
digitalWrite(outsPins[i], HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) {
|
|
||||||
outsClocksCounts[i]++;
|
|
||||||
} else {
|
|
||||||
outsClocksCounts[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pulseCounted = true;
|
pulseCounted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (masterClockMode) {
|
//this part gets the Pulse and Ticks ticking
|
||||||
case 0: //internal
|
//it's placed after the triggers to avoid problems on the start (when pulseCount==0)
|
||||||
if (clockCount == 0) {
|
if (tickCount < pulsePeriod) {
|
||||||
pulseCount++;
|
tickCount++;
|
||||||
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 {
|
} else {
|
||||||
clockCount = 0;
|
tickCount = 0;
|
||||||
}
|
if (pulseCount < PPQN) {
|
||||||
if (pulseCount >= PPQN) {
|
pulseCount++;
|
||||||
pulseCount = 0;
|
beatCounted = false; //reset pulse and beat count AFTER the pulse is incremented
|
||||||
|
pulseCounted = false;
|
||||||
|
} else {
|
||||||
|
pulseCount = 0; //Beat happens here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pull low all outputs after set pulse length
|
}
|
||||||
if (clockCount >= PULSE_LENGTH) {
|
}
|
||||||
for (int i = 0; i<6; i++) {
|
|
||||||
digitalWrite(outsPins[i], LOW);
|
void sendTriggers() {
|
||||||
|
//divider
|
||||||
|
if (pulseCount == 0 && !beatCounted) {
|
||||||
|
for (int i = 0; i<6; i++) {
|
||||||
|
playingModes[i] = clockModes[channels[i].mode]; //updated here to prevent sync problems for multipliers
|
||||||
|
if (playingModes[i] > 0) {
|
||||||
|
if (outsClocksCounts[i] == 0) { //Pulse on 0
|
||||||
|
if (channels[i].random == 0 || random(10) > channels[i].random) {
|
||||||
|
digitalWrite(outsPins[i], HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outsClocksCounts[i] < (playingModes[i] - 1)) {
|
||||||
|
outsClocksCounts[i]++;
|
||||||
|
} else {
|
||||||
|
outsClocksCounts[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
beatCounted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//multiplier
|
||||||
|
for (int i = 0; i<6; i++) {
|
||||||
|
if (playingModes[i] < 0) {
|
||||||
|
if (outsClocksCounts[i] == 0) { //Pulse on 0
|
||||||
|
if (channels[i].random == 0 || random(10) > channels[i].random) { //random
|
||||||
|
digitalWrite(outsPins[i], HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outsClocksCounts[i] < (PPQN / abs(playingModes[i])) - 1) {
|
||||||
|
outsClocksCounts[i]++;
|
||||||
|
} else {
|
||||||
|
outsClocksCounts[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +287,6 @@ void checkInputs() {
|
|||||||
} else if (channels[displayTab-1].mode > (sizeof(clockModes)/sizeof(int)) - 1) {
|
} else if (channels[displayTab-1].mode > (sizeof(clockModes)/sizeof(int)) - 1) {
|
||||||
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
|
} else if (displayTab != 0 && insideTab == 1) { //random
|
||||||
channels[displayTab-1].random = channels[displayTab-1].random + change;
|
channels[displayTab-1].random = channels[displayTab-1].random + change;
|
||||||
if (channels[displayTab-1].random > 9 || channels[displayTab-1].random < 0) {
|
if (channels[displayTab-1].random > 9 || channels[displayTab-1].random < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user