Store a plain Generator
in Sound
component.
This commit is contained in:
parent
b60183c448
commit
298012455a
14
src/lib.rs
14
src/lib.rs
|
@ -130,7 +130,7 @@ pub struct Sound {
|
||||||
pub paused: bool,
|
pub paused: bool,
|
||||||
pub restart: bool,
|
pub restart: bool,
|
||||||
#[reflect(ignore)]
|
#[reflect(ignore)]
|
||||||
pub generator: Option<syz::BufferGenerator>,
|
pub generator: Option<syz::Generator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Sound {
|
impl Default for Sound {
|
||||||
|
@ -284,7 +284,7 @@ fn add_generator(
|
||||||
handle
|
handle
|
||||||
.add_generator(&generator)
|
.add_generator(&generator)
|
||||||
.expect("Unable to add generator");
|
.expect("Unable to add generator");
|
||||||
sound.generator = Some(generator);
|
sound.generator = Some(generator.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,11 +500,16 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
||||||
assert!(pitch > 0. && pitch <= 2.);
|
assert!(pitch > 0. && pitch <= 2.);
|
||||||
if sound.restart {
|
if sound.restart {
|
||||||
if let Some(generator) = sound.generator.as_mut() {
|
if let Some(generator) = sound.generator.as_mut() {
|
||||||
|
if let Some(generator) = generator
|
||||||
|
.cast_to::<syz::BufferGenerator>()
|
||||||
|
.expect("Failed to cast")
|
||||||
|
{
|
||||||
generator
|
generator
|
||||||
.playback_position()
|
.playback_position()
|
||||||
.set(0.)
|
.set(0.)
|
||||||
.expect("Failed to restart");
|
.expect("Failed to restart");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sound.restart = false;
|
sound.restart = false;
|
||||||
}
|
}
|
||||||
if let Some(generator) = sound.generator.as_mut() {
|
if let Some(generator) = sound.generator.as_mut() {
|
||||||
|
@ -513,12 +518,17 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
||||||
.pitch_bend()
|
.pitch_bend()
|
||||||
.set(pitch)
|
.set(pitch)
|
||||||
.expect("Failed to set pitch");
|
.expect("Failed to set pitch");
|
||||||
|
if let Some(generator) = generator
|
||||||
|
.cast_to::<syz::BufferGenerator>()
|
||||||
|
.expect("Failed to cast")
|
||||||
|
{
|
||||||
generator
|
generator
|
||||||
.looping()
|
.looping()
|
||||||
.set(looping)
|
.set(looping)
|
||||||
.expect("Failed to set looping");
|
.expect("Failed to set looping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_source_playback_state(query: Query<&Source>) {
|
fn update_source_playback_state(query: Query<&Source>) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user