Reverse the order of clock mod options. #16

Merged
awonak merged 5 commits from reverse-clock-mod-index into main 2025-07-22 00:00:49 +00:00
3 changed files with 15 additions and 19 deletions

View File

@ -50,9 +50,6 @@ class Clock {
void Init() {
NeoSerial.begin(31250);
// Static pin definition for pulse out.
pinMode(PULSE_OUT_PIN, OUTPUT);
// Initialize the clock library
uClock.init();
uClock.setClockMode(uClock.INTERNAL_CLOCK);

View File

@ -135,13 +135,12 @@ void HandleIntClockTick(uint32_t tick) {
break;
}
const uint32_t pulse_high_ticks = CLOCK_MOD_PULSES[clock_index];
const uint16_t pulse_high_ticks = pgm_read_word_near(&CLOCK_MOD_PULSES[clock_index]);
const uint32_t pulse_low_ticks = tick + max((pulse_high_ticks / 2), 1L);
if (tick % pulse_high_ticks == 0) {
gravity.pulse.High();
}
if (pulse_low_ticks % pulse_high_ticks == 0) {
} else if (pulse_low_ticks % pulse_high_ticks == 0) {
gravity.pulse.Low();
}
}

View File

@ -34,28 +34,28 @@ static const byte MOD_CHOICE_SIZE = 25;
// Negative numbers are multipliers, positive are divisors.
static const int CLOCK_MOD[MOD_CHOICE_SIZE] PROGMEM = {
// Multipliers
-24, -16, -12, -8, -6, -4, -3, -2,
// Internal Clock Unity
1,
// Divisors
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 24, 32, 64, 128};
128, 64, 32, 24, 16, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
// Internal Clock Unity (quarter note)
1,
// Multipliers
-2, -3, -4, -6, -8, -12, -16, -24};
// This represents the number of clock pulses for a 96 PPQN clock source
// that match the above div/mult mods.
static const int CLOCK_MOD_PULSES[MOD_CHOICE_SIZE] PROGMEM = {
// Multiplier Pulses (96 / X)
4, 6, 8, 12, 16, 24, 32, 48,
// Divisor Pulses (96 * X)
12288, 6144, 3072, 2304, 1536, 1152, 1056, 960, 864, 768, 672, 576, 480, 384, 288, 192,
// Internal Clock Pulses
96,
// Divisor Pulses (96 * X)
192, 288, 384, 480, 576, 672, 768, 864, 960, 1056, 1152, 1536, 2304, 3072, 6144, 12288};
// Multiplier Pulses (96 / X)
48, 32, 24, 16, 12, 8, 6, 4};
static const byte DEFAULT_CLOCK_MOD_INDEX = 8; // x1 or 96 PPQN.
static const byte DEFAULT_CLOCK_MOD_INDEX = 16; // x1 or 96 PPQN.
static const byte PULSE_PPQN_24_CLOCK_MOD_INDEX = 0;
static const byte PULSE_PPQN_4_CLOCK_MOD_INDEX = 4;
static const byte PULSE_PPQN_1_CLOCK_MOD_INDEX = 8;
static const byte PULSE_PPQN_24_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 1;
static const byte PULSE_PPQN_4_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 6;
static const byte PULSE_PPQN_1_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 9;
class Channel {
public: