external beat clock partly works now
This commit is contained in:
@ -46,8 +46,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 clockCount = 0;
|
||||||
|
|
||||||
int pulseClockCount = 0;
|
|
||||||
int pulseCount = 0;
|
int pulseCount = 0;
|
||||||
int pulsePeriod;
|
int pulsePeriod;
|
||||||
bool isPlaying = 0;
|
bool isPlaying = 0;
|
||||||
@ -55,8 +53,10 @@ int needToResetChannel;
|
|||||||
bool beatCounted = false;
|
bool beatCounted = false;
|
||||||
bool pulseCounted = false;
|
bool pulseCounted = false;
|
||||||
|
|
||||||
int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn
|
unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
|
||||||
bool externalPulseCounted = true;
|
bool externalPulseCounted = true;
|
||||||
|
unsigned long lastExtPulseTime;
|
||||||
|
unsigned long newExtPulseTime;
|
||||||
|
|
||||||
int displayTab = 0;
|
int displayTab = 0;
|
||||||
int displayTabOld;
|
int displayTabOld;
|
||||||
@ -122,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(2000);
|
delay(1200);
|
||||||
|
|
||||||
updateScreen();
|
updateScreen();
|
||||||
updateTiming();
|
updateTiming();
|
||||||
@ -139,7 +139,7 @@ void clock() {
|
|||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
|
|
||||||
// Action on each pulse
|
// Action on each pulse
|
||||||
if (pulseClockCount == 0 && !pulseCounted) {
|
if (clockCount == 0 && !pulseCounted) {
|
||||||
|
|
||||||
//modulation
|
//modulation
|
||||||
for (int i = 0; i<6; i++) {
|
for (int i = 0; i<6; i++) {
|
||||||
@ -193,7 +193,7 @@ void clock() {
|
|||||||
|
|
||||||
switch (masterClockMode) {
|
switch (masterClockMode) {
|
||||||
case 0: //internal
|
case 0: //internal
|
||||||
if (pulseClockCount == 0) {
|
if (clockCount == 0) {
|
||||||
pulseCount++;
|
pulseCount++;
|
||||||
beatCounted = false;
|
beatCounted = false;
|
||||||
pulseCounted = false;
|
pulseCounted = false;
|
||||||
@ -207,18 +207,34 @@ void clock() {
|
|||||||
pulseCounted = false;
|
pulseCounted = false;
|
||||||
}
|
}
|
||||||
break;
|
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 (pulseClockCount < pulsePeriod) {
|
if (clockCount < pulsePeriod) {
|
||||||
pulseClockCount++;
|
clockCount++;
|
||||||
} else {
|
} else {
|
||||||
pulseClockCount = 0;
|
clockCount = 0;
|
||||||
}
|
}
|
||||||
if (pulseCount >= PPQN) {
|
if (pulseCount >= PPQN) {
|
||||||
pulseCount = 0;
|
pulseCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pull low all outputs after set pulse length
|
// pull low all outputs after set pulse length
|
||||||
if (pulseClockCount >= PULSE_LENGTH) {
|
if (clockCount >= PULSE_LENGTH) {
|
||||||
for (int i = 0; i<6; i++) {
|
for (int i = 0; i<6; i++) {
|
||||||
digitalWrite(outsPins[i], LOW);
|
digitalWrite(outsPins[i], LOW);
|
||||||
}
|
}
|
||||||
@ -231,7 +247,12 @@ void externalClock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateTiming() {
|
void updateTiming() {
|
||||||
pulsePeriod = 60000 / (bpm * PPQN);
|
if (masterClockMode == 0) {
|
||||||
|
pulsePeriod = 60000 / (bpm * PPQN);
|
||||||
|
} else if (masterClockMode == 2) { //for external beat clock
|
||||||
|
pulsePeriod = (newExtPulseTime - lastExtPulseTime) / PPQN;
|
||||||
|
//Serial.println("pulsePeriod");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetClocks() {
|
void resetClocks() {
|
||||||
@ -278,8 +299,8 @@ void checkInputs() {
|
|||||||
updateScreen();
|
updateScreen();
|
||||||
}
|
}
|
||||||
else if (encReleasedTime - encPressedTime < 2000 && displayTab == 0) { // switch to external clock mode
|
else if (encReleasedTime - encPressedTime < 2000 && displayTab == 0) { // switch to external clock mode
|
||||||
if (masterClockMode == 0) {
|
if (masterClockMode < 2) {
|
||||||
masterClockMode = 1;
|
masterClockMode++;
|
||||||
} else {
|
} else {
|
||||||
masterClockMode = 0;
|
masterClockMode = 0;
|
||||||
}
|
}
|
||||||
@ -383,8 +404,10 @@ void updateScreen() {
|
|||||||
if (displayTab == 0 && masterClockMode == 0) {
|
if (displayTab == 0 && masterClockMode == 0) {
|
||||||
display.print(bpm);
|
display.print(bpm);
|
||||||
display.println(F("bpm"));
|
display.println(F("bpm"));
|
||||||
} else if (displayTab == 0 && masterClockMode != 0) {
|
} else if (displayTab == 0 && masterClockMode == 1) {
|
||||||
display.println(F("EXT"));
|
display.println(F("EXT-24"));
|
||||||
|
} else if (displayTab == 0 && masterClockMode == 2) {
|
||||||
|
display.println(F("EXT-B"));
|
||||||
} else {
|
} else {
|
||||||
if (clockModes[channels[displayTab-1].mode] == 0) {
|
if (clockModes[channels[displayTab-1].mode] == 0) {
|
||||||
display.print(F("OFF"));
|
display.print(F("OFF"));
|
||||||
|
|||||||
Reference in New Issue
Block a user