34 Commits

Author SHA1 Message Date
acd028846c Full repo version bump to v2.0.0 2025-08-17 11:04:25 -07:00
ed625e75fc Merge pull request 'Fix Save/Load State' (#28) from fix-save-state into main
Reviewed-on: #28
2025-08-17 17:18:56 +00:00
b60dcc0e68 one more 2025-08-16 11:00:31 -07:00
909d589609 make version consistent 2025-08-16 10:58:42 -07:00
330f5e6ceb improve docstring comments 2025-08-16 10:47:06 -07:00
87dacd869b improve the usage of disabling interrupts to avoid a potential race condition with isr being called between private method execution. 2025-08-16 10:06:11 -07:00
64f467d6ac Add missing metadata field in _loadMetadata 2025-08-16 09:55:43 -07:00
84cafe2387 Fix bug in metadata save/load state.
The sketch_name char array was to short, causing a buffer overflow.
2025-08-16 09:51:05 -07:00
8bb89a5f4b formatting 2025-08-14 07:31:43 -07:00
499bc7a643 Added more details explaining the structure of the repo 2025-08-14 07:29:02 -07:00
3f670fa9f7 Update docs and example firmware 2025-08-13 07:42:02 -07:00
b5029bde88 add skeleton app to examples 2025-08-13 07:19:06 -07:00
4bcd618073 Add skeleton app to examples 2025-08-13 07:18:45 -07:00
6ada2aba30 Add option to rotate the display (#27)
I needed to cut the bootsplash to make room for adding this features.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/27
2025-08-10 02:47:59 +00:00
c5965aa1f7 bug fix - need to recalculate pulses when mod duty and swing are changed. 2025-08-09 18:45:21 -07:00
7c02628403 Add more EXT clock source options (#23)
Fixes https://github.com/awonak/alt-gravity/issues/12

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/23
2025-08-10 00:26:20 +00:00
1161da38c1 Add menu options for using cv input as Clock Run/Reset (#25)
Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/25
2025-08-10 00:25:06 +00:00
872af30fbc Refactor CV Mod (#24)
Move cv mod calculation to processClockTick. This is less ideas because it is an ISR, but it saves a significant amount of memory. Performance doesn't seem to take much of a hit.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/24
2025-08-09 23:59:24 +00:00
fc17afc9a1 Remove Reset State (#26)
This feature is essentially overlapping with loading default save slots. I need the few bytes it affords me.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/26
2025-08-09 23:57:10 +00:00
b6402380c0 fixed bug in cv mod of clock multiplication upper range. 2025-07-26 18:51:18 -07:00
19473db67e bump version in code 2025-07-24 18:38:34 -07:00
dd7217d04e Fix euclidean hit mod 2025-07-24 18:27:24 -07:00
d1c8ee16a4 EXT will reset clocks in MIDI clock mode.
Add reset behavior for EXT clock input when MIDI clock source is selected.

Fixes: https://git.pinkduck.xyz/awonak/libGravity/issues/22
2025-07-24 08:35:05 -07:00
65dde4d62e Reorganization of library structure to better match Arduino spec (#20)
Note, this will also require to you "uninstall and reinstall" the Arduino library due to the library file location changes.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/20
2025-07-24 15:07:15 +00:00
c7a3277b5f Memory improvements in bootsplash and StateManager 2025-07-24 07:53:41 -07:00
fb44601707 Merge branch 'main' of https://git.pinkduck.xyz/awonak/libGravity 2025-07-23 18:08:10 -07:00
ec34bc3a7b Fix metadata loading issues with Initialization and refactor Factory Reset. (#19)
Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/19
2025-07-23 03:32:16 +00:00
c5bddef66d Show loading bootsplash with firmware name and version (#18)
Bootsplash is displayed before EEPROM erase, which is a slow operation.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/18
2025-07-22 05:16:32 +00:00
b0accdc83a Fix Initial Transient State (#17)
There was an off-by-one error that was not properly loading transient state from the designated memory slot. Also fixes setting the last saved/loaded slot indicator with metadata.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/17
2025-07-22 05:12:45 +00:00
1c0fb86bc1 Reverse the order of clock mod options. (#16)
This now matches original Gravity behavior. Also, now when applying CV mod positive voltages increase clock mod instead of reducing it.

Also fix pulse out, which wasn't previously updated when CLOCK_MOD was moved to program mem.

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/16
2025-07-22 00:00:49 +00:00
01f32407f6 bump version 2025-07-20 17:53:03 -07:00
4f04137f67 Add global/hardware settings to metadata EEPROM (#15)
Settings like Encoder Direction and Display Orientation should persist when resetting channel state.

Fixes https://github.com/awonak/alt-gravity/issues/7

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/15
2025-07-21 00:27:32 +00:00
1bf90e1674 Mute channel when shift + play pressed (#14)
Fixes https://github.com/awonak/alt-gravity/issues/2

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/14
2025-07-21 00:01:18 +00:00
5729eef037 Factory Reset (#13)
Fixes https://github.com/awonak/alt-gravity/issues/1

Reviewed-on: https://git.pinkduck.xyz/awonak/libGravity/pulls/13
2025-07-21 00:00:47 +00:00
26 changed files with 669 additions and 527 deletions

View File

@ -1,6 +1,18 @@
# Sitka Instruments Gravity Firmware Abstraction
This library helps make writing firmware easier by abstracting away the initialization and peripheral interactions. Now your firmware code can just focus on the logic and behavior of the app, and keep the low level code neatly tucked away in this library.
This library helps make writing firmware for the [Sitka Instruments Gravity](https://sitkainstruments.com/gravity/) eurorack module easier by abstracting away the initialization and peripheral interactions. Now your firmware code can just focus on the logic and behavior of the app, and keep the low level code neatly tucked away in this library.
The latest releases of all Sitka Instruments Gravity firmware builds can be found on the [Updater](https://sitkainstruments.com/gravity/updater/) page. You can use this page to flash the latest build directly to the Arduino Nano on the back of your module.
## Project Code Layout
* [`src/`](src/) - **libGravity**: This is the hardware abstraction library used to simplify the creation of new Gravity module firmware by providing common reusable wrappers around the module peripherials like [DigitalOutput](src/digital_output.h#L18) providing methods like [`Update(uint8_t state)`](src/digital_output.h#L45) which allow you to set that output channel voltage high or low, and common module behavior like [Clock](src/clock.h#L30) which provides handlers like [`AttachExtHandler(callback)`](src/clock.h#L69) which takes a callback function to handle external clock tick behavior when receiving clock trigger.
* [`firmware/Gravity`](firmware/Gravity/) - **Alt Gravity**: This is the implementation of the default 6-channel trigger/gate clock modulation firmware. This is a full rewrite of the original firmware designed to use `libGravity` with a focus on open source friendlines.
* `firmware/GridSeq` - **GridSeq**: Comming Soon.
* [`examples/skeleton`](examples/skeleton/skeleton.ino) - **Skeleton**: This is the bare bones scaffloding for a `libGravity` firmware app.
## Installation
@ -17,13 +29,14 @@ Common directory locations:
* [uClock](https://github.com/midilab/uClock) [MIT] - (Included with this repo) Handle clock tempo, external clock input, and internal clock timer handler.
* [RotateEncoder](https://github.com/mathertel/RotaryEncoder) [BSD] - Library for reading and interpreting encoder rotation.
* [U8g2](https://github.com/olikraus/u8g2/) [MIT] - Graphics helper library.
* [NeoHWSerial](https://github.com/SlashDevin/NeoHWSerial) [GPL] - Hardware serial library with attachInterrupt.
## Example
Here's a trivial example showing some of the ways to interact with the library. This script rotates the active clock channel according to the set tempo. The encoder can change the temo or rotation direction. The play/pause button will toggle the clock activity on or off. The shift button will freeze the clock from advancing the channel rotation.
```cpp
#include "gravity.h"
#include "libGravity.h"
byte idx = 0;
bool reversed = false;
@ -75,11 +88,11 @@ void HandlePlayPressed() {
}
}
void HandleRotate(Direction dir, int val) {
void HandleRotate(int val) {
if (selected_param == 0) {
gravity.clock.SetTempo(gravity.clock.Tempo() + val);
} else if (selected_param == 1) {
reversed = (dir == DIRECTION_DECREMENT);
reversed = (val < 0);
}
}
@ -111,6 +124,14 @@ void UpdateDisplay() {
}
```
**Building New Firmware Using libGravity**
When starting a new firmware sketch you can use the [skeleton](examples/skeleton/skeleton.ino) app as a place to start.
**Building New Firmware from scratch**
If you do not want to use the libGravity hardware abstraction library and want to roll your own vanilla firmware, take a look at the [peripherials.h](src/peripherials.h) file for the pinout definitions used by the module.
### Build for release
```

View File

@ -17,7 +17,7 @@
* TODO: Store the calibration value in EEPROM.
*/
#include "gravity.h"
#include "libGravity.h"
#define TEXT_FONT u8g2_font_profont11_tf
#define INDICATOR_FONT u8g2_font_open_iconic_arrow_1x_t
@ -43,7 +43,7 @@ void NextCalibrationPoint() {
selected_param = (selected_param + 1) % 6;
}
void CalibrateCV(Direction dir, int val) {
void CalibrateCV(int val) {
AnalogInput* cv = (selected_param > 2) ? &gravity.cv2 : &gravity.cv1;
switch (selected_param % 3) {
case 0:

View File

@ -14,7 +14,7 @@
*
*/
#include "gravity.h"
#include "libGravity.h"
#define TEXT_FONT u8g2_font_profont11_tf
@ -39,7 +39,7 @@ void NextCalibrationPoint() {
selected_param = (selected_param + 1) % 2;
}
void CalibrateCV(Direction dir, int val) {
void CalibrateCV(int val) {
// AnalogInput* cv = (selected_param > 2) ? &gravity.cv2 : &gravity.cv1;
AnalogInput* cv = &gravity.cv1;
switch (selected_param % 2) {

View File

@ -17,7 +17,7 @@
*
*/
#include "gravity.h"
#include <libGravity.h>
// Firmware state variables.
struct Channel {

View File

@ -1,4 +1,4 @@
#include "gravity.h"
#include "libGravity.h"
byte idx = 0;
bool reversed = false;
@ -33,28 +33,28 @@ void IntClock(uint32_t tick) {
if (tick % 12 == 0 && ! freeze) {
gravity.outputs[idx].Low();
if (reversed) {
idx = (idx == 0) ? OUTPUT_COUNT - 1 : idx - 1;
idx = (idx == 0) ? Gravity::OUTPUT_COUNT - 1 : idx - 1;
} else {
idx = (idx + 1) % OUTPUT_COUNT;
idx = (idx + 1) % Gravity::OUTPUT_COUNT;
}
gravity.outputs[idx].High();
}
}
void HandlePlayPressed() {
gravity.clock.Pause();
gravity.clock.Stop();
if (gravity.clock.IsPaused()) {
for (int i = 0; i < OUTPUT_COUNT; i++) {
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
gravity.outputs[i].Low();
}
}
}
void HandleRotate(Direction dir, int val) {
void HandleRotate(int val) {
if (selected_param == 0) {
gravity.clock.SetTempo(gravity.clock.Tempo() + val);
} else if (selected_param == 1) {
reversed = (dir == DIRECTION_DECREMENT);
reversed = (val < 0);
}
}
@ -80,7 +80,7 @@ void UpdateDisplay() {
gravity.display.print("Direction: ");
gravity.display.print((reversed) ? "Backward" : "Forward");
gravity.display.drawChar(0, selected_param * 10, 0x10, 1, 0, 1);
gravity.display.drawStr(0, selected_param * 10, "x");
gravity.display.display();
}

View File

@ -0,0 +1,118 @@
/**
* @file skeleton.ino
* @author YOUR_NAME (<url>)
* @brief Skeleton app for Sitka Instruments Gravity.
* @version vX.Y.Z - MONTH YEAR YOUR_NAME
* @date YYYY-MM-DD
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
* Skeleton app for basic structure of a new firmware for Sitka Instruments
* Gravity using the libGravity library.
*
* 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>
// Global state for settings and app behavior.
struct AppState {
int tempo = Clock::DEFAULT_TEMPO;
Clock::Source selected_source = Clock::SOURCE_INTERNAL;
// Add app specific state variables here.
};
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();
// Non-ISR loop behavior.
}
//
// Firmware handlers for clocks.
//
void HandleIntClockTick(uint32_t tick) {
bool refresh = false;
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
// Process each output tick handlers.
}
}
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.
gravity.clock.Reset();
break;
default:
// Register EXT cv clock tick.
gravity.clock.Tick();
}
}
//
// UI handlers for encoder and buttons.
//
void HandlePlayPressed() {
}
void HandleEncoderPressed() {
}
void HandleRotate(int val) {
}
void HandlePressedRotate(int val) {
}
//
// Application logic goes here.
//

View File

@ -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.1 - June 2025 awonak - Full rewrite
* @version v2.0.0 - August 2025 awonak - Full rewrite
* @version v1.0 - August 2023 Oleksiy H - Initial release
* @date 2025-07-04
*
@ -37,16 +37,18 @@
* Shift - hold and rotate encoder to change current selected output channel.
*
* EXT:
* External clock input. When Gravity is set to INTERNAL clock mode, this
* input is used to reset clocks.
* 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 <gravity.h>
#include <libGravity.h>
#include "app_state.h"
#include "channel.h"
@ -85,18 +87,8 @@ void loop() {
// Process change in state of inputs and outputs.
gravity.Process();
// 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 if cv run or reset is active and read cv.
CheckRunReset(gravity.cv1, gravity.cv2);
// Check for dirty state eligible to be saved.
stateManager.update(app);
@ -135,13 +127,12 @@ void HandleIntClockTick(uint32_t tick) {
break;
}
const uint32_t pulse_high_ticks = CLOCK_MOD_PULSES[clock_index];
const uint16_t pulse_high_ticks = pgm_read_word_near(&CLOCK_MOD_PULSES[clock_index]);
const uint32_t pulse_low_ticks = tick + max((pulse_high_ticks / 2), 1L);
if (tick % pulse_high_ticks == 0) {
gravity.pulse.High();
}
if (pulse_low_ticks % pulse_high_ticks == 0) {
} else if (pulse_low_ticks % pulse_high_ticks == 0) {
gravity.pulse.Low();
}
}
@ -152,22 +143,61 @@ void HandleIntClockTick(uint32_t tick) {
}
void HandleExtClockTick() {
if (gravity.clock.InternalSource()) {
// Use EXT as Reset when internally clocked.
ResetOutputs();
gravity.clock.Reset();
} else {
// Register clock tick.
gravity.clock.Tick();
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() {
// Check if SHIFT is pressed to mute all/current channel.
if (gravity.shift_button.On()) {
if (app.selected_channel == 0) {
// Mute all channels
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
app.channel[i].toggleMute();
}
} else {
// Mute selected channel
auto& ch = GetSelectedChannel();
ch.toggleMute();
}
return;
}
gravity.clock.IsPaused()
? gravity.clock.Start()
: gravity.clock.Stop();
@ -179,29 +209,42 @@ void HandleEncoderPressed() {
// Check if leaving editing mode should apply a selection.
if (app.editing_param) {
if (app.selected_channel == 0) { // main page
// TODO: rewrite as switch
if (app.selected_param == PARAM_MAIN_ENCODER_DIR) {
bool reversed = app.selected_sub_param == 1;
gravity.encoder.SetReverseDirection(reversed);
}
if (app.selected_param == PARAM_MAIN_SAVE_DATA) {
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 < 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);
}
switch (app.selected_param) {
case PARAM_MAIN_ENCODER_DIR:
app.encoder_reversed = app.selected_sub_param == 1;
gravity.encoder.SetReverseDirection(app.encoder_reversed);
break;
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) {
app.selected_save_slot = app.selected_sub_param;
stateManager.saveData(app);
}
break;
case PARAM_MAIN_LOAD_DATA:
if (app.selected_sub_param < StateManager::MAX_SAVE_SLOTS) {
app.selected_save_slot = app.selected_sub_param;
// Load pattern data into app state.
stateManager.loadData(app, app.selected_save_slot);
// Load global performance settings if they have changed.
if (gravity.clock.Tempo() != app.tempo) {
gravity.clock.SetTempo(app.tempo);
}
// Load global settings only clock is not active.
if (gravity.clock.IsPaused()) {
InitGravity(app);
}
}
break;
case PARAM_MAIN_FACTORY_RESET:
if (app.selected_sub_param == 0) { // Erase
stateManager.factoryReset(app);
InitGravity(app);
}
break;
}
}
// Only mark dirty and reset selected_sub_param when leaving editing mode.
@ -251,6 +294,14 @@ 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);
@ -267,14 +318,16 @@ void editMainParameter(int val) {
}
break;
}
// These changes are applied upon encoder button press.
case PARAM_MAIN_ENCODER_DIR:
case PARAM_MAIN_ROTATE_DISP:
updateSelection(app.selected_sub_param, val, 2);
break;
case PARAM_MAIN_SAVE_DATA:
case PARAM_MAIN_LOAD_DATA:
updateSelection(app.selected_sub_param, val, MAX_SAVE_SLOTS + 1);
updateSelection(app.selected_sub_param, val, StateManager::MAX_SAVE_SLOTS + 1);
break;
case PARAM_MAIN_RESET_STATE:
case PARAM_MAIN_FACTORY_RESET:
updateSelection(app.selected_sub_param, val, 2);
break;
}
@ -336,6 +389,7 @@ void InitGravity(AppState& app) {
gravity.clock.SetTempo(app.tempo);
gravity.clock.SetSource(app.selected_source);
gravity.encoder.SetReverseDirection(app.encoder_reversed);
gravity.display.setFlipMode(app.rotate_display ? 1 : 0);
}
void ResetOutputs() {

View File

@ -2,8 +2,8 @@
* @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
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -12,24 +12,27 @@
#ifndef APP_STATE_H
#define APP_STATE_H
#include <gravity.h>
#include <libGravity.h>
#include "channel.h"
// Global state for settings and app behavior.
struct AppState {
int tempo = Clock::DEFAULT_TEMPO;
bool encoder_reversed = false;
bool refresh_screen = true;
bool editing_param = false;
Channel channel[Gravity::OUTPUT_COUNT];
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;
Channel channel[Gravity::OUTPUT_COUNT];
bool editing_param = false;
bool encoder_reversed = false;
bool rotate_display = false;
bool refresh_screen = true;
};
extern AppState app;
@ -38,28 +41,4 @@ static Channel& GetSelectedChannel() {
return app.channel[app.selected_channel - 1];
}
enum ParamsMainPage : uint8_t {
PARAM_MAIN_TEMPO,
PARAM_MAIN_SOURCE,
PARAM_MAIN_PULSE,
PARAM_MAIN_ENCODER_DIR,
PARAM_MAIN_SAVE_DATA,
PARAM_MAIN_LOAD_DATA,
PARAM_MAIN_RESET_STATE,
PARAM_MAIN_LAST,
};
enum ParamsChannelPage : uint8_t {
PARAM_CH_MOD,
PARAM_CH_PROB,
PARAM_CH_DUTY,
PARAM_CH_OFFSET,
PARAM_CH_SWING,
PARAM_CH_EUC_STEPS,
PARAM_CH_EUC_HITS,
PARAM_CH_CV1_DEST,
PARAM_CH_CV2_DEST,
PARAM_CH_LAST,
};
#endif // APP_STATE_H

View File

@ -2,8 +2,8 @@
* @file channel.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
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -13,7 +13,7 @@
#define CHANNEL_H
#include <Arduino.h>
#include <gravity.h>
#include <libGravity.h>
#include "euclidean.h"
@ -34,28 +34,28 @@ static const byte MOD_CHOICE_SIZE = 25;
// Negative numbers are multipliers, positive are divisors.
static const int CLOCK_MOD[MOD_CHOICE_SIZE] PROGMEM = {
// Multipliers
-24, -16, -12, -8, -6, -4, -3, -2,
// Internal Clock Unity
1,
// Divisors
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 24, 32, 64, 128};
128, 64, 32, 24, 16, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
// Internal Clock Unity (quarter note)
1,
// Multipliers
-2, -3, -4, -6, -8, -12, -16, -24};
// This represents the number of clock pulses for a 96 PPQN clock source
// that match the above div/mult mods.
static const int CLOCK_MOD_PULSES[MOD_CHOICE_SIZE] PROGMEM = {
// Multiplier Pulses (96 / X)
4, 6, 8, 12, 16, 24, 32, 48,
// Divisor Pulses (96 * X)
12288, 6144, 3072, 2304, 1536, 1152, 1056, 960, 864, 768, 672, 576, 480, 384, 288, 192,
// Internal Clock Pulses
96,
// Divisor Pulses (96 * X)
192, 288, 384, 480, 576, 672, 768, 864, 960, 1056, 1152, 1536, 2304, 3072, 6144, 12288};
// Multiplier Pulses (96 / X)
48, 32, 24, 16, 12, 8, 6, 4};
static const byte DEFAULT_CLOCK_MOD_INDEX = 8; // x1 or 96 PPQN.
static const byte DEFAULT_CLOCK_MOD_INDEX = 16; // x1 or 96 PPQN.
static const byte PULSE_PPQN_24_CLOCK_MOD_INDEX = 0;
static const byte PULSE_PPQN_4_CLOCK_MOD_INDEX = 4;
static const byte PULSE_PPQN_1_CLOCK_MOD_INDEX = 8;
static const byte PULSE_PPQN_24_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 1;
static const byte PULSE_PPQN_4_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 6;
static const byte PULSE_PPQN_1_CLOCK_MOD_INDEX = MOD_CHOICE_SIZE - 9;
class Channel {
public:
@ -70,14 +70,6 @@ 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;
@ -88,78 +80,106 @@ 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();
}
_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();
}
_recalculatePulses();
}
void setOffset(int off) {
base_offset = constrain(off, 0, 99);
if (!isCvModActive()) {
cvmod_offset = base_offset;
_recalculatePulses();
}
_recalculatePulses();
}
void setSwing(int val) {
base_swing = constrain(val, 50, 95);
if (!isCvModActive()) {
cvmod_swing = base_swing;
_recalculatePulses();
}
_recalculatePulses();
}
// Euclidean
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) {
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 setCv2Dest(CvDestination dest) { cv2_dest = dest; }
void setCv1Dest(CvDestination dest) {
cv1_dest = dest;
_recalculatePulses();
}
void setCv2Dest(CvDestination dest) {
cv2_dest = dest;
_recalculatePulses();
}
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(); }
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; }
// 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);
}
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; }
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);
}
void toggleMute() { mute = !mute; }
/**
* @brief Processes a clock tick and determines if the output should be high or low.
@ -168,6 +188,19 @@ class Channel {
* @param output The output object to be modified.
*/
void processClockTick(uint32_t tick, DigitalOutput& output) {
// Mute check
if (mute) {
output.Low();
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.
@ -203,56 +236,6 @@ 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) {
@ -262,13 +245,19 @@ class Channel {
}
void _recalculatePulses() {
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);
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);
// Calculate the down beat swing amount.
if (cvmod_swing > 50) {
int shifted_swing = cvmod_swing - 50;
if (swing > 50) {
int shifted_swing = swing - 50;
_swing_pulse_amount = (long)((mod_pulses * (100L - shifted_swing)) / 100L);
} else {
_swing_pulse_amount = 0;
@ -281,15 +270,6 @@ 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;
@ -298,6 +278,9 @@ class Channel {
// Euclidean pattern
Pattern pattern;
// Mute channel flag
bool mute;
// Pre-calculated pulse values for ISR performance
uint16_t _duty_pulses;
uint16_t _offset_pulses;

View File

@ -2,8 +2,8 @@
* @file display.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
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -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") =
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"
@ -96,6 +96,35 @@ constexpr uint8_t CHANNEL_BOXES_Y = 50;
constexpr uint8_t CHANNEL_BOX_WIDTH = 18;
constexpr uint8_t CHANNEL_BOX_HEIGHT = 14;
// Menu items for editing global parameters.
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_ROTATE_DISP,
PARAM_MAIN_SAVE_DATA,
PARAM_MAIN_LOAD_DATA,
PARAM_MAIN_FACTORY_RESET,
PARAM_MAIN_LAST,
};
// Menu items for editing channel parameters.
enum ParamsChannelPage : uint8_t {
PARAM_CH_MOD,
PARAM_CH_PROB,
PARAM_CH_DUTY,
PARAM_CH_OFFSET,
PARAM_CH_SWING,
PARAM_CH_EUC_STEPS,
PARAM_CH_EUC_HITS,
PARAM_CH_CV1_DEST,
PARAM_CH_CV2_DEST,
PARAM_CH_LAST,
};
// Helper function to draw centered text
void drawCenteredText(const char* text, int y, const uint8_t* font) {
gravity.display.setFont(font);
@ -187,10 +216,10 @@ void swingDivisionMark() {
// Human friendly display value for save slot.
String displaySaveSlot(int slot) {
if (slot >= 0 && slot < MAX_SAVE_SLOTS / 2) {
if (slot >= 0 && slot < StateManager::MAX_SAVE_SLOTS / 2) {
return String("A") + String(slot + 1);
} else if (slot >= MAX_SAVE_SLOTS / 2 && slot <= MAX_SAVE_SLOTS) {
return String("B") + String(slot - (MAX_SAVE_SLOTS / 2) + 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);
}
}
@ -228,11 +257,42 @@ void DisplayMainPage() {
case Clock::SOURCE_EXTERNAL_PPQN_4:
subText = F("4 PPQN");
break;
case Clock::SOURCE_EXTERNAL_PPQN_1:
subText = F("1 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 = 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:
mainText = F("OUT");
switch (app.selected_pulse) {
@ -254,9 +314,13 @@ void DisplayMainPage() {
mainText = F("DIR");
subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
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_LOAD_DATA:
if (app.selected_sub_param == MAX_SAVE_SLOTS) {
if (app.selected_sub_param == StateManager::MAX_SAVE_SLOTS) {
mainText = F("x");
subText = F("BACK TO MAIN");
} else {
@ -270,21 +334,22 @@ void DisplayMainPage() {
: F("LOAD FROM SLOT");
}
break;
case PARAM_MAIN_RESET_STATE:
case PARAM_MAIN_FACTORY_RESET:
if (app.selected_sub_param == 0) {
mainText = F("RST");
subText = F("RESET ALL");
mainText = F("DEL");
subText = F("FACTORY RESET");
} else {
mainText = F("x");
subText = F("BACK TO MAIN");
}
break;
}
drawCenteredText(mainText.c_str(), MAIN_TEXT_Y, LARGE_FONT);
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("PULSE OUT"), F("ENCODER DIR"), F("SAVE"), F("LOAD"), F("RESET")};
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);
}
@ -301,10 +366,12 @@ 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 = ch.getClockMod(withCvMod);
int mod_value = withCvMod ? ch.getClockModWithMod(cv1, cv2) : ch.getClockMod();
if (mod_value > 1) {
mainText = F("/");
mainText += String(mod_value);
@ -317,30 +384,30 @@ void DisplayChannelPage() {
break;
}
case PARAM_CH_PROB:
mainText = String(ch.getProbability(withCvMod)) + F("%");
mainText = String(withCvMod ? ch.getProbabilityWithMod(cv1, cv2) : ch.getProbability()) + F("%");
subText = F("HIT CHANCE");
break;
case PARAM_CH_DUTY:
mainText = String(ch.getDutyCycle(withCvMod)) + F("%");
mainText = String(withCvMod ? ch.getDutyCycleWithMod(cv1, cv2) : ch.getDutyCycle()) + F("%");
subText = F("PULSE WIDTH");
break;
case PARAM_CH_OFFSET:
mainText = String(ch.getOffset(withCvMod)) + F("%");
mainText = String(withCvMod ? ch.getOffsetWithMod(cv1, cv2) : ch.getOffset()) + F("%");
subText = F("SHIFT HIT");
break;
case PARAM_CH_SWING:
ch.getSwing() == 50
? mainText = F("OFF")
: mainText = String(ch.getSwing(withCvMod)) + F("%");
: mainText = String(withCvMod ? ch.getSwingWithMod(cv1, cv2) : ch.getSwing()) + F("%");
subText = "DOWN BEAT";
swingDivisionMark();
break;
case PARAM_CH_EUC_STEPS:
mainText = String(ch.getSteps(withCvMod));
mainText = String(withCvMod ? ch.getStepsWithMod(cv1, cv2) : ch.getSteps());
subText = "EUCLID STEPS";
break;
case PARAM_CH_EUC_HITS:
mainText = String(ch.getHits(withCvMod));
mainText = String(withCvMod ? ch.getHitsWithMod(cv1, cv2) : ch.getHits());
subText = "EUCLID HITS";
break;
case PARAM_CH_CV1_DEST:

View File

@ -2,8 +2,8 @@
* @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
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*

View File

@ -2,8 +2,8 @@
* @file save_state.cpp
* @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1
* @date 2025-07-04
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -15,66 +15,102 @@
#include "app_state.h"
// Define the constants for the current firmware.
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
const char StateManager::SEMANTIC_VERSION[] = "2.0.0"; // 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.
static const int EEPROM_DATA_START_ADDR = sizeof(StateManager::Metadata);
const int StateManager::METADATA_START_ADDR = 0;
const int StateManager::EEPROM_DATA_START_ADDR = sizeof(StateManager::Metadata);
StateManager::StateManager() : _isDirty(false), _lastChangeTime(0) {}
bool StateManager::initialize(AppState& app) {
noInterrupts();
bool success = false;
if (_isDataValid()) {
// Load data from the transient slot.
return loadData(app, MAX_SAVE_SLOTS);
} else {
// EEPROM does not contain save data for this firmware & version.
// Initialize eeprom and save default patter to all save slots.
reset(app);
_saveMetadata();
// MAX_SAVE_SLOTS slot is reserved for transient state.
for (int i = 0; i <= MAX_SAVE_SLOTS; i++) {
app.selected_save_slot = i;
_saveState(app, i);
}
return false;
// Load global settings.
_loadMetadata(app);
// Load app data from the transient slot.
_loadState(app, TRANSIENT_SLOT);
success = true;
}
// EEPROM does not contain save data for this firmware & version.
else {
// Erase EEPROM and initialize state. Save default pattern to all save slots.
factoryReset(app);
}
interrupts();
return success;
}
bool StateManager::loadData(AppState& app, byte slot_index) {
if (slot_index >= MAX_SAVE_SLOTS) return false;
// Check if slot_index is within max range + 1 for transient.
if (slot_index >= MAX_SAVE_SLOTS + 1) return false;
noInterrupts();
// Load the state data from the specified EEPROM slot and update the app state save slot.
_loadState(app, slot_index);
app.selected_save_slot = slot_index;
// Persist this change in the global metadata on next update.
_isDirty = true;
interrupts();
return true;
}
// Save app state to user specified save slot.
void StateManager::saveData(const AppState& app) {
if (app.selected_save_slot >= MAX_SAVE_SLOTS) return;
noInterrupts();
// Check if slot_index is within max range + 1 for transient.
if (app.selected_save_slot >= MAX_SAVE_SLOTS + 1) return;
_saveState(app, app.selected_save_slot);
_saveMetadata(app);
_isDirty = false;
interrupts();
}
// Save transient state if it has changed and enough time has passed since last save.
void StateManager::update(const AppState& app) {
if (_isDirty && (millis() - _lastChangeTime > SAVE_DELAY_MS)) {
// MAX_SAVE_SLOTS slot is reserved for transient state.
_saveState(app, MAX_SAVE_SLOTS);
noInterrupts();
_saveState(app, TRANSIENT_SLOT);
_saveMetadata(app);
_isDirty = false;
interrupts();
}
}
void StateManager::reset(AppState& app) {
app.tempo = Clock::DEFAULT_TEMPO;
app.encoder_reversed = false;
app.selected_param = 0;
app.selected_channel = 0;
app.selected_source = Clock::SOURCE_INTERNAL;
app.selected_pulse = Clock::PULSE_PPQN_24;
app.selected_save_slot = 0;
noInterrupts();
AppState default_app;
app.tempo = default_app.tempo;
app.selected_param = default_app.selected_param;
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();
}
// Load global settings from Metadata
_loadMetadata(app);
_isDirty = false;
interrupts();
}
void StateManager::markDirty() {
@ -82,61 +118,83 @@ void StateManager::markDirty() {
_lastChangeTime = millis();
}
// Erases all data in the EEPROM by writing 0 to every address.
void StateManager::factoryReset(AppState& app) {
noInterrupts();
for (unsigned int i = 0; i < EEPROM.length(); i++) {
EEPROM.write(i, 0);
}
// Initialize eeprom and save default patter to all save slots.
_saveMetadata(app);
reset(app);
for (int i = 0; i < MAX_SAVE_SLOTS; i++) {
app.selected_save_slot = i;
_saveState(app, i);
}
_saveState(app, TRANSIENT_SLOT);
interrupts();
}
bool StateManager::_isDataValid() {
Metadata load_meta;
EEPROM.get(0, load_meta);
bool name_match = (strcmp(load_meta.sketch_name, SKETCH_NAME) == 0);
bool version_match = (load_meta.version == SKETCH_VERSION);
Metadata metadata;
EEPROM.get(METADATA_START_ADDR, metadata);
bool name_match = (strcmp(metadata.sketch_name, SKETCH_NAME) == 0);
bool version_match = (strcmp(metadata.version, SEMANTIC_VERSION) == 0);
return name_match && version_match;
}
void StateManager::_saveState(const AppState& app, byte slot_index) {
if (app.selected_save_slot >= MAX_SAVE_SLOTS) return;
// Check if slot_index is within max range + 1 for transient.
if (app.selected_save_slot >= MAX_SAVE_SLOTS + 1) return;
noInterrupts();
static EepromData save_data;
save_data.tempo = app.tempo;
save_data.encoder_reversed = app.encoder_reversed;
save_data.selected_param = app.selected_param;
save_data.selected_channel = app.selected_channel;
save_data.selected_source = static_cast<byte>(app.selected_source);
save_data.selected_pulse = static_cast<byte>(app.selected_pulse);
save_data.selected_save_slot = app.selected_save_slot;
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
// "update" only save state for the current channel since other channels
// will not have changed when saving user edits.
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(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.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.cv1_dest = static_cast<byte>(ch.getCv1Dest());
save_ch.cv2_dest = static_cast<byte>(ch.getCv2Dest());
}
int address = EEPROM_DATA_START_ADDR + (slot_index * sizeof(EepromData));
EEPROM.put(address, save_data);
interrupts();
}
void StateManager::_loadState(AppState& app, byte slot_index) {
noInterrupts();
// Check if slot_index is within max range + 1 for transient.
if (slot_index >= MAX_SAVE_SLOTS + 1) return;
static EepromData load_data;
int address = EEPROM_DATA_START_ADDR + (slot_index * sizeof(EepromData));
EEPROM.get(address, load_data);
// Restore app state from loaded data.
app.tempo = load_data.tempo;
app.encoder_reversed = load_data.encoder_reversed;
app.selected_param = load_data.selected_param;
app.selected_channel = load_data.selected_channel;
app.selected_source = static_cast<Clock::Source>(load_data.selected_source);
app.selected_pulse = static_cast<Clock::Pulse>(load_data.selected_pulse);
app.selected_save_slot = slot_index;
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];
@ -152,14 +210,25 @@ void StateManager::_loadState(AppState& app, byte slot_index) {
ch.setCv1Dest(static_cast<CvDestination>(saved_ch_state.cv1_dest));
ch.setCv2Dest(static_cast<CvDestination>(saved_ch_state.cv2_dest));
}
interrupts();
}
void StateManager::_saveMetadata() {
noInterrupts();
void StateManager::_saveMetadata(const AppState& app) {
Metadata current_meta;
strcpy(current_meta.sketch_name, SKETCH_NAME);
current_meta.version = SKETCH_VERSION;
EEPROM.put(0, current_meta);
interrupts();
strcpy(current_meta.version, SEMANTIC_VERSION);
// Global user settings
current_meta.selected_save_slot = app.selected_save_slot;
current_meta.encoder_reversed = app.encoder_reversed;
current_meta.rotate_display = app.rotate_display;
EEPROM.put(METADATA_START_ADDR, current_meta);
}
void StateManager::_loadMetadata(AppState& app) {
Metadata metadata;
EEPROM.get(METADATA_START_ADDR, metadata);
app.selected_save_slot = metadata.selected_save_slot;
app.encoder_reversed = metadata.encoder_reversed;
app.rotate_display = metadata.rotate_display;
}

View File

@ -2,8 +2,8 @@
* @file save_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
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -13,21 +13,11 @@
#define SAVE_STATE_H
#include <Arduino.h>
#include <gravity.h>
#include <libGravity.h>
// Forward-declare AppState to avoid circular dependencies.
struct AppState;
// Define the constants for the current firmware.
const char SKETCH_NAME[] = "Gravity";
const byte SKETCH_VERSION = 7;
// Number of available save slots.
const byte MAX_SAVE_SLOTS = 10;
// 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
@ -38,6 +28,11 @@ static const unsigned long SAVE_DELAY_MS = 2000;
*/
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.
@ -52,11 +47,17 @@ class StateManager {
void update(const AppState& app);
// Indicate that state has changed and we should save.
void markDirty();
// Erase all data stored in the EEPROM.
void factoryReset(AppState& app);
// This struct holds the data that identifies the firmware version.
struct Metadata {
byte version;
char sketch_name[16];
char version[16];
// Additional global/hardware settings
byte selected_save_slot;
bool encoder_reversed;
bool rotate_display;
};
struct ChannelState {
byte base_clock_mod_index;
@ -72,21 +73,26 @@ class StateManager {
// This struct holds all the parameters we want to save.
struct EepromData {
int tempo;
bool encoder_reversed;
byte selected_param;
byte selected_channel;
byte selected_source;
byte selected_pulse;
byte selected_save_slot;
byte cv_run;
byte cv_reset;
ChannelState channel_data[Gravity::OUTPUT_COUNT];
};
private:
bool _isDataValid();
void _saveMetadata();
void _saveMetadata(const AppState& app);
void _loadMetadata(AppState& app);
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;
};

10
library.properties Normal file
View File

@ -0,0 +1,10 @@
name=libGravity
version=2.0.1
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,NeoHWSerial

View File

@ -2,8 +2,8 @@
* @file analog_input.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Class for interacting with analog inputs.
* @version 0.1
* @date 2025-05-23
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -19,6 +19,8 @@ const int CALIBRATED_HIGH = 512;
class AnalogInput {
public:
static const int GATE_THRESHOLD = 0;
AnalogInput() {}
~AnalogInput() {}
@ -74,6 +76,18 @@ 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_;

View File

@ -2,8 +2,8 @@
* @file button.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Wrapper class for interacting with trigger / gate inputs.
* @version 0.1
* @date 2025-04-20
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*

View File

@ -2,8 +2,8 @@
* @file clock.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Wrapper Class for clock timing functions.
* @version 0.1
* @date 2025-05-04
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -15,7 +15,7 @@
#include <NeoHWSerial.h>
#include "peripherials.h"
#include "uClock.h"
#include "uClock/uClock.h"
// MIDI clock, start, stop, and continue byte definitions - based on MIDI 1.0 Standards.
#define MIDI_CLOCK 0xF8
@ -35,24 +35,22 @@ class Clock {
SOURCE_INTERNAL,
SOURCE_EXTERNAL_PPQN_24,
SOURCE_EXTERNAL_PPQN_4,
SOURCE_EXTERNAL_PPQN_1,
SOURCE_EXTERNAL_MIDI,
SOURCE_LAST,
};
enum Pulse {
PULSE_NONE,
PULSE_PPQN_1,
PULSE_PPQN_4,
PULSE_PPQN_24,
PULSE_PPQN_4,
PULSE_PPQN_1,
PULSE_LAST,
};
void Init() {
NeoSerial.begin(31250);
// Static pin definition for pulse out.
pinMode(PULSE_OUT_PIN, OUTPUT);
// Initialize the clock library
uClock.init();
uClock.setClockMode(uClock.INTERNAL_CLOCK);
@ -99,6 +97,10 @@ class Clock {
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
uClock.setInputPPQN(uClock.PPQN_4);
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);

View File

@ -2,8 +2,8 @@
* @file digital_output.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Class for interacting with trigger / gate outputs.
* @version 0.1
* @date 2025-04-17
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
@ -82,7 +82,6 @@ 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) {

View File

@ -2,8 +2,8 @@
* @file encoder_dir.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Class for interacting with encoders.
* @version 0.1
* @date 2025-04-19
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*

View File

@ -1,15 +1,15 @@
/**
* @file gravity.cpp
* @file libGravity.cpp
* @author Adam Wonak (https://github.com/awonak)
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
* @version 0.1
* @date 2025-04-19
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*
*/
#include "gravity.h"
#include "libGravity.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.

View File

@ -1,9 +1,9 @@
/**
* @file gravity.h
* @file libGravity.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
* @version 0.1
* @date 2025-04-19
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*

View File

@ -2,8 +2,8 @@
* @file peripherials.h
* @author Adam Wonak (https://github.com/awonak)
* @brief Arduino pin definitions for the Sitka Instruments Gravity module.
* @version 0.1
* @date 2025-04-19
* @version 2.0.0
* @date 2025-08-17
*
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
*

View File

@ -32,7 +32,7 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "uClock.h"
#include "uClock/platforms/avr.h"
#include "platforms/avr.h"
//
// Platform specific timer setup/control

View File

@ -1,180 +0,0 @@
/*!
* @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__ */