forked from W4D/soundcube-firmware
sampler at 80 percent
This commit is contained in:
@ -35,8 +35,8 @@ DAC8552 dac(9, &SPI1);
|
|||||||
|
|
||||||
PWMAudio ui_snd(8);
|
PWMAudio ui_snd(8);
|
||||||
|
|
||||||
enum STATE {IDLE, BANK_A, BANK_B, BANK_C, BANK_D, CTEMPO};
|
enum STATE {BANK, SAMPLE, SEQUENCE, CTEMPO};
|
||||||
STATE state = IDLE;
|
STATE state = BANK;
|
||||||
|
|
||||||
//enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
//enum BUTTON {CVINL, CVINR, INL, INR, OUTR, OUTL, CVOUTR, CVOUTL, RIGHT, LEFT, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
enum BUTTON {MODE, LOOP, INL, INR, OUTR, OUTL, TEMPO, RESET, BACK, POWER, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
enum BUTTON {MODE, LOOP, INL, INR, OUTR, OUTL, TEMPO, RESET, BACK, POWER, SELECT, DEBUG1, DEBUG2, DEBUG3};
|
||||||
@ -45,9 +45,15 @@ int lut_ring_cw[48] = {39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,
|
|||||||
int lut_ring_ccw[48] = {40,41,42,43,44,45,46,47,48,49,50,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
|
int lut_ring_ccw[48] = {40,41,42,43,44,45,46,47,48,49,50,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
|
||||||
int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
|
int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
|
||||||
|
|
||||||
|
int lut_banks[4] = {56,55,67,66};
|
||||||
|
int lut_samples[4] = {62,58,60,64};
|
||||||
|
|
||||||
int active = 0;
|
int active = 0;
|
||||||
int active_led_ring = 0;
|
int active_led_ring = 0;
|
||||||
|
|
||||||
|
int selected_bank = 0;
|
||||||
|
int selected_sample = 0;
|
||||||
|
|
||||||
uint32_t lastTime = 0;
|
uint32_t lastTime = 0;
|
||||||
int32_t position = 0;
|
int32_t position = 0;
|
||||||
|
|
||||||
@ -424,27 +430,33 @@ int bar_old = -1;
|
|||||||
int set_bar = 0;
|
int set_bar = 0;
|
||||||
int16_t angle = 0;
|
int16_t angle = 0;
|
||||||
int32_t position_last = 0;
|
int32_t position_last = 0;
|
||||||
|
|
||||||
int16_t encdelta_raw = 0;
|
int16_t encdelta_raw = 0;
|
||||||
int16_t encdeltadiv = 1;
|
int16_t encdeltadiv = 512;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
position = ENC.getCumulativePosition();
|
position = ENC.getCumulativePosition();
|
||||||
angle = ENC.readAngle();
|
angle = ENC.readAngle();
|
||||||
encdelta_raw += (position - position_last);
|
encdelta_raw += (position - position_last);
|
||||||
|
|
||||||
|
// Serial.print(encdelta_raw);
|
||||||
|
// Serial.print(" \t");
|
||||||
|
|
||||||
int encdelta = 0;
|
int encdelta = 0;
|
||||||
if(abs(encdelta_raw) > encdeltadiv) {
|
if(abs(encdelta_raw) > encdeltadiv) {
|
||||||
encdelta = encdelta_raw > 0 ? 1 : -1;
|
encdelta = encdelta_raw > 0 ? 1 : -1;
|
||||||
encdelta_raw = 0;
|
encdelta_raw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(angle);
|
// Serial.print(angle);
|
||||||
Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
Serial.print(position);
|
// Serial.print(position);
|
||||||
Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
Serial.print(encdelta_raw);
|
// Serial.print(position_last);
|
||||||
Serial.print(" \t");
|
// Serial.print(" \t");
|
||||||
Serial.println(encdelta);
|
// Serial.print(encdelta_raw);
|
||||||
|
// Serial.print(" \t");
|
||||||
|
// Serial.println(encdelta);
|
||||||
|
|
||||||
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
uint32_t delta_bpm = floor((60000 / config.bpm) / 16);
|
||||||
|
|
||||||
@ -504,32 +516,55 @@ void loop() {
|
|||||||
ui_click = true;
|
ui_click = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttons[TEMPO]){
|
if(buttons[TEMPO] && buttonDown){
|
||||||
state = CTEMPO;
|
state = CTEMPO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
}
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
case IDLE:
|
case BANK:
|
||||||
break;
|
encdeltadiv = 512;
|
||||||
case BANK_A:
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
if(buttons[SELECT] && buttonDown){
|
if(buttons[SELECT] && buttonDown){
|
||||||
int n = steps[set_bar].len;
|
state = SAMPLE;
|
||||||
steps[set_bar].samples[n] = &samples[0];
|
|
||||||
steps[set_bar].len = (steps[set_bar].len + 1) % 4;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BANK_B:
|
case SAMPLE:
|
||||||
|
encdeltadiv = 512;
|
||||||
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
state = SEQUENCE;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = BANK;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BANK_C:
|
case SEQUENCE:
|
||||||
break;
|
encdeltadiv = 256;
|
||||||
case BANK_D:
|
encdelta_raw = 0;
|
||||||
|
encdelta = 0;
|
||||||
|
if(buttons[SELECT] && buttonDown){
|
||||||
|
int n = steps[set_bar].len;
|
||||||
|
steps[set_bar].samples[n] = &samples[selected_bank*4 + selected_sample];
|
||||||
|
steps[set_bar].len = (steps[set_bar].len + 1) % 4;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = SAMPLE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CTEMPO:
|
case CTEMPO:
|
||||||
encdeltadiv = 64;
|
encdeltadiv = 64;
|
||||||
encdelta_raw = 0;
|
encdelta_raw = 0;
|
||||||
encdelta = 0;
|
encdelta = 0;
|
||||||
if(buttons[SELECT] && buttonDown){
|
if(buttons[SELECT] && buttonDown){
|
||||||
state = IDLE;
|
state = BANK;
|
||||||
|
}
|
||||||
|
if(buttons[BACK] && buttonDown){
|
||||||
|
state = BANK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -566,19 +601,23 @@ void loop() {
|
|||||||
buttonChanged = false;
|
buttonChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(position < 0) position += 4096;
|
// if(position < 0) position += 4096;
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
case IDLE:
|
case BANK:
|
||||||
|
selected_bank += encdelta;
|
||||||
|
if(selected_bank == 4) selected_bank = 0;
|
||||||
|
if(selected_bank == -1) selected_bank = 3;
|
||||||
break;
|
break;
|
||||||
case BANK_A:
|
case SAMPLE:
|
||||||
set_bar = (position / 256) % 16;
|
selected_sample += encdelta;
|
||||||
|
if(selected_sample == 4) selected_sample = 0;
|
||||||
|
if(selected_sample == -1) selected_sample = 3;
|
||||||
break;
|
break;
|
||||||
case BANK_B:
|
case SEQUENCE:
|
||||||
break;
|
set_bar += encdelta;
|
||||||
case BANK_C:
|
if(set_bar == 16) set_bar = 0;
|
||||||
break;
|
if(set_bar == -1) set_bar = 15;
|
||||||
case BANK_D:
|
|
||||||
break;
|
break;
|
||||||
case CTEMPO:
|
case CTEMPO:
|
||||||
config.bpm += encdelta;
|
config.bpm += encdelta;
|
||||||
@ -591,14 +630,14 @@ void loop() {
|
|||||||
//dac.setValue(0, dactest ? 0 : sin((float)millis() / 100.0f) * 32768 + 32768);
|
//dac.setValue(0, dactest ? 0 : sin((float)millis() / 100.0f) * 32768 + 32768);
|
||||||
|
|
||||||
// empty LED matrix
|
// empty LED matrix
|
||||||
for (int i = 0; i < 13; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
ui_leds[lut_matrix[i]] = CRGB(0, 0, 0);
|
ui_leds[lut_banks[i]] = CRGB(0, 0, 0);
|
||||||
if(stream[i % NSTREAMS].isPlaying()) ui_leds[lut_matrix[i % NSTREAMS]] = CRGB(0, 50, 0);
|
ui_leds[lut_samples[i]] = CRGB(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set active LED matrix LED
|
// set active LED matrix LED
|
||||||
ui_leds[lut_matrix[active]] = CRGB(100, 100, 100);
|
ui_leds[lut_banks[selected_bank]] = CRGB(100, 50, 50);
|
||||||
|
ui_leds[lut_samples[selected_sample]] = CRGB(100, 0, 50);
|
||||||
|
|
||||||
for(int i = 0; i < 48; i++){
|
for(int i = 0; i < 48; i++){
|
||||||
int step = floor(i/3);
|
int step = floor(i/3);
|
||||||
@ -649,3 +688,5 @@ void loop() {
|
|||||||
vibration.update();
|
vibration.update();
|
||||||
position_last = position;
|
position_last = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user