Skip to content

Commit

Permalink
Merge pull request #205 from 4ms/gates-sense-fix
Browse files Browse the repository at this point in the history
Gates sense fix, and support SmartCoreProcessor checking if outputs are patched
  • Loading branch information
danngreen authored Feb 21, 2024
2 parents 1c90002 + c1eb301 commit b29d396
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
18 changes: 9 additions & 9 deletions firmware/src/audio/audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ void AudioStream::handle_patch_just_loaded() {
void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_block) {
handle_patch_mods(patch_mod_queue, player);

propagate_sense_pins(param_block.params[0]);

// TODO: handle second codec
if (ext_audio_connected)
AudioTestSignal::passthrough(audio_block.in_ext_codec, audio_block.out_ext_codec);
Expand All @@ -186,13 +184,14 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_blo
}

// Gate inputs
for (auto [i, gatein] : countzip(params.gate_ins)) {
if (!jack_is_patched(param_state.jack_senses, i + FirstGateInput))
gatein.register_state(false);
if (gatein.just_went_high())
player.set_panel_input(i + FirstGateInput, 8.f);
if (gatein.just_went_low())
player.set_panel_input(i + FirstGateInput, 0.f);
for (auto [i, gatein, sync_gatein] : countzip(params.gate_ins, param_state.gate_ins)) {

if (!jack_is_patched(param_state.jack_senses, i + FirstGateInput)) {
gatein = false;
} else
player.set_panel_input(i + FirstGateInput, gatein ? 8.f : 0.f);

sync_gatein.register_state(gatein);
}

// Pass Knob values to modules
Expand All @@ -214,6 +213,7 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock &param_blo
}

player.update_lights();
propagate_sense_pins(param_block.params[0]);
}

void AudioStream::process_nopatch(CombinedAudioBlock &audio_block, ParamBlock &param_block) {
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/core_m4/controls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void Controls::update_debouncers() {
}

void Controls::update_params() {
cur_params->gate_ins[0].copy_state(gate_in_1);
cur_params->gate_ins[1].copy_state(gate_in_2);
cur_params->gate_ins[0] = gate_in_1.is_high();
cur_params->gate_ins[1] = gate_in_2.is_high();

// Interpolate knob readings across the param block, since we capture them at a slower rate than audio process
if (_new_adc_data_ready) {
Expand Down
1 change: 0 additions & 1 deletion firmware/src/medium/conf/jack_sense_conf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ constexpr inline unsigned jacksense_pin_order[16] = {14, 11, 15, 13, 10, 8, 12,

constexpr inline bool jack_is_patched(uint32_t jack_sense_reading, unsigned panel_jack_idx) {
return (jack_sense_reading >> jacksense_pin_order[panel_jack_idx]) & 1;
// return jack_sense_reading & (1 << jacksense_pin_order[panel_jack_idx]);
}
8 changes: 4 additions & 4 deletions firmware/src/params/params.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace MetaModule
{
struct Params {
std::array<float, PanelDef::NumCVIn> cvjacks{};
std::array<Toggler, PanelDef::NumGateIn> gate_ins{};
std::array<bool, PanelDef::NumGateIn> gate_ins{};
std::array<Toggler, PanelDef::NumRgbButton> buttons{};
std::array<float, PanelDef::NumPot> knobs{};

Midi::Event midi_event;

uint32_t jack_senses;
uint32_t jack_senses{};

Params() {
clear();
Expand All @@ -26,7 +26,7 @@ struct Params {
for (float &cvjack : cvjacks)
cvjack = 0.f;
for (auto &gate_in : gate_ins)
gate_in.reset();
gate_in = false;
for (auto &button : buttons)
button.reset();
for (float &knob : knobs)
Expand All @@ -41,7 +41,7 @@ struct Params {
for (unsigned i = 0; i < PanelDef::NumCVIn; i++)
cvjacks[i] = that.cvjacks[i];
for (unsigned i = 0; i < PanelDef::NumGateIn; i++)
gate_ins[i].copy_state(that.gate_ins[i]);
gate_ins[i] = that.gate_ins[i];
for (unsigned i = 0; i < PanelDef::NumRgbButton; i++)
buttons[i].copy_state(that.buttons[i]);
for (unsigned i = 0; i < PanelDef::NumPot; i++)
Expand Down
50 changes: 39 additions & 11 deletions shared/CoreModules/SmartCoreProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ protected:
outputValues[idx.output_idx] = val;
}

template<Elem EL>
bool isPatched() requires(count(EL).num_outputs == 1)
{
auto idx = index(EL);
return outputPatched[idx.output_idx];
}

template<Elem EL>
bool isPatched() requires(count(EL).num_inputs == 1)
{
auto idx = index(EL);
return inputValues[idx.input_idx].has_value();
}

template<Elem EL>
std::optional<float> getInput() requires(count(EL).num_inputs == 1)
{
Expand Down Expand Up @@ -98,7 +112,15 @@ private:
ledValues[led_idx] = val;
}

protected:
constexpr static auto counts = ElementCount::count<INFO>();
constexpr static auto indices = ElementCount::get_indices<INFO>();

constexpr static auto index(Elem el) {
auto element_idx = element_index(el);
return indices[element_idx];
}

public:
float get_output(int output_id) const override {
if (output_id < (int)outputValues.size())
return outputValues[output_id]; // Note: this undoes what CommModule does
Expand All @@ -124,31 +146,37 @@ protected:
}
}

private:
constexpr static auto counts = ElementCount::count<INFO>();
constexpr static auto indices = ElementCount::get_indices<INFO>();

constexpr static auto index(Elem el) {
auto element_idx = element_index(el);
return indices[element_idx];
}

private:
void mark_all_inputs_unpatched() override {
std::fill(inputValues.begin(), inputValues.end(), std::nullopt);
}

void mark_input_unpatched(const int input_id) override {
inputValues[input_id].reset();
}

void mark_input_patched(const int input_id) override {
// do nothing here
// value will be set by next update
}

void mark_all_outputs_unpatched() override {
std::fill(outputPatched.begin(), outputPatched.end(), false);
}

void mark_output_unpatched(int output_id) override {
outputPatched[output_id] = false;
}

void mark_output_patched(int output_id) override {
outputPatched[output_id] = true;
}

private:
std::array<float, counts.num_params> paramValues{};
std::array<std::optional<float>, counts.num_inputs> inputValues{0};
std::array<float, counts.num_outputs> outputValues{};
std::array<float, counts.num_lights> ledValues{};
std::array<bool, counts.num_outputs> outputPatched{};
};

} // namespace MetaModule

0 comments on commit b29d396

Please sign in to comment.