firewheel_pool/
spatial_basic.rs1#[cfg(not(feature = "std"))]
2use bevy_platform::prelude::{vec, Vec};
3
4#[cfg(feature = "scheduled_events")]
5use firewheel_core::clock::EventInstant;
6
7use firewheel_core::{channel_config::NonZeroChannelCount, diff::Diff, node::NodeID};
8use firewheel_graph::{backend::AudioBackend, FirewheelCtx};
9
10use crate::FxChain;
11
12#[derive(Default, Debug, Clone, Copy, PartialEq)]
16pub struct SpatialBasicChain {
17 pub spatial_basic: firewheel_nodes::spatial_basic::SpatialBasicNode,
18}
19
20impl SpatialBasicChain {
21 pub fn set_params<B: AudioBackend>(
28 &mut self,
29 params: firewheel_nodes::spatial_basic::SpatialBasicNode,
30 #[cfg(feature = "scheduled_events")] time: Option<EventInstant>,
31 node_ids: &[NodeID],
32 cx: &mut FirewheelCtx<B>,
33 ) {
34 use firewheel_core::diff::PathBuilder;
35
36 let node_id = node_ids[0];
37
38 self.spatial_basic.diff(
39 ¶ms,
40 PathBuilder::default(),
41 #[cfg(not(feature = "scheduled_events"))]
42 &mut cx.event_queue(node_id),
43 #[cfg(feature = "scheduled_events")]
44 &mut cx.event_queue_scheduled(node_id, time),
45 );
46 }
47}
48
49impl FxChain for SpatialBasicChain {
50 fn construct_and_connect<B: AudioBackend>(
51 &mut self,
52 first_node_id: NodeID,
53 first_node_num_out_channels: NonZeroChannelCount,
54 dst_node_id: NodeID,
55 dst_num_channels: NonZeroChannelCount,
56 cx: &mut FirewheelCtx<B>,
57 ) -> Vec<NodeID> {
58 let spatial_basic_params = firewheel_nodes::spatial_basic::SpatialBasicNode::default();
59
60 let spatial_basic_node_id = cx.add_node(spatial_basic_params, None);
61
62 cx.connect(
63 first_node_id,
64 spatial_basic_node_id,
65 if first_node_num_out_channels.get().get() == 1 {
66 &[(0, 0), (0, 1)]
67 } else {
68 &[(0, 0), (1, 1)]
69 },
70 false,
71 )
72 .unwrap();
73
74 cx.connect(
75 spatial_basic_node_id,
76 dst_node_id,
77 if dst_num_channels.get().get() == 1 {
78 &[(0, 0), (1, 0)]
79 } else {
80 &[(0, 0), (1, 1)]
81 },
82 false,
83 )
84 .unwrap();
85
86 vec![spatial_basic_node_id]
87 }
88}