Vendorize uClock (#10)
Add copy of uClock to the repo including memory optimization changes. Also add user config setting for changing Pulse Out resolution. Reviewed-on: https://git.pinkduck.xyz/adam/libGravity/pulls/10 Co-authored-by: Adam Wonak <adam.wonak@gmail.com> Co-committed-by: Adam Wonak <adam.wonak@gmail.com>
This commit is contained in:
@ -101,6 +101,32 @@ void HandleIntClockTick(uint32_t tick) {
|
||||
}
|
||||
}
|
||||
|
||||
// Pulse Out gate
|
||||
if (app.selected_pulse != Clock::PULSE_NONE) {
|
||||
int clock_index;
|
||||
switch (app.selected_pulse) {
|
||||
case Clock::PULSE_PPQN_24:
|
||||
clock_index = 0;
|
||||
break;
|
||||
case Clock::PULSE_PPQN_4:
|
||||
clock_index = 4;
|
||||
break;
|
||||
case Clock::PULSE_PPQN_1:
|
||||
clock_index = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
const uint16_t pulse_high_ticks = clock_mod_pulses[clock_index];
|
||||
const uint32_t pulse_low_ticks = tick + max((long)(pulse_high_ticks / 2), 1L);
|
||||
|
||||
if (tick % pulse_high_ticks == 0) {
|
||||
gravity.pulse.High();
|
||||
}
|
||||
if (pulse_low_ticks % pulse_high_ticks == 0) {
|
||||
gravity.pulse.Low();
|
||||
}
|
||||
}
|
||||
|
||||
if (!app.editing_param) {
|
||||
app.refresh_screen |= refresh;
|
||||
}
|
||||
@ -197,6 +223,13 @@ void editMainParameter(int val) {
|
||||
gravity.clock.SetSource(app.selected_source);
|
||||
break;
|
||||
}
|
||||
case PARAM_MAIN_PULSE:
|
||||
byte pulse = static_cast<int>(app.selected_pulse);
|
||||
updateSelection(pulse, val, Clock::PULSE_LAST);
|
||||
app.selected_pulse = static_cast<Clock::Pulse>(pulse);
|
||||
if (app.selected_pulse == Clock::PULSE_NONE) {
|
||||
gravity.pulse.Low();
|
||||
}
|
||||
case PARAM_MAIN_ENCODER_DIR:
|
||||
updateSelection(app.selected_sub_param, val, 2);
|
||||
break;
|
||||
|
||||
@ -16,6 +16,7 @@ struct AppState {
|
||||
byte selected_channel = 0; // 0=tempo, 1-6=output channel
|
||||
byte selected_shuffle = 0;
|
||||
Clock::Source selected_source = Clock::SOURCE_INTERNAL;
|
||||
Clock::Pulse selected_pulse = Clock::PULSE_PPQN_24;
|
||||
Channel channel[Gravity::OUTPUT_COUNT];
|
||||
};
|
||||
|
||||
@ -28,6 +29,7 @@ static Channel& GetSelectedChannel() {
|
||||
enum ParamsMainPage {
|
||||
PARAM_MAIN_TEMPO,
|
||||
PARAM_MAIN_SOURCE,
|
||||
PARAM_MAIN_PULSE,
|
||||
PARAM_MAIN_ENCODER_DIR,
|
||||
PARAM_MAIN_RESET_STATE,
|
||||
PARAM_MAIN_LAST,
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <gravity.h>
|
||||
|
||||
#include "euclidean.h"
|
||||
|
||||
// Enums for CV configuration
|
||||
@ -66,7 +67,7 @@ class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
void setProbability(int prob) {
|
||||
void setProbability(int prob) {
|
||||
base_probability = constrain(prob, 0, 100);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_probability = base_probability;
|
||||
@ -74,20 +75,20 @@ class Channel {
|
||||
}
|
||||
|
||||
void setDutyCycle(int duty) {
|
||||
base_duty_cycle = constrain(duty, 1, 99);
|
||||
base_duty_cycle = constrain(duty, 1, 99);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_duty_cycle = base_duty_cycle;
|
||||
}
|
||||
}
|
||||
|
||||
void setOffset(int off) {
|
||||
void setOffset(int off) {
|
||||
base_offset = constrain(off, 0, 99);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_offset = base_offset;
|
||||
}
|
||||
}
|
||||
void setSwing(int val) {
|
||||
base_swing = constrain(val, 50, 95);
|
||||
base_swing = constrain(val, 50, 95);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_swing = base_swing;
|
||||
}
|
||||
@ -141,12 +142,12 @@ class Channel {
|
||||
bool hit = cvmod_probability >= random(0, 100);
|
||||
// Euclidean rhythm check
|
||||
switch (pattern.NextStep()) {
|
||||
case Pattern::REST: // Rest when active or fall back to probability
|
||||
hit = false;
|
||||
break;
|
||||
case Pattern::HIT: // Hit if probability is true
|
||||
hit &= true;
|
||||
break;
|
||||
case Pattern::REST: // Rest when active or fall back to probability
|
||||
hit = false;
|
||||
break;
|
||||
case Pattern::HIT: // Hit if probability is true
|
||||
hit &= true;
|
||||
break;
|
||||
}
|
||||
if (hit) {
|
||||
output.High();
|
||||
@ -192,11 +193,11 @@ class Channel {
|
||||
(cv_destination == CV_DEST_SWING)
|
||||
? constrain(base_swing + map(value, -512, 512, -25, 25), 50, 95)
|
||||
: base_swing;
|
||||
|
||||
|
||||
if (cv_destination == CV_DEST_EUC_STEPS) {
|
||||
pattern.SetSteps(map(value, -512, 512, 0, MAX_PATTERN_LEN));
|
||||
}
|
||||
|
||||
|
||||
if (cv_destination == CV_DEST_EUC_HITS) {
|
||||
pattern.SetHits(map(value, -512, 512, 0, pattern.GetSteps()));
|
||||
}
|
||||
|
||||
@ -68,16 +68,16 @@ static const unsigned char pause_icon[28] PROGMEM = {
|
||||
0x38, 0x0E, 0x00, 0x00};
|
||||
|
||||
// Constants for screen layout and fonts
|
||||
constexpr int SCREEN_CENTER_X = 32;
|
||||
constexpr int MAIN_TEXT_Y = 26;
|
||||
constexpr int SUB_TEXT_Y = 40;
|
||||
constexpr int VISIBLE_MENU_ITEMS = 3;
|
||||
constexpr int MENU_ITEM_HEIGHT = 14;
|
||||
constexpr int MENU_BOX_PADDING = 4;
|
||||
constexpr int MENU_BOX_WIDTH = 64;
|
||||
constexpr int CHANNEL_BOXES_Y = 50;
|
||||
constexpr int CHANNEL_BOX_WIDTH = 18;
|
||||
constexpr int CHANNEL_BOX_HEIGHT = 14;
|
||||
constexpr uint8_t SCREEN_CENTER_X = 32;
|
||||
constexpr uint8_t MAIN_TEXT_Y = 26;
|
||||
constexpr uint8_t SUB_TEXT_Y = 40;
|
||||
constexpr uint8_t VISIBLE_MENU_ITEMS = 3;
|
||||
constexpr uint8_t MENU_ITEM_HEIGHT = 14;
|
||||
constexpr uint8_t MENU_BOX_PADDING = 4;
|
||||
constexpr uint8_t MENU_BOX_WIDTH = 64;
|
||||
constexpr uint8_t CHANNEL_BOXES_Y = 50;
|
||||
constexpr uint8_t CHANNEL_BOX_WIDTH = 18;
|
||||
constexpr uint8_t CHANNEL_BOX_HEIGHT = 14;
|
||||
|
||||
// Helper function to draw centered text
|
||||
void drawCenteredText(const char* text, int y, const uint8_t* font) {
|
||||
@ -204,6 +204,23 @@ void DisplayMainPage() {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_PULSE:
|
||||
mainText = F("OUT");
|
||||
switch (app.selected_pulse) {
|
||||
case Clock::PULSE_NONE:
|
||||
subText = F("PULSE OFF");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_24:
|
||||
subText = F("24 PPQN PULSE");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_4:
|
||||
subText = F("4 PPQN PULSE");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_1:
|
||||
subText = F("1 PPQN PULSE");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_ENCODER_DIR:
|
||||
mainText = F("DIR");
|
||||
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
|
||||
@ -218,7 +235,7 @@ void DisplayMainPage() {
|
||||
drawCenteredText(subText.c_str(), SUB_TEXT_Y, TEXT_FONT);
|
||||
|
||||
// Draw Main Page menu items
|
||||
String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("ENCODER DIR"), F("RESET")};
|
||||
String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("PULSE OUT"), F("ENCODER DIR"), F("RESET")};
|
||||
drawMenuItems(menu_items, PARAM_MAIN_LAST);
|
||||
}
|
||||
|
||||
@ -329,7 +346,7 @@ void DisplayChannelPage() {
|
||||
|
||||
// Draw Channel Page menu items
|
||||
String menu_items[PARAM_CH_LAST] = {
|
||||
F("MOD"), F("PROBABILITY"), F("DUTY"), F("OFFSET"), F("SWING"), F("EUCLID STEPS"),
|
||||
F("MOD"), F("PROBABILITY"), F("DUTY"), F("OFFSET"), F("SWING"), F("EUCLID STEPS"),
|
||||
F("EUCLID HITS"), F("CV SOURCE"), F("CV DEST")};
|
||||
drawMenuItems(menu_items, PARAM_CH_LAST);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ bool StateManager::initialize(AppState& app) {
|
||||
app.selected_param = load_data.selected_param;
|
||||
app.selected_channel = load_data.selected_channel;
|
||||
app.selected_source = static_cast<Clock::Source>(load_data.selected_source);
|
||||
app.selected_pulse = static_cast<Clock::Pulse>(load_data.selected_pulse);
|
||||
|
||||
// Loop through and restore each channel's state.
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
@ -54,6 +55,7 @@ void StateManager::reset(AppState& app) {
|
||||
app.selected_param = 0;
|
||||
app.selected_channel = 0;
|
||||
app.selected_source = Clock::SOURCE_INTERNAL;
|
||||
app.selected_pulse = Clock::PULSE_PPQN_24;
|
||||
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
app.channel[i].Init();
|
||||
@ -61,7 +63,7 @@ void StateManager::reset(AppState& app) {
|
||||
|
||||
noInterrupts();
|
||||
_saveMetadata(); // Write the new metadata
|
||||
_saveState(app); // Write the new (default) app state
|
||||
_saveState(app); // Write the new (default) app state
|
||||
interrupts();
|
||||
|
||||
_isDirty = false;
|
||||
@ -97,6 +99,7 @@ void StateManager::_saveState(const AppState& app) {
|
||||
save_data.selected_param = app.selected_param;
|
||||
save_data.selected_channel = app.selected_channel;
|
||||
save_data.selected_source = static_cast<byte>(app.selected_source);
|
||||
save_data.selected_pulse = static_cast<byte>(app.selected_pulse);
|
||||
|
||||
// Loop through and populate each channel's state
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
|
||||
@ -54,6 +54,7 @@ class StateManager {
|
||||
byte selected_param;
|
||||
byte selected_channel;
|
||||
byte selected_source;
|
||||
byte selected_pulse;
|
||||
ChannelState channel_data[Gravity::OUTPUT_COUNT];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user