From 150e910ed43859496673e8b595aa3880bc96bffa Mon Sep 17 00:00:00 2001 From: Dominic DiTaranto Date: Tue, 24 Feb 2026 19:07:29 -0500 Subject: [PATCH] updating divisions --- include/globals.h | 6 ++-- src/EncoderHandler.cpp | 12 ++----- src/Gate.cpp | 80 ++++++++++++++++++++++++++++++++---------- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/include/globals.h b/include/globals.h index 4915f1d..8470f43 100644 --- a/include/globals.h +++ b/include/globals.h @@ -35,11 +35,11 @@ extern volatile uint32_t MASTER_TICK; // Modifiers in UI order -static std::array MODIFIERS = {8, 4, 2, 0, 1, 2, 3, 4, 8, 16}; +static std::array 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 -static std::array MOD_TYPES = {0, 0, 0, 0, 1, 1, 1, 1, 1, 1}; +static std::array MOD_TYPES = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}; // Modifier string -static std::array MODIFIER_STRINGS = {"x8", "x4", "x2", "x0", "/1", "/2", "/3", "/4", "/8", "/16"}; +static std::array MODIFIER_STRINGS = {"x32", "x16", "x12", "x8", "x6", "x4", "x3", "x2", "x0", "/1", "/2", "/3", "/4", "/6", "/8", "/16", "/32"}; inline uint32_t millis() { diff --git a/src/EncoderHandler.cpp b/src/EncoderHandler.cpp index aa000a6..f6ccf67 100644 --- a/src/EncoderHandler.cpp +++ b/src/EncoderHandler.cpp @@ -35,21 +35,16 @@ void EncoderHandler::gpio_callback(uint gpio, uint32_t events) { void EncoderHandler::setup() { self = this; - // 1. Setup Button (Standard GPIO) gpio_init(ENCODER_SW_PIN); gpio_set_dir(ENCODER_SW_PIN, GPIO_IN); 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); - // 2. Setup Rotation (PIO) - // Note: ENCODER_CLK_PIN and ENCODER_DT_PIN must be consecutive! PIO pio = pio0; uint offset = pio_add_program(pio, &quadrature_encoder_program); this->sm = pio_claim_unused_sm(pio, true); - // Internal pull-ups still needed for the PIO pins gpio_init(ENCODER_CLK_PIN); gpio_pull_up(ENCODER_CLK_PIN); gpio_init(ENCODER_DT_PIN); @@ -60,7 +55,6 @@ void EncoderHandler::setup() { this->last_count = 0; } -// Call this in your main loop or a timer void EncoderHandler::update() { 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 (delta < 0) { // Changed from > to < to reverse direction - display_handler->moveCursor(); // Clockwise + if (delta < 0) { + display_handler->moveCursor(); } else { - display_handler->moveCursor(0); // Counter-clockwise + display_handler->moveCursor(0); } last_count = current_count - (delta % TICKS_PER_DETENT); diff --git a/src/Gate.cpp b/src/Gate.cpp index 10b3ef5..d494c62 100644 --- a/src/Gate.cpp +++ b/src/Gate.cpp @@ -29,62 +29,104 @@ void Gate::setLen(uint32_t currentPeriod) { void Gate::setDiv(uint8_t modifier_selecton_index) { switch(modifier_selecton_index) { - case 0: // x8 (32nd triplets) - tickInterval = 12; // 96 / 12 hits per beat + case 0: // x32 + 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; divideMode = 0; modifier = 8; break; - case 1: // x4 (16th triplets) - tickInterval = 24; // 96 / 6 hits per beat + case 4: // x6 + tickInterval = 16; + isEnabled = true; + divideMode = 0; + modifier = 6; + break; + case 5: // x4 + tickInterval = 24; isEnabled = true; divideMode = 0; modifier = 4; break; - case 2: // x2 (8th triplets) - tickInterval = 48; // 96 / 3 hits per beat + case 6: // x3 + tickInterval = 32; + isEnabled = true; + divideMode = 0; + modifier = 3; + break; + case 7: // x2 + tickInterval = 48; isEnabled = true; divideMode = 0; modifier = 2; break; - case 3: // 0 (OFF) + case 8: // 0 (OFF) tickInterval = 0; isEnabled = false; divideMode = 0; modifier = 0; break; - case 4: // /1 (Quarter Notes - The Pulse) - tickInterval = 96; // 96 / 1 hit per beat + case 9: // /1 + tickInterval = 96; isEnabled = true; divideMode = 1; modifier = 1; break; - case 5: // /2 (8th Notes) - tickInterval = 192; // 96 * 2 (1 hit every 2 beats) + case 10: // /2 + tickInterval = 192; isEnabled = true; divideMode = 1; modifier = 2; break; - case 6: // /3 (Dotted Quarter or specialized) - tickInterval = 288; // 96 * 3 (1 hit every 3 beats) + case 11: // /3 + tickInterval = 288; isEnabled = true; divideMode = 1; modifier = 3; break; - case 7: // /4 (Whole Notes) - tickInterval = 384; // 96 * 4 (1 hit every 4 beats) + case 12: // /4 + tickInterval = 384; isEnabled = true; divideMode = 1; modifier = 4; break; - case 8: // /8 (2 Bar phrasing) - tickInterval = 768; // 96 * 8 (1 hit every 8 beats) + case 13: // /6 + tickInterval = 576; + isEnabled = true; + divideMode = 1; + modifier = 4; + break; + case 14: // /8 + tickInterval = 768; isEnabled = true; divideMode = 1; modifier = 8; break; - case 9: // /16 (4 Bar phrasing) - tickInterval = 1536; // 96 * 16 (1 hit every 16 beats) + case 15: // /16 + tickInterval = 1536; + isEnabled = true; + divideMode = 1; + modifier = 16; + break; + case 16: // /32 + tickInterval = 3072; isEnabled = true; divideMode = 1; modifier = 16;