Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e69dae28b | |||
e121945a7c | |||
6a2182ce52 | |||
7b0b3d8262 | |||
6f18f7ffbc | |||
888a9e78fc | |||
7738cdb27c | |||
0c8f557886 | |||
78e5bf2c45 | |||
3c557fa5ab |
|
@ -6,11 +6,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
runs-on: ubuntu-latest
|
||||||
matrix:
|
|
||||||
# os: [windows-latest, ubuntu-latest, macos-latest]
|
|
||||||
os: [ubuntu-latest]
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
|
@ -26,12 +22,7 @@ jobs:
|
||||||
~/.cargo/git/db/
|
~/.cargo/git/db/
|
||||||
target/
|
target/
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
- uses: dtolnay/rust-toolchain@master
|
- name: Install Nix
|
||||||
with:
|
uses: https://github.com/cachix/install-nix-action@v31
|
||||||
toolchain: stable
|
- name: Test
|
||||||
components: rustfmt, clippy
|
run: nix develop --command pre-commit run -a
|
||||||
- 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
|
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
*.dll
|
*.dll
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.direnv
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -2,6 +2,25 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## Version 0.10.0 - 2025-05-16
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Add Nix-based build and CI configuration.
|
||||||
|
- Update to Bevy 0.16.
|
||||||
|
|
||||||
|
## Version 0.9.1 - 2025-01-07
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Don't set position if values are NaN.
|
||||||
|
|
||||||
|
## Version 0.9.0 - 2024-12-06
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Upgrade to Bevy 0.15.
|
||||||
|
|
||||||
## Version 0.8.0 - 2024-12-02
|
## Version 0.8.0 - 2024-12-02
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bevy_synthizer"
|
name = "bevy_synthizer"
|
||||||
version = "0.8.0"
|
version = "0.10.0"
|
||||||
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
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"
|
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"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@ -10,12 +10,12 @@ repository = "https://labs.lightsout.games/projects/bevy_synthizer"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.14", default-features = false, features = ["bevy_asset"] }
|
bevy = { version = "0.16", default-features = false, features = ["bevy_asset"] }
|
||||||
synthizer = "0.5.6"
|
synthizer = "0.5.6"
|
||||||
thiserror = "1"
|
thiserror = "2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bevy = { version = "0.14", default-features = true }
|
bevy = { version = "0.16", default-features = true }
|
||||||
|
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
|
@ -31,14 +31,10 @@ fn load_and_create(
|
||||||
if !listeners.is_empty() {
|
if !listeners.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commands.spawn((
|
commands.spawn((Transform::default(), Listener, RotationTimer::default()));
|
||||||
TransformBundle::default(),
|
|
||||||
Listener,
|
|
||||||
RotationTimer::default(),
|
|
||||||
));
|
|
||||||
let handle = asset_server.load("footstep.wav");
|
let handle = asset_server.load("footstep.wav");
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))),
|
Transform::from_translation(Vec3::new(10., 0., 0.)),
|
||||||
Source::default(),
|
Source::default(),
|
||||||
Sound {
|
Sound {
|
||||||
audio: handle.into(),
|
audio: handle.into(),
|
||||||
|
|
|
@ -13,16 +13,12 @@ impl Default for RotationTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(mut commands: Commands, context: Res<Context>) {
|
fn setup(mut commands: Commands, context: Res<Context>) {
|
||||||
commands.spawn((
|
commands.spawn((Transform::default(), Listener, RotationTimer::default()));
|
||||||
TransformBundle::default(),
|
|
||||||
Listener,
|
|
||||||
RotationTimer::default(),
|
|
||||||
));
|
|
||||||
let generator: syz::Generator = syz::FastSineBankGenerator::new_sine(&context, 440.)
|
let generator: syz::Generator = syz::FastSineBankGenerator::new_sine(&context, 440.)
|
||||||
.expect("Failed to create generator")
|
.expect("Failed to create generator")
|
||||||
.into();
|
.into();
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))),
|
Transform::from_translation(Vec3::new(10., 0., 0.)),
|
||||||
Source::default(),
|
Source::default(),
|
||||||
Sound {
|
Sound {
|
||||||
audio: generator.into(),
|
audio: generator.into(),
|
||||||
|
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1747312588,
|
||||||
|
"narHash": "sha256-MmJvj6mlWzeRwKGLcwmZpKaOPZ5nJb/6al5CXqJsgjo=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "b1bebd0fe266bbd1820019612ead889e96a8fa2d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"utils": "utils"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
54
flake.nix
Normal file
54
flake.nix
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
utils,
|
||||||
|
}:
|
||||||
|
utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShell =
|
||||||
|
with pkgs;
|
||||||
|
mkShell.override { stdenv = pkgs.clangStdenv; } rec {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
cargo
|
||||||
|
rustc
|
||||||
|
rustfmt
|
||||||
|
rustPackages.clippy
|
||||||
|
cmake
|
||||||
|
pkg-config
|
||||||
|
pre-commit
|
||||||
|
git-cliff
|
||||||
|
cargo-release
|
||||||
|
cargo-outdated
|
||||||
|
];
|
||||||
|
buildInputs = [
|
||||||
|
udev
|
||||||
|
alsa-lib
|
||||||
|
vulkan-loader
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libXcursor
|
||||||
|
xorg.libXi
|
||||||
|
xorg.libXrandr
|
||||||
|
libxkbcommon
|
||||||
|
wayland
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
|
||||||
|
export RUSTFLAGS="-C link-arg=-Wl,-rpath,${lib.makeLibraryPath buildInputs}"
|
||||||
|
pre-commit install
|
||||||
|
'';
|
||||||
|
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
51
src/lib.rs
51
src/lib.rs
|
@ -2,9 +2,8 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
|
asset::{io::Reader, AssetLoader, LoadContext},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
reflect::TypePath,
|
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
pub use synthizer as syz;
|
pub use synthizer as syz;
|
||||||
|
@ -30,11 +29,11 @@ impl AssetLoader for BufferAssetLoader {
|
||||||
type Settings = ();
|
type Settings = ();
|
||||||
type Error = BufferAssetLoaderError;
|
type Error = BufferAssetLoaderError;
|
||||||
|
|
||||||
async fn load<'a>(
|
async fn load(
|
||||||
&'a self,
|
&self,
|
||||||
reader: &'a mut Reader<'_>,
|
reader: &mut dyn Reader,
|
||||||
_settings: &'a (),
|
_settings: &(),
|
||||||
_load_context: &'a mut LoadContext<'_>,
|
_load_context: &mut LoadContext<'_>,
|
||||||
) -> Result<Self::Asset, Self::Error> {
|
) -> Result<Self::Asset, Self::Error> {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
reader.read_to_end(&mut bytes).await?;
|
reader.read_to_end(&mut bytes).await?;
|
||||||
|
@ -189,7 +188,7 @@ fn update_listener(
|
||||||
context: ResMut<Context>,
|
context: ResMut<Context>,
|
||||||
listener: Query<Option<&GlobalTransform>, With<Listener>>,
|
listener: Query<Option<&GlobalTransform>, With<Listener>>,
|
||||||
) {
|
) {
|
||||||
if let Ok(transform) = listener.get_single() {
|
if let Ok(transform) = listener.single() {
|
||||||
let transform: Transform = transform
|
let transform: Transform = transform
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
let transform: Transform = (*v).into();
|
let transform: Transform = (*v).into();
|
||||||
|
@ -273,9 +272,9 @@ fn add_source_handle(
|
||||||
fn add_generator(
|
fn add_generator(
|
||||||
context: Res<Context>,
|
context: Res<Context>,
|
||||||
buffers: Res<Assets<Buffer>>,
|
buffers: Res<Assets<Buffer>>,
|
||||||
mut query: Query<(Entity, Option<&Parent>, &mut Sound)>,
|
mut query: Query<(Entity, Option<&ChildOf>, &mut Sound)>,
|
||||||
mut sources: Query<&mut Source>,
|
mut sources: Query<&mut Source>,
|
||||||
parents: Query<&Parent>,
|
parents: Query<&ChildOf>,
|
||||||
) {
|
) {
|
||||||
for (entity, parent, mut sound) in &mut query {
|
for (entity, parent, mut sound) in &mut query {
|
||||||
if sound.generator.is_some() {
|
if sound.generator.is_some() {
|
||||||
|
@ -287,11 +286,11 @@ fn add_generator(
|
||||||
let mut parent = parent;
|
let mut parent = 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.parent()).is_ok() {
|
||||||
target = Some(**p);
|
target = Some(p.parent());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parent = parents.get(**p).ok();
|
parent = parents.get(p.parent()).ok();
|
||||||
}
|
}
|
||||||
target.map(|v| sources.get_mut(v).unwrap())
|
target.map(|v| sources.get_mut(v).unwrap())
|
||||||
} else {
|
} else {
|
||||||
|
@ -342,7 +341,7 @@ fn add_generator(
|
||||||
fn add_sound_without_source(
|
fn add_sound_without_source(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
query: Query<Entity, (Added<Sound>, Without<Source>)>,
|
query: Query<Entity, (Added<Sound>, Without<Source>)>,
|
||||||
parents: Query<(&Parent, Option<&Source>)>,
|
parents: Query<(&ChildOf, Option<&Source>)>,
|
||||||
) {
|
) {
|
||||||
for entity in &query {
|
for entity in &query {
|
||||||
let mut has_source = false;
|
let mut has_source = false;
|
||||||
|
@ -352,7 +351,7 @@ fn add_sound_without_source(
|
||||||
has_source = true;
|
has_source = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
target = **parent;
|
target = parent.parent();
|
||||||
}
|
}
|
||||||
if !has_source {
|
if !has_source {
|
||||||
commands.entity(entity).insert(Source::default());
|
commands.entity(entity).insert(Source::default());
|
||||||
|
@ -442,14 +441,16 @@ fn update_source_properties(
|
||||||
if let Some(source) = handle.cast_to::<syz::Source3D>().expect("Failed to cast") {
|
if let Some(source) = handle.cast_to::<syz::Source3D>().expect("Failed to cast") {
|
||||||
if let Some(transform) = transform {
|
if let Some(transform) = transform {
|
||||||
let translation = transform.translation();
|
let translation = transform.translation();
|
||||||
source
|
if !translation.x.is_nan() && !translation.y.is_nan() && !translation.z.is_nan() {
|
||||||
.position()
|
source
|
||||||
.set((
|
.position()
|
||||||
translation.x as f64,
|
.set((
|
||||||
translation.y as f64,
|
translation.x as f64,
|
||||||
translation.z as f64,
|
translation.y as f64,
|
||||||
))
|
translation.z as f64,
|
||||||
.expect("Failed to set position");
|
))
|
||||||
|
.expect("Failed to set position");
|
||||||
|
}
|
||||||
let distance_model = distance_model
|
let distance_model = distance_model
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|v| *v)
|
.map(|v| *v)
|
||||||
|
@ -708,10 +709,10 @@ fn events(
|
||||||
if *generator.handle() == event.source {
|
if *generator.handle() == event.source {
|
||||||
match event.r#type {
|
match event.r#type {
|
||||||
syz::EventType::Finished => {
|
syz::EventType::Finished => {
|
||||||
output.send(SynthizerEvent::Finished(entity));
|
output.write(SynthizerEvent::Finished(entity));
|
||||||
}
|
}
|
||||||
syz::EventType::Looped => {
|
syz::EventType::Looped => {
|
||||||
output.send(SynthizerEvent::Looped(entity));
|
output.write(SynthizerEvent::Looped(entity));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user