updating divisions
This commit is contained in:
parent
347379424c
commit
150e910ed4
3 changed files with 67 additions and 31 deletions
|
|
@ -35,11 +35,11 @@ extern volatile uint32_t MASTER_TICK;
|
||||||
|
|
||||||
|
|
||||||
// Modifiers in UI order
|
// Modifiers in UI order
|
||||||
static std::array<uint8_t, 10> MODIFIERS = {8, 4, 2, 0, 1, 2, 3, 4, 8, 16};
|
static std::array<uint8_t, 17> MODIFIERS = {32, 16, 12, 8, 6, 4, 3, 2, 0, 1, 2, 3, 4, 6, 8, 16, 32};
|
||||||
// Modifier type; 0 = multiplicaton, 1 = division; matched with MODIFIERS
|
// Modifier type; 0 = multiplicaton, 1 = division; matched with MODIFIERS
|
||||||
static std::array<uint8_t, 10> MOD_TYPES = {0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
|
static std::array<uint8_t, 17> MOD_TYPES = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||||
// Modifier string
|
// Modifier string
|
||||||
static std::array<std::string, 10> MODIFIER_STRINGS = {"x8", "x4", "x2", "x0", "/1", "/2", "/3", "/4", "/8", "/16"};
|
static std::array<std::string, 17> MODIFIER_STRINGS = {"x32", "x16", "x12", "x8", "x6", "x4", "x3", "x2", "x0", "/1", "/2", "/3", "/4", "/6", "/8", "/16", "/32"};
|
||||||
|
|
||||||
|
|
||||||
inline uint32_t millis() {
|
inline uint32_t millis() {
|
||||||
|
|
|
||||||
|
|
@ -35,21 +35,16 @@ void EncoderHandler::gpio_callback(uint gpio, uint32_t events) {
|
||||||
void EncoderHandler::setup() {
|
void EncoderHandler::setup() {
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
// 1. Setup Button (Standard GPIO)
|
|
||||||
gpio_init(ENCODER_SW_PIN);
|
gpio_init(ENCODER_SW_PIN);
|
||||||
gpio_set_dir(ENCODER_SW_PIN, GPIO_IN);
|
gpio_set_dir(ENCODER_SW_PIN, GPIO_IN);
|
||||||
gpio_pull_up(ENCODER_SW_PIN);
|
gpio_pull_up(ENCODER_SW_PIN);
|
||||||
|
|
||||||
// Enable IRQ only for the switch
|
|
||||||
gpio_set_irq_enabled_with_callback(ENCODER_SW_PIN, GPIO_IRQ_EDGE_FALL, true, &EncoderHandler::gpio_callback);
|
gpio_set_irq_enabled_with_callback(ENCODER_SW_PIN, GPIO_IRQ_EDGE_FALL, true, &EncoderHandler::gpio_callback);
|
||||||
|
|
||||||
// 2. Setup Rotation (PIO)
|
|
||||||
// Note: ENCODER_CLK_PIN and ENCODER_DT_PIN must be consecutive!
|
|
||||||
PIO pio = pio0;
|
PIO pio = pio0;
|
||||||
uint offset = pio_add_program(pio, &quadrature_encoder_program);
|
uint offset = pio_add_program(pio, &quadrature_encoder_program);
|
||||||
this->sm = pio_claim_unused_sm(pio, true);
|
this->sm = pio_claim_unused_sm(pio, true);
|
||||||
|
|
||||||
// Internal pull-ups still needed for the PIO pins
|
|
||||||
gpio_init(ENCODER_CLK_PIN);
|
gpio_init(ENCODER_CLK_PIN);
|
||||||
gpio_pull_up(ENCODER_CLK_PIN);
|
gpio_pull_up(ENCODER_CLK_PIN);
|
||||||
gpio_init(ENCODER_DT_PIN);
|
gpio_init(ENCODER_DT_PIN);
|
||||||
|
|
@ -60,7 +55,6 @@ void EncoderHandler::setup() {
|
||||||
this->last_count = 0;
|
this->last_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call this in your main loop or a timer
|
|
||||||
void EncoderHandler::update() {
|
void EncoderHandler::update() {
|
||||||
int32_t current_count = quadrature_encoder_get_count(pio0, this->sm);
|
int32_t current_count = quadrature_encoder_get_count(pio0, this->sm);
|
||||||
|
|
||||||
|
|
@ -68,10 +62,10 @@ void EncoderHandler::update() {
|
||||||
|
|
||||||
if (abs(delta) >= TICKS_PER_DETENT) {
|
if (abs(delta) >= TICKS_PER_DETENT) {
|
||||||
|
|
||||||
if (delta < 0) { // Changed from > to < to reverse direction
|
if (delta < 0) {
|
||||||
display_handler->moveCursor(); // Clockwise
|
display_handler->moveCursor();
|
||||||
} else {
|
} else {
|
||||||
display_handler->moveCursor(0); // Counter-clockwise
|
display_handler->moveCursor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_count = current_count - (delta % TICKS_PER_DETENT);
|
last_count = current_count - (delta % TICKS_PER_DETENT);
|
||||||
|
|
|
||||||
80
src/Gate.cpp
80
src/Gate.cpp
|
|
@ -29,62 +29,104 @@ void Gate::setLen(uint32_t currentPeriod) {
|
||||||
|
|
||||||
void Gate::setDiv(uint8_t modifier_selecton_index) {
|
void Gate::setDiv(uint8_t modifier_selecton_index) {
|
||||||
switch(modifier_selecton_index) {
|
switch(modifier_selecton_index) {
|
||||||
case 0: // x8 (32nd triplets)
|
case 0: // x32
|
||||||
tickInterval = 12; // 96 / 12 hits per beat
|
tickInterval = 3;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 0;
|
||||||
|
modifier = 32;
|
||||||
|
break;
|
||||||
|
case 1: // x16
|
||||||
|
tickInterval = 6;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 0;
|
||||||
|
modifier = 16;
|
||||||
|
break;
|
||||||
|
case 2: // x12
|
||||||
|
tickInterval = 8;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 0;
|
||||||
|
modifier = 12;
|
||||||
|
break;
|
||||||
|
case 3: // x8
|
||||||
|
tickInterval = 12;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 0;
|
divideMode = 0;
|
||||||
modifier = 8;
|
modifier = 8;
|
||||||
break;
|
break;
|
||||||
case 1: // x4 (16th triplets)
|
case 4: // x6
|
||||||
tickInterval = 24; // 96 / 6 hits per beat
|
tickInterval = 16;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 0;
|
||||||
|
modifier = 6;
|
||||||
|
break;
|
||||||
|
case 5: // x4
|
||||||
|
tickInterval = 24;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 0;
|
divideMode = 0;
|
||||||
modifier = 4;
|
modifier = 4;
|
||||||
break;
|
break;
|
||||||
case 2: // x2 (8th triplets)
|
case 6: // x3
|
||||||
tickInterval = 48; // 96 / 3 hits per beat
|
tickInterval = 32;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 0;
|
||||||
|
modifier = 3;
|
||||||
|
break;
|
||||||
|
case 7: // x2
|
||||||
|
tickInterval = 48;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 0;
|
divideMode = 0;
|
||||||
modifier = 2;
|
modifier = 2;
|
||||||
break;
|
break;
|
||||||
case 3: // 0 (OFF)
|
case 8: // 0 (OFF)
|
||||||
tickInterval = 0;
|
tickInterval = 0;
|
||||||
isEnabled = false;
|
isEnabled = false;
|
||||||
divideMode = 0;
|
divideMode = 0;
|
||||||
modifier = 0;
|
modifier = 0;
|
||||||
break;
|
break;
|
||||||
case 4: // /1 (Quarter Notes - The Pulse)
|
case 9: // /1
|
||||||
tickInterval = 96; // 96 / 1 hit per beat
|
tickInterval = 96;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 1;
|
modifier = 1;
|
||||||
break;
|
break;
|
||||||
case 5: // /2 (8th Notes)
|
case 10: // /2
|
||||||
tickInterval = 192; // 96 * 2 (1 hit every 2 beats)
|
tickInterval = 192;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 2;
|
modifier = 2;
|
||||||
break;
|
break;
|
||||||
case 6: // /3 (Dotted Quarter or specialized)
|
case 11: // /3
|
||||||
tickInterval = 288; // 96 * 3 (1 hit every 3 beats)
|
tickInterval = 288;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 3;
|
modifier = 3;
|
||||||
break;
|
break;
|
||||||
case 7: // /4 (Whole Notes)
|
case 12: // /4
|
||||||
tickInterval = 384; // 96 * 4 (1 hit every 4 beats)
|
tickInterval = 384;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 4;
|
modifier = 4;
|
||||||
break;
|
break;
|
||||||
case 8: // /8 (2 Bar phrasing)
|
case 13: // /6
|
||||||
tickInterval = 768; // 96 * 8 (1 hit every 8 beats)
|
tickInterval = 576;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 1;
|
||||||
|
modifier = 4;
|
||||||
|
break;
|
||||||
|
case 14: // /8
|
||||||
|
tickInterval = 768;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 8;
|
modifier = 8;
|
||||||
break;
|
break;
|
||||||
case 9: // /16 (4 Bar phrasing)
|
case 15: // /16
|
||||||
tickInterval = 1536; // 96 * 16 (1 hit every 16 beats)
|
tickInterval = 1536;
|
||||||
|
isEnabled = true;
|
||||||
|
divideMode = 1;
|
||||||
|
modifier = 16;
|
||||||
|
break;
|
||||||
|
case 16: // /32
|
||||||
|
tickInterval = 3072;
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
divideMode = 1;
|
divideMode = 1;
|
||||||
modifier = 16;
|
modifier = 16;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue