fixed unwanted offset when changing subdiv with external clock, also seems like there's almost no delay between external trigger and outputs
This commit is contained in:
@ -54,8 +54,7 @@ bool isPlaying = false;
|
|||||||
unsigned int tickCount = 0;
|
unsigned int tickCount = 0;
|
||||||
unsigned int pulseCount = 0;
|
unsigned int pulseCount = 0;
|
||||||
|
|
||||||
unsigned int masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
|
byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - external beat
|
||||||
bool externalPulseCounted = true;
|
|
||||||
unsigned long lastExtPulseTime;
|
unsigned long lastExtPulseTime;
|
||||||
unsigned long newExtPulseTime;
|
unsigned long newExtPulseTime;
|
||||||
|
|
||||||
@ -97,12 +96,13 @@ void setup() {
|
|||||||
//Serial.begin(9600);
|
//Serial.begin(9600);
|
||||||
|
|
||||||
//check last bit in eeprom to know if settings were stored
|
//check last bit in eeprom to know if settings were stored
|
||||||
if (EEPROM.read(1023) == 'K') {
|
if (EEPROM.read(1023) == 'R') {
|
||||||
EEPROM.get(0, bpm);
|
EEPROM.get(0, bpm);
|
||||||
EEPROM.get(sizeof(int), channels);
|
EEPROM.get(sizeof(int), masterClockMode);
|
||||||
|
EEPROM.get(sizeof(int)+sizeof(byte), channels);
|
||||||
} else {
|
} else {
|
||||||
saveState();
|
saveState();
|
||||||
EEPROM.write(1023, 'K');
|
EEPROM.write(1023, 'R');
|
||||||
}
|
}
|
||||||
calculateCycles();
|
calculateCycles();
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ void clock() {
|
|||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
|
|
||||||
// Action on each pulse
|
// Action on each pulse
|
||||||
if (tickCount == 0 && masterClockMode == 0) {
|
if (tickCount == 0) { //&& masterClockMode == 0) {
|
||||||
sendTriggers();
|
sendTriggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,19 +176,8 @@ void clock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void externalClock() {
|
void externalClock() {
|
||||||
externalPulseCounted = false;
|
|
||||||
lastExtPulseTime = newExtPulseTime;
|
lastExtPulseTime = newExtPulseTime;
|
||||||
newExtPulseTime = millis();
|
newExtPulseTime = millis();
|
||||||
if (masterClockMode == 1) {
|
|
||||||
isPlaying = true;
|
|
||||||
sendTriggers();
|
|
||||||
tickCount = 0;
|
|
||||||
if (pulseCount < (PPQN-1)) {
|
|
||||||
pulseCount++;
|
|
||||||
} else {
|
|
||||||
pulseCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//reset cycles if there was no pulses for a while
|
//reset cycles if there was no pulses for a while
|
||||||
if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm
|
if ((newExtPulseTime - lastExtPulseTime) > 125) { //125ms is 20bpm
|
||||||
@ -196,14 +185,25 @@ void externalClock() {
|
|||||||
channelPulseCount[i] = 0;
|
channelPulseCount[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (masterClockMode == 1) { // EXT-24
|
||||||
|
if (!isPlaying) {
|
||||||
|
isPlaying = true;
|
||||||
|
}
|
||||||
|
tickCount = 0; //to make things happen in the main clock function
|
||||||
|
if (pulseCount < (PPQN-1)) {
|
||||||
|
pulseCount++;
|
||||||
|
} else {
|
||||||
|
pulseCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendTriggers() {
|
void sendTriggers() {
|
||||||
|
|
||||||
calculateCycles();
|
|
||||||
|
|
||||||
//switching modes on the beat and resetting channel clock
|
//switching modes on the beat and resetting channel clock
|
||||||
if (pulseCount == 0) {
|
if (pulseCount == 0) {
|
||||||
|
calculateCycles();
|
||||||
for (int i = 0; i<6; i++) {
|
for (int i = 0; i<6; i++) {
|
||||||
if (playingModes[i] != clockModes[channels[i].mode]) {
|
if (playingModes[i] != clockModes[channels[i].mode]) {
|
||||||
channelPulseCount[i] = 0;
|
channelPulseCount[i] = 0;
|
||||||
@ -268,7 +268,8 @@ void resetClocks() {
|
|||||||
|
|
||||||
void saveState() {
|
void saveState() {
|
||||||
EEPROM.put(0, bpm);
|
EEPROM.put(0, bpm);
|
||||||
EEPROM.put(sizeof(int), channels);
|
EEPROM.put(sizeof(int), masterClockMode);
|
||||||
|
EEPROM.put(sizeof(int)+sizeof(byte), channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkInputs() {
|
void checkInputs() {
|
||||||
|
|||||||
Reference in New Issue
Block a user