Compare commits
8 Commits
update-doc
...
gridseq
| Author | SHA1 | Date | |
|---|---|---|---|
| af3cfe9614 | |||
| 6ada2aba30 | |||
| c5965aa1f7 | |||
| 7c02628403 | |||
| 1161da38c1 | |||
| 872af30fbc | |||
| fc17afc9a1 | |||
| b6402380c0 |
@ -66,10 +66,6 @@ void setup() {
|
|||||||
// Start Gravity.
|
// Start Gravity.
|
||||||
gravity.Init();
|
gravity.Init();
|
||||||
|
|
||||||
// Show bootsplash when initializing firmware.
|
|
||||||
Bootsplash();
|
|
||||||
delay(2000);
|
|
||||||
|
|
||||||
// Initialize the state manager. This will load settings from EEPROM
|
// Initialize the state manager. This will load settings from EEPROM
|
||||||
stateManager.initialize(app);
|
stateManager.initialize(app);
|
||||||
InitGravity(app);
|
InitGravity(app);
|
||||||
@ -91,18 +87,8 @@ void loop() {
|
|||||||
// Process change in state of inputs and outputs.
|
// Process change in state of inputs and outputs.
|
||||||
gravity.Process();
|
gravity.Process();
|
||||||
|
|
||||||
// Read CVs and call the update function for each channel.
|
// Check if cv run or reset is active and read cv.
|
||||||
int cv1 = gravity.cv1.Read();
|
CheckRunReset(gravity.cv1, gravity.cv2);
|
||||||
int cv2 = gravity.cv2.Read();
|
|
||||||
|
|
||||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
|
||||||
auto& ch = app.channel[i];
|
|
||||||
// Only apply CV to the channel when the current channel has cv
|
|
||||||
// mod configured.
|
|
||||||
if (ch.isCvModActive()) {
|
|
||||||
ch.applyCvMod(cv1, cv2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for dirty state eligible to be saved.
|
// Check for dirty state eligible to be saved.
|
||||||
stateManager.update(app);
|
stateManager.update(app);
|
||||||
@ -171,6 +157,27 @@ void HandleExtClockTick() {
|
|||||||
app.refresh_screen = true;
|
app.refresh_screen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckRunReset(AnalogInput& cv1, AnalogInput& cv2) {
|
||||||
|
// Clock Run
|
||||||
|
if (app.cv_run == 1 || app.cv_run == 2) {
|
||||||
|
const int val = (app.cv_run == 1) ? cv1.Read() : cv2.Read();
|
||||||
|
if (val > AnalogInput::GATE_THRESHOLD && gravity.clock.IsPaused()) {
|
||||||
|
gravity.clock.Start();
|
||||||
|
app.refresh_screen = true;
|
||||||
|
} else if (val < AnalogInput::GATE_THRESHOLD && !gravity.clock.IsPaused()) {
|
||||||
|
gravity.clock.Stop();
|
||||||
|
ResetOutputs();
|
||||||
|
app.refresh_screen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clock Reset
|
||||||
|
if ((app.cv_reset == 1 && cv1.IsRisingEdge(AnalogInput::GATE_THRESHOLD)) ||
|
||||||
|
(app.cv_reset == 2 && cv2.IsRisingEdge(AnalogInput::GATE_THRESHOLD))) {
|
||||||
|
gravity.clock.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// UI handlers for encoder and buttons.
|
// UI handlers for encoder and buttons.
|
||||||
//
|
//
|
||||||
@ -202,37 +209,34 @@ void HandleEncoderPressed() {
|
|||||||
// Check if leaving editing mode should apply a selection.
|
// Check if leaving editing mode should apply a selection.
|
||||||
if (app.editing_param) {
|
if (app.editing_param) {
|
||||||
if (app.selected_channel == 0) { // main page
|
if (app.selected_channel == 0) { // main page
|
||||||
// TODO: rewrite as switch
|
switch (app.selected_param) {
|
||||||
if (app.selected_param == PARAM_MAIN_ENCODER_DIR) {
|
case PARAM_MAIN_ENCODER_DIR:
|
||||||
app.encoder_reversed = app.selected_sub_param == 1;
|
app.encoder_reversed = app.selected_sub_param == 1;
|
||||||
gravity.encoder.SetReverseDirection(app.encoder_reversed);
|
gravity.encoder.SetReverseDirection(app.encoder_reversed);
|
||||||
}
|
break;
|
||||||
if (app.selected_param == PARAM_MAIN_SAVE_DATA) {
|
case PARAM_MAIN_ROTATE_DISP:
|
||||||
|
app.rotate_display = app.selected_sub_param == 1;
|
||||||
|
gravity.display.setFlipMode(app.rotate_display ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case PARAM_MAIN_SAVE_DATA:
|
||||||
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
||||||
app.selected_save_slot = app.selected_sub_param;
|
app.selected_save_slot = app.selected_sub_param;
|
||||||
stateManager.saveData(app);
|
stateManager.saveData(app);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if (app.selected_param == PARAM_MAIN_LOAD_DATA) {
|
case PARAM_MAIN_LOAD_DATA:
|
||||||
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
||||||
app.selected_save_slot = app.selected_sub_param;
|
app.selected_save_slot = app.selected_sub_param;
|
||||||
stateManager.loadData(app, app.selected_save_slot);
|
stateManager.loadData(app, app.selected_save_slot);
|
||||||
InitGravity(app);
|
InitGravity(app);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if (app.selected_param == PARAM_MAIN_RESET_STATE) {
|
case PARAM_MAIN_FACTORY_RESET:
|
||||||
if (app.selected_sub_param == 0) { // Reset
|
|
||||||
stateManager.reset(app);
|
|
||||||
InitGravity(app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (app.selected_param == PARAM_MAIN_FACTORY_RESET) {
|
|
||||||
if (app.selected_sub_param == 0) { // Erase
|
if (app.selected_sub_param == 0) { // Erase
|
||||||
// Show bootsplash during slow erase operation.
|
|
||||||
Bootsplash();
|
|
||||||
stateManager.factoryReset(app);
|
stateManager.factoryReset(app);
|
||||||
InitGravity(app);
|
InitGravity(app);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only mark dirty and reset selected_sub_param when leaving editing mode.
|
// Only mark dirty and reset selected_sub_param when leaving editing mode.
|
||||||
@ -282,6 +286,14 @@ void editMainParameter(int val) {
|
|||||||
gravity.clock.SetTempo(gravity.clock.Tempo() + val);
|
gravity.clock.SetTempo(gravity.clock.Tempo() + val);
|
||||||
app.tempo = gravity.clock.Tempo();
|
app.tempo = gravity.clock.Tempo();
|
||||||
break;
|
break;
|
||||||
|
case PARAM_MAIN_RUN:
|
||||||
|
updateSelection(app.selected_sub_param, val, 3);
|
||||||
|
app.cv_run = app.selected_sub_param;
|
||||||
|
break;
|
||||||
|
case PARAM_MAIN_RESET:
|
||||||
|
updateSelection(app.selected_sub_param, val, 3);
|
||||||
|
app.cv_reset = app.selected_sub_param;
|
||||||
|
break;
|
||||||
case PARAM_MAIN_SOURCE: {
|
case PARAM_MAIN_SOURCE: {
|
||||||
byte source = static_cast<int>(app.selected_source);
|
byte source = static_cast<int>(app.selected_source);
|
||||||
updateSelection(source, val, Clock::SOURCE_LAST);
|
updateSelection(source, val, Clock::SOURCE_LAST);
|
||||||
@ -298,16 +310,15 @@ void editMainParameter(int val) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// These changes are applied upon encoder button press.
|
||||||
case PARAM_MAIN_ENCODER_DIR:
|
case PARAM_MAIN_ENCODER_DIR:
|
||||||
|
case PARAM_MAIN_ROTATE_DISP:
|
||||||
updateSelection(app.selected_sub_param, val, 2);
|
updateSelection(app.selected_sub_param, val, 2);
|
||||||
break;
|
break;
|
||||||
case PARAM_MAIN_SAVE_DATA:
|
case PARAM_MAIN_SAVE_DATA:
|
||||||
case PARAM_MAIN_LOAD_DATA:
|
case PARAM_MAIN_LOAD_DATA:
|
||||||
updateSelection(app.selected_sub_param, val, StateManager::MAX_SAVE_SLOTS + 1);
|
updateSelection(app.selected_sub_param, val, StateManager::MAX_SAVE_SLOTS + 1);
|
||||||
break;
|
break;
|
||||||
case PARAM_MAIN_RESET_STATE:
|
|
||||||
updateSelection(app.selected_sub_param, val, 2);
|
|
||||||
break;
|
|
||||||
case PARAM_MAIN_FACTORY_RESET:
|
case PARAM_MAIN_FACTORY_RESET:
|
||||||
updateSelection(app.selected_sub_param, val, 2);
|
updateSelection(app.selected_sub_param, val, 2);
|
||||||
break;
|
break;
|
||||||
@ -370,6 +381,7 @@ void InitGravity(AppState& app) {
|
|||||||
gravity.clock.SetTempo(app.tempo);
|
gravity.clock.SetTempo(app.tempo);
|
||||||
gravity.clock.SetSource(app.selected_source);
|
gravity.clock.SetSource(app.selected_source);
|
||||||
gravity.encoder.SetReverseDirection(app.encoder_reversed);
|
gravity.encoder.SetReverseDirection(app.encoder_reversed);
|
||||||
|
gravity.display.setFlipMode(app.rotate_display ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetOutputs() {
|
void ResetOutputs() {
|
||||||
|
|||||||
@ -25,10 +25,13 @@ struct AppState {
|
|||||||
byte selected_channel = 0; // 0=tempo, 1-6=output channel
|
byte selected_channel = 0; // 0=tempo, 1-6=output channel
|
||||||
byte selected_swing = 0;
|
byte selected_swing = 0;
|
||||||
byte selected_save_slot = 0; // The currently active save slot.
|
byte selected_save_slot = 0; // The currently active save slot.
|
||||||
|
byte cv_run = 0;
|
||||||
|
byte cv_reset = 0;
|
||||||
Clock::Source selected_source = Clock::SOURCE_INTERNAL;
|
Clock::Source selected_source = Clock::SOURCE_INTERNAL;
|
||||||
Clock::Pulse selected_pulse = Clock::PULSE_PPQN_24;
|
Clock::Pulse selected_pulse = Clock::PULSE_PPQN_24;
|
||||||
bool editing_param = false;
|
bool editing_param = false;
|
||||||
bool encoder_reversed = false;
|
bool encoder_reversed = false;
|
||||||
|
bool rotate_display = false;
|
||||||
bool refresh_screen = true;
|
bool refresh_screen = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -70,14 +70,6 @@ class Channel {
|
|||||||
base_duty_cycle = 50;
|
base_duty_cycle = 50;
|
||||||
base_offset = 0;
|
base_offset = 0;
|
||||||
base_swing = 50;
|
base_swing = 50;
|
||||||
base_euc_steps = 1;
|
|
||||||
base_euc_hits = 1;
|
|
||||||
|
|
||||||
cvmod_clock_mod_index = base_clock_mod_index;
|
|
||||||
cvmod_probability = base_probability;
|
|
||||||
cvmod_duty_cycle = base_duty_cycle;
|
|
||||||
cvmod_offset = base_offset;
|
|
||||||
cvmod_swing = base_swing;
|
|
||||||
|
|
||||||
cv1_dest = CV_DEST_NONE;
|
cv1_dest = CV_DEST_NONE;
|
||||||
cv2_dest = CV_DEST_NONE;
|
cv2_dest = CV_DEST_NONE;
|
||||||
@ -88,78 +80,104 @@ class Channel {
|
|||||||
_recalculatePulses();
|
_recalculatePulses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; }
|
||||||
|
|
||||||
// Setters (Set the BASE value)
|
// Setters (Set the BASE value)
|
||||||
|
|
||||||
void setClockMod(int index) {
|
void setClockMod(int index) {
|
||||||
base_clock_mod_index = constrain(index, 0, MOD_CHOICE_SIZE - 1);
|
base_clock_mod_index = constrain(index, 0, MOD_CHOICE_SIZE - 1);
|
||||||
if (!isCvModActive()) {
|
|
||||||
cvmod_clock_mod_index = base_clock_mod_index;
|
|
||||||
_recalculatePulses();
|
_recalculatePulses();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void setProbability(int prob) {
|
void setProbability(int prob) {
|
||||||
base_probability = constrain(prob, 0, 100);
|
base_probability = constrain(prob, 0, 100);
|
||||||
if (!isCvModActive()) {
|
|
||||||
cvmod_probability = base_probability;
|
|
||||||
_recalculatePulses();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDutyCycle(int duty) {
|
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;
|
|
||||||
_recalculatePulses();
|
_recalculatePulses();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void setOffset(int off) {
|
void setOffset(int off) {
|
||||||
base_offset = constrain(off, 0, 99);
|
base_offset = constrain(off, 0, 99);
|
||||||
if (!isCvModActive()) {
|
|
||||||
cvmod_offset = base_offset;
|
|
||||||
_recalculatePulses();
|
_recalculatePulses();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void setSwing(int val) {
|
void setSwing(int val) {
|
||||||
base_swing = constrain(val, 50, 95);
|
base_swing = constrain(val, 50, 95);
|
||||||
if (!isCvModActive()) {
|
|
||||||
cvmod_swing = base_swing;
|
|
||||||
_recalculatePulses();
|
_recalculatePulses();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Euclidean
|
// Euclidean
|
||||||
void setSteps(int val) {
|
void setSteps(int val) {
|
||||||
base_euc_steps = constrain(val, 1, MAX_PATTERN_LEN);
|
|
||||||
if (cv1_dest != CV_DEST_EUC_STEPS && cv2_dest != CV_DEST_EUC_STEPS) {
|
|
||||||
pattern.SetSteps(val);
|
pattern.SetSteps(val);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void setHits(int val) {
|
void setHits(int val) {
|
||||||
base_euc_hits = constrain(val, 1, base_euc_steps);
|
|
||||||
if (cv1_dest != CV_DEST_EUC_HITS && cv2_dest != CV_DEST_EUC_HITS) {
|
|
||||||
pattern.SetHits(val);
|
pattern.SetHits(val);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void setCv1Dest(CvDestination dest) { cv1_dest = dest; }
|
void setCv1Dest(CvDestination dest) {
|
||||||
void setCv2Dest(CvDestination dest) { cv2_dest = dest; }
|
cv1_dest = dest;
|
||||||
|
_recalculatePulses();
|
||||||
|
}
|
||||||
|
void setCv2Dest(CvDestination dest) {
|
||||||
|
cv2_dest = dest;
|
||||||
|
_recalculatePulses();
|
||||||
|
}
|
||||||
CvDestination getCv1Dest() const { return cv1_dest; }
|
CvDestination getCv1Dest() const { return cv1_dest; }
|
||||||
CvDestination getCv2Dest() const { return cv2_dest; }
|
CvDestination getCv2Dest() const { return cv2_dest; }
|
||||||
|
|
||||||
// Getters (Get the BASE value for editing or cv modded value for display)
|
// Getters (Get the BASE value for editing or cv modded value for display)
|
||||||
|
int getProbability() const { return base_probability; }
|
||||||
|
int getDutyCycle() const { return base_duty_cycle; }
|
||||||
|
int getOffset() const { return base_offset; }
|
||||||
|
int getSwing() const { return base_swing; }
|
||||||
|
int getClockMod() const { return pgm_read_word_near(&CLOCK_MOD[getClockModIndex()]); }
|
||||||
|
int getClockModIndex() const { return base_clock_mod_index; }
|
||||||
|
byte getSteps() const { return pattern.GetSteps(); }
|
||||||
|
byte getHits() const { return pattern.GetHits(); }
|
||||||
|
|
||||||
int getProbability(bool withCvMod = false) const { return withCvMod ? cvmod_probability : base_probability; }
|
// Getters that calculate the value with CV modulation applied.
|
||||||
int getDutyCycle(bool withCvMod = false) const { return withCvMod ? cvmod_duty_cycle : base_duty_cycle; }
|
int getClockModIndexWithMod(int cv1_val, int cv2_val) {
|
||||||
int getOffset(bool withCvMod = false) const { return withCvMod ? cvmod_offset : base_offset; }
|
int clock_mod_index = _calculateMod(CV_DEST_MOD, cv1_val, cv2_val, -(MOD_CHOICE_SIZE / 2), MOD_CHOICE_SIZE / 2);
|
||||||
int getSwing(bool withCvMod = false) const { return withCvMod ? cvmod_swing : base_swing; }
|
return constrain(base_clock_mod_index + clock_mod_index, 0, MOD_CHOICE_SIZE - 1);
|
||||||
int getClockMod(bool withCvMod = false) const { return pgm_read_word_near(&CLOCK_MOD[getClockModIndex(withCvMod)]); }
|
}
|
||||||
int getClockModIndex(bool withCvMod = false) const { return withCvMod ? cvmod_clock_mod_index : base_clock_mod_index; }
|
|
||||||
bool isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; }
|
|
||||||
|
|
||||||
byte getSteps(bool withCvMod = false) const { return withCvMod ? pattern.GetSteps() : base_euc_steps; }
|
int getClockModWithMod(int cv1_val, int cv2_val) {
|
||||||
byte getHits(bool withCvMod = false) const { return withCvMod ? pattern.GetHits() : base_euc_hits; }
|
int clock_mod = _calculateMod(CV_DEST_MOD, cv1_val, cv2_val, -(MOD_CHOICE_SIZE / 2), MOD_CHOICE_SIZE / 2);
|
||||||
|
return pgm_read_word_near(&CLOCK_MOD[getClockModIndexWithMod(cv1_val, cv2_val)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getProbabilityWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int prob_mod = _calculateMod(CV_DEST_PROB, cv1_val, cv2_val, -50, 50);
|
||||||
|
return constrain(base_probability + prob_mod, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getDutyCycleWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int duty_mod = _calculateMod(CV_DEST_DUTY, cv1_val, cv2_val, -50, 50);
|
||||||
|
return constrain(base_duty_cycle + duty_mod, 1, 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getOffsetWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int offset_mod = _calculateMod(CV_DEST_OFFSET, cv1_val, cv2_val, -50, 50);
|
||||||
|
return constrain(base_offset + offset_mod, 0, 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSwingWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int swing_mod = _calculateMod(CV_DEST_SWING, cv1_val, cv2_val, -25, 25);
|
||||||
|
return constrain(base_swing + swing_mod, 50, 95);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte getStepsWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int step_mod = _calculateMod(CV_DEST_EUC_STEPS, cv1_val, cv2_val, 0, MAX_PATTERN_LEN);
|
||||||
|
return constrain(pattern.GetSteps() + step_mod, 1, MAX_PATTERN_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte getHitsWithMod(int cv1_val, int cv2_val) {
|
||||||
|
// The number of hits is dependent on the modulated number of steps.
|
||||||
|
byte modulated_steps = getStepsWithMod(cv1_val, cv2_val);
|
||||||
|
int hit_mod = _calculateMod(CV_DEST_EUC_HITS, cv1_val, cv2_val, 0, modulated_steps);
|
||||||
|
return constrain(pattern.GetHits() + hit_mod, 1, modulated_steps);
|
||||||
|
}
|
||||||
|
|
||||||
void toggleMute() { mute = !mute; }
|
void toggleMute() { mute = !mute; }
|
||||||
|
|
||||||
@ -176,6 +194,13 @@ class Channel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isCvModActive()) _recalculatePulses();
|
||||||
|
|
||||||
|
int cv1 = gravity.cv1.Read();
|
||||||
|
int cv2 = gravity.cv2.Read();
|
||||||
|
int cvmod_clock_mod_index = getClockModIndexWithMod(cv1, cv2);
|
||||||
|
int cvmod_probability = getProbabilityWithMod(cv1, cv2);
|
||||||
|
|
||||||
const uint16_t mod_pulses = pgm_read_word_near(&CLOCK_MOD_PULSES[cvmod_clock_mod_index]);
|
const uint16_t mod_pulses = pgm_read_word_near(&CLOCK_MOD_PULSES[cvmod_clock_mod_index]);
|
||||||
|
|
||||||
// Conditionally apply swing on down beats.
|
// Conditionally apply swing on down beats.
|
||||||
@ -211,56 +236,6 @@ class Channel {
|
|||||||
output.Low();
|
output.Low();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @brief Calculate and store cv modded values using bipolar mapping.
|
|
||||||
* Default to base value if not the current CV destination.
|
|
||||||
*
|
|
||||||
* @param cv1_val analog input reading for cv1
|
|
||||||
* @param cv2_val analog input reading for cv2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void applyCvMod(int cv1_val, int cv2_val) {
|
|
||||||
// Note: This is optimized for cpu performance. This method is called
|
|
||||||
// from the main loop and stores the cv mod values. This reduces CPU
|
|
||||||
// cycles inside the internal clock interrupt, which is preferrable.
|
|
||||||
// However, if RAM usage grows too much, we have an opportunity to
|
|
||||||
// refactor this to store just the CV read values, and calculate the
|
|
||||||
// cv mod value per channel inside the getter methods by passing cv
|
|
||||||
// values. This would reduce RAM usage, but would introduce a
|
|
||||||
// significant CPU cost, which may have undesirable performance issues.
|
|
||||||
if (!isCvModActive()) {
|
|
||||||
cvmod_clock_mod_index = base_clock_mod_index;
|
|
||||||
cvmod_probability = base_clock_mod_index;
|
|
||||||
cvmod_duty_cycle = base_clock_mod_index;
|
|
||||||
cvmod_offset = base_clock_mod_index;
|
|
||||||
cvmod_swing = base_clock_mod_index;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dest_mod = _calculateMod(CV_DEST_MOD, cv1_val, cv2_val, -(MOD_CHOICE_SIZE / 2), MOD_CHOICE_SIZE / 2);
|
|
||||||
cvmod_clock_mod_index = constrain(base_clock_mod_index + dest_mod, 0, 100);
|
|
||||||
|
|
||||||
int prob_mod = _calculateMod(CV_DEST_PROB, cv1_val, cv2_val, -50, 50);
|
|
||||||
cvmod_probability = constrain(base_probability + prob_mod, 0, 100);
|
|
||||||
|
|
||||||
int duty_mod = _calculateMod(CV_DEST_DUTY, cv1_val, cv2_val, -50, 50);
|
|
||||||
cvmod_duty_cycle = constrain(base_duty_cycle + duty_mod, 1, 99);
|
|
||||||
|
|
||||||
int offset_mod = _calculateMod(CV_DEST_OFFSET, cv1_val, cv2_val, -50, 50);
|
|
||||||
cvmod_offset = constrain(base_offset + offset_mod, 0, 99);
|
|
||||||
|
|
||||||
int swing_mod = _calculateMod(CV_DEST_SWING, cv1_val, cv2_val, -25, 25);
|
|
||||||
cvmod_swing = constrain(base_swing + swing_mod, 50, 95);
|
|
||||||
|
|
||||||
int step_mod = _calculateMod(CV_DEST_EUC_STEPS, cv1_val, cv2_val, 0, MAX_PATTERN_LEN);
|
|
||||||
pattern.SetSteps(base_euc_steps + step_mod);
|
|
||||||
|
|
||||||
int hit_mod = _calculateMod(CV_DEST_EUC_HITS, cv1_val, cv2_val, 0, pattern.GetSteps());
|
|
||||||
pattern.SetHits(base_euc_hits + hit_mod);
|
|
||||||
|
|
||||||
// After all cvmod values are updated, recalculate clock pulse modifiers.
|
|
||||||
_recalculatePulses();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) {
|
int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) {
|
||||||
@ -270,13 +245,19 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _recalculatePulses() {
|
void _recalculatePulses() {
|
||||||
const uint16_t mod_pulses = pgm_read_word_near(&CLOCK_MOD_PULSES[cvmod_clock_mod_index]);
|
int cv1 = gravity.cv1.Read();
|
||||||
_duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L);
|
int cv2 = gravity.cv2.Read();
|
||||||
_offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L);
|
int clock_mod_index = getClockModIndexWithMod(cv1, cv2);
|
||||||
|
int duty_cycle = getDutyCycleWithMod(cv1, cv2);
|
||||||
|
int offset = getOffsetWithMod(cv1, cv2);
|
||||||
|
int swing = getSwingWithMod(cv1, cv2);
|
||||||
|
const uint16_t mod_pulses = pgm_read_word_near(&CLOCK_MOD_PULSES[clock_mod_index]);
|
||||||
|
_duty_pulses = max((long)((mod_pulses * (100L - duty_cycle)) / 100L), 1L);
|
||||||
|
_offset_pulses = (long)((mod_pulses * (100L - offset)) / 100L);
|
||||||
|
|
||||||
// Calculate the down beat swing amount.
|
// Calculate the down beat swing amount.
|
||||||
if (cvmod_swing > 50) {
|
if (swing > 50) {
|
||||||
int shifted_swing = cvmod_swing - 50;
|
int shifted_swing = swing - 50;
|
||||||
_swing_pulse_amount = (long)((mod_pulses * (100L - shifted_swing)) / 100L);
|
_swing_pulse_amount = (long)((mod_pulses * (100L - shifted_swing)) / 100L);
|
||||||
} else {
|
} else {
|
||||||
_swing_pulse_amount = 0;
|
_swing_pulse_amount = 0;
|
||||||
@ -289,15 +270,6 @@ class Channel {
|
|||||||
byte base_duty_cycle;
|
byte base_duty_cycle;
|
||||||
byte base_offset;
|
byte base_offset;
|
||||||
byte base_swing;
|
byte base_swing;
|
||||||
byte base_euc_steps;
|
|
||||||
byte base_euc_hits;
|
|
||||||
|
|
||||||
// Base value with cv mod applied.
|
|
||||||
byte cvmod_clock_mod_index;
|
|
||||||
byte cvmod_probability;
|
|
||||||
byte cvmod_duty_cycle;
|
|
||||||
byte cvmod_offset;
|
|
||||||
byte cvmod_swing;
|
|
||||||
|
|
||||||
// CV mod configuration
|
// CV mod configuration
|
||||||
CvDestination cv1_dest;
|
CvDestination cv1_dest;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const uint8_t TEXT_FONT[437] U8G2_FONT_SECTION("velvetscreen") PROGMEM =
|
|||||||
* https://stncrn.github.io/u8g2-unifont-helper/
|
* https://stncrn.github.io/u8g2-unifont-helper/
|
||||||
* "%/0123456789ABCDEFILNORSTUVXx"
|
* "%/0123456789ABCDEFILNORSTUVXx"
|
||||||
*/
|
*/
|
||||||
const uint8_t LARGE_FONT[766] U8G2_FONT_SECTION("stk-l") =
|
const uint8_t LARGE_FONT[766] U8G2_FONT_SECTION("stk-l") PROGMEM =
|
||||||
"\35\0\4\4\4\5\3\1\6\20\30\0\0\27\0\0\0\1\77\0\0\2\341%'\17;\226\261\245FL"
|
"\35\0\4\4\4\5\3\1\6\20\30\0\0\27\0\0\0\1\77\0\0\2\341%'\17;\226\261\245FL"
|
||||||
"\64B\214\30\22\223\220)Bj\10Q\232\214\42R\206\310\210\21d\304\30\32a\254\304\270!\0/\14"
|
"\64B\214\30\22\223\220)Bj\10Q\232\214\42R\206\310\210\21d\304\30\32a\254\304\270!\0/\14"
|
||||||
"\272\272\275\311H\321g\343\306\1\60\37|\373\35CJT\20:fW\207\320\210\60\42\304\204\30D\247"
|
"\272\272\275\311H\321g\343\306\1\60\37|\373\35CJT\20:fW\207\320\210\60\42\304\204\30D\247"
|
||||||
@ -100,11 +100,13 @@ constexpr uint8_t CHANNEL_BOX_HEIGHT = 14;
|
|||||||
enum ParamsMainPage : uint8_t {
|
enum ParamsMainPage : uint8_t {
|
||||||
PARAM_MAIN_TEMPO,
|
PARAM_MAIN_TEMPO,
|
||||||
PARAM_MAIN_SOURCE,
|
PARAM_MAIN_SOURCE,
|
||||||
|
PARAM_MAIN_RUN,
|
||||||
|
PARAM_MAIN_RESET,
|
||||||
PARAM_MAIN_PULSE,
|
PARAM_MAIN_PULSE,
|
||||||
PARAM_MAIN_ENCODER_DIR,
|
PARAM_MAIN_ENCODER_DIR,
|
||||||
|
PARAM_MAIN_ROTATE_DISP,
|
||||||
PARAM_MAIN_SAVE_DATA,
|
PARAM_MAIN_SAVE_DATA,
|
||||||
PARAM_MAIN_LOAD_DATA,
|
PARAM_MAIN_LOAD_DATA,
|
||||||
PARAM_MAIN_RESET_STATE,
|
|
||||||
PARAM_MAIN_FACTORY_RESET,
|
PARAM_MAIN_FACTORY_RESET,
|
||||||
PARAM_MAIN_LAST,
|
PARAM_MAIN_LAST,
|
||||||
};
|
};
|
||||||
@ -255,11 +257,42 @@ void DisplayMainPage() {
|
|||||||
case Clock::SOURCE_EXTERNAL_PPQN_4:
|
case Clock::SOURCE_EXTERNAL_PPQN_4:
|
||||||
subText = F("4 PPQN");
|
subText = F("4 PPQN");
|
||||||
break;
|
break;
|
||||||
|
case Clock::SOURCE_EXTERNAL_PPQN_1:
|
||||||
|
subText = F("1 PPQN");
|
||||||
|
break;
|
||||||
case Clock::SOURCE_EXTERNAL_MIDI:
|
case Clock::SOURCE_EXTERNAL_MIDI:
|
||||||
subText = F("MIDI");
|
subText = F("MIDI");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PARAM_MAIN_RUN:
|
||||||
|
mainText = F("RUN");
|
||||||
|
switch (app.cv_run) {
|
||||||
|
case 0:
|
||||||
|
subText = F("NONE");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
subText = F("CV 1");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
subText = F("CV 2");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PARAM_MAIN_RESET:
|
||||||
|
mainText = F("RST");
|
||||||
|
switch (app.cv_reset) {
|
||||||
|
case 0:
|
||||||
|
subText = F("NONE");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
subText = F("CV 1");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
subText = F("CV 2");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PARAM_MAIN_PULSE:
|
case PARAM_MAIN_PULSE:
|
||||||
mainText = F("OUT");
|
mainText = F("OUT");
|
||||||
switch (app.selected_pulse) {
|
switch (app.selected_pulse) {
|
||||||
@ -281,6 +314,10 @@ void DisplayMainPage() {
|
|||||||
mainText = F("DIR");
|
mainText = F("DIR");
|
||||||
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
|
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
|
||||||
break;
|
break;
|
||||||
|
case PARAM_MAIN_ROTATE_DISP:
|
||||||
|
mainText = F("ROT");
|
||||||
|
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("FLIPPED");
|
||||||
|
break;
|
||||||
case PARAM_MAIN_SAVE_DATA:
|
case PARAM_MAIN_SAVE_DATA:
|
||||||
case PARAM_MAIN_LOAD_DATA:
|
case PARAM_MAIN_LOAD_DATA:
|
||||||
if (app.selected_sub_param == StateManager::MAX_SAVE_SLOTS) {
|
if (app.selected_sub_param == StateManager::MAX_SAVE_SLOTS) {
|
||||||
@ -297,15 +334,6 @@ void DisplayMainPage() {
|
|||||||
: F("LOAD FROM SLOT");
|
: F("LOAD FROM SLOT");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PARAM_MAIN_RESET_STATE:
|
|
||||||
if (app.selected_sub_param == 0) {
|
|
||||||
mainText = F("RST");
|
|
||||||
subText = F("RESET ALL");
|
|
||||||
} else {
|
|
||||||
mainText = F("x");
|
|
||||||
subText = F("BACK TO MAIN");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PARAM_MAIN_FACTORY_RESET:
|
case PARAM_MAIN_FACTORY_RESET:
|
||||||
if (app.selected_sub_param == 0) {
|
if (app.selected_sub_param == 0) {
|
||||||
mainText = F("DEL");
|
mainText = F("DEL");
|
||||||
@ -321,7 +349,7 @@ void DisplayMainPage() {
|
|||||||
drawCenteredText(subText.c_str(), SUB_TEXT_Y, TEXT_FONT);
|
drawCenteredText(subText.c_str(), SUB_TEXT_Y, TEXT_FONT);
|
||||||
|
|
||||||
// Draw Main Page menu items
|
// Draw Main Page menu items
|
||||||
String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("PULSE OUT"), F("ENCODER DIR"), F("SAVE"), F("LOAD"), F("RESET"), F("ERASE")};
|
String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("CLK RUN"), F("CLK RESET"), F("PULSE OUT"), F("ENCODER DIR"), F("ROTATE DISP"), F("SAVE"), F("LOAD"), F("ERASE")};
|
||||||
drawMenuItems(menu_items, PARAM_MAIN_LAST);
|
drawMenuItems(menu_items, PARAM_MAIN_LAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,10 +366,12 @@ void DisplayChannelPage() {
|
|||||||
// When editing a param, just show the base value. When not editing show
|
// When editing a param, just show the base value. When not editing show
|
||||||
// the value with cv mod.
|
// the value with cv mod.
|
||||||
bool withCvMod = !app.editing_param;
|
bool withCvMod = !app.editing_param;
|
||||||
|
int cv1 = gravity.cv1.Read();
|
||||||
|
int cv2 = gravity.cv2.Read();
|
||||||
|
|
||||||
switch (app.selected_param) {
|
switch (app.selected_param) {
|
||||||
case PARAM_CH_MOD: {
|
case PARAM_CH_MOD: {
|
||||||
int mod_value = ch.getClockMod(withCvMod);
|
int mod_value = withCvMod ? ch.getClockModWithMod(cv1, cv2) : ch.getClockMod();
|
||||||
if (mod_value > 1) {
|
if (mod_value > 1) {
|
||||||
mainText = F("/");
|
mainText = F("/");
|
||||||
mainText += String(mod_value);
|
mainText += String(mod_value);
|
||||||
@ -354,30 +384,30 @@ void DisplayChannelPage() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PARAM_CH_PROB:
|
case PARAM_CH_PROB:
|
||||||
mainText = String(ch.getProbability(withCvMod)) + F("%");
|
mainText = String(withCvMod ? ch.getProbabilityWithMod(cv1, cv2) : ch.getProbability()) + F("%");
|
||||||
subText = F("HIT CHANCE");
|
subText = F("HIT CHANCE");
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_DUTY:
|
case PARAM_CH_DUTY:
|
||||||
mainText = String(ch.getDutyCycle(withCvMod)) + F("%");
|
mainText = String(withCvMod ? ch.getDutyCycleWithMod(cv1, cv2) : ch.getDutyCycle()) + F("%");
|
||||||
subText = F("PULSE WIDTH");
|
subText = F("PULSE WIDTH");
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_OFFSET:
|
case PARAM_CH_OFFSET:
|
||||||
mainText = String(ch.getOffset(withCvMod)) + F("%");
|
mainText = String(withCvMod ? ch.getOffsetWithMod(cv1, cv2) : ch.getOffset()) + F("%");
|
||||||
subText = F("SHIFT HIT");
|
subText = F("SHIFT HIT");
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_SWING:
|
case PARAM_CH_SWING:
|
||||||
ch.getSwing() == 50
|
ch.getSwing() == 50
|
||||||
? mainText = F("OFF")
|
? mainText = F("OFF")
|
||||||
: mainText = String(ch.getSwing(withCvMod)) + F("%");
|
: mainText = String(withCvMod ? ch.getSwingWithMod(cv1, cv2) : ch.getSwing()) + F("%");
|
||||||
subText = "DOWN BEAT";
|
subText = "DOWN BEAT";
|
||||||
swingDivisionMark();
|
swingDivisionMark();
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_EUC_STEPS:
|
case PARAM_CH_EUC_STEPS:
|
||||||
mainText = String(ch.getSteps(withCvMod));
|
mainText = String(withCvMod ? ch.getStepsWithMod(cv1, cv2) : ch.getSteps());
|
||||||
subText = "EUCLID STEPS";
|
subText = "EUCLID STEPS";
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_EUC_HITS:
|
case PARAM_CH_EUC_HITS:
|
||||||
mainText = String(ch.getHits(withCvMod));
|
mainText = String(withCvMod ? ch.getHitsWithMod(cv1, cv2) : ch.getHits());
|
||||||
subText = "EUCLID HITS";
|
subText = "EUCLID HITS";
|
||||||
break;
|
break;
|
||||||
case PARAM_CH_CV1_DEST:
|
case PARAM_CH_CV1_DEST:
|
||||||
@ -469,22 +499,4 @@ void UpdateDisplay() {
|
|||||||
} while (gravity.display.nextPage());
|
} while (gravity.display.nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bootsplash() {
|
|
||||||
gravity.display.firstPage();
|
|
||||||
do {
|
|
||||||
int textWidth;
|
|
||||||
String loadingText = F("LOADING....");
|
|
||||||
gravity.display.setFont(TEXT_FONT);
|
|
||||||
|
|
||||||
textWidth = gravity.display.getStrWidth(StateManager::SKETCH_NAME);
|
|
||||||
gravity.display.drawStr(16 + (textWidth / 2), 20, StateManager::SKETCH_NAME);
|
|
||||||
|
|
||||||
textWidth = gravity.display.getStrWidth(StateManager::SEMANTIC_VERSION);
|
|
||||||
gravity.display.drawStr(16 + (textWidth / 2), 32, StateManager::SEMANTIC_VERSION);
|
|
||||||
|
|
||||||
textWidth = gravity.display.getStrWidth(loadingText.c_str());
|
|
||||||
gravity.display.drawStr(26 + (textWidth / 2), 44, loadingText.c_str());
|
|
||||||
} while (gravity.display.nextPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DISPLAY_H
|
#endif // DISPLAY_H
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
// Define the constants for the current firmware.
|
// Define the constants for the current firmware.
|
||||||
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
|
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
|
||||||
const char StateManager::SEMANTIC_VERSION[] = "V2.0.0BETA3"; // NOTE: This should match the version in the library.properties file.
|
const char StateManager::SEMANTIC_VERSION[] = "2.0.0"; // NOTE: This should match the version in the library.properties file.
|
||||||
|
|
||||||
// Number of available save slots.
|
// Number of available save slots.
|
||||||
const byte StateManager::MAX_SAVE_SLOTS = 10;
|
const byte StateManager::MAX_SAVE_SLOTS = 10;
|
||||||
@ -87,6 +87,8 @@ void StateManager::reset(AppState& app) {
|
|||||||
app.selected_channel = default_app.selected_channel;
|
app.selected_channel = default_app.selected_channel;
|
||||||
app.selected_source = default_app.selected_source;
|
app.selected_source = default_app.selected_source;
|
||||||
app.selected_pulse = default_app.selected_pulse;
|
app.selected_pulse = default_app.selected_pulse;
|
||||||
|
app.cv_run = default_app.cv_run;
|
||||||
|
app.cv_reset = default_app.cv_reset;
|
||||||
|
|
||||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||||
app.channel[i].Init();
|
app.channel[i].Init();
|
||||||
@ -140,6 +142,8 @@ void StateManager::_saveState(const AppState& app, byte slot_index) {
|
|||||||
save_data.selected_channel = app.selected_channel;
|
save_data.selected_channel = app.selected_channel;
|
||||||
save_data.selected_source = static_cast<byte>(app.selected_source);
|
save_data.selected_source = static_cast<byte>(app.selected_source);
|
||||||
save_data.selected_pulse = static_cast<byte>(app.selected_pulse);
|
save_data.selected_pulse = static_cast<byte>(app.selected_pulse);
|
||||||
|
save_data.cv_run = app.cv_run;
|
||||||
|
save_data.cv_reset = app.cv_reset;
|
||||||
|
|
||||||
// TODO: break this out into a separate function. Save State should be
|
// TODO: break this out into a separate function. Save State should be
|
||||||
// broken out into global / per-channel save methods. When saving via
|
// broken out into global / per-channel save methods. When saving via
|
||||||
@ -148,13 +152,13 @@ void StateManager::_saveState(const AppState& app, byte slot_index) {
|
|||||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||||
const auto& ch = app.channel[i];
|
const auto& ch = app.channel[i];
|
||||||
auto& save_ch = save_data.channel_data[i];
|
auto& save_ch = save_data.channel_data[i];
|
||||||
save_ch.base_clock_mod_index = ch.getClockModIndex(false);
|
save_ch.base_clock_mod_index = ch.getClockModIndex();
|
||||||
save_ch.base_probability = ch.getProbability(false);
|
save_ch.base_probability = ch.getProbability();
|
||||||
save_ch.base_duty_cycle = ch.getDutyCycle(false);
|
save_ch.base_duty_cycle = ch.getDutyCycle();
|
||||||
save_ch.base_offset = ch.getOffset(false);
|
save_ch.base_offset = ch.getOffset();
|
||||||
save_ch.base_swing = ch.getSwing(false);
|
save_ch.base_swing = ch.getSwing();
|
||||||
save_ch.base_euc_steps = ch.getSteps(false);
|
save_ch.base_euc_steps = ch.getSteps();
|
||||||
save_ch.base_euc_hits = ch.getHits(false);
|
save_ch.base_euc_hits = ch.getHits();
|
||||||
save_ch.cv1_dest = static_cast<byte>(ch.getCv1Dest());
|
save_ch.cv1_dest = static_cast<byte>(ch.getCv1Dest());
|
||||||
save_ch.cv2_dest = static_cast<byte>(ch.getCv2Dest());
|
save_ch.cv2_dest = static_cast<byte>(ch.getCv2Dest());
|
||||||
}
|
}
|
||||||
@ -179,6 +183,8 @@ void StateManager::_loadState(AppState& app, byte slot_index) {
|
|||||||
app.selected_channel = load_data.selected_channel;
|
app.selected_channel = load_data.selected_channel;
|
||||||
app.selected_source = static_cast<Clock::Source>(load_data.selected_source);
|
app.selected_source = static_cast<Clock::Source>(load_data.selected_source);
|
||||||
app.selected_pulse = static_cast<Clock::Pulse>(load_data.selected_pulse);
|
app.selected_pulse = static_cast<Clock::Pulse>(load_data.selected_pulse);
|
||||||
|
app.cv_run = load_data.cv_run;
|
||||||
|
app.cv_reset = load_data.cv_reset;
|
||||||
|
|
||||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||||
auto& ch = app.channel[i];
|
auto& ch = app.channel[i];
|
||||||
@ -206,6 +212,7 @@ void StateManager::_saveMetadata(const AppState& app) {
|
|||||||
// Global user settings
|
// Global user settings
|
||||||
current_meta.selected_save_slot = app.selected_save_slot;
|
current_meta.selected_save_slot = app.selected_save_slot;
|
||||||
current_meta.encoder_reversed = app.encoder_reversed;
|
current_meta.encoder_reversed = app.encoder_reversed;
|
||||||
|
current_meta.rotate_display = app.rotate_display;
|
||||||
|
|
||||||
EEPROM.put(METADATA_START_ADDR, current_meta);
|
EEPROM.put(METADATA_START_ADDR, current_meta);
|
||||||
interrupts();
|
interrupts();
|
||||||
|
|||||||
@ -52,11 +52,12 @@ class StateManager {
|
|||||||
|
|
||||||
// This struct holds the data that identifies the firmware version.
|
// This struct holds the data that identifies the firmware version.
|
||||||
struct Metadata {
|
struct Metadata {
|
||||||
char sketch_name[16];
|
char sketch_name[12];
|
||||||
char version[16];
|
char version[5];
|
||||||
// Additional global/hardware settings
|
// Additional global/hardware settings
|
||||||
byte selected_save_slot;
|
byte selected_save_slot;
|
||||||
bool encoder_reversed;
|
bool encoder_reversed;
|
||||||
|
bool rotate_display;
|
||||||
};
|
};
|
||||||
struct ChannelState {
|
struct ChannelState {
|
||||||
byte base_clock_mod_index;
|
byte base_clock_mod_index;
|
||||||
@ -76,6 +77,8 @@ class StateManager {
|
|||||||
byte selected_channel;
|
byte selected_channel;
|
||||||
byte selected_source;
|
byte selected_source;
|
||||||
byte selected_pulse;
|
byte selected_pulse;
|
||||||
|
byte cv_run;
|
||||||
|
byte cv_reset;
|
||||||
ChannelState channel_data[Gravity::OUTPUT_COUNT];
|
ChannelState channel_data[Gravity::OUTPUT_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
167
firmware/GridSeq/GridSeq.ino
Normal file
167
firmware/GridSeq/GridSeq.ino
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/**
|
||||||
|
* @file GridSeq.ino
|
||||||
|
* @author Adam Wonak (https://github.com/awonak/)
|
||||||
|
* @brief Grid based step sequencer firmware for Gravity by Sitka Instruments.
|
||||||
|
* @version v1.0.0 - August 2025 awonak
|
||||||
|
* @date 2025-08-12
|
||||||
|
*
|
||||||
|
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||||
|
*
|
||||||
|
* Grid based step sequencer with lots of dynamic features.
|
||||||
|
*
|
||||||
|
* Pattern:
|
||||||
|
* - length
|
||||||
|
* - clock division
|
||||||
|
* - probability
|
||||||
|
* - fill density
|
||||||
|
* - direction (fwd, rev, pend, rand)
|
||||||
|
* - mode:
|
||||||
|
* - step equencer
|
||||||
|
* - euclidean rhythm
|
||||||
|
* - pattern (grids like presets)
|
||||||
|
*
|
||||||
|
* Step:
|
||||||
|
* - gate / trigger
|
||||||
|
* - duty / duration
|
||||||
|
* - probability
|
||||||
|
* - ratchet / retrig
|
||||||
|
*
|
||||||
|
* Global:
|
||||||
|
* - internal / external / midi
|
||||||
|
* - run / reset
|
||||||
|
* - mute
|
||||||
|
* - save / load banks
|
||||||
|
* - 6 channel / 3 channel accent
|
||||||
|
*
|
||||||
|
* ENCODER:
|
||||||
|
* Press: change between selecting a parameter and editing the parameter.
|
||||||
|
* Hold & Rotate: change current selected output channel.
|
||||||
|
*
|
||||||
|
* BTN1:
|
||||||
|
* Play/pause - start or stop the internal clock.
|
||||||
|
*
|
||||||
|
* BTN2:
|
||||||
|
* Shift - hold and rotate encoder to change current selected output channel.
|
||||||
|
*
|
||||||
|
* EXT:
|
||||||
|
* External clock input. When Gravity is set to INTERNAL or MIDI clock
|
||||||
|
* source, this input is used to reset clocks.
|
||||||
|
*
|
||||||
|
* CV1:
|
||||||
|
* External analog input used to provide modulation to any channel parameter.
|
||||||
|
*
|
||||||
|
* CV2:
|
||||||
|
* External analog input used to provide modulation to any channel parameter.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libGravity.h>
|
||||||
|
|
||||||
|
#include "app_state.h"
|
||||||
|
#include "channel.h"
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
|
AppState app;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Arduino setup and loop.
|
||||||
|
//
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Start Gravity.
|
||||||
|
gravity.Init();
|
||||||
|
|
||||||
|
// Clock handlers.
|
||||||
|
gravity.clock.AttachIntHandler(HandleIntClockTick);
|
||||||
|
gravity.clock.AttachExtHandler(HandleExtClockTick);
|
||||||
|
|
||||||
|
// Encoder rotate and press handlers.
|
||||||
|
gravity.encoder.AttachPressHandler(HandleEncoderPressed);
|
||||||
|
gravity.encoder.AttachRotateHandler(HandleRotate);
|
||||||
|
gravity.encoder.AttachPressRotateHandler(HandlePressedRotate);
|
||||||
|
|
||||||
|
// Button press handlers.
|
||||||
|
gravity.play_button.AttachPressHandler(HandlePlayPressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Process change in state of inputs and outputs.
|
||||||
|
gravity.Process();
|
||||||
|
|
||||||
|
// Check if cv run or reset is active and read cv.
|
||||||
|
CheckRunReset(gravity.cv1, gravity.cv2);
|
||||||
|
|
||||||
|
if (app.refresh_screen) {
|
||||||
|
UpdateDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Firmware handlers for clocks.
|
||||||
|
//
|
||||||
|
|
||||||
|
void HandleIntClockTick(uint32_t tick) {
|
||||||
|
bool refresh = false;
|
||||||
|
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||||
|
app.channel[i].processClockTick(tick, gravity.outputs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleExtClockTick() {
|
||||||
|
switch (app.selected_source) {
|
||||||
|
case Clock::SOURCE_INTERNAL:
|
||||||
|
case Clock::SOURCE_EXTERNAL_MIDI:
|
||||||
|
// Use EXT as Reset when not used for clock source.
|
||||||
|
ResetOutputs();
|
||||||
|
gravity.clock.Reset();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Register EXT cv clock tick.
|
||||||
|
gravity.clock.Tick();
|
||||||
|
}
|
||||||
|
app.refresh_screen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckRunReset(AnalogInput& cv1, AnalogInput& cv2) {
|
||||||
|
// Clock Run
|
||||||
|
if (app.cv_run == 1 || app.cv_run == 2) {
|
||||||
|
const int val = (app.cv_run == 1) ? cv1.Read() : cv2.Read();
|
||||||
|
if (val > AnalogInput::GATE_THRESHOLD && gravity.clock.IsPaused()) {
|
||||||
|
gravity.clock.Start();
|
||||||
|
app.refresh_screen = true;
|
||||||
|
} else if (val < AnalogInput::GATE_THRESHOLD && !gravity.clock.IsPaused()) {
|
||||||
|
gravity.clock.Stop();
|
||||||
|
ResetOutputs();
|
||||||
|
app.refresh_screen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clock Reset
|
||||||
|
if ((app.cv_reset == 1 && cv1.IsRisingEdge(AnalogInput::GATE_THRESHOLD)) ||
|
||||||
|
(app.cv_reset == 2 && cv2.IsRisingEdge(AnalogInput::GATE_THRESHOLD))) {
|
||||||
|
gravity.clock.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// UI handlers for encoder and buttons.
|
||||||
|
//
|
||||||
|
|
||||||
|
void HandlePlayPressed() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleEncoderPressed() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleRotate(int val) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandlePressedRotate(int val) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: move to libGravity
|
||||||
|
void ResetOutputs() {
|
||||||
|
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||||
|
gravity.outputs[i].Low();
|
||||||
|
}
|
||||||
|
}
|
||||||
38
firmware/GridSeq/app_state.h
Normal file
38
firmware/GridSeq/app_state.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* @file app_state.h
|
||||||
|
* @author Adam Wonak (https://github.com/awonak/)
|
||||||
|
* @brief Alt firmware version of Gravity by Sitka Instruments.
|
||||||
|
* @version 2.0.1
|
||||||
|
* @date 2025-07-04
|
||||||
|
*
|
||||||
|
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APP_STATE_H
|
||||||
|
#define APP_STATE_H
|
||||||
|
|
||||||
|
#include <libGravity.h>
|
||||||
|
|
||||||
|
#include "channel.h"
|
||||||
|
|
||||||
|
// Global state for settings and app behavior.
|
||||||
|
struct AppState {
|
||||||
|
int tempo = Clock::DEFAULT_TEMPO;
|
||||||
|
Clock::Source selected_source = Clock::SOURCE_INTERNAL;
|
||||||
|
Channel channel[Gravity::OUTPUT_COUNT];
|
||||||
|
byte selected_param = 0;
|
||||||
|
byte selected_channel = 0; // 0=tempo, 1-6=output channel
|
||||||
|
byte cv_run = 0;
|
||||||
|
byte cv_reset = 0;
|
||||||
|
bool editing_param = false;
|
||||||
|
bool refresh_screen = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern AppState app;
|
||||||
|
|
||||||
|
static Channel& GetSelectedChannel() {
|
||||||
|
return app.channel[app.selected_channel - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // APP_STATE_H
|
||||||
129
firmware/GridSeq/channel.h
Normal file
129
firmware/GridSeq/channel.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/**
|
||||||
|
* @file channel.h
|
||||||
|
* @author Adam Wonak (https://github.com/awonak/)
|
||||||
|
* @brief Grid Sequencer.
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2025-08-12
|
||||||
|
*
|
||||||
|
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHANNEL_H
|
||||||
|
#define CHANNEL_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <libGravity.h>
|
||||||
|
|
||||||
|
#include "euclidean.h"
|
||||||
|
|
||||||
|
// Enums for CV Mod destination
|
||||||
|
enum CvDestination : uint8_t {
|
||||||
|
CV_DEST_NONE,
|
||||||
|
CV_DEST_MODE,
|
||||||
|
CV_DEST_LENGTH,
|
||||||
|
CV_DEST_DIV,
|
||||||
|
CV_DEST_PROB,
|
||||||
|
CV_DEST_DENSITY,
|
||||||
|
CV_DEST_LAST,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enums for GridSeq modes
|
||||||
|
enum Mode : uint8_t {
|
||||||
|
MODE_SEQ,
|
||||||
|
MODE_EUCLIDEAN,
|
||||||
|
MODE_PATTERN,
|
||||||
|
MODE_LAST,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Channel {
|
||||||
|
public:
|
||||||
|
Channel() {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init() {
|
||||||
|
base_probability = 100;
|
||||||
|
|
||||||
|
cv1_dest = CV_DEST_NONE;
|
||||||
|
cv2_dest = CV_DEST_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; }
|
||||||
|
|
||||||
|
// Setters (Set the BASE value)
|
||||||
|
|
||||||
|
void setProbability(int prob) {
|
||||||
|
base_probability = constrain(prob, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCv1Dest(CvDestination dest) {
|
||||||
|
cv1_dest = dest;
|
||||||
|
}
|
||||||
|
void setCv2Dest(CvDestination dest) {
|
||||||
|
cv2_dest = dest;
|
||||||
|
}
|
||||||
|
CvDestination getCv1Dest() const { return cv1_dest; }
|
||||||
|
CvDestination getCv2Dest() const { return cv2_dest; }
|
||||||
|
|
||||||
|
// Getters (Get the BASE value for editing or cv modded value for display)
|
||||||
|
int getProbability() const { return base_probability; }
|
||||||
|
|
||||||
|
// Getters that calculate the value with CV modulation applied.
|
||||||
|
int getProbabilityWithMod(int cv1_val, int cv2_val) {
|
||||||
|
int prob_mod = _calculateMod(CV_DEST_PROB, cv1_val, cv2_val, -50, 50);
|
||||||
|
return constrain(base_probability + prob_mod, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleMute() { mute = !mute; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Processes a clock tick and determines if the output should be high or low.
|
||||||
|
* Note: this method is called from an ISR and must be kept as simple as possible.
|
||||||
|
* @param tick The current clock tick count.
|
||||||
|
* @param output The output object to be modified.
|
||||||
|
*/
|
||||||
|
void processClockTick(uint32_t tick, DigitalOutput& output) {
|
||||||
|
// Mute check
|
||||||
|
if (mute) {
|
||||||
|
output.Low();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cv1 = gravity.cv1.Read();
|
||||||
|
int cv2 = gravity.cv2.Read();
|
||||||
|
int cvmod_probability = getProbabilityWithMod(cv1, cv2);
|
||||||
|
|
||||||
|
// Duty cycle high check logic
|
||||||
|
if (!output.On()) {
|
||||||
|
// Step check
|
||||||
|
bool hit = cvmod_probability >= random(0, 100);
|
||||||
|
if (hit) {
|
||||||
|
output.Trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) {
|
||||||
|
int mod1 = (cv1_dest == dest) ? map(cv1_val, -512, 512, min_range, max_range) : 0;
|
||||||
|
int mod2 = (cv2_dest == dest) ? map(cv2_val, -512, 512, min_range, max_range) : 0;
|
||||||
|
return mod1 + mod2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// User-settable base values.
|
||||||
|
byte base_probability;
|
||||||
|
|
||||||
|
// CV mod configuration
|
||||||
|
CvDestination cv1_dest;
|
||||||
|
CvDestination cv2_dest;
|
||||||
|
|
||||||
|
// Mute channel flag
|
||||||
|
bool mute;
|
||||||
|
|
||||||
|
uint16_t _duty_pulses;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CHANNEL_H
|
||||||
93
firmware/GridSeq/display.h
Normal file
93
firmware/GridSeq/display.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/**
|
||||||
|
* @file display.h
|
||||||
|
* @author Adam Wonak (https://github.com/awonak/)
|
||||||
|
* @brief Alt firmware version of Gravity by Sitka Instruments.
|
||||||
|
* @version 1.0.0
|
||||||
|
* @date 2025-07-04
|
||||||
|
*
|
||||||
|
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISPLAY_H
|
||||||
|
#define DISPLAY_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "app_state.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// UI Display functions for drawing the UI to the OLED display.
|
||||||
|
//
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Font: velvetscreen.bdf 9pt
|
||||||
|
* https://stncrn.github.io/u8g2-unifont-helper/
|
||||||
|
* "%/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
*/
|
||||||
|
const uint8_t TEXT_FONT[437] U8G2_FONT_SECTION("velvetscreen") PROGMEM =
|
||||||
|
"\64\0\2\2\3\3\2\3\4\5\5\0\0\5\0\5\0\0\221\0\0\1\230 \4\200\134%\11\255tT"
|
||||||
|
"R\271RI(\6\252\334T\31)\7\252\134bJ\12+\7\233\345\322J\0,\5\221T\4-\5\213"
|
||||||
|
"f\6.\5\211T\2/\6\244\354c\33\60\10\254\354T\64\223\2\61\7\353\354\222\254\6\62\11\254l"
|
||||||
|
"\66J*\217\0\63\11\254l\66J\32\215\4\64\10\254l\242\34\272\0\65\11\254l\206\336h$\0\66"
|
||||||
|
"\11\254\354T^\61)\0\67\10\254lF\216u\4\70\11\254\354TL*&\5\71\11\254\354TL;"
|
||||||
|
")\0:\6\231UR\0A\10\254\354T\34S\6B\11\254lV\34)\216\4C\11\254\354T\324\61"
|
||||||
|
")\0D\10\254lV\64G\2E\10\254l\206\36z\4F\10\254l\206^\71\3G\11\254\354TN"
|
||||||
|
"\63)\0H\10\254l\242\34S\6I\6\251T\206\0J\10\254\354k\231\24\0K\11\254l\242J\62"
|
||||||
|
"\225\1L\7\254lr{\4M\11\255t\362ZI\353\0N\11\255t\362TI\356\0O\10\254\354T"
|
||||||
|
"\64\223\2P\11\254lV\34)g\0Q\10\254\354T\264b\12R\10\254lV\34\251\31S\11\254\354"
|
||||||
|
"FF\32\215\4T\7\253dVl\1U\10\254l\242\63)\0V\11\255t\262Ne\312\21W\12\255"
|
||||||
|
"t\262J*\251.\0X\11\254l\242L*\312\0Y\12\255tr\252\63\312(\2Z\7\253df*"
|
||||||
|
"\7p\10\255\364V\266\323\2q\7\255\364\216\257\5r\10\253d\242\32*\2t\6\255t\376#w\11"
|
||||||
|
"\255\364V\245FN\13x\6\233dR\7\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Font: STK-L.bdf 36pt
|
||||||
|
* https://stncrn.github.io/u8g2-unifont-helper/
|
||||||
|
* "%/0123456789ABCDEFILNORSTUVXx"
|
||||||
|
*/
|
||||||
|
const uint8_t LARGE_FONT[766] U8G2_FONT_SECTION("stk-l") PROGMEM =
|
||||||
|
"\35\0\4\4\4\5\3\1\6\20\30\0\0\27\0\0\0\1\77\0\0\2\341%'\17;\226\261\245FL"
|
||||||
|
"\64B\214\30\22\223\220)Bj\10Q\232\214\42R\206\310\210\21d\304\30\32a\254\304\270!\0/\14"
|
||||||
|
"\272\272\275\311H\321g\343\306\1\60\37|\373\35CJT\20:fW\207\320\210\60\42\304\204\30D\247"
|
||||||
|
"\214\331\354\20\11%\212\314\0\61\24z\275\245a\244\12\231\71\63b\214\220q\363\377(E\6\62\33|"
|
||||||
|
"\373\35ShT\20:fl\344\14\211\231\301\306T\71\202#g\371\340\201\1\63\34|\373\35ShT"
|
||||||
|
"\20:fl\344@r\264\263\222\344,\215\35\42\241\6\225\31\0\64 |\373-!\203\206\214!\62\204"
|
||||||
|
"\314\220A#\10\215\30\65b\324\210Q\306\354\354\1\213\225\363\1\65\32|\373\15\25[\214\234/\10)"
|
||||||
|
"Y\61j\350\310Y\32;DB\15*\63\0\66\33}\33\236SiV\14;gt^\230Y\302\202\324"
|
||||||
|
"\71\273;EbM\252\63\0\67\23|\373\205\25\17R\316\207\344\350p\312\201#\347\35\0\70 |\373"
|
||||||
|
"\35ShT\20:f\331!\22D\310 :\205\206\10\11B\307\354\354\20\11\65\250\314\0\71\32|\373"
|
||||||
|
"\35ShT\20:fg\207H,Q\223r\276\30DB\15*\63\0A\26}\33\246r\247\322P\62"
|
||||||
|
"j\310\250\21\343\354\335\203\357\354w\3B$}\33\206Dj\226\214\42\61l\304\260\21\303F\14\33\61"
|
||||||
|
"\212\304\222MF\221\30v\316\236=\10\301b\11\0C\27}\33\236Si\226\20Bft\376O\211\215"
|
||||||
|
" Db\215\42$\0D\33}\33\206Dj\226\214\32\62l\304\260\21\343\354\177vl\304(\22K\324"
|
||||||
|
"$\2E\22|\373\205\17R\316KD\30\215\234_>x`\0F\20|\373\205\17R\316\227i\262\31"
|
||||||
|
"\71\377\22\0I\7s\333\204\77HL\15{\333\205\201\363\377\77|\360`\0N$}\33\6\201\346\314"
|
||||||
|
"\35;\206\12U\242D&\306\230\30cd\210\221!fF\230\31a(+\314\256\63\67\0O\26}\33"
|
||||||
|
"\236Si\226\214\32\61\316\376\277\33\61j\310\232Tg\0R\61\216;\6Ek\230\14#\61n\304\270"
|
||||||
|
"\21\343F\214\33\61n\304\60\22\243\210\60Q\224j\310\260\61\243\306\20\232\325\230QD\206\221\30\67b"
|
||||||
|
"\334\301\1S\42\216;\236c\211\226\220\42\61n\304\270\21c\307R\232,[\262\203\307\216\65h\16\25"
|
||||||
|
"\21&\253\320\0T\15}\33\206\17R\15\235\377\377\25\0U\21|\373\205a\366\377\237\215\30\64D\15"
|
||||||
|
"*\63\0V\26\177\371\205\221\366\377\313\21\343\206\220\42C\25\11r'\313\16\3X)~;\206\201\6"
|
||||||
|
"\217\221\30\66\204\20\31\42\244\206\14Cg\320$Q\222\6\315!\33\62\212\10\31BD\206\215 v\320"
|
||||||
|
"\302\1x\24\312\272\205A\206\216\220@c\212\224\31$S\14\262h\0\0\0\0\4\377\377\0";
|
||||||
|
|
||||||
|
#define play_icon_width 14
|
||||||
|
#define play_icon_height 14
|
||||||
|
static const unsigned char play_icon[28] PROGMEM = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x7C, 0x00, 0xFC, 0x00, 0xFC, 0x03,
|
||||||
|
0xFC, 0x0F, 0xFC, 0x0F, 0xFC, 0x03, 0xFC, 0x00, 0x7C, 0x00, 0x3C, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
static const unsigned char pause_icon[28] PROGMEM = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E,
|
||||||
|
0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E,
|
||||||
|
0x38, 0x0E, 0x00, 0x00};
|
||||||
|
|
||||||
|
void UpdateDisplay() {
|
||||||
|
app.refresh_screen = false;
|
||||||
|
gravity.display.firstPage();
|
||||||
|
do {
|
||||||
|
} while (gravity.display.nextPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DISPLAY_H
|
||||||
100
firmware/GridSeq/euclidean.h
Normal file
100
firmware/GridSeq/euclidean.h
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* @file euclidean.h
|
||||||
|
* @author Adam Wonak (https://github.com/awonak/)
|
||||||
|
* @brief Alt firmware version of Gravity by Sitka Instruments.
|
||||||
|
* @version 2.0.1
|
||||||
|
* @date 2025-07-04
|
||||||
|
*
|
||||||
|
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EUCLIDEAN_H
|
||||||
|
#define EUCLIDEAN_H
|
||||||
|
|
||||||
|
#define MAX_PATTERN_LEN 32
|
||||||
|
|
||||||
|
struct EuclideanState {
|
||||||
|
uint8_t steps;
|
||||||
|
uint8_t hits;
|
||||||
|
uint8_t offset;
|
||||||
|
uint8_t padding;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EuclideanState DEFAULT_PATTERN = {1, 1};
|
||||||
|
|
||||||
|
class Euclidean {
|
||||||
|
public:
|
||||||
|
Euclidean() {}
|
||||||
|
~Euclidean() {}
|
||||||
|
|
||||||
|
enum Step : uint8_t {
|
||||||
|
REST,
|
||||||
|
HIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
void Init(EuclideanState state) {
|
||||||
|
steps_ = constrain(state.steps, 1, MAX_PATTERN_LEN);
|
||||||
|
hits_ = constrain(state.hits, 1, steps_);
|
||||||
|
updatePattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
EuclideanState GetState() const { return {steps_, hits_}; }
|
||||||
|
|
||||||
|
Step GetCurrentStep(byte i) {
|
||||||
|
if (i >= MAX_PATTERN_LEN) return REST;
|
||||||
|
return (pattern_bitmap_ & (1UL << i)) ? HIT : REST;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSteps(int steps) {
|
||||||
|
steps_ = constrain(steps, 1, MAX_PATTERN_LEN);
|
||||||
|
hits_ = min(hits_, steps_);
|
||||||
|
updatePattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetHits(int hits) {
|
||||||
|
hits_ = constrain(hits, 1, steps_);
|
||||||
|
updatePattern();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reset() { step_index_ = 0; }
|
||||||
|
|
||||||
|
uint8_t GetSteps() const { return steps_; }
|
||||||
|
uint8_t GetHits() const { return hits_; }
|
||||||
|
uint8_t GetStepIndex() const { return step_index_; }
|
||||||
|
|
||||||
|
Step NextStep() {
|
||||||
|
if (steps_ == 0) return REST;
|
||||||
|
|
||||||
|
Step value = GetCurrentStep(step_index_);
|
||||||
|
step_index_ = (step_index_ < steps_ - 1) ? step_index_ + 1 : 0;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t steps_ = 0;
|
||||||
|
uint8_t hits_ = 0;
|
||||||
|
volatile uint8_t step_index_ = 0;
|
||||||
|
uint32_t pattern_bitmap_ = 0;
|
||||||
|
|
||||||
|
// Update the euclidean rhythm pattern using bitmap
|
||||||
|
void updatePattern() {
|
||||||
|
pattern_bitmap_ = 0; // Clear the bitmap
|
||||||
|
|
||||||
|
if (steps_ == 0) return;
|
||||||
|
|
||||||
|
byte bucket = 0;
|
||||||
|
// Set the first bit (index 0) if it's a HIT
|
||||||
|
pattern_bitmap_ |= (1UL << 0);
|
||||||
|
|
||||||
|
for (int i = 1; i < steps_; i++) {
|
||||||
|
bucket += hits_;
|
||||||
|
if (bucket >= steps_) {
|
||||||
|
bucket -= steps_;
|
||||||
|
pattern_bitmap_ |= (1UL << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
0
firmware/GridSeq/step.h
Normal file
0
firmware/GridSeq/step.h
Normal file
@ -1,5 +1,5 @@
|
|||||||
name=libGravity
|
name=libGravity
|
||||||
version=2.0.0beta3
|
version=2.0.0
|
||||||
author=Adam Wonak
|
author=Adam Wonak
|
||||||
maintainer=awonak <github.com/awonak>
|
maintainer=awonak <github.com/awonak>
|
||||||
sentence=Hardware abstraction library for Sitka Instruments Gravity eurorack module
|
sentence=Hardware abstraction library for Sitka Instruments Gravity eurorack module
|
||||||
|
|||||||
@ -19,6 +19,8 @@ const int CALIBRATED_HIGH = 512;
|
|||||||
|
|
||||||
class AnalogInput {
|
class AnalogInput {
|
||||||
public:
|
public:
|
||||||
|
static const int GATE_THRESHOLD = 0;
|
||||||
|
|
||||||
AnalogInput() {}
|
AnalogInput() {}
|
||||||
~AnalogInput() {}
|
~AnalogInput() {}
|
||||||
|
|
||||||
@ -74,6 +76,18 @@ class AnalogInput {
|
|||||||
*/
|
*/
|
||||||
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
|
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for a rising edge transition across a threshold.
|
||||||
|
*
|
||||||
|
* @param threshold The value that the input must cross.
|
||||||
|
* @return True if the value just crossed the threshold from below, false otherwise.
|
||||||
|
*/
|
||||||
|
inline bool IsRisingEdge(int16_t threshold) const {
|
||||||
|
bool was_high = old_read_ > threshold;
|
||||||
|
bool is_high = read_ > threshold;
|
||||||
|
return is_high && !was_high;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t pin_;
|
uint8_t pin_;
|
||||||
int16_t read_;
|
int16_t read_;
|
||||||
|
|||||||
@ -35,15 +35,16 @@ class Clock {
|
|||||||
SOURCE_INTERNAL,
|
SOURCE_INTERNAL,
|
||||||
SOURCE_EXTERNAL_PPQN_24,
|
SOURCE_EXTERNAL_PPQN_24,
|
||||||
SOURCE_EXTERNAL_PPQN_4,
|
SOURCE_EXTERNAL_PPQN_4,
|
||||||
|
SOURCE_EXTERNAL_PPQN_1,
|
||||||
SOURCE_EXTERNAL_MIDI,
|
SOURCE_EXTERNAL_MIDI,
|
||||||
SOURCE_LAST,
|
SOURCE_LAST,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Pulse {
|
enum Pulse {
|
||||||
PULSE_NONE,
|
PULSE_NONE,
|
||||||
PULSE_PPQN_1,
|
|
||||||
PULSE_PPQN_4,
|
|
||||||
PULSE_PPQN_24,
|
PULSE_PPQN_24,
|
||||||
|
PULSE_PPQN_4,
|
||||||
|
PULSE_PPQN_1,
|
||||||
PULSE_LAST,
|
PULSE_LAST,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,6 +97,10 @@ class Clock {
|
|||||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||||
uClock.setInputPPQN(uClock.PPQN_4);
|
uClock.setInputPPQN(uClock.PPQN_4);
|
||||||
break;
|
break;
|
||||||
|
case SOURCE_EXTERNAL_PPQN_1:
|
||||||
|
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||||
|
uClock.setInputPPQN(uClock.PPQN_1);
|
||||||
|
break;
|
||||||
case SOURCE_EXTERNAL_MIDI:
|
case SOURCE_EXTERNAL_MIDI:
|
||||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||||
uClock.setInputPPQN(uClock.PPQN_24);
|
uClock.setInputPPQN(uClock.PPQN_24);
|
||||||
|
|||||||
@ -82,7 +82,6 @@ class DigitalOutput {
|
|||||||
unsigned long last_triggered_;
|
unsigned long last_triggered_;
|
||||||
uint8_t trigger_duration_;
|
uint8_t trigger_duration_;
|
||||||
uint8_t cv_pin_;
|
uint8_t cv_pin_;
|
||||||
uint8_t led_pin_;
|
|
||||||
bool on_;
|
bool on_;
|
||||||
|
|
||||||
void update(uint8_t state) {
|
void update(uint8_t state) {
|
||||||
|
|||||||
Reference in New Issue
Block a user