Compare commits
7 Commits
reduce-mem
...
bootsplash
| Author | SHA1 | Date | |
|---|---|---|---|
| 527889c1c2 | |||
| ba1a47bfc7 | |||
| d34acd4477 | |||
| d66839b12f | |||
| 1ae9f5b545 | |||
| 1155978e51 | |||
| d30e9e2f85 |
@ -19,8 +19,6 @@ const int CALIBRATED_HIGH = 512;
|
||||
|
||||
class AnalogInput {
|
||||
public:
|
||||
static const int GATE_THRESHOLD = 0;
|
||||
|
||||
AnalogInput() {}
|
||||
~AnalogInput() {}
|
||||
|
||||
@ -76,18 +74,6 @@ class AnalogInput {
|
||||
*/
|
||||
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:
|
||||
uint8_t pin_;
|
||||
int16_t read_;
|
||||
@ -15,7 +15,7 @@
|
||||
#include <NeoHWSerial.h>
|
||||
|
||||
#include "peripherials.h"
|
||||
#include "uClock/uClock.h"
|
||||
#include "uClock.h"
|
||||
|
||||
// MIDI clock, start, stop, and continue byte definitions - based on MIDI 1.0 Standards.
|
||||
#define MIDI_CLOCK 0xF8
|
||||
@ -35,8 +35,6 @@ class Clock {
|
||||
SOURCE_INTERNAL,
|
||||
SOURCE_EXTERNAL_PPQN_24,
|
||||
SOURCE_EXTERNAL_PPQN_4,
|
||||
SOURCE_EXTERNAL_PPQN_2,
|
||||
SOURCE_EXTERNAL_PPQN_1,
|
||||
SOURCE_EXTERNAL_MIDI,
|
||||
SOURCE_LAST,
|
||||
};
|
||||
@ -98,14 +96,6 @@ class Clock {
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_4);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_2:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_2);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_1:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_1);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_MIDI:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_24);
|
||||
@ -82,6 +82,7 @@ class DigitalOutput {
|
||||
unsigned long last_triggered_;
|
||||
uint8_t trigger_duration_;
|
||||
uint8_t cv_pin_;
|
||||
uint8_t led_pin_;
|
||||
bool on_;
|
||||
|
||||
void update(uint8_t state) {
|
||||
@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <libGravity.h>
|
||||
#include "gravity.h"
|
||||
|
||||
// Firmware state variables.
|
||||
struct Channel {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* @file Gravity.ino
|
||||
* @author Adam Wonak (https://github.com/awonak/)
|
||||
* @brief Alt firmware version of Gravity by Sitka Instruments.
|
||||
* @version v2.0.0 - June 2025 awonak - Full rewrite
|
||||
* @version v2.0.1 - June 2025 awonak - Full rewrite
|
||||
* @version v1.0 - August 2023 Oleksiy H - Initial release
|
||||
* @date 2025-07-04
|
||||
*
|
||||
@ -37,18 +37,16 @@
|
||||
* 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.
|
||||
* External clock input. When Gravity is set to INTERNAL clock mode, 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 <gravity.h>
|
||||
|
||||
#include "app_state.h"
|
||||
#include "channel.h"
|
||||
@ -91,8 +89,18 @@ 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);
|
||||
// Read CVs and call the update function for each channel.
|
||||
int cv1 = gravity.cv1.Read();
|
||||
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.
|
||||
stateManager.update(app);
|
||||
@ -147,41 +155,17 @@ void HandleIntClockTick(uint32_t tick) {
|
||||
}
|
||||
|
||||
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();
|
||||
if (gravity.clock.InternalSource()) {
|
||||
// Use EXT as Reset when internally clocked.
|
||||
ResetOutputs();
|
||||
gravity.clock.Reset();
|
||||
} else {
|
||||
// Register 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.
|
||||
//
|
||||
@ -219,21 +203,26 @@ void HandleEncoderPressed() {
|
||||
gravity.encoder.SetReverseDirection(app.encoder_reversed);
|
||||
}
|
||||
if (app.selected_param == PARAM_MAIN_SAVE_DATA) {
|
||||
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
||||
if (app.selected_sub_param < MAX_SAVE_SLOTS) {
|
||||
app.selected_save_slot = app.selected_sub_param;
|
||||
stateManager.saveData(app);
|
||||
}
|
||||
}
|
||||
if (app.selected_param == PARAM_MAIN_LOAD_DATA) {
|
||||
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
|
||||
if (app.selected_sub_param < MAX_SAVE_SLOTS) {
|
||||
app.selected_save_slot = app.selected_sub_param;
|
||||
stateManager.loadData(app, app.selected_save_slot);
|
||||
InitGravity(app);
|
||||
}
|
||||
}
|
||||
if (app.selected_param == PARAM_MAIN_RESET_STATE) {
|
||||
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
|
||||
// Show bootsplash during slow erase operation.
|
||||
Bootsplash();
|
||||
stateManager.factoryReset(app);
|
||||
InitGravity(app);
|
||||
@ -287,14 +276,6 @@ void editMainParameter(int val) {
|
||||
gravity.clock.SetTempo(gravity.clock.Tempo() + val);
|
||||
app.tempo = gravity.clock.Tempo();
|
||||
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: {
|
||||
byte source = static_cast<int>(app.selected_source);
|
||||
updateSelection(source, val, Clock::SOURCE_LAST);
|
||||
@ -311,13 +292,15 @@ void editMainParameter(int val) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
// These changes are applied upon encoder button press.
|
||||
case PARAM_MAIN_ENCODER_DIR:
|
||||
updateSelection(app.selected_sub_param, val, 2);
|
||||
break;
|
||||
case PARAM_MAIN_SAVE_DATA:
|
||||
case PARAM_MAIN_LOAD_DATA:
|
||||
updateSelection(app.selected_sub_param, val, StateManager::MAX_SAVE_SLOTS + 1);
|
||||
updateSelection(app.selected_sub_param, val, MAX_SAVE_SLOTS + 1);
|
||||
break;
|
||||
case PARAM_MAIN_RESET_STATE:
|
||||
updateSelection(app.selected_sub_param, val, 2);
|
||||
break;
|
||||
case PARAM_MAIN_FACTORY_RESET:
|
||||
updateSelection(app.selected_sub_param, val, 2);
|
||||
|
||||
@ -12,26 +12,24 @@
|
||||
#ifndef APP_STATE_H
|
||||
#define APP_STATE_H
|
||||
|
||||
#include <libGravity.h>
|
||||
#include <gravity.h>
|
||||
|
||||
#include "channel.h"
|
||||
|
||||
// Global state for settings and app behavior.
|
||||
struct AppState {
|
||||
int tempo = Clock::DEFAULT_TEMPO;
|
||||
Channel channel[Gravity::OUTPUT_COUNT];
|
||||
bool encoder_reversed = false;
|
||||
bool refresh_screen = true;
|
||||
bool editing_param = false;
|
||||
byte selected_param = 0;
|
||||
byte selected_sub_param = 0; // Temporary value for editing params.
|
||||
byte selected_channel = 0; // 0=tempo, 1-6=output channel
|
||||
byte selected_swing = 0;
|
||||
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::Pulse selected_pulse = Clock::PULSE_PPQN_24;
|
||||
bool editing_param = false;
|
||||
bool encoder_reversed = false;
|
||||
bool refresh_screen = true;
|
||||
Channel channel[Gravity::OUTPUT_COUNT];
|
||||
};
|
||||
|
||||
extern AppState app;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#define CHANNEL_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <libGravity.h>
|
||||
#include <gravity.h>
|
||||
|
||||
#include "euclidean.h"
|
||||
|
||||
@ -70,6 +70,14 @@ class Channel {
|
||||
base_duty_cycle = 50;
|
||||
base_offset = 0;
|
||||
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;
|
||||
cv2_dest = CV_DEST_NONE;
|
||||
@ -80,100 +88,78 @@ class Channel {
|
||||
_recalculatePulses();
|
||||
}
|
||||
|
||||
bool isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; }
|
||||
|
||||
// Setters (Set the BASE value)
|
||||
|
||||
void setClockMod(int index) {
|
||||
base_clock_mod_index = constrain(index, 0, MOD_CHOICE_SIZE - 1);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_clock_mod_index = base_clock_mod_index;
|
||||
_recalculatePulses();
|
||||
}
|
||||
}
|
||||
|
||||
void setProbability(int prob) {
|
||||
base_probability = constrain(prob, 0, 100);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_probability = base_probability;
|
||||
_recalculatePulses();
|
||||
}
|
||||
}
|
||||
|
||||
void setDutyCycle(int duty) {
|
||||
base_duty_cycle = constrain(duty, 1, 99);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_duty_cycle = base_duty_cycle;
|
||||
_recalculatePulses();
|
||||
}
|
||||
}
|
||||
|
||||
void setOffset(int off) {
|
||||
base_offset = constrain(off, 0, 99);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_offset = base_offset;
|
||||
_recalculatePulses();
|
||||
}
|
||||
}
|
||||
void setSwing(int val) {
|
||||
base_swing = constrain(val, 50, 95);
|
||||
if (!isCvModActive()) {
|
||||
cvmod_swing = base_swing;
|
||||
_recalculatePulses();
|
||||
}
|
||||
}
|
||||
|
||||
// Euclidean
|
||||
void setSteps(int val) {
|
||||
pattern.SetSteps(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);
|
||||
}
|
||||
}
|
||||
void setHits(int val) {
|
||||
pattern.SetHits(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);
|
||||
}
|
||||
}
|
||||
|
||||
void setCv1Dest(CvDestination dest) {
|
||||
cv1_dest = dest;
|
||||
_recalculatePulses();
|
||||
}
|
||||
void setCv2Dest(CvDestination dest) {
|
||||
cv2_dest = dest;
|
||||
_recalculatePulses();
|
||||
}
|
||||
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; }
|
||||
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(); }
|
||||
|
||||
// Getters that calculate the value with CV modulation applied.
|
||||
int getClockModIndexWithMod(int cv1_val, int cv2_val) {
|
||||
int clock_mod_index = _calculateMod(CV_DEST_MOD, cv1_val, cv2_val, -(MOD_CHOICE_SIZE / 2), MOD_CHOICE_SIZE / 2);
|
||||
return constrain(base_clock_mod_index + clock_mod_index, 0, MOD_CHOICE_SIZE - 1);
|
||||
}
|
||||
int getProbability(bool withCvMod = false) const { return withCvMod ? cvmod_probability : base_probability; }
|
||||
int getDutyCycle(bool withCvMod = false) const { return withCvMod ? cvmod_duty_cycle : base_duty_cycle; }
|
||||
int getOffset(bool withCvMod = false) const { return withCvMod ? cvmod_offset : base_offset; }
|
||||
int getSwing(bool withCvMod = false) const { return withCvMod ? cvmod_swing : base_swing; }
|
||||
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; }
|
||||
|
||||
int getClockModWithMod(int cv1_val, int cv2_val) {
|
||||
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);
|
||||
}
|
||||
byte getSteps(bool withCvMod = false) const { return withCvMod ? pattern.GetSteps() : base_euc_steps; }
|
||||
byte getHits(bool withCvMod = false) const { return withCvMod ? pattern.GetHits() : base_euc_hits; }
|
||||
|
||||
void toggleMute() { mute = !mute; }
|
||||
|
||||
@ -190,13 +176,6 @@ class Channel {
|
||||
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]);
|
||||
|
||||
// Conditionally apply swing on down beats.
|
||||
@ -232,6 +211,56 @@ class Channel {
|
||||
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, MAX_PATTERN_LEN);
|
||||
pattern.SetHits(base_euc_hits + hit_mod);
|
||||
|
||||
// After all cvmod values are updated, recalculate clock pulse modifiers.
|
||||
_recalculatePulses();
|
||||
}
|
||||
|
||||
private:
|
||||
int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) {
|
||||
@ -241,19 +270,13 @@ class Channel {
|
||||
}
|
||||
|
||||
void _recalculatePulses() {
|
||||
int cv1 = gravity.cv1.Read();
|
||||
int cv2 = gravity.cv2.Read();
|
||||
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);
|
||||
const uint16_t mod_pulses = pgm_read_word_near(&CLOCK_MOD_PULSES[cvmod_clock_mod_index]);
|
||||
_duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L);
|
||||
_offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L);
|
||||
|
||||
// Calculate the down beat swing amount.
|
||||
if (swing > 50) {
|
||||
int shifted_swing = swing - 50;
|
||||
if (cvmod_swing > 50) {
|
||||
int shifted_swing = cvmod_swing - 50;
|
||||
_swing_pulse_amount = (long)((mod_pulses * (100L - shifted_swing)) / 100L);
|
||||
} else {
|
||||
_swing_pulse_amount = 0;
|
||||
@ -266,6 +289,15 @@ class Channel {
|
||||
byte base_duty_cycle;
|
||||
byte base_offset;
|
||||
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
|
||||
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/
|
||||
* "%/0123456789ABCDEFILNORSTUVXx"
|
||||
*/
|
||||
const uint8_t LARGE_FONT[766] U8G2_FONT_SECTION("stk-l") PROGMEM =
|
||||
const uint8_t LARGE_FONT[766] U8G2_FONT_SECTION("stk-l") =
|
||||
"\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"
|
||||
@ -100,12 +100,11 @@ constexpr uint8_t CHANNEL_BOX_HEIGHT = 14;
|
||||
enum ParamsMainPage : uint8_t {
|
||||
PARAM_MAIN_TEMPO,
|
||||
PARAM_MAIN_SOURCE,
|
||||
PARAM_MAIN_RUN,
|
||||
PARAM_MAIN_RESET,
|
||||
PARAM_MAIN_PULSE,
|
||||
PARAM_MAIN_ENCODER_DIR,
|
||||
PARAM_MAIN_SAVE_DATA,
|
||||
PARAM_MAIN_LOAD_DATA,
|
||||
PARAM_MAIN_RESET_STATE,
|
||||
PARAM_MAIN_FACTORY_RESET,
|
||||
PARAM_MAIN_LAST,
|
||||
};
|
||||
@ -124,22 +123,6 @@ enum ParamsChannelPage : uint8_t {
|
||||
PARAM_CH_LAST,
|
||||
};
|
||||
|
||||
// Common/resused strings stored as const to save on flash memory.
|
||||
const char* const STR_24_PPQN = "24 PPQN";
|
||||
const char* const STR_4_PPQN = "4 PPQN";
|
||||
const char* const STR_1_PPQN = "1 PPQN";
|
||||
const char* const STR_CV_1 = "CV 1";
|
||||
const char* const STR_CV_2 = "CV 2";
|
||||
const char* const STR_NONE = "NONE";
|
||||
const char* const STR_EXT = "EXT";
|
||||
const char* const STR_X = "X";
|
||||
const char* const STR_DEFAULT = "DEFAULT";
|
||||
const char* const STR_REVERSED = "REVERSED";
|
||||
const char* const STR_FLIPPED = "FLIPPED";
|
||||
const char* const STR_BACK = "BACK TO MAIN";
|
||||
const char* const STR_EUC_STEPS = "EUCLID STEPS";
|
||||
const char* const STR_EUC_HITS = "EUCLID HITS";
|
||||
|
||||
// Helper function to draw centered text
|
||||
void drawCenteredText(const char* text, int y, const uint8_t* font) {
|
||||
gravity.display.setFont(font);
|
||||
@ -231,10 +214,10 @@ void swingDivisionMark() {
|
||||
|
||||
// Human friendly display value for save slot.
|
||||
String displaySaveSlot(int slot) {
|
||||
if (slot >= 0 && slot < StateManager::MAX_SAVE_SLOTS / 2) {
|
||||
if (slot >= 0 && slot < MAX_SAVE_SLOTS / 2) {
|
||||
return String("A") + String(slot + 1);
|
||||
} else if (slot >= StateManager::MAX_SAVE_SLOTS / 2 && slot <= StateManager::MAX_SAVE_SLOTS) {
|
||||
return String("B") + String(slot - (StateManager::MAX_SAVE_SLOTS / 2) + 1);
|
||||
} else if (slot >= MAX_SAVE_SLOTS / 2 && slot <= MAX_SAVE_SLOTS) {
|
||||
return String("B") + String(slot - (MAX_SAVE_SLOTS / 2) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,61 +236,30 @@ void DisplayMainPage() {
|
||||
case PARAM_MAIN_TEMPO:
|
||||
// Serial MIDI is too unstable to display bpm in real time.
|
||||
if (app.selected_source == Clock::SOURCE_EXTERNAL_MIDI) {
|
||||
mainText = STR_EXT;
|
||||
mainText = F("EXT");
|
||||
} else {
|
||||
mainText = String(gravity.clock.Tempo());
|
||||
}
|
||||
subText = F("BPM");
|
||||
break;
|
||||
case PARAM_MAIN_SOURCE:
|
||||
mainText = STR_EXT;
|
||||
mainText = F("EXT");
|
||||
switch (app.selected_source) {
|
||||
case Clock::SOURCE_INTERNAL:
|
||||
mainText = F("INT");
|
||||
subText = F("CLOCK");
|
||||
break;
|
||||
case Clock::SOURCE_EXTERNAL_PPQN_24:
|
||||
subText = STR_24_PPQN;
|
||||
subText = F("24 PPQN");
|
||||
break;
|
||||
case Clock::SOURCE_EXTERNAL_PPQN_4:
|
||||
subText = STR_4_PPQN;
|
||||
break;
|
||||
case Clock::SOURCE_EXTERNAL_PPQN_1:
|
||||
subText = STR_1_PPQN;
|
||||
subText = F("4 PPQN");
|
||||
break;
|
||||
case Clock::SOURCE_EXTERNAL_MIDI:
|
||||
subText = F("MIDI");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_RUN:
|
||||
mainText = F("RUN");
|
||||
switch (app.cv_run) {
|
||||
case 0:
|
||||
subText = STR_NONE;
|
||||
break;
|
||||
case 1:
|
||||
subText = STR_CV_1;
|
||||
break;
|
||||
case 2:
|
||||
subText = STR_CV_2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_RESET:
|
||||
mainText = F("RST");
|
||||
switch (app.cv_reset) {
|
||||
case 0:
|
||||
subText = STR_NONE;
|
||||
break;
|
||||
case 1:
|
||||
subText = STR_CV_1;
|
||||
break;
|
||||
case 2:
|
||||
subText = STR_CV_2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_PULSE:
|
||||
mainText = F("OUT");
|
||||
switch (app.selected_pulse) {
|
||||
@ -315,25 +267,25 @@ void DisplayMainPage() {
|
||||
subText = F("PULSE OFF");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_24:
|
||||
subText = STR_24_PPQN;
|
||||
subText = F("24 PPQN PULSE");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_4:
|
||||
subText = STR_4_PPQN;
|
||||
subText = F("4 PPQN PULSE");
|
||||
break;
|
||||
case Clock::PULSE_PPQN_1:
|
||||
subText = STR_1_PPQN;
|
||||
subText = F("1 PPQN PULSE");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PARAM_MAIN_ENCODER_DIR:
|
||||
mainText = F("DIR");
|
||||
subText = app.selected_sub_param == 0 ? STR_DEFAULT : STR_REVERSED;
|
||||
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
|
||||
break;
|
||||
case PARAM_MAIN_SAVE_DATA:
|
||||
case PARAM_MAIN_LOAD_DATA:
|
||||
if (app.selected_sub_param == StateManager::MAX_SAVE_SLOTS) {
|
||||
mainText = STR_X;
|
||||
subText = STR_BACK;
|
||||
if (app.selected_sub_param == MAX_SAVE_SLOTS) {
|
||||
mainText = F("x");
|
||||
subText = F("BACK TO MAIN");
|
||||
} else {
|
||||
// Indicate currently active slot.
|
||||
if (app.selected_sub_param == app.selected_save_slot) {
|
||||
@ -345,13 +297,22 @@ void DisplayMainPage() {
|
||||
: F("LOAD FROM SLOT");
|
||||
}
|
||||
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:
|
||||
if (app.selected_sub_param == 0) {
|
||||
mainText = F("DEL");
|
||||
subText = F("FACTORY RESET");
|
||||
} else {
|
||||
mainText = STR_X;
|
||||
subText = STR_BACK;
|
||||
mainText = F("x");
|
||||
subText = F("BACK TO MAIN");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -360,7 +321,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("CLK RUN"), F("CLK RESET"), F("PULSE OUT"), F("ENCODER DIR"), F("SAVE"), F("LOAD"), F("ERASE")};
|
||||
String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("PULSE OUT"), F("ENCODER DIR"), F("SAVE"), F("LOAD"), F("RESET"), F("ERASE")};
|
||||
drawMenuItems(menu_items, PARAM_MAIN_LAST);
|
||||
}
|
||||
|
||||
@ -377,12 +338,10 @@ void DisplayChannelPage() {
|
||||
// When editing a param, just show the base value. When not editing show
|
||||
// the value with cv mod.
|
||||
bool withCvMod = !app.editing_param;
|
||||
int cv1 = gravity.cv1.Read();
|
||||
int cv2 = gravity.cv2.Read();
|
||||
|
||||
switch (app.selected_param) {
|
||||
case PARAM_CH_MOD: {
|
||||
int mod_value = withCvMod ? ch.getClockModWithMod(cv1, cv2): ch.getClockMod();
|
||||
int mod_value = ch.getClockMod(withCvMod);
|
||||
if (mod_value > 1) {
|
||||
mainText = F("/");
|
||||
mainText += String(mod_value);
|
||||
@ -395,31 +354,31 @@ void DisplayChannelPage() {
|
||||
break;
|
||||
}
|
||||
case PARAM_CH_PROB:
|
||||
mainText = String(withCvMod ? ch.getProbabilityWithMod(cv1, cv2) : ch.getProbability()) + F("%");
|
||||
mainText = String(ch.getProbability(withCvMod)) + F("%");
|
||||
subText = F("HIT CHANCE");
|
||||
break;
|
||||
case PARAM_CH_DUTY:
|
||||
mainText = String(withCvMod ? ch.getDutyCycleWithMod(cv1, cv2) : ch.getDutyCycle()) + F("%");
|
||||
mainText = String(ch.getDutyCycle(withCvMod)) + F("%");
|
||||
subText = F("PULSE WIDTH");
|
||||
break;
|
||||
case PARAM_CH_OFFSET:
|
||||
mainText = String(withCvMod ? ch.getOffsetWithMod(cv1, cv2) : ch.getOffset()) + F("%");
|
||||
mainText = String(ch.getOffset(withCvMod)) + F("%");
|
||||
subText = F("SHIFT HIT");
|
||||
break;
|
||||
case PARAM_CH_SWING:
|
||||
ch.getSwing() == 50
|
||||
? mainText = F("OFF")
|
||||
: mainText = String(withCvMod ? ch.getSwingWithMod(cv1, cv2) : ch.getSwing()) + F("%");
|
||||
subText = F("DOWN BEAT");
|
||||
: mainText = String(ch.getSwing(withCvMod)) + F("%");
|
||||
subText = "DOWN BEAT";
|
||||
swingDivisionMark();
|
||||
break;
|
||||
case PARAM_CH_EUC_STEPS:
|
||||
mainText = String(withCvMod ? ch.getStepsWithMod(cv1, cv2) : ch.getSteps());
|
||||
subText = STR_EUC_STEPS;
|
||||
mainText = String(ch.getSteps(withCvMod));
|
||||
subText = "EUCLID STEPS";
|
||||
break;
|
||||
case PARAM_CH_EUC_HITS:
|
||||
mainText = String(withCvMod ? ch.getHitsWithMod(cv1, cv2) : ch.getHits());
|
||||
subText = STR_EUC_HITS;
|
||||
mainText = String(ch.getHits(withCvMod));
|
||||
subText = "EUCLID HITS";
|
||||
break;
|
||||
case PARAM_CH_CV1_DEST:
|
||||
case PARAM_CH_CV2_DEST: {
|
||||
@ -444,10 +403,10 @@ void DisplayChannelPage() {
|
||||
subText = F("SWING");
|
||||
break;
|
||||
case CV_DEST_EUC_STEPS:
|
||||
subText = STR_EUC_STEPS;
|
||||
subText = F("EUCLID STEPS");
|
||||
break;
|
||||
case CV_DEST_EUC_HITS:
|
||||
subText = STR_EUC_HITS;
|
||||
subText = F("EUCLID HITS");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -514,17 +473,16 @@ 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(SKETCH_NAME);
|
||||
gravity.display.drawStr(16 + (textWidth / 2), 20, SKETCH_NAME);
|
||||
|
||||
textWidth = gravity.display.getStrWidth(StateManager::SEMANTIC_VERSION);
|
||||
gravity.display.drawStr(16 + (textWidth / 2), 32, StateManager::SEMANTIC_VERSION);
|
||||
textWidth = gravity.display.getStrWidth(SEMANTIC_VERSION);
|
||||
gravity.display.drawStr(16 + (textWidth / 2), 32, SEMANTIC_VERSION);
|
||||
|
||||
textWidth = gravity.display.getStrWidth(loadingText.c_str());
|
||||
gravity.display.drawStr(26 + (textWidth / 2), 44, loadingText.c_str());
|
||||
textWidth = gravity.display.getStrWidth("LOADING....");
|
||||
gravity.display.drawStr(26 + (textWidth / 2), 44, "LOADING....");
|
||||
} while (gravity.display.nextPage());
|
||||
}
|
||||
|
||||
|
||||
@ -15,20 +15,9 @@
|
||||
|
||||
#include "app_state.h"
|
||||
|
||||
// Define the constants for the current firmware.
|
||||
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
|
||||
const char StateManager::SEMANTIC_VERSION[] = "V2.0.0BETA4"; // NOTE: This should match the version in the library.properties file.
|
||||
|
||||
// Number of available save slots.
|
||||
const byte StateManager::MAX_SAVE_SLOTS = 10;
|
||||
const byte StateManager::TRANSIENT_SLOT = 10;
|
||||
|
||||
// Define the minimum amount of time between EEPROM writes.
|
||||
const unsigned long StateManager::SAVE_DELAY_MS = 2000;
|
||||
|
||||
// Calculate the starting address for EepromData, leaving space for metadata.
|
||||
const int StateManager::METADATA_START_ADDR = 0;
|
||||
const int StateManager::EEPROM_DATA_START_ADDR = sizeof(StateManager::Metadata);
|
||||
static const int METADATA_START_ADDR = 0;
|
||||
static const int EEPROM_DATA_START_ADDR = sizeof(StateManager::Metadata);
|
||||
|
||||
StateManager::StateManager() : _isDirty(false), _lastChangeTime(0) {}
|
||||
|
||||
@ -87,8 +76,6 @@ void StateManager::reset(AppState& app) {
|
||||
app.selected_channel = default_app.selected_channel;
|
||||
app.selected_source = default_app.selected_source;
|
||||
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++) {
|
||||
app.channel[i].Init();
|
||||
@ -142,8 +129,6 @@ void StateManager::_saveState(const AppState& app, byte slot_index) {
|
||||
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);
|
||||
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
|
||||
// broken out into global / per-channel save methods. When saving via
|
||||
@ -152,13 +137,13 @@ void StateManager::_saveState(const AppState& app, byte slot_index) {
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
const auto& ch = app.channel[i];
|
||||
auto& save_ch = save_data.channel_data[i];
|
||||
save_ch.base_clock_mod_index = ch.getClockModIndex();
|
||||
save_ch.base_probability = ch.getProbability();
|
||||
save_ch.base_duty_cycle = ch.getDutyCycle();
|
||||
save_ch.base_offset = ch.getOffset();
|
||||
save_ch.base_swing = ch.getSwing();
|
||||
save_ch.base_euc_steps = ch.getSteps();
|
||||
save_ch.base_euc_hits = ch.getHits();
|
||||
save_ch.base_clock_mod_index = ch.getClockModIndex(false);
|
||||
save_ch.base_probability = ch.getProbability(false);
|
||||
save_ch.base_duty_cycle = ch.getDutyCycle(false);
|
||||
save_ch.base_offset = ch.getOffset(false);
|
||||
save_ch.base_swing = ch.getSwing(false);
|
||||
save_ch.base_euc_steps = ch.getSteps(false);
|
||||
save_ch.base_euc_hits = ch.getHits(false);
|
||||
save_ch.cv1_dest = static_cast<byte>(ch.getCv1Dest());
|
||||
save_ch.cv2_dest = static_cast<byte>(ch.getCv2Dest());
|
||||
}
|
||||
@ -183,8 +168,6 @@ void StateManager::_loadState(AppState& app, byte slot_index) {
|
||||
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);
|
||||
app.cv_run = load_data.cv_run;
|
||||
app.cv_reset = load_data.cv_reset;
|
||||
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
auto& ch = app.channel[i];
|
||||
|
||||
@ -13,11 +13,22 @@
|
||||
#define SAVE_STATE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <libGravity.h>
|
||||
#include <gravity.h>
|
||||
|
||||
// Forward-declare AppState to avoid circular dependencies.
|
||||
struct AppState;
|
||||
|
||||
// Define the constants for the current firmware.
|
||||
const char SKETCH_NAME[] = "ALT GRAVITY";
|
||||
const char SEMANTIC_VERSION[] = "V2.0.0BETA2";
|
||||
|
||||
// Number of available save slots.
|
||||
const byte MAX_SAVE_SLOTS = 10; // Count of save slots 0 - 9 to save/load presets.
|
||||
const byte TRANSIENT_SLOT = 10; // Transient slot index to persist state when powered off.
|
||||
|
||||
// Define the minimum amount of time between EEPROM writes.
|
||||
static const unsigned long SAVE_DELAY_MS = 2000;
|
||||
|
||||
/**
|
||||
* @brief Manages saving and loading of the application state to and from EEPROM.
|
||||
* The number of user slots is defined by MAX_SAVE_SLOTS, and one additional slot
|
||||
@ -28,11 +39,6 @@ struct AppState;
|
||||
*/
|
||||
class StateManager {
|
||||
public:
|
||||
static const char SKETCH_NAME[];
|
||||
static const char SEMANTIC_VERSION[];
|
||||
static const byte MAX_SAVE_SLOTS;
|
||||
static const byte TRANSIENT_SLOT;
|
||||
|
||||
StateManager();
|
||||
|
||||
// Populate the AppState instance with values from EEPROM if they exist.
|
||||
@ -76,8 +82,6 @@ class StateManager {
|
||||
byte selected_channel;
|
||||
byte selected_source;
|
||||
byte selected_pulse;
|
||||
byte cv_run;
|
||||
byte cv_reset;
|
||||
ChannelState channel_data[Gravity::OUTPUT_COUNT];
|
||||
};
|
||||
|
||||
@ -88,10 +92,6 @@ class StateManager {
|
||||
void _saveState(const AppState& app, byte slot_index);
|
||||
void _loadState(AppState& app, byte slot_index);
|
||||
|
||||
static const unsigned long SAVE_DELAY_MS;
|
||||
static const int METADATA_START_ADDR;
|
||||
static const int EEPROM_DATA_START_ADDR;
|
||||
|
||||
bool _isDirty;
|
||||
unsigned long _lastChangeTime;
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file libGravity.cpp
|
||||
* @file gravity.cpp
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
|
||||
* @version 0.1
|
||||
@ -9,7 +9,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libGravity.h"
|
||||
#include "gravity.h"
|
||||
|
||||
// Initialize the static pointer for the EncoderDir class to null. We want to
|
||||
// have a static pointer to decouple the ISR from the global gravity object.
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file libGravity.h
|
||||
* @file gravity.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
|
||||
* @version 0.1
|
||||
@ -1,10 +0,0 @@
|
||||
name=libGravity
|
||||
version=2.0.0beta3
|
||||
author=Adam Wonak
|
||||
maintainer=awonak <github.com/awonak>
|
||||
sentence=Hardware abstraction library for Sitka Instruments Gravity eurorack module
|
||||
category=Other
|
||||
license=MIT
|
||||
url=https://github.com/awonak/libGravity
|
||||
architectures=avr
|
||||
depends=uClock,RotaryEncoder,U8g2
|
||||
@ -32,7 +32,7 @@
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "uClock.h"
|
||||
#include "platforms/avr.h"
|
||||
#include "uClock/platforms/avr.h"
|
||||
|
||||
//
|
||||
// Platform specific timer setup/control
|
||||
180
uClock/uClock.h
Executable file
180
uClock/uClock.h
Executable file
@ -0,0 +1,180 @@
|
||||
/*!
|
||||
* @file uClock.h
|
||||
* Project BPM clock generator for Arduino
|
||||
* @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(RPI2040, Teensy, Seedstudio XIAO M0 and ESP32)
|
||||
* @version 2.2.1
|
||||
* @author Romulo Silva
|
||||
* @date 10/06/2017
|
||||
* @license MIT - (c) 2024 - Romulo Silva - contact@midilab.co
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __U_CLOCK_H__
|
||||
#define __U_CLOCK_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
namespace umodular { namespace clock {
|
||||
|
||||
#define MIN_BPM 1
|
||||
#define MAX_BPM 400
|
||||
|
||||
#define PHASE_FACTOR 16
|
||||
#define PLL_X 220
|
||||
|
||||
#define SECS_PER_MIN (60UL)
|
||||
#define SECS_PER_HOUR (3600UL)
|
||||
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
|
||||
|
||||
class uClockClass {
|
||||
|
||||
public:
|
||||
enum ClockMode {
|
||||
INTERNAL_CLOCK = 0,
|
||||
EXTERNAL_CLOCK
|
||||
};
|
||||
|
||||
enum ClockState {
|
||||
PAUSED = 0,
|
||||
STARTING,
|
||||
STARTED
|
||||
};
|
||||
|
||||
enum PPQNResolution {
|
||||
PPQN_1 = 1,
|
||||
PPQN_2 = 2,
|
||||
PPQN_4 = 4,
|
||||
PPQN_8 = 8,
|
||||
PPQN_12 = 12,
|
||||
PPQN_24 = 24,
|
||||
PPQN_48 = 48,
|
||||
PPQN_96 = 96,
|
||||
PPQN_384 = 384,
|
||||
PPQN_480 = 480,
|
||||
PPQN_960 = 960
|
||||
};
|
||||
|
||||
ClockState clock_state;
|
||||
|
||||
uClockClass();
|
||||
|
||||
void setOnOutputPPQN(void (*callback)(uint32_t tick)) {
|
||||
onOutputPPQNCallback = callback;
|
||||
}
|
||||
|
||||
void setOnSync24(void (*callback)(uint32_t tick)) {
|
||||
onSync24Callback = callback;
|
||||
}
|
||||
|
||||
void setOnClockStart(void (*callback)()) {
|
||||
onClockStartCallback = callback;
|
||||
}
|
||||
|
||||
void setOnClockStop(void (*callback)()) {
|
||||
onClockStopCallback = callback;
|
||||
}
|
||||
|
||||
void init();
|
||||
void setOutputPPQN(PPQNResolution resolution);
|
||||
void setInputPPQN(PPQNResolution resolution);
|
||||
|
||||
void handleTimerInt();
|
||||
void handleExternalClock();
|
||||
void resetCounters();
|
||||
|
||||
// external class control
|
||||
void start();
|
||||
void stop();
|
||||
void pause();
|
||||
void setTempo(float bpm);
|
||||
float getTempo();
|
||||
|
||||
// for software timer implementation(fallback for no board support)
|
||||
void run();
|
||||
|
||||
// external timming control
|
||||
void setClockMode(ClockMode tempo_mode);
|
||||
ClockMode getClockMode();
|
||||
void clockMe();
|
||||
// for smooth slave tempo calculate display you should raise the
|
||||
// buffer_size of ext_interval_buffer in between 64 to 128. 254 max size.
|
||||
// note: this doesn't impact on sync time, only display time getTempo()
|
||||
// if you dont want to use it, it is default set it to 1 for memory save
|
||||
void setExtIntervalBuffer(uint8_t buffer_size);
|
||||
|
||||
// elapsed time support
|
||||
uint8_t getNumberOfSeconds(uint32_t time);
|
||||
uint8_t getNumberOfMinutes(uint32_t time);
|
||||
uint8_t getNumberOfHours(uint32_t time);
|
||||
uint8_t getNumberOfDays(uint32_t time);
|
||||
uint32_t getNowTimer();
|
||||
uint32_t getPlayTime();
|
||||
|
||||
uint32_t bpmToMicroSeconds(float bpm);
|
||||
|
||||
private:
|
||||
float inline freqToBpm(uint32_t freq);
|
||||
float inline constrainBpm(float bpm);
|
||||
void calculateReferencedata();
|
||||
|
||||
void (*onOutputPPQNCallback)(uint32_t tick);
|
||||
void (*onSync24Callback)(uint32_t tick);
|
||||
void (*onClockStartCallback)();
|
||||
void (*onClockStopCallback)();
|
||||
|
||||
// clock input/output control
|
||||
PPQNResolution output_ppqn = PPQN_96;
|
||||
PPQNResolution input_ppqn = PPQN_24;
|
||||
// output and internal counters, ticks and references
|
||||
uint32_t tick;
|
||||
uint32_t int_clock_tick;
|
||||
uint8_t mod_clock_counter;
|
||||
uint16_t mod_clock_ref;
|
||||
|
||||
uint8_t mod_sync24_counter;
|
||||
uint16_t mod_sync24_ref;
|
||||
uint32_t sync24_tick;
|
||||
|
||||
// external clock control
|
||||
volatile uint32_t ext_clock_us;
|
||||
volatile uint32_t ext_clock_tick;
|
||||
volatile uint32_t ext_interval;
|
||||
uint32_t last_interval;
|
||||
uint32_t sync_interval;
|
||||
|
||||
float tempo;
|
||||
uint32_t start_timer;
|
||||
ClockMode clock_mode;
|
||||
|
||||
volatile uint32_t * ext_interval_buffer = nullptr;
|
||||
uint8_t ext_interval_buffer_size;
|
||||
uint16_t ext_interval_idx;
|
||||
};
|
||||
|
||||
} } // end namespace umodular::clock
|
||||
|
||||
extern umodular::clock::uClockClass uClock;
|
||||
|
||||
extern "C" {
|
||||
extern volatile uint32_t _millis;
|
||||
}
|
||||
|
||||
#endif /* __U_CLOCK_H__ */
|
||||
Reference in New Issue
Block a user