Changed data structure
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
#include <FlexiTimer2.h>
|
#include <FlexiTimer2.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
#define VERSION "REV2 PREP"
|
#define VERSION "0.9b"
|
||||||
|
|
||||||
#define SCREEN_ADDRESS 0x3C
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
@ -43,29 +43,35 @@ const int outsPins[6] = { 7, 8, 10, 6, 9, 11 };
|
|||||||
//*/
|
//*/
|
||||||
|
|
||||||
|
|
||||||
const int clockModes[17] = { -24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32 }; //positive - divide, negative - multiply, 0 - off
|
const int subDivs[17] = { -24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32 }; //positive - divide, negative - multiply, 0 - off
|
||||||
|
|
||||||
unsigned int bpm = 130;
|
unsigned int bpm = 130;
|
||||||
bool bpmModulationChannel; //0 - CV1, 1 - CV2
|
bool bpmModulationChannel; //0 - CV1, 1 - CV2
|
||||||
byte bpmModulationRange = 0;
|
byte bpmModulationRange = 0;
|
||||||
|
|
||||||
struct channel {
|
struct channel {
|
||||||
unsigned int mode; //need to be changed to subdiv
|
byte mode; //0 - CLK, 1 - RND, 2 - SEQ
|
||||||
unsigned int random;
|
byte subDiv;
|
||||||
bool modulationChannel; //0 - CV1, 1 - CV2
|
byte CV1Target; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern
|
||||||
int modulationRange;
|
byte CV1Value;
|
||||||
unsigned int offset;
|
byte CV2Target;
|
||||||
|
byte CV2Value;
|
||||||
|
byte offset;
|
||||||
|
byte random;
|
||||||
|
byte seqPattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
channel channels[6] = { //array of channel settings
|
channel channels[6] = { //array of channel settings
|
||||||
{ 7, 0, 0, 0, 0 },
|
{ 0, 7, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 0 },
|
{ 0, 7, 1, 0, 0, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 0 },
|
{ 0, 7, 2, 0, 0, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 0 },
|
{ 0, 7, 0, 0, 3, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 0 },
|
{ 0, 7, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 0 }
|
{ 0, 7, 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
byte memCode = 'A'; //Change to different letter if you changed the data structure
|
||||||
|
|
||||||
int channelPulseCount[6];
|
int channelPulseCount[6];
|
||||||
int channelPulsesPerCycle[6];
|
int channelPulsesPerCycle[6];
|
||||||
int playingModes[6]; //actual channel modes array updated from channels object on each beat
|
int playingModes[6]; //actual channel modes array updated from channels object on each beat
|
||||||
@ -121,12 +127,11 @@ const unsigned char splash_logo[] PROGMEM = {
|
|||||||
0xff, 0xc0, 0x00
|
0xff, 0xc0, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Serial.begin(9600);
|
//Serial.begin(9600);
|
||||||
|
|
||||||
//check last bit in eeprom to know if the correct settings were stored
|
//check last bit in eeprom to know if the correct settings were stored
|
||||||
if (EEPROM.read(1023) == 'S') {
|
if (EEPROM.read(1023) == memCode) {
|
||||||
int addr = 0;
|
int addr = 0;
|
||||||
EEPROM.get(addr, bpm);
|
EEPROM.get(addr, bpm);
|
||||||
addr = addr + sizeof(bpm);
|
addr = addr + sizeof(bpm);
|
||||||
@ -139,7 +144,7 @@ void setup() {
|
|||||||
EEPROM.get(addr, channels);
|
EEPROM.get(addr, channels);
|
||||||
} else {
|
} else {
|
||||||
saveState();
|
saveState();
|
||||||
EEPROM.write(1023, 'S');
|
EEPROM.write(1023, memCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
pinMode(ENC_BTN_PIN, INPUT_PULLUP);
|
pinMode(ENC_BTN_PIN, INPUT_PULLUP);
|
||||||
@ -308,7 +313,7 @@ void externalClock() {
|
|||||||
void sendTriggers() {
|
void sendTriggers() {
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
if (playingModes[i] != clockModes[channels[i].mode]) {
|
if (playingModes[i] != subDivs[channels[i].mode]) {
|
||||||
needPulseReset[i] = true;
|
needPulseReset[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,17 +347,18 @@ void sendTriggers() {
|
|||||||
void calculateCycles() {
|
void calculateCycles() {
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
if (channels[i].modulationRange == 0) {
|
if (channels[i].CV1Target != 1 && channels[i].CV2Target != 1) {
|
||||||
playingModes[i] = clockModes[channels[i].mode];
|
playingModes[i] = subDivs[channels[i].mode];
|
||||||
} else { //modulation happens here
|
} else if (channels[i].CV1Target == 1) { //modulation happens here
|
||||||
int mod;
|
int mod;
|
||||||
if (!channels[i].modulationChannel) {
|
mod = a1Input;
|
||||||
mod = a1Input;
|
mod = map(mod, 0, 1023, 0, channels[i].CV1Value);
|
||||||
} else {
|
playingModes[i] = subDivs[channels[i].mode - mod]; //subtracting because the innitial array is backwards
|
||||||
mod = a2Input;
|
} else if (channels[i].CV2Target == 1) { //modulation happens here
|
||||||
}
|
int mod;
|
||||||
mod = map(mod, 0, 1023, 0, channels[i].modulationRange);
|
mod = a1Input;
|
||||||
playingModes[i] = clockModes[channels[i].mode - mod]; //subtracting because the innitiall array is backwards
|
mod = map(mod, 0, 1023, 0, channels[i].CV2Value);
|
||||||
|
playingModes[i] = subDivs[channels[i].mode - mod]; //subtracting because the innitial array is backwards
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playingModes[i] > 0) {
|
if (playingModes[i] > 0) {
|
||||||
@ -46,8 +46,8 @@ void checkInputs() {
|
|||||||
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
|
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
|
||||||
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
|
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
|
||||||
channels[displayTab - 1].mode = 0;
|
channels[displayTab - 1].mode = 0;
|
||||||
} else if (channels[displayTab - 1].mode > (sizeof(clockModes) / sizeof(int)) - 1) {
|
} else if (channels[displayTab - 1].mode > (sizeof(subDivs) / sizeof(int)) - 1) {
|
||||||
channels[displayTab - 1].mode = (sizeof(clockModes) / sizeof(int)) - 1;
|
channels[displayTab - 1].mode = (sizeof(subDivs) / sizeof(int)) - 1;
|
||||||
}
|
}
|
||||||
if (!isPlaying) {
|
if (!isPlaying) {
|
||||||
calculateCycles();
|
calculateCycles();
|
||||||
@ -102,8 +102,8 @@ void checkInputs() {
|
|||||||
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
|
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
|
||||||
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
|
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
|
||||||
channels[displayTab - 1].mode = 0;
|
channels[displayTab - 1].mode = 0;
|
||||||
} else if (channels[displayTab - 1].mode > (sizeof(clockModes) / sizeof(int)) - 1) {
|
} else if (channels[displayTab - 1].mode > (sizeof(subDivs) / sizeof(int)) - 1) {
|
||||||
channels[displayTab - 1].mode = (sizeof(clockModes) / sizeof(int)) - 1;
|
channels[displayTab - 1].mode = (sizeof(subDivs) / sizeof(int)) - 1;
|
||||||
}
|
}
|
||||||
if (!isPlaying) {
|
if (!isPlaying) {
|
||||||
calculateCycles();
|
calculateCycles();
|
||||||
@ -172,10 +172,16 @@ void updateScreen() {
|
|||||||
} else {
|
} else {
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
}
|
}
|
||||||
display.setCursor(94, 25);
|
display.setCursor(94, 25);
|
||||||
if (channels[displayTab - 1].modulationRange > 0) {
|
if (channels[displayTab - 1].CV1Target == 1) {
|
||||||
display.print(F("+/-"));
|
display.print(F("DIV"));
|
||||||
display.print(channels[displayTab - 1].modulationRange);
|
display.print(channels[displayTab - 1].CV1Value);
|
||||||
|
} else if (channels[displayTab - 1].CV1Target == 2) {
|
||||||
|
display.print(F("RND"));
|
||||||
|
display.print(channels[displayTab - 1].CV1Value);
|
||||||
|
} else if (channels[displayTab - 1].CV1Target == 3) {
|
||||||
|
display.print(F("PAT"));
|
||||||
|
display.print(channels[displayTab - 1].CV1Value);
|
||||||
} else {
|
} else {
|
||||||
display.print(F("OFF "));
|
display.print(F("OFF "));
|
||||||
}
|
}
|
||||||
@ -219,14 +225,14 @@ void updateScreen() {
|
|||||||
display.setTextSize(2);
|
display.setTextSize(2);
|
||||||
display.println(F("1/16"));
|
display.println(F("1/16"));
|
||||||
} else {
|
} else {
|
||||||
if (clockModes[channels[displayTab - 1].mode] == 0) {
|
if (subDivs[channels[displayTab - 1].mode] == 0) {
|
||||||
display.print(F("OFF"));
|
display.print(F("OFF"));
|
||||||
} else if (clockModes[channels[displayTab - 1].mode] > 0) {
|
} else if (subDivs[channels[displayTab - 1].mode] > 0) {
|
||||||
display.print(F("/"));
|
display.print(F("/"));
|
||||||
display.print(abs(clockModes[channels[displayTab - 1].mode]));
|
display.print(abs(subDivs[channels[displayTab - 1].mode]));
|
||||||
} else {
|
} else {
|
||||||
display.print(F("x"));
|
display.print(F("x"));
|
||||||
display.print(abs(clockModes[channels[displayTab - 1].mode]));
|
display.print(abs(subDivs[channels[displayTab - 1].mode]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user