20 MidiFaderMode midiMode READ midiMode WRITE setMidiMode NOTIFY midiModeChanged)
34 struct FaderProcessingCaches
43 std::vector<dsp::AudioPort *> audio_ins_rt_;
44 std::vector<dsp::AudioPort *> audio_outs_rt_;
86 std::pair<std::span<float>, std::span<float>> stereo_bufs,
100 dsp::PortType signal_type,
101 bool hard_limit_output,
102 bool make_params_automatable,
105 QObject * parent =
nullptr);
111 MidiFaderMode midiMode ()
const {
return midi_mode_.load (); }
114 if (midi_mode_.load () == mode)
117 midi_mode_.store (mode);
118 Q_EMIT midiModeChanged (mode);
124 if (amp_id_.has_value ())
126 return &get_amp_param ();
130 zrythm::dsp::ProcessorParameter * balance ()
const
132 if (balance_id_.has_value ())
134 return &get_balance_param ();
138 zrythm::dsp::ProcessorParameter * mute ()
const
140 if (mute_id_.has_value ())
142 return &get_mute_param ();
146 zrythm::dsp::ProcessorParameter * solo ()
const
148 if (solo_id_.has_value ())
150 return &get_solo_param ();
154 zrythm::dsp::ProcessorParameter * listen ()
const
156 if (listen_id_.has_value ())
158 return &get_listen_param ();
162 zrythm::dsp::ProcessorParameter * monoToggle ()
const
164 if (mono_compat_enabled_id_.has_value ())
166 return &get_mono_compat_enabled_param ();
170 zrythm::dsp::ProcessorParameter * swapPhaseToggle ()
const
172 if (swap_phase_id_.has_value ())
174 return &get_swap_phase_param ();
186 const auto &mute_param = get_mute_param ();
187 return mute_param.range ().isToggled (mute_param.currentValue ());
195 const auto &solo_param = get_solo_param ();
196 return solo_param.range ().isToggled (solo_param.currentValue ());
204 const auto &listened_param = get_listen_param ();
205 return listened_param.range ().isToggled (listened_param.currentValue ());
213 const auto &_param = get_amp_param ();
214 return amp_param.range ().convertFrom0To1 (amp_param.currentValue ());
217 std::string db_string_getter ()
const;
221 mute_gain_cb_ = std::move (cb);
226 preprocess_audio_cb_ = std::move (cb);
233 void custom_prepare_for_processing (
234 const graph::GraphNode * node,
235 units::sample_rate_t sample_rate,
236 units::sample_u32_t max_block_length)
override;
238 void custom_release_resources ()
override;
243 const dsp::TempoMap &tempo_map)
noexcept override;
247 bool is_audio ()
const {
return signal_type_ == dsp::PortType::Audio; }
248 bool is_midi ()
const {
return signal_type_ == dsp::PortType::Midi; }
250 bool hard_limiting_enabled ()
const {
return hard_limit_output_; }
255 dsp::ProcessorParameter &get_amp_param ()
const;
256 dsp::ProcessorParameter &get_balance_param ()
const;
257 dsp::ProcessorParameter &get_mute_param ()
const;
258 dsp::ProcessorParameter &get_solo_param ()
const;
259 dsp::ProcessorParameter &get_listen_param ()
const;
260 dsp::ProcessorParameter &get_mono_compat_enabled_param ()
const;
261 dsp::ProcessorParameter &get_swap_phase_param ()
const;
262 dsp::AudioPort &get_stereo_in_port ()
const
266 throw std::runtime_error (
"Not an audio fader");
268 return *get_input_ports ().at (0).get_object_as<dsp::AudioPort> ();
270 dsp::AudioPort &get_stereo_out_port ()
const
274 throw std::runtime_error (
"Not an audio fader");
276 return *get_output_ports ().at (0).get_object_as<dsp::AudioPort> ();
278 dsp::MidiPort &get_midi_in_port ()
const
280 return *get_input_ports ().front ().get_object_as<dsp::MidiPort> ();
282 dsp::MidiPort &get_midi_out_port ()
const
284 return *get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
287 auto currently_soloed_rt () const noexcept [[clang::nonblocking]]
289 return processing_caches_->solo_param_->range ().isToggled (
290 processing_caches_->solo_param_->currentValue ());
293 bool currently_listened_rt () const noexcept [[clang::nonblocking]]
295 const auto &listened_param = processing_caches_->listen_param_;
296 return listened_param->range ().isToggled (listened_param->currentValue ());
300 static constexpr auto kMidiModeKey =
"midiMode"sv;
301 friend void to_json (nlohmann::json &j,
const Fader &fader);
302 friend void from_json (
const nlohmann::json &j,
Fader &fader);
310 void init_param_caches ();
316 float calculate_target_gain_rt ()
const;
318 bool effectively_muted ()
const
323 bool effectively_muted_rt ()
const
325 const auto currently_muted_rt = [
this] () {
326 return processing_caches_->mute_param_->range ().isToggled (
327 processing_caches_->mute_param_->currentValue ());
330 return currently_muted_rt () || should_be_muted_cb_ (currently_soloed_rt ());
334 dsp::PortType signal_type_;
336 bool hard_limit_output_{};
345 float last_cc_volume_ = 0.f;
350 std::optional<dsp::ProcessorParameter::Uuid> amp_id_;
353 std::optional<dsp::ProcessorParameter::Uuid> balance_id_;
358 std::optional<dsp::ProcessorParameter::Uuid> mute_id_;
361 std::optional<dsp::ProcessorParameter::Uuid> solo_id_;
364 std::optional<dsp::ProcessorParameter::Uuid> listen_id_;
367 std::optional<dsp::ProcessorParameter::Uuid> mono_compat_enabled_id_;
370 std::optional<dsp::ProcessorParameter::Uuid> swap_phase_id_;
372 std::atomic<MidiFaderMode> midi_mode_{
383 juce::SmoothedValue<float> current_gain_{ 0.f };
387 std::optional<PreProcessAudioCallback> preprocess_audio_cb_;
392 std::unique_ptr<FaderProcessingCaches> processing_caches_;