diff --git a/firmware/src/audio/audio.cc b/firmware/src/audio/audio.cc index de93cd6c4..cc7657159 100644 --- a/firmware/src/audio/audio.cc +++ b/firmware/src/audio/audio.cc @@ -162,8 +162,6 @@ void AudioStream::handle_patch_just_loaded() { void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock ¶m_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); @@ -186,13 +184,14 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock ¶m_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 @@ -214,6 +213,7 @@ void AudioStream::process(CombinedAudioBlock &audio_block, ParamBlock ¶m_blo } player.update_lights(); + propagate_sense_pins(param_block.params[0]); } void AudioStream::process_nopatch(CombinedAudioBlock &audio_block, ParamBlock ¶m_block) { diff --git a/firmware/src/core_m4/controls.cc b/firmware/src/core_m4/controls.cc index 0cf71b5a5..5bc08483c 100644 --- a/firmware/src/core_m4/controls.cc +++ b/firmware/src/core_m4/controls.cc @@ -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) { diff --git a/firmware/src/medium/conf/jack_sense_conf.hh b/firmware/src/medium/conf/jack_sense_conf.hh index 9e4b72df5..8c5174cfa 100644 --- a/firmware/src/medium/conf/jack_sense_conf.hh +++ b/firmware/src/medium/conf/jack_sense_conf.hh @@ -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]); } diff --git a/firmware/src/params/params.hh b/firmware/src/params/params.hh index 86f13ae61..c9d60d79a 100644 --- a/firmware/src/params/params.hh +++ b/firmware/src/params/params.hh @@ -10,13 +10,13 @@ namespace MetaModule { struct Params { std::array cvjacks{}; - std::array gate_ins{}; + std::array gate_ins{}; std::array buttons{}; std::array knobs{}; Midi::Event midi_event; - uint32_t jack_senses; + uint32_t jack_senses{}; Params() { clear(); @@ -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) @@ -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++) diff --git a/shared/CoreModules/SmartCoreProcessor.hh b/shared/CoreModules/SmartCoreProcessor.hh index d43e414bb..0c3a07eba 100644 --- a/shared/CoreModules/SmartCoreProcessor.hh +++ b/shared/CoreModules/SmartCoreProcessor.hh @@ -29,6 +29,20 @@ protected: outputValues[idx.output_idx] = val; } + template + bool isPatched() requires(count(EL).num_outputs == 1) + { + auto idx = index(EL); + return outputPatched[idx.output_idx]; + } + + template + bool isPatched() requires(count(EL).num_inputs == 1) + { + auto idx = index(EL); + return inputValues[idx.input_idx].has_value(); + } + template std::optional getInput() requires(count(EL).num_inputs == 1) { @@ -98,7 +112,15 @@ private: ledValues[led_idx] = val; } -protected: + constexpr static auto counts = ElementCount::count(); + constexpr static auto indices = ElementCount::get_indices(); + + 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 @@ -124,31 +146,37 @@ protected: } } -private: - constexpr static auto counts = ElementCount::count(); - constexpr static auto indices = ElementCount::get_indices(); - - 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 paramValues{}; std::array, counts.num_inputs> inputValues{0}; std::array outputValues{}; std::array ledValues{}; + std::array outputPatched{}; }; } // namespace MetaModule