changed most declarations typedefs. the ones that are not changed yet need to be reviewed in detail
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
|
||||
#define VERSION "V:1.2A2"
|
||||
|
||||
byte memCode = '0'; //Change to different letter if you changed the data structure
|
||||
uint8_t memCode = '0'; //Change to different letter if you changed the data structure
|
||||
|
||||
uint16_t CV1Calibration = 512;
|
||||
uint16_t CV2Calibration = 512;
|
||||
@ -19,17 +19,17 @@ bool showDone = false;
|
||||
|
||||
const int subDivs[] = { -24, -12, -8, -6, -4, -3, -2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 24, 32, 64, 128 }; //positive - divide, negative - multiply, 0 - off
|
||||
|
||||
byte bpm = 130;
|
||||
byte bpmModulationChannel = 200; //0 - CV1, 1 - CV2, 255 - OFF
|
||||
byte bpmModulationRange = 0;
|
||||
uint8_t bpm = 130;
|
||||
uint8_t bpmModulationChannel = 200; //0 - CV1, 1 - CV2, 255 - OFF
|
||||
uint8_t bpmModulationRange = 0;
|
||||
|
||||
struct channel {
|
||||
byte mode : 3; //mv: 7. 0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate
|
||||
byte subDiv : 5; //mv: 31
|
||||
byte random : 4; //mv: 15
|
||||
byte seqPattern : 5;
|
||||
byte CV1Target : 3; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern
|
||||
byte CV2Target : 3;
|
||||
uint8_t mode : 3; //mv: 7. 0 - CLK, 1 - RND, 2 - SEQ, 3 - SWING, 4 - Gate
|
||||
uint8_t subDiv : 5; //mv: 31
|
||||
uint8_t random : 4; //mv: 15
|
||||
uint8_t seqPattern : 5;
|
||||
uint8_t CV1Target : 3; //0 - Off, 1 - Subdiv, 2 - RND, 3 - SeqPattern
|
||||
uint8_t CV2Target : 3;
|
||||
uint8_t swing : 3;
|
||||
uint8_t offset : 7; //mv: 127
|
||||
uint8_t gate : 7;
|
||||
@ -48,7 +48,7 @@ channel channels[7] = { //array of channel settings
|
||||
|
||||
struct sequence {
|
||||
uint32_t sequence;
|
||||
uint8_t length : 5 ; //don't forget to add 1, values 0 - 31
|
||||
uint8_t length : 5 ; //don't forget to add 1 where needed, values 0 - 31
|
||||
};
|
||||
|
||||
sequence sequences[] {
|
||||
@ -86,63 +86,63 @@ sequence sequences[] {
|
||||
{0b000000000000000000000000000000000, 15}
|
||||
};
|
||||
|
||||
byte currentStep[7] = {0};
|
||||
uint8_t currentStep[7] = {0};
|
||||
int8_t stepNumSelected = 0;
|
||||
byte patternToEdit;
|
||||
uint8_t patternToEdit;
|
||||
|
||||
unsigned int channelPulseCount[7];
|
||||
unsigned int channelPulsesPerCycle[7];
|
||||
byte sixteenthPulseCount = 0;
|
||||
uint8_t sixteenthPulseCount = 0;
|
||||
int playingModes[7]; // should be renamed to currentSubdivs or something. Updated from channels object on beat and with applied CV modulation
|
||||
int playingModesOld[7];
|
||||
|
||||
unsigned int pulsePeriod;
|
||||
bool isPlaying;// = false; // replace to something like byte status where 1xxxxxx isPlaying, x1xxxxx isRecording etc
|
||||
uint16_t pulsePeriod;
|
||||
bool isPlaying;// = false; // replace to something like uint8_t status where 1xxxxxx isPlaying, x1xxxxx isRecording etc
|
||||
bool isRecording = false;
|
||||
bool recordToNextStep = false;
|
||||
bool MIDIClockReceived = false;
|
||||
|
||||
unsigned int tickCount = 0;
|
||||
unsigned int pulseCount = 0;
|
||||
uint16_t tickCount = 0;
|
||||
uint16_t pulseCount = 0;
|
||||
|
||||
byte masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - MIDI
|
||||
byte extClockPPQN = 0; // 0 - 24, 1 - 4 (1/16)
|
||||
byte extraChannel = 0; // 0 - off, 1 - pulse out = 7th channel
|
||||
unsigned long lastExtPulseTime = 0;
|
||||
unsigned long newExtPulseTime = 0;
|
||||
uint8_t masterClockMode = 0; // 0 - internal, 1 - external 24ppqn, 2 - MIDI
|
||||
uint8_t extClockPPQN = 0; // 0 - 24, 1 - 4 (1/16)
|
||||
uint8_t extraChannel = 0; // 0 - off, 1 - pulse out = 7th channel
|
||||
uint32_t lastExtPulseTime = 0;
|
||||
uint32_t newExtPulseTime = 0;
|
||||
|
||||
bool needPulseReset[] = { true, true, true, true, true, true, true };
|
||||
bool needPulseReset[] = { true, true, true, true, true, true, true }; //to optimise, can be switched to uint8_t
|
||||
uint16_t gateLengthTime[] = {0, 0, 0, 0, 0, 0, 0};
|
||||
uint16_t gateCountDown[7];
|
||||
bool stepIsOdd = 1;
|
||||
|
||||
byte displayTab = 0;
|
||||
uint8_t displayTab = 0;
|
||||
bool insideTab = false;
|
||||
byte menuItem = 0;
|
||||
uint8_t menuItem = 0;
|
||||
bool menuItemSelected = false;
|
||||
byte lastMenuItem = 3;
|
||||
byte displayScreen = 0; //0 - main, 1 - sequencer, 2 - settings
|
||||
uint8_t lastMenuItem = 3;
|
||||
uint8_t displayScreen = 0; //0 - main, 1 - sequencer, 2 - settings
|
||||
|
||||
bool playBtnPushed = false;
|
||||
bool shiftBtnPushed = false;
|
||||
|
||||
int CV1Input = 0;
|
||||
int CV2Input = 0;
|
||||
int16_t CV1Input = 0;
|
||||
int16_t CV2Input = 0;
|
||||
|
||||
int encPositionOld = 0;
|
||||
int encDirectionOld = 0;
|
||||
unsigned long encPressedTime;
|
||||
unsigned long encReleasedTime;
|
||||
unsigned long playPressedTime;
|
||||
unsigned long playReleasedTime;
|
||||
unsigned long shiftPressedTime;
|
||||
unsigned long shiftReleasedTime;
|
||||
uint8_t encDirectionOld = 0;
|
||||
uint32_t encPressedTime;
|
||||
uint32_t encReleasedTime;
|
||||
uint32_t playPressedTime;
|
||||
uint32_t playReleasedTime;
|
||||
uint32_t shiftPressedTime;
|
||||
uint32_t shiftReleasedTime;
|
||||
bool encBtnPushed;
|
||||
|
||||
int extResetCountdown;
|
||||
int extTriggerCount;
|
||||
|
||||
//unsigned long lastInteractionTime; // used for display timeout
|
||||
//uint32_t lastInteractionTime; // used for display timeout
|
||||
|
||||
U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R2, SCL, SDA, U8X8_PIN_NONE);
|
||||
RotaryEncoder encoder(ENC_D1_PIN, ENC_D2_PIN, RotaryEncoder::LatchMode::TWO03);
|
||||
@ -161,7 +161,7 @@ void setup() {
|
||||
pinMode(EXT_INPUT_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(EXT_INPUT_PIN), externalClock, FALLING);
|
||||
|
||||
for (byte i = 0; i < 6; i++) {
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
pinMode(outsPins[i], OUTPUT);
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ void clock() {
|
||||
}
|
||||
if (bpmModulationRange != 0) {
|
||||
calculateBPMTiming();
|
||||
for (byte i; i < 7; i++) {
|
||||
for (uint8_t i; i < 7; i++) {
|
||||
if (channels[i].mode == 4) {
|
||||
calculateGate(i);
|
||||
}
|
||||
@ -263,7 +263,7 @@ void clock() {
|
||||
}
|
||||
|
||||
// pull low all outputs after set pulse length
|
||||
for (byte i = 0; i < 7; i++) {
|
||||
for (uint8_t i = 0; i < 7; i++) {
|
||||
if (channels[i].mode != 4 && tickCount >= PULSE_LENGTH) { //everything but gate mode
|
||||
digitalWrite(outsPins[i], LOW);
|
||||
} else if (channels[i].mode == 4 && tickCount >= gateCountDown[i]) { //gate mode gateLengthTime[i] < pulsePeriod
|
||||
@ -328,7 +328,7 @@ void externalClock() {
|
||||
|
||||
void sendTriggers() { //rename to onPulse or something
|
||||
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
if (playingModes[i] != subDivs[channels[i].subDiv] && playingModesOld[i] != playingModes[i]) {
|
||||
needPulseReset[i] = true;
|
||||
playingModesOld[i] = playingModes[i];
|
||||
@ -337,11 +337,11 @@ void sendTriggers() { //rename to onPulse or something
|
||||
//16th notes for sequencer and swing
|
||||
if (sixteenthPulseCount == 0) {
|
||||
stepIsOdd = !stepIsOdd;
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
|
||||
//pattern modulation
|
||||
int seqMod = 0;
|
||||
byte seqPattern;
|
||||
uint8_t seqPattern;
|
||||
if (channels[i].CV2Target == 3) {
|
||||
seqMod = map(CV2Input, -1, 1024, -8, 8); //-1 and 1024 are to try to make the last step not at max value (should make the range from -7 to +7)
|
||||
} else if (channels[i].CV1Target == 3) {
|
||||
@ -372,7 +372,7 @@ void sendTriggers() { //rename to onPulse or something
|
||||
}
|
||||
} else {
|
||||
sixteenthPulseCount = 0;
|
||||
for (byte i; i < 7; i++) {
|
||||
for (uint8_t i; i < 7; i++) {
|
||||
if (channels[i].mode == 2 && currentStep[i] < sequences[channels[i].seqPattern].length) {
|
||||
currentStep[i] ++;
|
||||
} else {
|
||||
@ -385,7 +385,7 @@ void sendTriggers() { //rename to onPulse or something
|
||||
//switching modes on the beat and resetting channel clock
|
||||
if (pulseCount == 0) {
|
||||
calculateCycles();
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
if (needPulseReset[i] == true) {
|
||||
channelPulseCount[i] = 0;
|
||||
needPulseReset[i] = false;
|
||||
@ -397,10 +397,10 @@ void sendTriggers() { //rename to onPulse or something
|
||||
}
|
||||
|
||||
//multiplier
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
|
||||
//RND modulation
|
||||
byte randMod = 0;
|
||||
uint8_t randMod = 0;
|
||||
if (channels[i].CV1Target == 2) {
|
||||
randMod = randMod + CV1Input;
|
||||
}
|
||||
@ -410,7 +410,7 @@ void sendTriggers() { //rename to onPulse or something
|
||||
if (channels[i].CV1Target == 2 || channels[i].CV2Target == 2) {
|
||||
randMod = map(randMod, 0, 1023, -5, +5);
|
||||
}
|
||||
byte randAmount = channels[i].random + randMod;
|
||||
uint8_t randAmount = channels[i].random + randMod;
|
||||
if (randAmount > 100) {
|
||||
randAmount = 0;
|
||||
} else if (randAmount > 10) {
|
||||
@ -441,7 +441,7 @@ void sendTriggers() { //rename to onPulse or something
|
||||
|
||||
void calculateCycles() {
|
||||
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
int mod = 0; //subdiv modulation happens here
|
||||
if (channels[i].CV1Target == 1) {
|
||||
mod = map(CV1Input, -1, 1024, -5, 5);
|
||||
@ -476,9 +476,9 @@ void calculateBPMTiming() {
|
||||
} else if (bpmModulationRange != 0 && bpmModulationChannel == 1) {
|
||||
mod = map(CV2Input, 0, 1023, bpmModulationRange * -10, bpmModulationRange * 10);
|
||||
}
|
||||
byte calcbpm = bpm + mod;
|
||||
uint8_t calcbpm = bpm + mod;
|
||||
if (calcbpm > MAXBPM) { calcbpm = MAXBPM; };
|
||||
pulsePeriod = 600000 / (calcbpm * PPQN);
|
||||
pulsePeriod = 600000 / (calcbpm * PPQN); //optimisation: try using floats, maybe it'll make it more precise, like 60000.0 / ((float)(calcbpm * PPQN));
|
||||
|
||||
} else if (masterClockMode == 1 && extClockPPQN == 1) { //for ext 1/16 clock
|
||||
pulsePeriod = (newExtPulseTime - lastExtPulseTime) * 10 / 6;
|
||||
@ -486,21 +486,21 @@ void calculateBPMTiming() {
|
||||
}
|
||||
|
||||
void resetClocks() {
|
||||
for (byte i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
for (uint8_t i = 0; i < (extraChannel ? 7 : 6); i++) {
|
||||
channelPulseCount[i] = 0;
|
||||
digitalWrite(outsPins[i], LOW); //to avoid stuck leds
|
||||
}
|
||||
pulseCount = 0;
|
||||
tickCount = 0;
|
||||
sixteenthPulseCount = 0;
|
||||
for (byte i; i < 7; i++) {
|
||||
for (uint8_t i; i < 7; i++) {
|
||||
currentStep[i] = 0;
|
||||
}
|
||||
stepIsOdd = 1;
|
||||
}
|
||||
|
||||
void saveState() {
|
||||
int addr = 0;
|
||||
uint16_t addr = 0;
|
||||
EEPROM.put(addr, bpm);
|
||||
addr = addr + sizeof(bpm);
|
||||
EEPROM.put(addr, bpmModulationChannel);
|
||||
@ -529,7 +529,7 @@ void saveState() {
|
||||
void loadState() {
|
||||
//check last bit in eeprom to know if the correct settings were stored
|
||||
if (EEPROM.read(1023) == memCode) {
|
||||
int addr = 0;
|
||||
uint16_t addr = 0;
|
||||
EEPROM.get(addr, bpm);
|
||||
addr = addr + sizeof(bpm);
|
||||
EEPROM.get(addr, bpmModulationChannel);
|
||||
|
||||
Reference in New Issue
Block a user