Added sequence player

This commit is contained in:
2023-07-30 23:25:14 +03:00
parent fe99d57afa
commit 189e233481
2 changed files with 52 additions and 19 deletions

View File

@ -65,23 +65,18 @@ channel channels[6] = { //array of channel settings
{ 0, 7, 0, 3, 0, 3, 0, 0, 0 }
};
bool sequences[8][16] {
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0}
};
byte seqStepCount[8] = {0,0,0,0,0,0,0,0};
bool seqA1[16] = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0};
bool seqA2[16] = {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0};
bool seqA3[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
bool seqA4[16] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0};
bool *currentSeq;
int currentStep = 0;
byte memCode = 'A'; //Change to different letter if you changed the data structure
int channelPulseCount[6];
int channelPulsesPerCycle[6];
int sixteenthPulseCount = 0;
int playingModes[6]; //actual channel modes array updated from channels object on each beat
unsigned int pulsePeriod;
@ -272,6 +267,25 @@ void sendTriggers() {
}
}
//16th notes for sequencer
if (sixteenthPulseCount == 0) {
for (byte i = 0; i < 6; i++) {
if (channels[i].mode == 2 && channelPulseCount[i] == 0 && currentSeq[currentStep]) {
digitalWrite(outsPins[i], HIGH);
}
}
}
if (sixteenthPulseCount < (PPQN / 4) - 1) {
sixteenthPulseCount++;
} else {
sixteenthPulseCount = 0;
if (currentStep < 15) {
currentStep ++;
} else {
currentStep = 0;
}
}
//switching modes on the beat and resetting channel clock
if (pulseCount == 0) {
calculateCycles();
@ -285,7 +299,6 @@ void sendTriggers() {
//multiplier
for (byte i = 0; i < 6; i++) {
int currentSeq = channels[i].seqPattern;
//RND modulation
byte randMod = 0;
@ -306,9 +319,9 @@ void sendTriggers() {
}
if ((channels[i].mode == 0 && channelPulseCount[i] == channels[i].offset) || //CLK with offset
(channels[i].mode == 1 && channelPulseCount[i] == 0 && (random(10) + 1) > randAmount) //|| //RND
//(channels[i].mode == 2 && channelPulseCount[i] == 0 && sequences[currentSeq][0]) //SEQ (for some reason doesn't lke variables inside the index)
if ((channels[i].mode == 0 && channelPulseCount[i] == channels[i].offset) //CLK with offset
|| (channels[i].mode == 1 && channelPulseCount[i] == 0 && (random(10) + 1) > randAmount) //RND
//|| (channels[i].mode == 2 && channelPulseCount[i] == 0 && currentSeq[currentStep])
) {
digitalWrite(outsPins[i], HIGH);
}
@ -318,6 +331,7 @@ void sendTriggers() {
channelPulseCount[i] = 0;
}
}
}
void calculateCycles() {
@ -337,10 +351,12 @@ void calculateCycles() {
playingModes[i] = subDivs[channels[i].subDiv - mod];
}
if (playingModes[i] > 0) {
if (playingModes[i] > 0 && channels[i].mode != 2) {
channelPulsesPerCycle[i] = (playingModes[i] * PPQN) - 1;
} else {
} else if (playingModes[i] <= 0 && channels[i].mode != 2) {
channelPulsesPerCycle[i] = (PPQN / abs(playingModes[i])) - 1;
} else if (channels[i].mode == 2) { //Sequencer plays 1/16th
channelPulsesPerCycle[i] = (PPQN / 4) - 1;
}
if (channels[i].offset > channelPulsesPerCycle[i]) {
channels[i].offset = channelPulsesPerCycle[i];