18 MidiFaderMode midiMode READ midiMode WRITE setMidiMode NOTIFY midiModeChanged)
32 struct FaderProcessingCaches
41 std::vector<dsp::AudioPort *> audio_ins_rt_;
42 std::vector<dsp::AudioPort *> audio_outs_rt_;
83 std::pair<std::span<float>, std::span<float>> stereo_bufs,
97 dsp::PortType signal_type,
98 bool hard_limit_output,
99 bool make_params_automatable,
102 QObject * parent =
nullptr);
111 if (midi_mode_ == mode)
115 Q_EMIT midiModeChanged (mode);
121 if (amp_id_.has_value ())
123 return &get_amp_param ();
127 zrythm::dsp::ProcessorParameter * balance ()
const
129 if (balance_id_.has_value ())
131 return &get_balance_param ();
135 zrythm::dsp::ProcessorParameter * mute ()
const
137 if (mute_id_.has_value ())
139 return &get_mute_param ();
143 zrythm::dsp::ProcessorParameter * solo ()
const
145 if (solo_id_.has_value ())
147 return &get_solo_param ();
151 zrythm::dsp::ProcessorParameter * listen ()
const
153 if (listen_id_.has_value ())
155 return &get_listen_param ();
159 zrythm::dsp::ProcessorParameter * monoToggle ()
const
161 if (mono_compat_enabled_id_.has_value ())
163 return &get_mono_compat_enabled_param ();
167 zrythm::dsp::ProcessorParameter * swapPhaseToggle ()
const
169 if (swap_phase_id_.has_value ())
171 return &get_swap_phase_param ();
183 const auto &mute_param = get_mute_param ();
184 return mute_param.range ().isToggled (mute_param.currentValue ());
192 const auto &solo_param = get_solo_param ();
193 return solo_param.range ().isToggled (solo_param.currentValue ());
201 const auto &listened_param = get_listen_param ();
202 return listened_param.range ().isToggled (listened_param.currentValue ());
210 const auto &_param = get_amp_param ();
211 return amp_param.range ().convertFrom0To1 (amp_param.currentValue ());
214 std::string db_string_getter ()
const;
218 mute_gain_cb_ = std::move (cb);
223 preprocess_audio_cb_ = std::move (cb);
230 void custom_prepare_for_processing (
231 const graph::GraphNode * node,
232 units::sample_rate_t sample_rate,
233 units::sample_u32_t max_block_length)
override;
235 void custom_release_resources ()
override;
240 const dsp::TempoMap &tempo_map)
noexcept override;
244 bool is_audio ()
const {
return signal_type_ == dsp::PortType::Audio; }
245 bool is_midi ()
const {
return signal_type_ == dsp::PortType::Midi; }
247 bool hard_limiting_enabled ()
const {
return hard_limit_output_; }
252 dsp::ProcessorParameter &get_amp_param ()
const;
253 dsp::ProcessorParameter &get_balance_param ()
const;
254 dsp::ProcessorParameter &get_mute_param ()
const;
255 dsp::ProcessorParameter &get_solo_param ()
const;
256 dsp::ProcessorParameter &get_listen_param ()
const;
257 dsp::ProcessorParameter &get_mono_compat_enabled_param ()
const;
258 dsp::ProcessorParameter &get_swap_phase_param ()
const;
259 dsp::AudioPort &get_stereo_in_port ()
const
263 throw std::runtime_error (
"Not an audio fader");
265 return *get_input_ports ().at (0).get_object_as<dsp::AudioPort> ();
267 dsp::AudioPort &get_stereo_out_port ()
const
271 throw std::runtime_error (
"Not an audio fader");
273 return *get_output_ports ().at (0).get_object_as<dsp::AudioPort> ();
275 dsp::MidiPort &get_midi_in_port ()
const
277 return *get_input_ports ().front ().get_object_as<dsp::MidiPort> ();
279 dsp::MidiPort &get_midi_out_port ()
const
281 return *get_output_ports ().front ().get_object_as<dsp::MidiPort> ();
284 auto currently_soloed_rt () const noexcept [[clang::nonblocking]]
286 return processing_caches_->solo_param_->range ().isToggled (
287 processing_caches_->solo_param_->currentValue ());
290 bool currently_listened_rt () const noexcept [[clang::nonblocking]]
292 const auto &listened_param = processing_caches_->listen_param_;
293 return listened_param->range ().isToggled (listened_param->currentValue ());
297 static constexpr auto kMidiModeKey =
"midiMode"sv;
298 friend void to_json (nlohmann::json &j,
const Fader &fader);
299 friend void from_json (
const nlohmann::json &j,
Fader &fader);
307 void init_param_caches ();
313 float calculate_target_gain_rt ()
const;
315 bool effectively_muted ()
const
320 bool effectively_muted_rt ()
const
322 const auto currently_muted_rt = [
this] () {
323 return processing_caches_->mute_param_->range ().isToggled (
324 processing_caches_->mute_param_->currentValue ());
327 return currently_muted_rt () || should_be_muted_cb_ (currently_soloed_rt ());
331 dsp::PortType signal_type_;
333 bool hard_limit_output_{};
342 float last_cc_volume_ = 0.f;
347 std::optional<dsp::ProcessorParameter::Uuid> amp_id_;
350 std::optional<dsp::ProcessorParameter::Uuid> balance_id_;
355 std::optional<dsp::ProcessorParameter::Uuid> mute_id_;
358 std::optional<dsp::ProcessorParameter::Uuid> solo_id_;
361 std::optional<dsp::ProcessorParameter::Uuid> listen_id_;
364 std::optional<dsp::ProcessorParameter::Uuid> mono_compat_enabled_id_;
367 std::optional<dsp::ProcessorParameter::Uuid> swap_phase_id_;
379 juce::SmoothedValue<float> current_gain_{ 0.f };
383 std::optional<PreProcessAudioCallback> preprocess_audio_cb_;
388 std::unique_ptr<FaderProcessingCaches> processing_caches_;