3 Commits

Author SHA1 Message Date
1b2629de17 refactor when we recalculate pulses. 2025-09-01 10:08:16 -07:00
b39f7a0bbc refactor when we recalculate pulses. 2025-09-01 08:41:47 -07:00
acd028846c Full repo version bump to v2.0.0 2025-08-17 11:04:25 -07:00
15 changed files with 77 additions and 71 deletions

View File

@ -2,7 +2,7 @@
* @file Gravity.ino * @file Gravity.ino
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @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 * @version v1.0 - August 2023 Oleksiy H - Initial release
* @date 2025-07-04 * @date 2025-07-04
* *
@ -90,6 +90,13 @@ void loop() {
// Check if cv run or reset is active and read cv. // Check if cv run or reset is active and read cv.
CheckRunReset(gravity.cv1, gravity.cv2); CheckRunReset(gravity.cv1, gravity.cv2);
// Process clock pulses.
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
if (app.channel[i].isCvModActive()) {
app.channel[i].recalculatePulses();
}
}
// Check for dirty state eligible to be saved. // Check for dirty state eligible to be saved.
stateManager.update(app); stateManager.update(app);
@ -281,6 +288,7 @@ void HandleRotate(int val) {
void HandlePressedRotate(int val) { void HandlePressedRotate(int val) {
updateSelection(app.selected_channel, val, Gravity::OUTPUT_COUNT + 1); updateSelection(app.selected_channel, val, Gravity::OUTPUT_COUNT + 1);
app.selected_param = 0; app.selected_param = 0;
app.editing_param = false;
stateManager.markDirty(); stateManager.markDirty();
app.refresh_screen = true; app.refresh_screen = true;
} }

View File

@ -2,8 +2,8 @@
* @file app_state.h * @file app_state.h
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *

View File

@ -2,8 +2,8 @@
* @file channel.h * @file channel.h
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *
@ -77,16 +77,16 @@ class Channel {
pattern.Init(DEFAULT_PATTERN); pattern.Init(DEFAULT_PATTERN);
// Calcule the clock mod pulses on init. // Calcule the clock mod pulses on init.
_recalculatePulses(); recalculatePulses();
} }
bool isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; } bool inline isCvModActive() const { return cv1_dest != CV_DEST_NONE || cv2_dest != CV_DEST_NONE; }
// Setters (Set the BASE value) // Setters (Set the BASE value)
void setClockMod(int index) { void setClockMod(int index) {
base_clock_mod_index = constrain(index, 0, MOD_CHOICE_SIZE - 1); base_clock_mod_index = constrain(index, 0, MOD_CHOICE_SIZE - 1);
_recalculatePulses(); recalculatePulses();
} }
void setProbability(int prob) { void setProbability(int prob) {
@ -95,16 +95,17 @@ class Channel {
void setDutyCycle(int duty) { void setDutyCycle(int duty) {
base_duty_cycle = constrain(duty, 1, 99); base_duty_cycle = constrain(duty, 1, 99);
_recalculatePulses(); recalculatePulses();
} }
void setOffset(int off) { void setOffset(int off) {
base_offset = constrain(off, 0, 99); base_offset = constrain(off, 0, 99);
_recalculatePulses(); recalculatePulses();
} }
void setSwing(int val) { void setSwing(int val) {
base_swing = constrain(val, 50, 95); base_swing = constrain(val, 50, 95);
_recalculatePulses(); recalculatePulses();
} }
// Euclidean // Euclidean
@ -117,11 +118,11 @@ class Channel {
void setCv1Dest(CvDestination dest) { void setCv1Dest(CvDestination dest) {
cv1_dest = dest; cv1_dest = dest;
_recalculatePulses(); recalculatePulses();
} }
void setCv2Dest(CvDestination dest) { void setCv2Dest(CvDestination dest) {
cv2_dest = dest; cv2_dest = dest;
_recalculatePulses(); recalculatePulses();
} }
CvDestination getCv1Dest() const { return cv1_dest; } CvDestination getCv1Dest() const { return cv1_dest; }
CvDestination getCv2Dest() const { return cv2_dest; } CvDestination getCv2Dest() const { return cv2_dest; }
@ -194,26 +195,22 @@ class Channel {
return; return;
} }
if (isCvModActive()) _recalculatePulses(); int cvmod_probability = base_probability;
if (cv1_dest == CV_DEST_PROB || cv2_dest == CV_DEST_PROB) {
int cv1 = gravity.cv1.Read(); cvmod_probability = getProbabilityWithMod(gravity.cv1.Read(), gravity.cv2.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. // Conditionally apply swing on down beats.
uint16_t swing_pulses = 0; uint16_t swing_pulses = 0;
if (_swing_pulse_amount > 0 && (tick / mod_pulses) % 2 == 1) { if (_swing_pulses > 0 && (tick / _mod_pulses) % 2 == 1) {
swing_pulses = _swing_pulse_amount; swing_pulses = _swing_pulses;
} }
// Duty cycle high check logic // Duty cycle high check logic
const uint32_t current_tick_offset = tick + _offset_pulses + swing_pulses; const uint32_t current_tick_offset = tick + _offset_pulses + swing_pulses;
if (!output.On()) { if (!output.On()) {
// Step check // Step check
if (current_tick_offset % mod_pulses == 0) { if (current_tick_offset % _mod_pulses == 0) {
bool hit = cvmod_probability >= random(0, 100); bool hit = cvmod_probability >= random(0, 100);
// Euclidean rhythm hit check // Euclidean rhythm hit check
switch (pattern.NextStep()) { switch (pattern.NextStep()) {
@ -232,11 +229,31 @@ class Channel {
// Duty cycle low check // Duty cycle low check
const uint32_t duty_cycle_end_tick = tick + _duty_pulses + _offset_pulses + swing_pulses; const uint32_t duty_cycle_end_tick = tick + _duty_pulses + _offset_pulses + swing_pulses;
if (duty_cycle_end_tick % mod_pulses == 0) { if (duty_cycle_end_tick % _mod_pulses == 0) {
output.Low(); output.Low();
} }
} }
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);
_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 (swing > 50) {
int shifted_swing = swing - 50;
_swing_pulses = (long)((_mod_pulses * (100L - shifted_swing)) / 100L);
} else {
_swing_pulses = 0;
}
}
private: private:
int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) { int _calculateMod(CvDestination dest, int cv1_val, int cv2_val, int min_range, int max_range) {
int mod1 = (cv1_dest == dest) ? map(cv1_val, -512, 512, min_range, max_range) : 0; int mod1 = (cv1_dest == dest) ? map(cv1_val, -512, 512, min_range, max_range) : 0;
@ -244,26 +261,6 @@ class Channel {
return mod1 + mod2; return mod1 + mod2;
} }
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);
// Calculate the down beat swing amount.
if (swing > 50) {
int shifted_swing = swing - 50;
_swing_pulse_amount = (long)((mod_pulses * (100L - shifted_swing)) / 100L);
} else {
_swing_pulse_amount = 0;
}
}
// User-settable base values. // User-settable base values.
byte base_clock_mod_index; byte base_clock_mod_index;
byte base_probability; byte base_probability;
@ -282,9 +279,10 @@ class Channel {
bool mute; bool mute;
// Pre-calculated pulse values for ISR performance // Pre-calculated pulse values for ISR performance
uint16_t _mod_pulses;
uint16_t _duty_pulses; uint16_t _duty_pulses;
uint16_t _offset_pulses; uint16_t _offset_pulses;
uint16_t _swing_pulse_amount; uint16_t _swing_pulses;
}; };
#endif // CHANNEL_H #endif // CHANNEL_H

View File

@ -2,8 +2,8 @@
* @file display.h * @file display.h
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *

View File

@ -2,8 +2,8 @@
* @file euclidean.h * @file euclidean.h
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *

View File

@ -2,8 +2,8 @@
* @file save_state.cpp * @file save_state.cpp
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *
@ -17,7 +17,7 @@
// Define the constants for the current firmware. // Define the constants for the current firmware.
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY"; const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
const char StateManager::SEMANTIC_VERSION[] = "2.0.1"; // NOTE: This should match the version in the library.properties file. const char StateManager::SEMANTIC_VERSION[] = "2.0.0"; // NOTE: This should match the version in the library.properties file.
// Number of available save slots. // Number of available save slots.
const byte StateManager::MAX_SAVE_SLOTS = 10; const byte StateManager::MAX_SAVE_SLOTS = 10;

View File

@ -2,8 +2,8 @@
* @file save_state.h * @file save_state.h
* @author Adam Wonak (https://github.com/awonak/) * @author Adam Wonak (https://github.com/awonak/)
* @brief Alt firmware version of Gravity by Sitka Instruments. * @brief Alt firmware version of Gravity by Sitka Instruments.
* @version 2.0.1 * @version 2.0.0
* @date 2025-07-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *

View File

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

View File

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

View File

@ -2,8 +2,8 @@
* @file clock.h * @file clock.h
* @author Adam Wonak (https://github.com/awonak) * @author Adam Wonak (https://github.com/awonak)
* @brief Wrapper Class for clock timing functions. * @brief Wrapper Class for clock timing functions.
* @version 0.1 * @version 2.0.0
* @date 2025-05-04 * @date 2025-08-17
* *
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com * @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
* *

View File

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

View File

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

View File

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

View File

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

View File

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