Compare commits
No commits in common. "5615a28ece0bf70e8258e586ef1217f415f2f10b" and "4e6c01d654430931205ec01be6d28c6a8f9bcfb9" have entirely different histories.
5615a28ece
...
4e6c01d654
53
src/lib.rs
53
src/lib.rs
|
@ -73,16 +73,6 @@ impl Default for Sound {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut)]
|
|
||||||
// #[reflect(Component)]
|
|
||||||
pub struct PannerStrategy(pub syz::PannerStrategy);
|
|
||||||
|
|
||||||
impl Default for PannerStrategy {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self(syz::PannerStrategy::Delegate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut)]
|
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut)]
|
||||||
pub struct DistanceModel(pub syz::DistanceModel);
|
pub struct DistanceModel(pub syz::DistanceModel);
|
||||||
|
|
||||||
|
@ -199,33 +189,11 @@ fn swap_buffers(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_panner_strategy(
|
|
||||||
changed: Query<Entity, Changed<PannerStrategy>>,
|
|
||||||
removed: RemovedComponents<PannerStrategy>,
|
|
||||||
mut sounds: Query<&mut Sound>,
|
|
||||||
) {
|
|
||||||
let mut check = vec![];
|
|
||||||
for entity in changed.iter() {
|
|
||||||
check.push(entity);
|
|
||||||
}
|
|
||||||
for entity in removed.iter() {
|
|
||||||
check.push(entity);
|
|
||||||
}
|
|
||||||
for entity in check.iter() {
|
|
||||||
if let Ok(mut sound) = sounds.get_mut(*entity) {
|
|
||||||
if sound.source.is_some() {
|
|
||||||
sound.source = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_sound_properties(
|
pub fn update_sound_properties(
|
||||||
context: Res<syz::Context>,
|
context: Res<syz::Context>,
|
||||||
buffers: Res<Assets<Buffer>>,
|
buffers: Res<Assets<Buffer>>,
|
||||||
mut query: Query<(
|
mut query: Query<(
|
||||||
&mut Sound,
|
&mut Sound,
|
||||||
Option<&PannerStrategy>,
|
|
||||||
Option<&DistanceModel>,
|
Option<&DistanceModel>,
|
||||||
Option<&DistanceRef>,
|
Option<&DistanceRef>,
|
||||||
Option<&DistanceMax>,
|
Option<&DistanceMax>,
|
||||||
|
@ -240,7 +208,6 @@ pub fn update_sound_properties(
|
||||||
) {
|
) {
|
||||||
for (
|
for (
|
||||||
mut sound,
|
mut sound,
|
||||||
panner_strategy,
|
|
||||||
distance_model,
|
distance_model,
|
||||||
distance_ref,
|
distance_ref,
|
||||||
distance_max,
|
distance_max,
|
||||||
|
@ -283,10 +250,9 @@ pub fn update_sound_properties(
|
||||||
if let Some(generator) = sound.generator.as_mut() {
|
if let Some(generator) = sound.generator.as_mut() {
|
||||||
generator.buffer().set(&**b).expect("Unable to set buffer");
|
generator.buffer().set(&**b).expect("Unable to set buffer");
|
||||||
if let Some(translation) = translation {
|
if let Some(translation) = translation {
|
||||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
|
||||||
let source = syz::Source3D::new(
|
let source = syz::Source3D::new(
|
||||||
&context,
|
&context,
|
||||||
*panner_strategy,
|
syz::PannerStrategy::Delegate,
|
||||||
(
|
(
|
||||||
translation.x as f64,
|
translation.x as f64,
|
||||||
translation.y as f64,
|
translation.y as f64,
|
||||||
|
@ -299,19 +265,20 @@ pub fn update_sound_properties(
|
||||||
.expect("Unable to add generator");
|
.expect("Unable to add generator");
|
||||||
sound.source = Some(source.into());
|
sound.source = Some(source.into());
|
||||||
} else if let Some(scalar_pan) = scalar_pan {
|
} else if let Some(scalar_pan) = scalar_pan {
|
||||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
let source = syz::ScalarPannedSource::new(
|
||||||
let source =
|
&context,
|
||||||
syz::ScalarPannedSource::new(&context, *panner_strategy, **scalar_pan)
|
syz::PannerStrategy::Delegate,
|
||||||
.expect("Failed to create source");
|
**scalar_pan,
|
||||||
|
)
|
||||||
|
.expect("Failed to create source");
|
||||||
source
|
source
|
||||||
.add_generator(generator)
|
.add_generator(generator)
|
||||||
.expect("Failed to add generator");
|
.expect("Failed to add generator");
|
||||||
sound.source = Some(source.into());
|
sound.source = Some(source.into());
|
||||||
} else if let Some(angular_pan) = angular_pan {
|
} else if let Some(angular_pan) = angular_pan {
|
||||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
|
||||||
let source = syz::AngularPannedSource::new(
|
let source = syz::AngularPannedSource::new(
|
||||||
&context,
|
&context,
|
||||||
*panner_strategy,
|
syz::PannerStrategy::Delegate,
|
||||||
angular_pan.azimuth,
|
angular_pan.azimuth,
|
||||||
angular_pan.elevation,
|
angular_pan.elevation,
|
||||||
)
|
)
|
||||||
|
@ -592,10 +559,6 @@ impl Plugin for SynthizerPlugin {
|
||||||
CoreStage::PostUpdate,
|
CoreStage::PostUpdate,
|
||||||
swap_buffers.before(update_sound_properties),
|
swap_buffers.before(update_sound_properties),
|
||||||
)
|
)
|
||||||
.add_system_to_stage(
|
|
||||||
CoreStage::PostUpdate,
|
|
||||||
change_panner_strategy.before(update_sound_properties),
|
|
||||||
)
|
|
||||||
.add_system_to_stage(
|
.add_system_to_stage(
|
||||||
CoreStage::PostUpdate,
|
CoreStage::PostUpdate,
|
||||||
update_listener
|
update_listener
|
||||||
|
|
Loading…
Reference in New Issue
Block a user