Compare commits
75 Commits
refactor-s
...
main
Author | SHA1 | Date | |
---|---|---|---|
0c8f557886 | |||
78e5bf2c45 | |||
3c557fa5ab | |||
fe5816b722 | |||
0cb5bd59f6 | |||
041165cf61 | |||
45746803c9 | |||
4c02a98eb4 | |||
2364f638db | |||
3bcf232f1e | |||
7cef2fedd5 | |||
6cf5d92cb8 | |||
3d422dc9e4 | |||
96f3457d55 | |||
6b19103d5a | |||
3cd68ddcbe | |||
d34c3d6e96 | |||
d7e9b1b70c | |||
2080019421 | |||
4c1471c2ab | |||
04372328c8 | |||
1fb0aa763a | |||
53891eeaa8 | |||
2553ea9bc2 | |||
d6e3ba6a89 | |||
e605495d9f | |||
b76ca95495 | |||
9f684880ed | |||
4f972e3bd4 | |||
c739219a70 | |||
f69758164b | |||
459d074040 | |||
c14f94eb76 | |||
3e0b0a3e7f | |||
855fb714da | |||
b1c1e82866 | |||
18dd994077 | |||
f23edf1136 | |||
b381e1501f | |||
35f132d858 | |||
f498565215 | |||
ef7649bc01 | |||
40e1bc6fcd | |||
5606c69bb7 | |||
1aaa6a80c6 | |||
ba3e3ad410 | |||
7a6d40d28a | |||
274c18b8ff | |||
08815a3c29 | |||
47429c2df2 | |||
5f2881d1c8 | |||
32734f31d5 | |||
cabc938ab7 | |||
36f7c62836 | |||
6ef9d3a56a | |||
b6407a7366 | |||
8cc4c0ee94 | |||
b4d298636d | |||
3fecb314f6 | |||
9cb1d1d447 | |||
298012455a | |||
b60183c448 | |||
0f4aa54612 | |||
d69ef38486 | |||
07d6d99ba7 | |||
ed38b30843 | |||
fe63521737 | |||
ba45547038 | |||
72c63af910 | |||
7906d93277 | |||
9b7fb16ee5 | |||
aa60e1d70f | |||
e4b1df13ce | |||
d500c9c445 | |||
9d65ed0f68 |
39
.gitea/workflows/release.yml
Normal file
39
.gitea/workflows/release.yml
Normal file
|
@ -0,0 +1,39 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pre-commit
|
||||
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
target/
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rustfmt, clippy
|
||||
- name: install Linux build dependencies
|
||||
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libclang-dev cmake
|
||||
if: runner.os == 'linux'
|
||||
- uses: actions/setup-python@v3
|
||||
- uses: pre-commit/action@v3.0.1
|
||||
- name: Publish
|
||||
run: cargo publish
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
37
.gitea/workflows/test.yml
Normal file
37
.gitea/workflows/test.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
name: Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
# os: [windows-latest, ubuntu-latest, macos-latest]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pre-commit
|
||||
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
target/
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
components: rustfmt, clippy
|
||||
- name: install Linux build dependencies
|
||||
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libclang-dev cmake
|
||||
if: runner.os == 'linux'
|
||||
- uses: actions/setup-python@v3
|
||||
- uses: pre-commit/action@v3.0.1
|
10
.pre-commit-config.yaml
Normal file
10
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
fail_fast: true
|
||||
repos:
|
||||
- repo: https://github.com/doublify/pre-commit-rust
|
||||
rev: v1.0
|
||||
hooks:
|
||||
- id: fmt
|
||||
args: [--, --check]
|
||||
- id: cargo-check
|
||||
args: [--bins, --examples]
|
||||
- id: clippy
|
99
CHANGELOG.md
Normal file
99
CHANGELOG.md
Normal file
|
@ -0,0 +1,99 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Version 0.9.0 - 2024-12-06
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Upgrade to Bevy 0.15.
|
||||
|
||||
## Version 0.8.0 - 2024-12-02
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Clear generator when source is cleared, and improve handling for changing source types.
|
||||
|
||||
### Features
|
||||
|
||||
- Add `Sound.playback_position` to support initializing new buffers at non-zero playback position.
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Clean up code.
|
||||
|
||||
## Version 0.7.0 - 2024-07-07
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Add pre-commit.
|
||||
- Switch to Gitea Actions.
|
||||
- Upgrade to Bevy 0.14.
|
||||
|
||||
## Version 0.6.0 - 2024-03-14
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Upgrade Bevy to v0.13.
|
||||
|
||||
## Version 0.5.0 - 2024-02-09
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Clean up `LastAudio` when `Sound` is removed, not `Source`.
|
||||
|
||||
### Features
|
||||
|
||||
- [**breaking**] Renamed `SynthizerSets::First` to `SynthizerSets::PreUpdate` and moved remaining systems into `PostUpdate`.
|
||||
- [**breaking**] Removed `Sound.restart`. Clear `Sound.generator` for equivalent functionality.
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Clean up code.
|
||||
- Bump dependencies.
|
||||
|
||||
## Version 0.4.0 - 2023-07-16
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Update to Bevy 0.11.
|
||||
|
||||
## Version 0.3.2 - 2023-05-04
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Instantiate sources for sounds without a source in `PreUpdate`.
|
||||
|
||||
## Version 0.3.1 - 2023-04-04
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Only `update_source_properties` and `update_listener` need to run after transform propagation.
|
||||
|
||||
## Version 0.3.0 - 2023-04-03
|
||||
|
||||
### Features
|
||||
|
||||
- [**breaking**] Renamed `SynthizerSystems` to `SynthizerSets`.
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Restructure system schedule to more idiomatic Bevy 0.10 style.
|
||||
|
||||
## Version 0.2.0 - 2023-03-06
|
||||
|
||||
### Features
|
||||
|
||||
- `Sound` components can now get audio from either buffers or generators.
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Update to Bevy 0.10.
|
||||
|
||||
## Version 0.1.0 - 2022-12-17
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- Initial release.
|
||||
|
||||
<!-- generated by git-cliff -->
|
18
Cargo.toml
18
Cargo.toml
|
@ -1,16 +1,24 @@
|
|||
[package]
|
||||
name = "bevy_synthizer"
|
||||
version = "0.1.0"
|
||||
version = "0.9.0"
|
||||
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
||||
description = "A Bevy plugin for Synthizer, a library for 3D audio and synthesis with a focus on games and VR applications"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
repository = "https://labs.lightsout.games/projects/bevy_synthizer"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
bevy = { version = "0.8", default-features = false, features = ["bevy_asset"] }
|
||||
synthizer = { git = "https://github.com/synthizer/synthizer-rs" }
|
||||
bevy = { version = "0.15", default-features = false, features = ["bevy_asset"] }
|
||||
synthizer = "0.5.6"
|
||||
thiserror = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
bevy = { version = "0.8", default-features = true }
|
||||
bevy = { version = "0.15", default-features = true }
|
||||
|
||||
[package.metadata.release]
|
||||
publish = false
|
||||
push = false
|
||||
pre-release-hook = ["git-cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"]
|
||||
pre-release-commit-message = "Release"
|
||||
|
|
60
cliff.toml
Normal file
60
cliff.toml
Normal file
|
@ -0,0 +1,60 @@
|
|||
# configuration file for git-cliff (0.1.0)
|
||||
|
||||
[changelog]
|
||||
# changelog header
|
||||
header = """
|
||||
# Changelog\n
|
||||
All notable changes to this project will be documented in this file.\n
|
||||
"""
|
||||
# template for the changelog body
|
||||
# https://tera.netlify.app/docs/#introduction
|
||||
body = """
|
||||
{% if version %}\
|
||||
## Version {{ version | trim_start_matches(pat="v") }} - {{ timestamp | date(format="%Y-%m-%d") }}
|
||||
{% else %}\
|
||||
## Unreleased
|
||||
{% endif %}\
|
||||
{% for group, commits in commits | group_by(attribute="group") %}
|
||||
### {{ group | upper_first }}
|
||||
{% for commit in commits %}
|
||||
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
|
||||
{% endfor %}
|
||||
{% endfor %}\n
|
||||
"""
|
||||
# remove the leading and trailing whitespace from the template
|
||||
trim = true
|
||||
# changelog footer
|
||||
footer = """
|
||||
<!-- generated by git-cliff -->
|
||||
"""
|
||||
|
||||
[git]
|
||||
# parse the commits based on https://www.conventionalcommits.org
|
||||
conventional_commits = true
|
||||
# filter out the commits that are not conventional
|
||||
filter_unconventional = true
|
||||
# regex for parsing and grouping commits
|
||||
commit_parsers = [
|
||||
{ message = "^feat", group = "Features"},
|
||||
{ message = "^fix", group = "Bug Fixes"},
|
||||
{ message = "^doc", group = "Documentation"},
|
||||
{ message = "^perf", group = "Performance"},
|
||||
{ message = "^refactor", group = "Refactor"},
|
||||
{ message = "^style", group = "Styling"},
|
||||
{ message = "^test", group = "Testing"},
|
||||
{ message = "^chore\\(release\\): prepare for", skip = true},
|
||||
{ message = "^chore", group = "Miscellaneous Tasks"},
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
# filter out the commits that are not matched by commit parsers
|
||||
filter_commits = false
|
||||
# glob pattern for matching git tags
|
||||
tag_pattern = "v[0-9]*"
|
||||
# regex for skipping tags
|
||||
skip_tags = ""
|
||||
# regex for ignoring tags
|
||||
ignore_tags = ""
|
||||
# sort the tags chronologically
|
||||
date_order = false
|
||||
# sort the commits inside sections by oldest/newest order
|
||||
sort_commits = "oldest"
|
69
examples/buffer.rs
Normal file
69
examples/buffer.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use std::f32;
|
||||
|
||||
use bevy::{asset::LoadedFolder, prelude::*};
|
||||
use bevy_synthizer::*;
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
struct RotationTimer(Timer);
|
||||
|
||||
impl Default for RotationTimer {
|
||||
fn default() -> Self {
|
||||
Self(Timer::from_seconds(30., TimerMode::Repeating))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Default, Deref, DerefMut)]
|
||||
struct AssetHandles(Handle<LoadedFolder>);
|
||||
|
||||
fn setup(asset_server: Res<AssetServer>, mut handles: ResMut<AssetHandles>) {
|
||||
**handles = asset_server.load_folder(".");
|
||||
}
|
||||
|
||||
fn load_and_create(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
handles: Res<AssetHandles>,
|
||||
listeners: Query<&Listener>,
|
||||
) {
|
||||
if !asset_server.is_loaded_with_dependencies(&**handles) {
|
||||
return;
|
||||
}
|
||||
if !listeners.is_empty() {
|
||||
return;
|
||||
}
|
||||
commands.spawn((Transform::default(), Listener, RotationTimer::default()));
|
||||
let handle = asset_server.load("footstep.wav");
|
||||
commands.spawn((
|
||||
Transform::from_translation(Vec3::new(10., 0., 0.)),
|
||||
Source::default(),
|
||||
Sound {
|
||||
audio: handle.into(),
|
||||
looping: true,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn rotate_listener(time: Res<Time>, mut query: Query<(&mut RotationTimer, &mut Transform)>) {
|
||||
for (mut timer, mut transform) in query.iter_mut() {
|
||||
timer.tick(time.delta());
|
||||
let angle = f32::consts::PI * 2. * timer.fraction();
|
||||
transform.rotation = Quat::from_rotation_z(angle);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
SynthizerPlugin {
|
||||
default_panner_strategy: Some(bevy_synthizer::syz::PannerStrategy::Hrtf),
|
||||
default_distance_model: Some(bevy_synthizer::syz::DistanceModel::Inverse),
|
||||
..default()
|
||||
},
|
||||
))
|
||||
.init_resource::<AssetHandles>()
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, (load_and_create, rotate_listener))
|
||||
.run();
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
use std::f32;
|
||||
|
||||
use bevy::{asset::LoadState, prelude::*};
|
||||
use bevy_synthizer::*;
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
struct RotationTimer(Timer);
|
||||
|
||||
impl Default for RotationTimer {
|
||||
fn default() -> Self {
|
||||
Self(Timer::from_seconds(30., true))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AssetHandles {
|
||||
sounds: Vec<HandleUntyped>,
|
||||
loaded: bool,
|
||||
}
|
||||
|
||||
fn setup(asset_server: Res<AssetServer>, mut handles: ResMut<AssetHandles>) {
|
||||
handles.sounds = asset_server.load_folder(".").expect("Failed to load sfx");
|
||||
}
|
||||
|
||||
fn load_and_create(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut handles: ResMut<AssetHandles>,
|
||||
) {
|
||||
if handles.loaded {
|
||||
return;
|
||||
}
|
||||
handles.loaded = asset_server
|
||||
.get_group_load_state(handles.sounds.iter().map(|handle| handle.id))
|
||||
== LoadState::Loaded;
|
||||
if handles.loaded {
|
||||
commands
|
||||
.spawn_bundle(TransformBundle::default())
|
||||
.insert(Listener)
|
||||
.insert(RotationTimer::default());
|
||||
let handle = handles.sounds[0].clone();
|
||||
let buffer = asset_server.get_handle(handle);
|
||||
commands
|
||||
.spawn_bundle(TransformBundle::from(Transform::from_translation(
|
||||
Vec3::new(10., 0., 0.),
|
||||
)))
|
||||
.insert(Source::default())
|
||||
.insert(Sound {
|
||||
buffer,
|
||||
looping: true,
|
||||
..default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate_listener(time: Res<Time>, mut query: Query<(&mut RotationTimer, &mut Transform)>) {
|
||||
for (mut timer, mut transform) in query.iter_mut() {
|
||||
timer.tick(time.delta());
|
||||
let angle = f32::consts::PI * 2. * timer.percent();
|
||||
transform.rotation = Quat::from_rotation_z(angle);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.insert_resource(SynthizerConfig {
|
||||
default_panner_strategy: Some(bevy_synthizer::syz::PannerStrategy::Hrtf),
|
||||
default_distance_model: Some(bevy_synthizer::syz::DistanceModel::Inverse),
|
||||
..default()
|
||||
})
|
||||
.add_plugin(SynthizerPlugin)
|
||||
.add_system(bevy::window::close_on_esc)
|
||||
.init_resource::<AssetHandles>()
|
||||
.add_startup_system(setup)
|
||||
.add_system(load_and_create)
|
||||
.add_system(rotate_listener)
|
||||
.run();
|
||||
}
|
52
examples/generator.rs
Normal file
52
examples/generator.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use std::f32;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_synthizer::*;
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
struct RotationTimer(Timer);
|
||||
|
||||
impl Default for RotationTimer {
|
||||
fn default() -> Self {
|
||||
Self(Timer::from_seconds(30., TimerMode::Repeating))
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, context: Res<Context>) {
|
||||
commands.spawn((Transform::default(), Listener, RotationTimer::default()));
|
||||
let generator: syz::Generator = syz::FastSineBankGenerator::new_sine(&context, 440.)
|
||||
.expect("Failed to create generator")
|
||||
.into();
|
||||
commands.spawn((
|
||||
Transform::from_translation(Vec3::new(10., 0., 0.)),
|
||||
Source::default(),
|
||||
Sound {
|
||||
audio: generator.into(),
|
||||
looping: true,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn rotate_listener(time: Res<Time>, mut query: Query<(&mut RotationTimer, &mut Transform)>) {
|
||||
for (mut timer, mut transform) in query.iter_mut() {
|
||||
timer.tick(time.delta());
|
||||
let angle = f32::consts::PI * 2. * timer.fraction();
|
||||
transform.rotation = Quat::from_rotation_z(angle);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
SynthizerPlugin {
|
||||
default_panner_strategy: Some(bevy_synthizer::syz::PannerStrategy::Hrtf),
|
||||
default_distance_model: Some(bevy_synthizer::syz::DistanceModel::Inverse),
|
||||
..default()
|
||||
},
|
||||
))
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, rotate_listener)
|
||||
.run();
|
||||
}
|
465
src/lib.rs
465
src/lib.rs
|
@ -2,40 +2,43 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use bevy::{
|
||||
asset::{AssetLoader, LoadContext, LoadedAsset},
|
||||
asset::{io::Reader, AssetLoader, LoadContext},
|
||||
prelude::*,
|
||||
reflect::TypeUuid,
|
||||
transform::TransformSystem,
|
||||
utils::BoxedFuture,
|
||||
};
|
||||
pub use synthizer as syz;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Clone, Debug, Deref, DerefMut, PartialEq, TypeUuid)]
|
||||
#[uuid = "6b6b533a-bb1f-11ec-bda2-00155d8fdde9"]
|
||||
#[derive(Asset, Clone, Debug, Deref, DerefMut, PartialEq, Eq, TypePath)]
|
||||
pub struct Buffer(syz::Buffer);
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
struct BufferAssetLoader;
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BufferAssetLoaderError {
|
||||
#[error("Could not load asset: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error("Synthizer error: {0}")]
|
||||
SynthizerError(#[from] synthizer::Error),
|
||||
}
|
||||
|
||||
impl AssetLoader for BufferAssetLoader {
|
||||
fn load<'a>(
|
||||
&'a self,
|
||||
bytes: &'a [u8],
|
||||
load_context: &'a mut LoadContext,
|
||||
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
|
||||
Box::pin(async move {
|
||||
let buffer: Option<Buffer> =
|
||||
match load_context.path().extension().unwrap().to_str().unwrap() {
|
||||
"flac" | "mp3" | "wav" => {
|
||||
syz::Buffer::from_encoded_data(bytes).map(Buffer).ok()
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(buffer) = buffer {
|
||||
load_context.set_default_asset(LoadedAsset::new(buffer));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
type Asset = Buffer;
|
||||
type Settings = ();
|
||||
type Error = BufferAssetLoaderError;
|
||||
|
||||
async fn load(
|
||||
&self,
|
||||
reader: &mut dyn Reader,
|
||||
_settings: &(),
|
||||
_load_context: &mut LoadContext<'_>,
|
||||
) -> Result<Self::Asset, Self::Error> {
|
||||
let mut bytes = Vec::new();
|
||||
reader.read_to_end(&mut bytes).await?;
|
||||
let buffer = syz::Buffer::from_encoded_data(&bytes).map(Buffer)?;
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &[&str] {
|
||||
|
@ -43,6 +46,9 @@ impl AssetLoader for BufferAssetLoader {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug, Deref, DerefMut)]
|
||||
pub struct Context(syz::Context);
|
||||
|
||||
#[derive(Component, Clone, Debug, Reflect)]
|
||||
#[reflect(Component)]
|
||||
pub struct Source {
|
||||
|
@ -63,7 +69,6 @@ impl Default for Source {
|
|||
}
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Deref, DerefMut)]
|
||||
// #[reflect(Component)]
|
||||
pub struct PannerStrategy(pub syz::PannerStrategy);
|
||||
|
||||
impl Default for PannerStrategy {
|
||||
|
@ -120,33 +125,56 @@ impl ScalarPan {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug, Reflect)]
|
||||
#[reflect(Component)]
|
||||
#[derive(Component, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Audio {
|
||||
Buffer(Handle<Buffer>),
|
||||
Generator(syz::Generator),
|
||||
}
|
||||
|
||||
impl Default for Audio {
|
||||
fn default() -> Self {
|
||||
Self::Buffer(default())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Handle<Buffer>> for Audio {
|
||||
fn from(value: Handle<Buffer>) -> Self {
|
||||
Audio::Buffer(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<syz::Generator> for Audio {
|
||||
fn from(value: syz::Generator) -> Self {
|
||||
Self::Generator(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Clone, Debug)]
|
||||
pub struct Sound {
|
||||
pub buffer: Handle<Buffer>,
|
||||
pub audio: Audio,
|
||||
pub gain: f64,
|
||||
pub pitch: f64,
|
||||
pub looping: bool,
|
||||
pub playback_position: f64,
|
||||
pub paused: bool,
|
||||
pub restart: bool,
|
||||
#[reflect(ignore)]
|
||||
pub generator: Option<syz::BufferGenerator>,
|
||||
pub generator: Option<syz::Generator>,
|
||||
}
|
||||
|
||||
impl Default for Sound {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
buffer: default(),
|
||||
audio: default(),
|
||||
gain: 1.,
|
||||
pitch: 1.,
|
||||
looping: false,
|
||||
playback_position: default(),
|
||||
paused: false,
|
||||
restart: false,
|
||||
generator: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Debug)]
|
||||
pub enum SynthizerEvent {
|
||||
Finished(Entity),
|
||||
Looped(Entity),
|
||||
|
@ -157,7 +185,7 @@ pub enum SynthizerEvent {
|
|||
pub struct Listener;
|
||||
|
||||
fn update_listener(
|
||||
context: ResMut<syz::Context>,
|
||||
context: ResMut<Context>,
|
||||
listener: Query<Option<&GlobalTransform>, With<Listener>>,
|
||||
) {
|
||||
if let Ok(transform) = listener.get_single() {
|
||||
|
@ -192,7 +220,7 @@ fn update_listener(
|
|||
}
|
||||
|
||||
fn add_source_handle(
|
||||
context: Res<syz::Context>,
|
||||
context: Res<Context>,
|
||||
mut query: Query<(
|
||||
&mut Source,
|
||||
Option<&PannerStrategy>,
|
||||
|
@ -202,7 +230,9 @@ fn add_source_handle(
|
|||
)>,
|
||||
) {
|
||||
for (mut source, panner_strategy, transform, angular_pan, scalar_pan) in &mut query {
|
||||
if source.handle.is_none() {
|
||||
if source.handle.is_some() {
|
||||
continue;
|
||||
}
|
||||
let panner_strategy = panner_strategy.cloned().unwrap_or_default();
|
||||
let handle: syz::Source = if let Some(transform) = transform {
|
||||
let translation = transform.translation();
|
||||
|
@ -237,23 +267,23 @@ fn add_source_handle(
|
|||
};
|
||||
source.handle = Some(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_generator(
|
||||
context: Res<syz::Context>,
|
||||
context: Res<Context>,
|
||||
buffers: Res<Assets<Buffer>>,
|
||||
mut query: Query<(Entity, Option<&Parent>, &mut Sound)>,
|
||||
mut sources: Query<&mut Source>,
|
||||
parents: Query<&Parent>,
|
||||
) {
|
||||
for (entity, parent, mut sound) in &mut query {
|
||||
if sound.generator.is_none() {
|
||||
if let Some(b) = buffers.get(&sound.buffer) {
|
||||
if sound.generator.is_some() {
|
||||
continue;
|
||||
}
|
||||
let mut source = if let Ok(s) = sources.get_mut(entity) {
|
||||
Some(s)
|
||||
} else if let Some(parent) = parent {
|
||||
let mut parent: Option<&Parent> = Some(parent);
|
||||
} else if parent.is_some() {
|
||||
let mut parent = parent;
|
||||
let mut target = None;
|
||||
while let Some(p) = parent {
|
||||
if sources.get(**p).is_ok() {
|
||||
|
@ -268,104 +298,111 @@ fn add_generator(
|
|||
};
|
||||
if let Some(source) = source.as_mut() {
|
||||
if let Some(handle) = source.handle.as_mut() {
|
||||
let generator: Option<syz::Generator> = match &sound.audio {
|
||||
Audio::Buffer(buffer) => {
|
||||
if let Some(b) = buffers.get(buffer) {
|
||||
let generator = syz::BufferGenerator::new(&context)
|
||||
.expect("Failed to create generator");
|
||||
generator.buffer().set(&**b).expect("Unable to set buffer");
|
||||
assert!(sound.playback_position >= 0.);
|
||||
generator
|
||||
.playback_position()
|
||||
.set(sound.playback_position)
|
||||
.expect("Failed to set playback position");
|
||||
Some(generator.into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Audio::Generator(generator) => Some(generator.clone()),
|
||||
};
|
||||
let Some(generator) = generator else {
|
||||
continue;
|
||||
};
|
||||
assert!(sound.gain >= 0.);
|
||||
generator
|
||||
.gain()
|
||||
.set(sound.gain)
|
||||
.expect("Failed to set gain");
|
||||
assert!(sound.pitch > 0. && sound.pitch <= 2.);
|
||||
generator
|
||||
.pitch_bend()
|
||||
.set(sound.pitch)
|
||||
.expect("Failed to set pitch");
|
||||
handle
|
||||
.add_generator(&generator)
|
||||
.add_generator(generator.handle())
|
||||
.expect("Unable to add generator");
|
||||
sound.generator = Some(generator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_sound_without_source(
|
||||
mut commands: Commands,
|
||||
query: Query<
|
||||
(Entity, Option<&Parent>, Option<&GlobalTransform>),
|
||||
(Added<Sound>, Without<Source>),
|
||||
>,
|
||||
parents: Query<&Parent>,
|
||||
sources: Query<&Source>,
|
||||
transforms: Query<&GlobalTransform>,
|
||||
query: Query<Entity, (Added<Sound>, Without<Source>)>,
|
||||
parents: Query<(&Parent, Option<&Source>)>,
|
||||
) {
|
||||
for (entity, parent, transform) in &query {
|
||||
let should_check_for_transform = transform.is_none();
|
||||
let mut has_transform = false;
|
||||
let source = if let Some(parent) = parent {
|
||||
if should_check_for_transform {
|
||||
has_transform = transforms.get(**parent).is_ok();
|
||||
}
|
||||
let mut target = None;
|
||||
let mut parent: Option<&Parent> = Some(parent);
|
||||
while let Some(p) = parent {
|
||||
if should_check_for_transform && !has_transform {
|
||||
has_transform = transforms.get(**p).is_ok();
|
||||
}
|
||||
if sources.get(**p).is_ok() {
|
||||
target = Some(**p);
|
||||
for entity in &query {
|
||||
let mut has_source = false;
|
||||
let mut target = entity;
|
||||
while let Ok((parent, source)) = parents.get(target) {
|
||||
if source.is_some() {
|
||||
has_source = true;
|
||||
break;
|
||||
}
|
||||
parent = parents.get(**p).ok();
|
||||
}
|
||||
target.map(|v| sources.get(v).unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if source.is_none() {
|
||||
let id = commands.entity(entity).insert(Source::default()).id();
|
||||
if has_transform {
|
||||
commands
|
||||
.entity(id)
|
||||
.insert_bundle(TransformBundle::default());
|
||||
target = **parent;
|
||||
}
|
||||
if !has_source {
|
||||
commands.entity(entity).insert(Source::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Deref, DerefMut)]
|
||||
struct LastBuffer(HashMap<Entity, Handle<Buffer>>);
|
||||
#[derive(Resource, Default, Deref, DerefMut)]
|
||||
struct LastAudio(HashMap<Entity, Audio>);
|
||||
|
||||
fn swap_buffers(
|
||||
mut last_buffer: ResMut<LastBuffer>,
|
||||
mut last_audio: ResMut<LastAudio>,
|
||||
mut query: Query<(Entity, &mut Sound), Changed<Sound>>,
|
||||
) {
|
||||
for (entity, mut sound) in &mut query {
|
||||
if let Some(l) = last_buffer.get(&entity) {
|
||||
if sound.buffer != *l {
|
||||
if let Some(l) = last_audio.get(&entity) {
|
||||
if sound.generator.is_some() && sound.audio != *l {
|
||||
sound.generator = None;
|
||||
sound.playback_position = 0.;
|
||||
}
|
||||
}
|
||||
last_buffer.insert(entity, sound.buffer.clone());
|
||||
last_audio.insert(entity, sound.audio.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn change_panner_strategy(
|
||||
changed: Query<Entity, Changed<PannerStrategy>>,
|
||||
removed: RemovedComponents<PannerStrategy>,
|
||||
changed: Query<(Entity, Ref<PannerStrategy>)>,
|
||||
mut removed: RemovedComponents<PannerStrategy>,
|
||||
mut sources: Query<&mut Source>,
|
||||
) {
|
||||
let mut check = vec![];
|
||||
for entity in &changed {
|
||||
for (entity, change) in &changed {
|
||||
if !change.is_added() && change.is_changed() {
|
||||
check.push(entity);
|
||||
}
|
||||
for entity in removed.iter() {
|
||||
}
|
||||
for entity in removed.read() {
|
||||
check.push(entity);
|
||||
}
|
||||
for entity in check.iter() {
|
||||
if let Ok(mut source) = sources.get_mut(*entity) {
|
||||
let Ok(mut source) = sources.get_mut(*entity) else {
|
||||
continue;
|
||||
};
|
||||
if source.handle.is_some() {
|
||||
source.handle = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_source_properties(
|
||||
context: Res<syz::Context>,
|
||||
context: Res<Context>,
|
||||
mut query: Query<(
|
||||
&mut Source,
|
||||
Option<&DistanceModel>,
|
||||
|
@ -377,6 +414,7 @@ fn update_source_properties(
|
|||
Option<&AngularPan>,
|
||||
Option<&ScalarPan>,
|
||||
Option<&GlobalTransform>,
|
||||
Option<&mut Sound>,
|
||||
)>,
|
||||
) {
|
||||
for (
|
||||
|
@ -390,15 +428,18 @@ fn update_source_properties(
|
|||
angular_pan,
|
||||
scalar_pan,
|
||||
transform,
|
||||
sound,
|
||||
) in &mut query
|
||||
{
|
||||
let Source { gain, .. } = *source;
|
||||
assert!(gain >= 0.);
|
||||
if let Some(handle) = source.handle.as_mut() {
|
||||
let Some(handle) = source.handle.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
handle.gain().set(gain).expect("Failed to set gain");
|
||||
let mut clear_source = false;
|
||||
if let Some(source) = handle.cast_to::<syz::Source3D>().expect("Failed to cast") {
|
||||
if let Some(transform) = transform {
|
||||
if let Some(source) = handle.cast_to::<syz::Source3D>().unwrap() {
|
||||
let translation = transform.translation();
|
||||
source
|
||||
.position()
|
||||
|
@ -436,6 +477,7 @@ fn update_source_properties(
|
|||
.map(|v| **v)
|
||||
.unwrap_or_else(|| context.default_rolloff().get().unwrap());
|
||||
assert!(rolloff >= 0.);
|
||||
assert!(rolloff >= 0.);
|
||||
source
|
||||
.rolloff()
|
||||
.set(rolloff)
|
||||
|
@ -448,10 +490,9 @@ fn update_source_properties(
|
|||
.closeness_boost()
|
||||
.set(closeness_boost)
|
||||
.expect("Failed to set closeness_boost");
|
||||
let closeness_boost_distance =
|
||||
closeness_boost_distance.map(|v| **v).unwrap_or_else(|| {
|
||||
context.default_closeness_boost_distance().get().unwrap()
|
||||
});
|
||||
let closeness_boost_distance = closeness_boost_distance
|
||||
.map(|v| **v)
|
||||
.unwrap_or_else(|| context.default_closeness_boost_distance().get().unwrap());
|
||||
assert!(closeness_boost_distance >= 0.);
|
||||
source
|
||||
.closeness_boost_distance()
|
||||
|
@ -460,8 +501,11 @@ fn update_source_properties(
|
|||
} else {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if let Some(angular_pan) = angular_pan {
|
||||
if let Some(source) = handle.cast_to::<syz::AngularPannedSource>().unwrap() {
|
||||
} else if let Some(source) = handle
|
||||
.cast_to::<syz::AngularPannedSource>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
if let Some(angular_pan) = angular_pan {
|
||||
assert!(angular_pan.azimuth >= 0. && angular_pan.azimuth <= 360.);
|
||||
source
|
||||
.azimuth()
|
||||
|
@ -475,8 +519,11 @@ fn update_source_properties(
|
|||
} else {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if let Some(scalar_pan) = scalar_pan {
|
||||
if let Some(source) = handle.cast_to::<syz::ScalarPannedSource>().unwrap() {
|
||||
} else if let Some(source) = handle
|
||||
.cast_to::<syz::ScalarPannedSource>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
if let Some(scalar_pan) = scalar_pan {
|
||||
assert!(**scalar_pan >= -1. && **scalar_pan <= 1.);
|
||||
source
|
||||
.panning_scalar()
|
||||
|
@ -485,9 +532,22 @@ fn update_source_properties(
|
|||
} else {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if handle
|
||||
.cast_to::<syz::DirectSource>()
|
||||
.expect("Failed to cast")
|
||||
.is_some()
|
||||
{
|
||||
if transform.is_some() || angular_pan.is_some() || scalar_pan.is_some() {
|
||||
clear_source = true;
|
||||
}
|
||||
} else if source.handle.is_some() {
|
||||
clear_source = true;
|
||||
}
|
||||
if clear_source {
|
||||
source.handle = None;
|
||||
if let Some(mut sound) = sound {
|
||||
sound.generator = None;
|
||||
sound.playback_position = 0.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -502,22 +562,31 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
..
|
||||
} = *sound;
|
||||
assert!(gain >= 0.);
|
||||
assert!(pitch >= 0.);
|
||||
if sound.restart {
|
||||
if let Some(generator) = sound.generator.as_mut() {
|
||||
generator
|
||||
assert!(pitch > 0. && pitch <= 2.);
|
||||
let Some(generator) = &sound.generator else {
|
||||
continue;
|
||||
};
|
||||
if let Some(generator) = generator
|
||||
.cast_to::<syz::BufferGenerator>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
sound.playback_position = generator
|
||||
.playback_position()
|
||||
.set(0.)
|
||||
.expect("Failed to restart");
|
||||
.get()
|
||||
.expect("Failed to getplayback position");
|
||||
}
|
||||
sound.restart = false;
|
||||
}
|
||||
if let Some(generator) = sound.generator.as_mut() {
|
||||
let Some(generator) = sound.generator.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
generator.gain().set(gain).expect("Failed to set gain");
|
||||
generator
|
||||
.pitch_bend()
|
||||
.set(pitch)
|
||||
.expect("Failed to set pitch");
|
||||
if let Some(generator) = generator
|
||||
.cast_to::<syz::BufferGenerator>()
|
||||
.expect("Failed to cast")
|
||||
{
|
||||
generator
|
||||
.looping()
|
||||
.set(looping)
|
||||
|
@ -528,46 +597,37 @@ fn update_sound_properties(mut query: Query<&mut Sound>) {
|
|||
|
||||
fn update_source_playback_state(query: Query<&Source>) {
|
||||
for source in &query {
|
||||
if let Some(handle) = &source.handle {
|
||||
let Some(handle) = &source.handle else {
|
||||
continue;
|
||||
};
|
||||
if source.paused {
|
||||
handle.pause().expect("Failed to pause");
|
||||
} else {
|
||||
handle.play().expect("Failed to play");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_sound_playback_state(query: Query<&Sound>) {
|
||||
for sound in &query {
|
||||
if let Some(generator) = &sound.generator {
|
||||
let Some(generator) = &sound.generator else {
|
||||
continue;
|
||||
};
|
||||
if sound.paused {
|
||||
generator.pause().expect("Failed to pause");
|
||||
} else {
|
||||
generator.play().expect("Failed to play");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_sound(mut last_buffer: ResMut<LastBuffer>, removed: RemovedComponents<Source>) {
|
||||
for entity in removed.iter() {
|
||||
fn remove_sound(mut last_buffer: ResMut<LastAudio>, mut removed: RemovedComponents<Sound>) {
|
||||
for entity in removed.read() {
|
||||
last_buffer.remove(&entity);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, Debug)]
|
||||
pub struct SynthizerConfig {
|
||||
pub default_panner_strategy: Option<syz::PannerStrategy>,
|
||||
pub default_distance_model: Option<syz::DistanceModel>,
|
||||
pub default_distance_ref: Option<f64>,
|
||||
pub default_distance_max: Option<f64>,
|
||||
pub default_rolloff: Option<f64>,
|
||||
pub default_closeness_boost: Option<f64>,
|
||||
pub default_closeness_boost_distance: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Resource, Debug)]
|
||||
pub struct SynthizerDefaults {
|
||||
pub panner_strategy: syz::PannerStrategy,
|
||||
pub distance_model: syz::DistanceModel,
|
||||
|
@ -579,8 +639,8 @@ pub struct SynthizerDefaults {
|
|||
}
|
||||
|
||||
fn sync_config(
|
||||
context: Res<syz::Context>,
|
||||
config: Res<SynthizerConfig>,
|
||||
context: Res<Context>,
|
||||
config: Res<SynthizerPlugin>,
|
||||
defaults: Res<SynthizerDefaults>,
|
||||
) {
|
||||
if config.is_changed() {
|
||||
|
@ -632,14 +692,18 @@ fn sync_config(
|
|||
}
|
||||
|
||||
fn events(
|
||||
context: Res<syz::Context>,
|
||||
context: Res<Context>,
|
||||
sounds: Query<(Entity, &Sound)>,
|
||||
mut output: EventWriter<SynthizerEvent>,
|
||||
) {
|
||||
context.get_events().for_each(|event| {
|
||||
if let Ok(event) = event {
|
||||
let Ok(event) = event else {
|
||||
return;
|
||||
};
|
||||
for (entity, sound) in &sounds {
|
||||
if let Some(generator) = &sound.generator {
|
||||
let Some(generator) = &sound.generator else {
|
||||
continue;
|
||||
};
|
||||
if *generator.handle() == event.source {
|
||||
match event.r#type {
|
||||
syz::EventType::Finished => {
|
||||
|
@ -653,27 +717,50 @@ fn events(
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(SystemLabel, Clone, Hash, Debug, PartialEq, Eq)]
|
||||
pub enum SynthizerSystems {
|
||||
#[derive(SystemSet, Clone, Hash, Debug, PartialEq, Eq)]
|
||||
pub enum SynthizerSets {
|
||||
PreUpdate,
|
||||
UpdateHandles,
|
||||
UpdateProperties,
|
||||
UpdateState,
|
||||
Last,
|
||||
}
|
||||
|
||||
pub struct SynthizerPlugin;
|
||||
#[derive(Resource)]
|
||||
struct InitializationGuard(syz::InitializationGuard);
|
||||
|
||||
#[derive(Resource, Clone, Copy, Default, Debug)]
|
||||
pub struct SynthizerPlugin {
|
||||
pub default_panner_strategy: Option<syz::PannerStrategy>,
|
||||
pub default_distance_model: Option<syz::DistanceModel>,
|
||||
pub default_distance_ref: Option<f64>,
|
||||
pub default_distance_max: Option<f64>,
|
||||
pub default_rolloff: Option<f64>,
|
||||
pub default_closeness_boost: Option<f64>,
|
||||
pub default_closeness_boost_distance: Option<f64>,
|
||||
pub log_level: syz::LogLevel,
|
||||
pub log_to_stderr: bool,
|
||||
}
|
||||
|
||||
impl Plugin for SynthizerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
let guard = syz::initialize().expect("Failed to initialize Synthizer");
|
||||
let context = syz::Context::new().expect("Failed to create Synthizer context");
|
||||
if !app.world.contains_resource::<SynthizerConfig>() {
|
||||
app.insert_resource(SynthizerConfig::default());
|
||||
if !app.world().contains_resource::<SynthizerPlugin>() {
|
||||
app.insert_resource(*self);
|
||||
}
|
||||
let config = *app.world().get_resource::<SynthizerPlugin>().unwrap();
|
||||
let mut syz_config = syz::LibraryConfig::new();
|
||||
syz_config.log_level(config.log_level);
|
||||
if config.log_to_stderr {
|
||||
syz_config.log_to_stderr();
|
||||
}
|
||||
let guard = syz_config
|
||||
.initialize()
|
||||
.expect("Failed to initialize Synthizer");
|
||||
let guard = InitializationGuard(guard);
|
||||
let context = syz::Context::new().expect("Failed to create Synthizer context");
|
||||
let defaults = SynthizerDefaults {
|
||||
panner_strategy: context.default_panner_strategy().get().unwrap(),
|
||||
distance_model: context.default_distance_model().get().unwrap(),
|
||||
|
@ -684,70 +771,62 @@ impl Plugin for SynthizerPlugin {
|
|||
closeness_boost_distance: context.default_closeness_boost_distance().get().unwrap(),
|
||||
};
|
||||
context.enable_events().expect("Failed to enable events");
|
||||
app.add_asset::<Buffer>()
|
||||
let context = Context(context);
|
||||
app.init_asset::<Buffer>()
|
||||
.init_asset_loader::<BufferAssetLoader>()
|
||||
.register_type::<DistanceRef>()
|
||||
.register_type::<DistanceMax>()
|
||||
.register_type::<Rolloff>()
|
||||
.register_type::<ClosenessBoostDistance>()
|
||||
.register_type::<AngularPan>()
|
||||
.register_type::<ScalarPan>()
|
||||
.register_type::<Source>()
|
||||
.register_type::<Listener>()
|
||||
.insert_resource(guard)
|
||||
.insert_resource(context)
|
||||
.init_resource::<LastBuffer>()
|
||||
.init_resource::<LastAudio>()
|
||||
.insert_resource(defaults)
|
||||
.add_event::<SynthizerEvent>()
|
||||
.add_system_to_stage(CoreStage::PreUpdate, sync_config)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
swap_buffers.before(SynthizerSystems::UpdateHandles),
|
||||
.add_systems(
|
||||
PreUpdate,
|
||||
(sync_config, swap_buffers, change_panner_strategy)
|
||||
.in_set(SynthizerSets::PreUpdate),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
change_panner_strategy.before(SynthizerSystems::UpdateHandles),
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(add_sound_without_source, add_source_handle, add_generator)
|
||||
.in_set(SynthizerSets::UpdateHandles),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
add_source_handle
|
||||
.label(SynthizerSystems::UpdateHandles)
|
||||
.before(SynthizerSystems::UpdateProperties),
|
||||
.configure_sets(
|
||||
PostUpdate,
|
||||
SynthizerSets::UpdateHandles.before(SynthizerSets::UpdateProperties),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
add_generator
|
||||
.label(SynthizerSystems::UpdateHandles)
|
||||
.before(SynthizerSystems::UpdateProperties),
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
update_sound_properties.in_set(SynthizerSets::UpdateProperties),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
add_sound_without_source
|
||||
.label(SynthizerSystems::UpdateHandles)
|
||||
.before(SynthizerSystems::UpdateProperties),
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(update_listener, update_source_properties)
|
||||
.in_set(SynthizerSets::UpdateProperties)
|
||||
.after(TransformSystem::TransformPropagate),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
update_listener
|
||||
.label(SynthizerSystems::UpdateProperties)
|
||||
.after(TransformSystem::TransformPropagate)
|
||||
.before(SynthizerSystems::UpdateState),
|
||||
.configure_sets(
|
||||
PostUpdate,
|
||||
SynthizerSets::UpdateProperties.before(SynthizerSets::UpdateState),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
update_source_properties
|
||||
.label(SynthizerSystems::UpdateProperties)
|
||||
.after(TransformSystem::TransformPropagate)
|
||||
.before(SynthizerSystems::UpdateState),
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(update_source_playback_state, update_sound_playback_state)
|
||||
.in_set(SynthizerSets::UpdateState),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
update_sound_properties
|
||||
.label(SynthizerSystems::UpdateProperties)
|
||||
.before(SynthizerSystems::UpdateState),
|
||||
.configure_sets(
|
||||
PostUpdate,
|
||||
SynthizerSets::UpdateState.before(SynthizerSets::Last),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
update_source_playback_state.label(SynthizerSystems::UpdateState),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
update_sound_playback_state.label(SynthizerSystems::UpdateState),
|
||||
)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_sound)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, events);
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(remove_sound, events).in_set(SynthizerSets::Last),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user