Add per-channel CV Input mod configuration #4

Merged
awonak merged 6 commits from refs/pull/4/head into main 2025-06-14 21:26:34 +00:00
4 changed files with 185 additions and 59 deletions
Showing only changes of commit b733915232 - Show all commits

View File

@ -88,7 +88,7 @@ void loop() {
// Process change in state of inputs and outputs. // Process change in state of inputs and outputs.
gravity.Process(); gravity.Process();
// NEW: Read CVs and call the main-loop-safe update function for each channel. // Read CVs and call the update function for each channel.
int cv1 = gravity.cv1.Read(); int cv1 = gravity.cv1.Read();
int cv2 = gravity.cv2.Read(); int cv2 = gravity.cv2.Read();
for (int i = 0; i < OUTPUT_COUNT; i++) { for (int i = 0; i < OUTPUT_COUNT; i++) {

View File

@ -4,7 +4,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <gravity.h> #include <gravity.h>
// Enums for CV configuration (still needed) // Enums for CV configuration
enum CvSource { enum CvSource {
CV_NONE, CV_NONE,
CV_1, CV_1,
@ -66,7 +66,7 @@ class Channel {
* @param output The output object to be modified. * @param output The output object to be modified.
*/ */
void processClockTick(uint32_t tick, DigitalOutput& output) { void processClockTick(uint32_t tick, DigitalOutput& output) {
// Use pre-calculated final values // Calculate output duty cycle state using cv modded values to determine pulse counts.
const uint32_t mod_pulses = clock_mod_pulses[cvmod_clock_mod_index]; const uint32_t mod_pulses = clock_mod_pulses[cvmod_clock_mod_index];
const uint32_t duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L); const uint32_t duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L);
const uint32_t offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L); const uint32_t offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L);
@ -89,7 +89,7 @@ class Channel {
void applyCvMod(int cv1_value, int cv2_value) { void applyCvMod(int cv1_value, int cv2_value) {
if (!isCvModActive()) { if (!isCvModActive()) {
// If CV is off, ensure final values match the base values. // If CV is off, ensure cv modded values match the base values.
cvmod_clock_mod_index = base_clock_mod_index; cvmod_clock_mod_index = base_clock_mod_index;
cvmod_probability = base_probability; cvmod_probability = base_probability;
cvmod_duty_cycle = base_duty_cycle; cvmod_duty_cycle = base_duty_cycle;
@ -97,10 +97,10 @@ class Channel {
return; return;
} }
// The channel knows its own config, so it selects the correct CV value. // Use the CV value for current selected cv source.
int value = (cv_source == CV_1) ? cv1_value : cv2_value; int value = (cv_source == CV_1) ? cv1_value : cv2_value;
// Calculate and store final values using bipolar mapping. // Calculate and store cv modded values using bipolar mapping.
// Default to base value if not the current CV destination. // Default to base value if not the current CV destination.
cvmod_clock_mod_index = (cv_destination == CV_DEST_MOD) cvmod_clock_mod_index = (cv_destination == CV_DEST_MOD)
@ -128,10 +128,10 @@ class Channel {
byte base_offset = 0; byte base_offset = 0;
// Base value with cv mod applied. // Base value with cv mod applied.
volatile byte cvmod_clock_mod_index; byte cvmod_clock_mod_index;
volatile byte cvmod_probability; byte cvmod_probability;
volatile byte cvmod_duty_cycle; byte cvmod_duty_cycle;
volatile byte cvmod_offset; byte cvmod_offset;
int duty_cycle_pulses; int duty_cycle_pulses;
int offset_pulses; int offset_pulses;