2019-06-28 01:03:40 +02:00
|
|
|
#include <CapacitiveSensor.h>
|
|
|
|
#include <MIDI.h>
|
|
|
|
#include <HID.h>
|
|
|
|
|
2019-06-29 02:42:38 +02:00
|
|
|
#define BPQN 24 // Ableton sends 24, VCV rack only one, by standard should be 24?
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
#define NOTEOffset 36
|
2019-06-30 00:39:01 +02:00
|
|
|
#define DRUMSHIFT 6
|
2019-06-27 18:58:37 +02:00
|
|
|
#define drumOffset 60
|
2019-03-08 21:10:15 +01:00
|
|
|
#define MINUTE 60000
|
2019-03-09 15:23:18 +01:00
|
|
|
#define MIDICLOCK 0xf8
|
2019-06-27 18:58:37 +02:00
|
|
|
#define MAXKEYS 48
|
|
|
|
#define MAXDPAD 3
|
2019-06-29 02:42:38 +02:00
|
|
|
#define MAXSTEP 16
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-08 21:10:15 +01:00
|
|
|
MIDI_CREATE_DEFAULT_INSTANCE();
|
2019-06-28 01:03:40 +02:00
|
|
|
|
2019-03-10 02:33:59 +01:00
|
|
|
typedef struct SequencerStep* link;
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
typedef struct OCTAVEStatus { // This struct is for an OCTAVE status. Each bool is for 1 NOTE
|
2019-03-04 18:54:22 +01:00
|
|
|
bool stat[12];
|
|
|
|
int nOct;
|
|
|
|
} octst;
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-10 02:33:59 +01:00
|
|
|
typedef struct SequencerStep {
|
2019-06-30 00:39:01 +02:00
|
|
|
bool clean = LOW;
|
2019-06-28 01:03:40 +02:00
|
|
|
bool kboard_s[MAXKEYS];
|
|
|
|
bool dpad_s[MAXDPAD];
|
2019-06-29 02:42:38 +02:00
|
|
|
unsigned short stepnumber;
|
2019-03-10 02:33:59 +01:00
|
|
|
link next;
|
|
|
|
} step;
|
2019-03-09 15:23:18 +01:00
|
|
|
|
2019-03-09 19:14:18 +01:00
|
|
|
// PIN DECLARATIONS
|
2019-06-27 18:58:37 +02:00
|
|
|
int NOTE[12] = { // Pins used to read each note (C is 0, B is 11)
|
2019-03-09 15:23:18 +01:00
|
|
|
22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44 };
|
2019-06-27 18:58:37 +02:00
|
|
|
int OCTAVE[4] = { // Pins associated to each OCTAVE's contact bar
|
2019-03-09 15:23:18 +01:00
|
|
|
12, 9, 8, 10 };
|
2019-06-27 18:58:37 +02:00
|
|
|
int SEND[3] = { // Pins used as sender for capacitive touch buttons
|
2019-03-09 19:14:18 +01:00
|
|
|
5, 4, 16 };
|
2019-06-27 18:58:37 +02:00
|
|
|
int RECEIVE[3] = { // Pins used as receiver for capacitive touch buttons
|
2019-06-30 00:39:01 +02:00
|
|
|
6, 1, 17 };
|
2019-06-28 01:48:24 +02:00
|
|
|
int LEDS[4] = { // Pins used for leds
|
|
|
|
21, 20, 19, 18 };
|
2019-06-27 18:58:37 +02:00
|
|
|
int OW = 2; // Pin used for overwrite switch
|
|
|
|
int DEL = -1; // Pin used for delete button
|
2019-06-28 00:14:44 +02:00
|
|
|
int ADD = 14; // Pin used for add button
|
2019-03-09 19:14:18 +01:00
|
|
|
|
2019-03-10 02:33:59 +01:00
|
|
|
// GLOBAL SETTINGS
|
2019-06-28 00:14:44 +02:00
|
|
|
//bool overwrite; // Step content is overwritten with pressed keys, could not be needed
|
2019-03-09 19:14:18 +01:00
|
|
|
|
2019-03-10 02:33:59 +01:00
|
|
|
// PLACEHOLDERS
|
2019-03-09 19:14:18 +01:00
|
|
|
byte velocity = 100; //
|
|
|
|
int bpm = 360; //
|
2019-06-27 18:58:37 +02:00
|
|
|
|
2019-03-09 19:14:18 +01:00
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
// SEQUENCER POINTERS AND RELATED ARRAYS
|
|
|
|
link head[6];
|
|
|
|
link current[6];
|
|
|
|
link previous;
|
|
|
|
unsigned short nstep[6]; // Keeps track of the sequencer steps
|
|
|
|
bool mute[6];
|
|
|
|
byte channel; // Current selected channel. Drums are shifted of DRUMSHIFT channels (so channels can only be 6)
|
2019-03-10 02:33:59 +01:00
|
|
|
|
|
|
|
// SYSTEM VARIABLES
|
2019-06-27 18:58:37 +02:00
|
|
|
int arp = 0; // Keeps track of last played NOTE if arpeggiating
|
2019-03-09 19:14:18 +01:00
|
|
|
int midiclock = 0; // Used to sync with MIDI clock
|
2019-06-29 02:42:38 +02:00
|
|
|
bool add_step = LOW; // This is used to remember the addition of a step
|
2019-06-30 00:39:01 +02:00
|
|
|
bool del_step = LOW; // This is used to remember the deletion of a step
|
|
|
|
bool chan_up = LOW; // Only for now because I have few buttons :C
|
2019-06-27 18:58:37 +02:00
|
|
|
int sem_beat = 0; // Basic semaphore used to sync with MIDI beat
|
|
|
|
int sem_gate = 0; // Basic semaphore used for gate timing
|
|
|
|
unsigned long last_gate = 0; // Gate start time for last sequencer step
|
2019-06-30 00:39:01 +02:00
|
|
|
unsigned long gate_length = 100; // ms of keypress if arpeggiator
|
2019-06-27 18:58:37 +02:00
|
|
|
bool dpadhit = LOW; // If any drum pad has been hit in this cycle, this is true
|
2019-03-09 19:14:18 +01:00
|
|
|
int npressed; // Number of keys pressed, used to avoid doing anything when no keys are pressed
|
2019-06-27 18:58:37 +02:00
|
|
|
bool kboard[MAXKEYS]; // Last status of keyboard
|
|
|
|
bool dpad[MAXDPAD]; // Last status of Capacitive Buttons
|
|
|
|
CapacitiveSensor* bCap[MAXDPAD];
|
2019-03-09 15:23:18 +01:00
|
|
|
|
2018-11-11 01:11:49 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void setup() {
|
2019-06-28 01:48:24 +02:00
|
|
|
for (int cOCTAVE = 0; cOCTAVE < 4; cOCTAVE++) pinMode(OCTAVE[cOCTAVE], OUTPUT);
|
|
|
|
for (int cNOTE = 0; cNOTE < 12; cNOTE++) pinMode(NOTE[cNOTE], INPUT);
|
|
|
|
for (int cLED = 0; cLED < 4; cLED++) pinMode(LEDS[cLED], OUTPUT);
|
2019-06-27 18:58:37 +02:00
|
|
|
for (int cButton = 0; cButton < MAXDPAD; cButton++) { // Capacitive Buttons configuration
|
|
|
|
bCap[cButton] = new CapacitiveSensor(SEND[cButton], RECEIVE[cButton]); // Initialized
|
2019-03-09 19:14:18 +01:00
|
|
|
bCap[cButton]->set_CS_AutocaL_Millis(0xFFFFFFFF); // No recalibration
|
2019-06-30 00:39:01 +02:00
|
|
|
bCap[cButton]->set_CS_Timeout_Millis(1); // Timeout set to 20ms (instead of 2s)
|
2019-06-27 18:58:37 +02:00
|
|
|
dpad[cButton] = LOW; // Button starts LOW
|
2019-03-09 15:23:18 +01:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
for (int cStat = 0; cStat < MAXKEYS; cStat++) kboard[cStat] = LOW; // All keyboard keys start LOW
|
2019-03-09 15:23:18 +01:00
|
|
|
|
2019-03-08 21:10:15 +01:00
|
|
|
MIDI.begin(MIDI_CHANNEL_OFF);
|
2018-10-31 17:18:50 +01:00
|
|
|
Serial.begin(115200);
|
2019-03-09 15:23:18 +01:00
|
|
|
|
2019-06-28 01:03:40 +02:00
|
|
|
pinMode(OW, INPUT_PULLUP); // Used for overwrite switch
|
|
|
|
pinMode(ADD, INPUT_PULLUP); // Used for overwrite switch
|
2019-06-29 02:42:38 +02:00
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
for (int i = 0, i < 6, i++){
|
|
|
|
current[i] = NULL;
|
|
|
|
head[i] = NULL;
|
|
|
|
nstep[i] = 0;
|
|
|
|
mute[i] = LOW;
|
|
|
|
}
|
|
|
|
channel = 1;
|
|
|
|
|
2019-06-29 02:42:38 +02:00
|
|
|
for (int i = 0; i < 16; i++) { // Boot up fancyness!
|
|
|
|
display(i);
|
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
// ONLY FOR DEBUG
|
|
|
|
for (int i=0; i<16, i++){
|
|
|
|
for (byte chan=1; chan <= 6; chan++) insertStep(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
display(0);
|
2018-11-11 02:00:08 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
void loop() {
|
2019-03-09 19:14:18 +01:00
|
|
|
sync();
|
2019-06-30 00:39:01 +02:00
|
|
|
// add_step = (add_step || !digitalRead(ADD));
|
|
|
|
// del_step = (del_step || !digitalRead(DEL));
|
|
|
|
chan_up = (chan_up || !digitalRead(ADD))
|
2019-06-28 01:48:24 +02:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
if (sem_beat > 0) {
|
|
|
|
sem_beat--;
|
2019-06-29 02:42:38 +02:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
if (sem_gate > 0) { // If step was shorter than gate, close all open notes before next step
|
|
|
|
sem_gate--;
|
2019-06-30 00:39:01 +02:00
|
|
|
for (byte chan = 1; chan <= 6; chan++) {
|
|
|
|
if (mute[chan]) continue;
|
|
|
|
for (int i = 0; i < MAXKEYS; i++) if (current[chan]->kboard_s[i] && !kboard[i]) playNote(i, !current[chan]->kboard_s[i], chan);
|
|
|
|
for (int i = 0; i < MAXDPAD; i++) if (current[chan]->dpad_s[i] && !dpad[i]) playDrum(i, !current[chan]->dpad_s[i], chan);
|
|
|
|
}
|
2019-06-27 18:58:37 +02:00
|
|
|
}
|
2019-06-30 00:39:01 +02:00
|
|
|
|
|
|
|
if (add_step && !del_step) {
|
2019-06-29 02:42:38 +02:00
|
|
|
add_step = LOW;
|
2019-06-30 00:39:01 +02:00
|
|
|
if (nstep[channel-1] < MAXSTEP) insertStep(channel-1);
|
|
|
|
}
|
|
|
|
if (del_step && !add_step) {
|
|
|
|
del_step = LOW;
|
|
|
|
if (nstep[channel-1] < MAXSTEP) deleteStep(channel-1);
|
|
|
|
}
|
|
|
|
if (add_step && del_step) {
|
|
|
|
add_step = LOW;
|
|
|
|
del_step = LOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ONLY FOR NOW because I don't have enough buttons :C
|
|
|
|
if (chan_up) {
|
|
|
|
chan_up = LOW;
|
|
|
|
channel++;
|
|
|
|
if (channel > 6) channel = (byte) 1;
|
2019-06-29 02:42:38 +02:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
nextStep();
|
2019-06-30 00:39:01 +02:00
|
|
|
display(current[channel-1]->stepnumber);
|
|
|
|
for (byte chan = 1; chan <= 6; chan++) {
|
|
|
|
if (mute[chan]) continue;
|
|
|
|
if (current[chan] != NULL) { // Play all step notes and begin counting for gate
|
|
|
|
for (int i = 0; i < MAXKEYS; i++) if (current[chan]->kboard_s[i] && !kboard[i]) playNote(i, current[chan]->kboard_s[i]);
|
|
|
|
for (int i = 0; i < MAXDPAD; i++) if (current[chan]->dpad_s[i] && !dpad[i]) playDrum(i, current[chan]->dpad_s[i]);
|
|
|
|
}
|
2019-06-27 18:58:37 +02:00
|
|
|
}
|
2019-06-30 00:39:01 +02:00
|
|
|
last_gate = millis();
|
|
|
|
sem_gate++;
|
2019-03-09 15:23:18 +01:00
|
|
|
}
|
2019-06-29 02:42:38 +02:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
if (sem_gate > 0 && (millis() - last_gate) > gate_length) {
|
|
|
|
sem_gate--;
|
2019-06-30 00:39:01 +02:00
|
|
|
for (byte chan = 1; chan <= 6; chan++) {
|
|
|
|
if (mute[chan]) continue;
|
|
|
|
for (int i = 0; i < MAXKEYS; i++) if (current[chan]->kboard_s[i] && !kboard[i]) playNote(i, !current[chan]->kboard_s[i], chan);
|
|
|
|
for (int i = 0; i < MAXDPAD; i++) if (current[chan]->dpad_s[i] && !dpad[i]) playDrum(i, !current[chan]->dpad_s[i], chan);
|
|
|
|
}
|
2019-06-27 18:58:37 +02:00
|
|
|
}
|
2019-06-29 02:42:38 +02:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
dpadhit = LOW;
|
|
|
|
for (int cButton = 0; cButton < MAXDPAD; cButton++) {
|
|
|
|
dpad[cButton] = evalButton(bCap[cButton], dpad[cButton], cButton);
|
2019-06-28 01:03:40 +02:00
|
|
|
dpadhit = (dpad[cButton] || dpadhit);
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
2019-03-10 02:33:59 +01:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
npressed = 0;
|
|
|
|
for (int cOCTAVE = 0; cOCTAVE < 4; cOCTAVE++) {
|
|
|
|
digitalWrite(OCTAVE[cOCTAVE], HIGH);
|
|
|
|
npressed += eval(scan(cOCTAVE));
|
|
|
|
digitalWrite(OCTAVE[cOCTAVE], LOW);
|
2019-03-09 19:14:18 +01:00
|
|
|
}
|
2019-06-28 00:14:44 +02:00
|
|
|
|
|
|
|
if (digitalRead(OW)) {
|
2019-06-30 00:39:01 +02:00
|
|
|
if (npressed > 0) for (int i = 0; i < MAXKEYS; i++) current[channel-1]->kboard_s[i] = kboard[i];
|
|
|
|
if (dpadhit) for (int i = 0; i < MAXDPAD; i++) current[channel-1]->dpad_s[i] = dpad[i];
|
|
|
|
current[channel-1]->clean = LOW;
|
2018-11-11 02:00:08 +01:00
|
|
|
}
|
2018-10-31 17:21:02 +01:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
// Hardware specific functions
|
2019-03-04 18:56:20 +01:00
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
octst scan(int nOct) { // This function reads the 12 NOTE pins and returns a struct
|
|
|
|
int c; // with 1 bool for each NOTE
|
2019-03-04 18:54:22 +01:00
|
|
|
octst output;
|
2018-10-31 17:18:50 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
output.nOct = nOct;
|
2018-11-11 01:11:49 +01:00
|
|
|
|
2019-03-04 18:54:22 +01:00
|
|
|
for (c = 0; c < 12; c++) {
|
2019-06-27 18:58:37 +02:00
|
|
|
output.stat[c] = digitalRead(NOTE[c]);
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
2019-03-04 18:54:22 +01:00
|
|
|
return output;
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
|
|
|
|
2019-06-28 01:48:24 +02:00
|
|
|
void display(int number){
|
|
|
|
for(int i = 0; i < 4; i++) {
|
2019-06-29 02:42:38 +02:00
|
|
|
digitalWrite(LEDS[i], number & (unsigned short) 1);
|
|
|
|
number = number >> 1;
|
|
|
|
}
|
2019-06-28 01:48:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
bool evalButton(CapacitiveSensor* b, bool value, int note_number) {
|
|
|
|
long sensor = b->capacitiveSensor(1);
|
2019-06-29 02:42:38 +02:00
|
|
|
// Serial.println(sensor);
|
2019-06-27 18:58:37 +02:00
|
|
|
|
|
|
|
if (sensor > 15) {
|
|
|
|
if (value) return HIGH;
|
|
|
|
else {
|
2019-06-30 00:39:01 +02:00
|
|
|
playDrum(note_number, HIGH, channel);
|
2019-06-27 18:58:37 +02:00
|
|
|
return HIGH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!value) return LOW;
|
|
|
|
else {
|
2019-06-30 00:39:01 +02:00
|
|
|
playDrum(note_number, LOW, channel);
|
2019-06-27 18:58:37 +02:00
|
|
|
return LOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE Functions
|
|
|
|
|
2019-03-08 21:10:15 +01:00
|
|
|
int eval(octst input) {
|
|
|
|
int pressed = 0;
|
2019-06-27 18:58:37 +02:00
|
|
|
int sNOTE = input.nOct * 12;
|
2019-03-08 21:10:15 +01:00
|
|
|
|
|
|
|
for (int c = 0; c < 12; c++) {
|
2019-06-27 18:58:37 +02:00
|
|
|
if (input.stat[c] ^ kboard[c + sNOTE]) {
|
2019-06-30 00:39:01 +02:00
|
|
|
playNote(c + sNOTE, input.stat[c], channel);
|
2019-06-27 18:58:37 +02:00
|
|
|
kboard[c + sNOTE] = input.stat[c];
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
2019-06-27 18:58:37 +02:00
|
|
|
if (kboard[c + sNOTE] == HIGH) pressed++;
|
2018-10-31 17:18:50 +01:00
|
|
|
}
|
2019-03-08 21:10:15 +01:00
|
|
|
return pressed;
|
2018-11-11 01:11:49 +01:00
|
|
|
}
|
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
void playNote(int c, bool status, byte chan) {
|
2019-06-27 18:58:37 +02:00
|
|
|
byte n = c + NOTEOffset;
|
2019-03-08 21:10:15 +01:00
|
|
|
if (status == HIGH) {
|
2019-06-30 00:39:01 +02:00
|
|
|
MIDI.sendNoteOn(n, velocity, chan);
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
|
|
|
else if (status == LOW) {
|
2019-06-30 00:39:01 +02:00
|
|
|
MIDI.sendNoteOff(n, velocity, chan);
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
void playDrum(int c, bool status, byte chan) {
|
2019-06-27 18:58:37 +02:00
|
|
|
byte n = c + drumOffset;
|
|
|
|
if (status == HIGH) {
|
2019-06-30 00:39:01 +02:00
|
|
|
MIDI.sendNoteOn(n, velocity, (byte)(chan + DRUMSHIFT));
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
2019-06-27 18:58:37 +02:00
|
|
|
else if (status == LOW) {
|
2019-06-30 00:39:01 +02:00
|
|
|
MIDI.sendNoteOff(n, velocity, (byte)(chan + DRUMSHIFT));
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|
2019-03-09 19:14:18 +01:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
// Sync functions
|
|
|
|
|
2019-03-09 19:14:18 +01:00
|
|
|
void sync() {
|
2019-06-29 02:42:38 +02:00
|
|
|
if (Serial.available()) {
|
|
|
|
if (Serial.read() == MIDICLOCK) {
|
|
|
|
//sem_beat++;
|
|
|
|
midiclock++;
|
|
|
|
if (midiclock == BPQN){
|
|
|
|
midiclock = 0;
|
|
|
|
sem_beat++;
|
|
|
|
}
|
2019-06-28 01:48:24 +02:00
|
|
|
}
|
2019-03-09 19:14:18 +01:00
|
|
|
}
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
|
|
|
|
2019-06-27 18:58:37 +02:00
|
|
|
// List management functions
|
|
|
|
|
2019-03-10 02:33:59 +01:00
|
|
|
link newStep() {
|
|
|
|
return (link)malloc(sizeof(struct SequencerStep));
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
bool insertStep(byte chan) {
|
2019-03-10 02:33:59 +01:00
|
|
|
link newS = newStep();
|
2019-06-29 02:42:38 +02:00
|
|
|
link buffer;
|
2019-03-10 02:33:59 +01:00
|
|
|
if (newS == NULL) {
|
|
|
|
free(newS);
|
|
|
|
return LOW;
|
|
|
|
}
|
|
|
|
|
2019-06-29 02:42:38 +02:00
|
|
|
for (int i = 0; i < MAXKEYS; i++) newS->kboard_s[i] = LOW;
|
|
|
|
for (int i = 0; i < MAXDPAD; i++) newS->dpad_s[i] = LOW;
|
2019-06-27 18:58:37 +02:00
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
if (current[chan] == NULL) {
|
2019-03-10 02:33:59 +01:00
|
|
|
newS->next = newS;
|
2019-06-29 02:42:38 +02:00
|
|
|
newS->stepnumber = (unsigned short) 0;
|
2019-06-30 00:39:01 +02:00
|
|
|
current[chan] = newS;
|
|
|
|
head[chan] = newS;
|
|
|
|
nstep[chan] = 1;
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-06-29 02:42:38 +02:00
|
|
|
newS->stepnumber = nstep;
|
2019-06-30 00:39:01 +02:00
|
|
|
buffer = current[chan];
|
|
|
|
while (buffer->next != head[chan]) buffer = buffer->next;
|
2019-06-29 02:42:38 +02:00
|
|
|
buffer->next = newS;
|
2019-06-30 00:39:01 +02:00
|
|
|
newS->next = head[chan];
|
|
|
|
nstep[chan]++;
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
|
|
|
return HIGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nextStep() {
|
2019-06-30 00:39:01 +02:00
|
|
|
for (byte chan=1; chan <= 6; chan++) {
|
|
|
|
if (current[chan] == NULL) continue;
|
|
|
|
current[chan] = current[chan]->next;
|
|
|
|
}
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
bool deleteStep(byte chan) {
|
|
|
|
if (nstep[chan] < 1) return LOW;
|
|
|
|
|
|
|
|
if (!current[chan]->clean) {
|
|
|
|
for (int i = 0; i < MAXKEYS; i++) current[chan]->kboard_s[i] = LOW;
|
|
|
|
for (int i = 0; i < MAXDPAD; i++) current[chan]->dpad_s[i] = LOW;
|
|
|
|
current[chan]->clean = HIGH;
|
|
|
|
return LOW;
|
|
|
|
}
|
2019-03-10 02:33:59 +01:00
|
|
|
|
2019-06-30 00:39:01 +02:00
|
|
|
if (nstep[chan] == 1) {
|
2019-03-10 02:33:59 +01:00
|
|
|
free(current);
|
2019-06-30 00:39:01 +02:00
|
|
|
head[chan] = NULL;
|
|
|
|
current[chan] = NULL;
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-06-30 00:39:01 +02:00
|
|
|
link buffer = current[chan];
|
|
|
|
while (buffer->next != current[chan]) buffer = buffer->next;
|
|
|
|
buffer->next = current[chan]->next;
|
|
|
|
if (current[chan] == head[chan]) {
|
|
|
|
head[chan] = head[chan]->next;
|
|
|
|
int i = 0
|
|
|
|
buffer = head[chan]
|
|
|
|
do {
|
|
|
|
buffer->stepnumber = i;
|
|
|
|
buffer = buffer->next;
|
|
|
|
i++;
|
|
|
|
} while (buffer != head[chan])
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffer = buffer->next;
|
|
|
|
while (buffer != head[chan]) {
|
|
|
|
buffer->stepnumber--;
|
|
|
|
buffer = buffer->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(current[chan]);
|
|
|
|
buffer = buffer->next;
|
2019-03-10 02:33:59 +01:00
|
|
|
}
|
2019-06-30 00:39:01 +02:00
|
|
|
nstep[chan]--;
|
2019-03-10 02:33:59 +01:00
|
|
|
return HIGH;
|
2019-03-08 21:10:15 +01:00
|
|
|
}
|