Skip to content

Commit

Permalink
Fix FFT-related attributes not being applied after being changed in t…
Browse files Browse the repository at this point in the history
…he UI
  • Loading branch information
Limeth committed Nov 25, 2020
1 parent 204c2e9 commit c22a918
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions src/effect/effect_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl BindableProperty for EffectParamCustomColor {
pub struct EffectParamCustomFFT {
pub effect_param: EffectParamTexture,
pub effect_param_previous: Option<EffectParamTexture>,
pub audio_fft: Arc<GlobalStateAudioFFT>,
pub audio_fft: Option<Arc<GlobalStateAudioFFT>>,
pub property_mix: LoadedValueTypeProperty<LoadedValueTypePropertyDescriptorI32>,
pub property_channel: LoadedValueTypeProperty<LoadedValueTypePropertyDescriptorI32>,
pub property_dampening_factor_attack: LoadedValueTypeProperty<LoadedValueTypePropertyDescriptorF64>,
Expand Down Expand Up @@ -558,15 +558,32 @@ impl EffectParamCustomFFT {
WindowFunction::Hanning,
);

Ok(Self {
let mut result = Self {
effect_param: EffectParam::new(param.disable()),
effect_param_previous: param_previous.map(|param_previous| EffectParam::new(param_previous.disable())),
audio_fft: GLOBAL_STATE.request_audio_fft(&audio_fft_descriptor),
audio_fft: None,
property_mix,
property_channel,
property_dampening_factor_attack,
property_dampening_factor_release,
})
};

result.request_audio_fft();

Ok(result)
}

fn request_audio_fft(&mut self) {
let audio_fft_descriptor = GlobalStateAudioFFTDescriptor::new(
self.property_mix.get_value() as usize - 1,
self.property_channel.get_value() as usize - 1,
self.property_dampening_factor_attack.get_value() / 100.0,
self.property_dampening_factor_release.get_value() / 100.0,
// TODO: Make customizable, but provide a sane default value
WindowFunction::Hanning,
);

self.audio_fft = Some(GLOBAL_STATE.request_audio_fft(&audio_fft_descriptor));
}
}

Expand All @@ -583,10 +600,11 @@ impl BindableProperty for EffectParamCustomFFT {
self.property_channel.reload_settings(settings);
self.property_dampening_factor_attack.reload_settings(settings);
self.property_dampening_factor_release.reload_settings(settings);
self.request_audio_fft();
}

fn prepare_values(&mut self) {
let fft_result = if let Some(result) = self.audio_fft.retrieve_result() {
let fft_result = if let Some(result) = self.audio_fft.as_mut().unwrap().retrieve_result() {
result
} else {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl WindowFunction {
}
}

#[derive(Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct GlobalStateAudioFFTDescriptor {
mix: usize,
channel: usize,
Expand Down

0 comments on commit c22a918

Please sign in to comment.