Changed data structure

This commit is contained in:
2023-07-27 23:41:38 +03:00
parent 2e0bca0e10
commit b4f89a838d
8 changed files with 51 additions and 39 deletions

View File

@ -5,7 +5,7 @@
#include <FlexiTimer2.h>
#include <EEPROM.h>
#define VERSION "REV2 PREP"
#define VERSION "0.9b"
#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;
bool bpmModulationChannel; //0 - CV1, 1 - CV2
byte bpmModulationRange = 0;
struct channel {
unsigned int mode; //need to be changed to subdiv
unsigned int random;
bool modulationChannel; //0 - CV1, 1 - CV2
int modulationRange;
unsigned int offset;
byte mode; //0 - CLK, 1 - RND, 2 - SEQ
byte subDiv;
byte CV1Target; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern
byte CV1Value;
byte CV2Target;
byte CV2Value;
byte offset;
byte random;
byte seqPattern;
};
channel channels[6] = { //array of channel settings
{ 7, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 0 }
{ 0, 7, 0, 0, 0, 0, 0, 0 },
{ 0, 7, 1, 0, 0, 0, 0, 0 },
{ 0, 7, 2, 0, 0, 0, 0, 0 },
{ 0, 7, 0, 0, 3, 0, 0, 0 },
{ 0, 7, 0, 0, 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 channelPulsesPerCycle[6];
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
};
void setup() {
//Serial.begin(9600);
//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;
EEPROM.get(addr, bpm);
addr = addr + sizeof(bpm);
@ -139,7 +144,7 @@ void setup() {
EEPROM.get(addr, channels);
} else {
saveState();
EEPROM.write(1023, 'S');
EEPROM.write(1023, memCode);
}
pinMode(ENC_BTN_PIN, INPUT_PULLUP);
@ -308,7 +313,7 @@ void externalClock() {
void sendTriggers() {
for (int i = 0; i < 6; i++) {
if (playingModes[i] != clockModes[channels[i].mode]) {
if (playingModes[i] != subDivs[channels[i].mode]) {
needPulseReset[i] = true;
}
}
@ -342,17 +347,18 @@ void sendTriggers() {
void calculateCycles() {
for (int i = 0; i < 6; i++) {
if (channels[i].modulationRange == 0) {
playingModes[i] = clockModes[channels[i].mode];
} else { //modulation happens here
if (channels[i].CV1Target != 1 && channels[i].CV2Target != 1) {
playingModes[i] = subDivs[channels[i].mode];
} else if (channels[i].CV1Target == 1) { //modulation happens here
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]; //subtracting because the innitiall array is backwards
mod = map(mod, 0, 1023, 0, channels[i].CV1Value);
playingModes[i] = subDivs[channels[i].mode - mod]; //subtracting because the innitial array is backwards
} else if (channels[i].CV2Target == 1) { //modulation happens here
int mod;
mod = a1Input;
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) {

View File

@ -46,8 +46,8 @@ void checkInputs() {
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
channels[displayTab - 1].mode = 0;
} else if (channels[displayTab - 1].mode > (sizeof(clockModes) / sizeof(int)) - 1) {
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(subDivs) / sizeof(int)) - 1;
}
if (!isPlaying) {
calculateCycles();
@ -102,8 +102,8 @@ void checkInputs() {
channels[displayTab - 1].mode = channels[displayTab - 1].mode - change;
if (channels[displayTab - 1].mode == 65535) { //65535 is 0-1 for unsigned vars
channels[displayTab - 1].mode = 0;
} else if (channels[displayTab - 1].mode > (sizeof(clockModes) / sizeof(int)) - 1) {
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(subDivs) / sizeof(int)) - 1;
}
if (!isPlaying) {
calculateCycles();

View File

@ -173,9 +173,15 @@ void updateScreen() {
display.setTextColor(SSD1306_WHITE);
}
display.setCursor(94, 25);
if (channels[displayTab - 1].modulationRange > 0) {
display.print(F("+/-"));
display.print(channels[displayTab - 1].modulationRange);
if (channels[displayTab - 1].CV1Target == 1) {
display.print(F("DIV"));
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 {
display.print(F("OFF "));
}
@ -219,14 +225,14 @@ void updateScreen() {
display.setTextSize(2);
display.println(F("1/16"));
} else {
if (clockModes[channels[displayTab - 1].mode] == 0) {
if (subDivs[channels[displayTab - 1].mode] == 0) {
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(abs(clockModes[channels[displayTab - 1].mode]));
display.print(abs(subDivs[channels[displayTab - 1].mode]));
} else {
display.print(F("x"));
display.print(abs(clockModes[channels[displayTab - 1].mode]));
display.print(abs(subDivs[channels[displayTab - 1].mode]));
}
}