Compare commits
No commits in common. "4c1471c2abed1003815ccc4adba61f6fcc514979" and "2553ea9bc2fdb0ba806528a621556172ed2366ef" have entirely different histories.
4c1471c2ab
...
2553ea9bc2
46
src/lib.rs
46
src/lib.rs
|
@ -153,6 +153,7 @@ pub struct Sound {
|
||||||
pub pitch: f64,
|
pub pitch: f64,
|
||||||
pub looping: bool,
|
pub looping: bool,
|
||||||
pub paused: bool,
|
pub paused: bool,
|
||||||
|
pub restart: bool,
|
||||||
pub generator: Option<syz::Generator>,
|
pub generator: Option<syz::Generator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +165,7 @@ impl Default for Sound {
|
||||||
pitch: 1.,
|
pitch: 1.,
|
||||||
looping: false,
|
looping: false,
|
||||||
paused: false,
|
paused: false,
|
||||||
|
restart: false,
|
||||||
generator: None,
|
generator: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,8 +276,8 @@ fn add_generator(
|
||||||
if sound.generator.is_none() {
|
if sound.generator.is_none() {
|
||||||
let mut source = if let Ok(s) = sources.get_mut(entity) {
|
let mut source = if let Ok(s) = sources.get_mut(entity) {
|
||||||
Some(s)
|
Some(s)
|
||||||
} else if parent.is_some() {
|
} else if let Some(parent) = parent {
|
||||||
let mut parent = parent;
|
let mut parent: Option<&Parent> = Some(parent);
|
||||||
let mut target = None;
|
let mut target = None;
|
||||||
while let Some(p) = parent {
|
while let Some(p) = parent {
|
||||||
if sources.get(**p).is_ok() {
|
if sources.get(**p).is_ok() {
|
||||||
|
@ -355,7 +357,7 @@ fn swap_buffers(
|
||||||
) {
|
) {
|
||||||
for (entity, mut sound) in &mut query {
|
for (entity, mut sound) in &mut query {
|
||||||
if let Some(l) = last_audio.get(&entity) {
|
if let Some(l) = last_audio.get(&entity) {
|
||||||
if sound.generator.is_some() && sound.audio != *l {
|
if sound.audio != *l {
|
||||||
sound.generator = None;
|
sound.generator = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,6 +533,20 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
||||||
} = *sound;
|
} = *sound;
|
||||||
assert!(gain >= 0.);
|
assert!(gain >= 0.);
|
||||||
assert!(pitch > 0. && pitch <= 2.);
|
assert!(pitch > 0. && pitch <= 2.);
|
||||||
|
if sound.restart {
|
||||||
|
if let Some(generator) = sound.generator.as_mut() {
|
||||||
|
if let Some(generator) = generator
|
||||||
|
.cast_to::<syz::BufferGenerator>()
|
||||||
|
.expect("Failed to cast")
|
||||||
|
{
|
||||||
|
generator
|
||||||
|
.playback_position()
|
||||||
|
.set(0.)
|
||||||
|
.expect("Failed to restart");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sound.restart = false;
|
||||||
|
}
|
||||||
if let Some(generator) = sound.generator.as_mut() {
|
if let Some(generator) = sound.generator.as_mut() {
|
||||||
generator.gain().set(gain).expect("Failed to set gain");
|
generator.gain().set(gain).expect("Failed to set gain");
|
||||||
generator
|
generator
|
||||||
|
@ -574,7 +590,7 @@ fn update_sound_playback_state(query: Query<&Sound>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_sound(mut last_buffer: ResMut<LastAudio>, mut removed: RemovedComponents<Sound>) {
|
fn remove_sound(mut last_buffer: ResMut<LastAudio>, mut removed: RemovedComponents<Source>) {
|
||||||
for entity in removed.iter() {
|
for entity in removed.iter() {
|
||||||
last_buffer.remove(&entity);
|
last_buffer.remove(&entity);
|
||||||
}
|
}
|
||||||
|
@ -651,9 +667,11 @@ fn events(
|
||||||
) {
|
) {
|
||||||
context.get_events().for_each(|event| {
|
context.get_events().for_each(|event| {
|
||||||
if let Ok(event) = event {
|
if let Ok(event) = event {
|
||||||
|
let mut matched = false;
|
||||||
for (entity, sound) in &sounds {
|
for (entity, sound) in &sounds {
|
||||||
if let Some(generator) = &sound.generator {
|
if let Some(generator) = &sound.generator {
|
||||||
if *generator.handle() == event.source {
|
if *generator.handle() == event.source {
|
||||||
|
matched = true;
|
||||||
match event.r#type {
|
match event.r#type {
|
||||||
syz::EventType::Finished => {
|
syz::EventType::Finished => {
|
||||||
output.send(SynthizerEvent::Finished(entity));
|
output.send(SynthizerEvent::Finished(entity));
|
||||||
|
@ -667,13 +685,16 @@ fn events(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !matched {
|
||||||
|
println!("No match");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SystemSet, Clone, Hash, Debug, PartialEq, Eq)]
|
#[derive(SystemSet, Clone, Hash, Debug, PartialEq, Eq)]
|
||||||
pub enum SynthizerSets {
|
pub enum SynthizerSets {
|
||||||
PreUpdate,
|
First,
|
||||||
UpdateHandles,
|
UpdateHandles,
|
||||||
UpdateProperties,
|
UpdateProperties,
|
||||||
UpdateState,
|
UpdateState,
|
||||||
|
@ -740,12 +761,21 @@ impl Plugin for SynthizerPlugin {
|
||||||
.add_event::<SynthizerEvent>()
|
.add_event::<SynthizerEvent>()
|
||||||
.add_systems(
|
.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
(sync_config, swap_buffers, change_panner_strategy).in_set(SynthizerSets::PreUpdate),
|
(
|
||||||
|
sync_config,
|
||||||
|
swap_buffers,
|
||||||
|
change_panner_strategy,
|
||||||
|
add_sound_without_source,
|
||||||
|
)
|
||||||
|
.in_set(SynthizerSets::First),
|
||||||
|
)
|
||||||
|
.configure_set(
|
||||||
|
PreUpdate,
|
||||||
|
SynthizerSets::First.before(SynthizerSets::UpdateHandles),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
(add_sound_without_source, add_source_handle, add_generator)
|
(add_source_handle, add_generator).in_set(SynthizerSets::UpdateHandles),
|
||||||
.in_set(SynthizerSets::UpdateHandles),
|
|
||||||
)
|
)
|
||||||
.configure_set(
|
.configure_set(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user