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 e11a783dd8 - Show all commits

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
docs docs
.vscode .vscode
.DS_Store

View File

@ -47,7 +47,7 @@ class Channel {
void setCvSource(CvSource source) { cv_source = source; } void setCvSource(CvSource source) { cv_source = source; }
void setCvDestination(CvDestination dest) { cv_destination = dest; } void setCvDestination(CvDestination dest) { cv_destination = dest; }
// Getters (Get the BASE value for the UI) // Getters (Get the BASE value for editing or cv modded value for display)
int getProbability(bool withCvMod = false) const { return withCvMod ? cvmod_probability : base_probability; } 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 getDutyCycle(bool withCvMod = false) const { return withCvMod ? cvmod_duty_cycle : base_duty_cycle; }
@ -63,7 +63,7 @@ class Channel {
/** /**
* @brief Processes a clock tick and determines if the output should be high or low. * @brief Processes a clock tick and determines if the output should be high or low.
* @param tick The current clock tick count. * @param tick The current clock tick count.
* @param output The output object (or a reference to its state) 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 // Use pre-calculated final values
@ -121,33 +121,24 @@ class Channel {
} }
private: private:
/**
* @brief Recalculates pulse values based on current channel settings.
* Should be called whenever mod, duty cycle, or offset changes.
*/
void updatePulses() {
const uint32_t mod_pulses = clock_mod_pulses[cvmod_clock_mod_index];
duty_cycle_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L);
offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L);
}
// User-settable "base" values. // User-settable "base" values.
byte base_clock_mod_index = 7; byte base_clock_mod_index = 7;
byte base_probability = 100; byte base_probability = 100;
byte base_duty_cycle = 50; byte base_duty_cycle = 50;
byte base_offset = 0; byte base_offset = 0;
// Base value with cv mod applied.
volatile byte cvmod_clock_mod_index;
volatile byte cvmod_probability;
volatile byte cvmod_duty_cycle;
volatile byte cvmod_offset;
int duty_cycle_pulses; int duty_cycle_pulses;
int offset_pulses; int offset_pulses;
// CV configuration // CV configuration
CvSource cv_source = CV_NONE; CvSource cv_source = CV_NONE;
CvDestination cv_destination = CV_DEST_NONE; CvDestination cv_destination = CV_DEST_NONE;
volatile byte cvmod_clock_mod_index;
volatile byte cvmod_probability;
volatile byte cvmod_duty_cycle;
volatile byte cvmod_offset;
}; };
#endif // CHANNEL_H #endif // CHANNEL_H

View File

@ -19,7 +19,7 @@
// Peripheral input pins // Peripheral input pins
#define ENCODER_PIN1 17 // A3 #define ENCODER_PIN1 17 // A3
#define ENCODER_PIN2 4 #define ENCODER_PIN2 4
#define ENCODER_SW_PIN 14 #define ENCODER_SW_PIN 14 // A0
// Clock and CV Inputs // Clock and CV Inputs
#define EXT_PIN 2 #define EXT_PIN 2