Skip to content

Commit 30f4621

Browse files
committed
add default values for nodes with const generics
1 parent b0f37eb commit 30f4621

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

crates/firewheel-nodes/src/convolution.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use firewheel_core::{
2020
sample_resource::SampleResourceF32,
2121
};
2222

23+
pub type ConvolutionNodeMono = ConvolutionNode<1>;
24+
pub type ConvolutionNodeStereo = ConvolutionNode<2>;
25+
2326
/// Imparts characteristics of an [`ImpulseResponse`] to the input signal.
2427
///
2528
/// Convolution is often used to achieve reverb effects, but is more
@@ -28,7 +31,7 @@ use firewheel_core::{
2831
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
2932
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
3033
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31-
pub struct ConvolutionNode<const CHANNELS: usize> {
34+
pub struct ConvolutionNode<const CHANNELS: usize = 2> {
3235
/// Pause the convolution processing.
3336
///
3437
/// This prevents a tail from ringing out when you want all sound to
@@ -63,12 +66,15 @@ pub struct ConvolutionNode<const CHANNELS: usize> {
6366
pub smooth_seconds: f32,
6467
}
6568

69+
pub type ConvolutionNodeConfigMono = ConvolutionNodeConfig<1>;
70+
pub type ConvolutionNodeConfigStereo = ConvolutionNodeConfig<2>;
71+
6672
/// Node configuration for [`ConvolutionNode`].
6773
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6874
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
6975
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
7076
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
71-
pub struct ConvolutionNodeConfig<const CHANNELS: usize> {
77+
pub struct ConvolutionNodeConfig<const CHANNELS: usize = 2> {
7278
/// The maximum number of supported IR channels (must be
7379
/// `ChannelCount::MONO` or `ChannelCount::STEREO`). This determines the
7480
/// number of buffers allocated. Loading an impulse response with more

crates/firewheel-nodes/src/fast_filters/bandpass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub type FastBandpassStereoNode = FastBandpassNode<2>;
3232
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
3333
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
3434
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35-
pub struct FastBandpassNode<const CHANNELS: usize> {
35+
pub struct FastBandpassNode<const CHANNELS: usize = 2> {
3636
/// The cutoff frequency in hertz in the range `[20.0, 20480.0]`.
3737
pub cutoff_hz: f32,
3838
/// Whether or not this node is enabled.

crates/firewheel-nodes/src/fast_filters/highpass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub type FastHighpassStereoNode = FastHighpassNode<2>;
2929
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
3030
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
3131
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
32-
pub struct FastHighpassNode<const CHANNELS: usize> {
32+
pub struct FastHighpassNode<const CHANNELS: usize = 2> {
3333
/// The cutoff frequency in hertz in the range `[20.0, 20480.0]`.
3434
pub cutoff_hz: f32,
3535
/// Whether or not this node is enabled.

crates/firewheel-nodes/src/fast_filters/lowpass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub type FastLowpassStereoNode = FastLowpassNode<2>;
2828
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
2929
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
3030
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31-
pub struct FastLowpassNode<const CHANNELS: usize> {
31+
pub struct FastLowpassNode<const CHANNELS: usize = 2> {
3232
/// The cutoff frequency in hertz in the range `[20.0, 20480.0]`.
3333
pub cutoff_hz: f32,
3434
/// Whether or not this node is enabled.

crates/firewheel-nodes/src/peak_meter.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ impl Default for PeakMeterSmootherConfig {
4747
}
4848
}
4949

50+
pub type PeakMeterSmootherMono = PeakMeterSmoother<1>;
51+
pub type PeakMeterSmootherStereo = PeakMeterSmoother<2>;
52+
5053
/// A helper struct to smooth out the output of [`PeakMeterNode`]. This
5154
/// can be used to drive the animation of a peak meter in a GUI.
5255
#[derive(Debug, Clone, Copy)]
53-
pub struct PeakMeterSmoother<const NUM_CHANNELS: usize> {
56+
pub struct PeakMeterSmoother<const NUM_CHANNELS: usize = 2> {
5457
/// The current smoothed peak value of each channel, in decibels.
5558
smoothed_peaks: [f32; NUM_CHANNELS],
5659
clipped_frames_left: [usize; NUM_CHANNELS],
@@ -158,19 +161,25 @@ impl<const NUM_CHANNELS: usize> PeakMeterSmoother<NUM_CHANNELS> {
158161
}
159162
}
160163

164+
pub type PeakMeterNodeMono = PeakMeterNode<1>;
165+
pub type PeakMeterNodeStereo = PeakMeterNode<2>;
166+
161167
/// A node that calculates the peak amplitude of a signal, and then sends that value
162168
/// to [`PeakMeterState`].
163169
#[derive(Diff, Patch, Debug, Clone, Copy, PartialEq, Eq)]
164170
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))]
165171
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
166172
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
167-
pub struct PeakMeterNode<const NUM_CHANNELS: usize> {
173+
pub struct PeakMeterNode<const NUM_CHANNELS: usize = 2> {
168174
pub enabled: bool,
169175
}
170176

177+
pub type PeakMeterStateMono = PeakMeterState<1>;
178+
pub type PeakMeterStateStereo = PeakMeterState<2>;
179+
171180
/// The state of a [`PeakMeterNode`]. This contains the calculated peak values.
172181
#[derive(Clone)]
173-
pub struct PeakMeterState<const NUM_CHANNELS: usize> {
182+
pub struct PeakMeterState<const NUM_CHANNELS: usize = 2> {
174183
shared_state: ArcGc<SharedState<NUM_CHANNELS>>,
175184
}
176185

crates/firewheel-nodes/src/svf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ pub enum SvfType {
9898
Allpass,
9999
}
100100

101+
pub type SvfNodeMono = SvfNode<1>;
102+
pub type SvfNodeStereo = SvfNode<2>;
103+
101104
/// An SVF (state variable filter) node
102105
///
103106
/// This is based on the filter model developed by Andrew Simper:
@@ -106,7 +109,7 @@ pub enum SvfType {
106109
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
107110
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
108111
#[derive(Diff, Patch, Debug, Clone, Copy, PartialEq)]
109-
pub struct SvfNode<const CHANNELS: usize> {
112+
pub struct SvfNode<const CHANNELS: usize = 2> {
110113
/// The type of filter
111114
pub filter_type: SvfType,
112115

0 commit comments

Comments
 (0)