From c408176665c890c5e1fa8a15da5a1fa49f9f9fff Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Sat, 4 Nov 2023 19:02:58 -0400 Subject: [PATCH 1/6] Initial work for build_audio_source_from_path --- .gitignore | 1 + src/fmod_studio.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6aa133e..72d09be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ assets/ *.so.* demo_project/ Cargo.lock +.vscode/ diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index e30fc61..332e339 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -2,13 +2,14 @@ use std::env::var; use std::fs::canonicalize; use std::path::{Path, PathBuf}; -use bevy::prelude::{debug, trace, Resource}; +use bevy::prelude::{debug, trace, Resource, AudioSource}; #[cfg(feature = "live-update")] use libfmod::ffi::FMOD_STUDIO_INIT_LIVEUPDATE; use libfmod::ffi::{ FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_NORMAL, FMOD_STUDIO_LOAD_BANK_NORMAL, }; use libfmod::Studio; +use crate::components::audio_source::AudioSource as BevyFmodAudioSource; #[derive(Resource)] pub struct FmodStudio(pub Studio); @@ -66,4 +67,10 @@ impl FmodStudio { studio } + + pub fn build_audio_source_from_path(&self, path: &str) -> BevyFmodAudioSource{ + let event_description = self.0.get_event(path).expect("The event is expected to exist in the FMOD project."); + BevyFmodAudioSource::new(event_description) + } + } From c94f66143cb19ad3d6cf15a1ecff24b27ead5641 Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Sat, 4 Nov 2023 19:19:43 -0400 Subject: [PATCH 2/6] ran cargo format --- src/fmod_studio.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index 332e339..9c21035 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -2,14 +2,14 @@ use std::env::var; use std::fs::canonicalize; use std::path::{Path, PathBuf}; -use bevy::prelude::{debug, trace, Resource, AudioSource}; +use crate::components::audio_source::AudioSource as BevyFmodAudioSource; +use bevy::prelude::{debug, trace, Resource}; #[cfg(feature = "live-update")] use libfmod::ffi::FMOD_STUDIO_INIT_LIVEUPDATE; use libfmod::ffi::{ FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_NORMAL, FMOD_STUDIO_LOAD_BANK_NORMAL, }; use libfmod::Studio; -use crate::components::audio_source::AudioSource as BevyFmodAudioSource; #[derive(Resource)] pub struct FmodStudio(pub Studio); @@ -68,9 +68,11 @@ impl FmodStudio { studio } - pub fn build_audio_source_from_path(&self, path: &str) -> BevyFmodAudioSource{ - let event_description = self.0.get_event(path).expect("The event is expected to exist in the FMOD project."); + pub fn build_audio_source_from_path(&self, path: &str) -> BevyFmodAudioSource { + let event_description = self + .0 + .get_event(path) + .expect("The event is expected to exist in the FMOD project."); BevyFmodAudioSource::new(event_description) } - } From 5f779a0108338973fb83262da733d4df8885afba Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Sun, 5 Nov 2023 17:52:54 -0500 Subject: [PATCH 3/6] Removed dependency alias --- src/fmod_studio.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index 9c21035..2d470b9 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -2,7 +2,7 @@ use std::env::var; use std::fs::canonicalize; use std::path::{Path, PathBuf}; -use crate::components::audio_source::AudioSource as BevyFmodAudioSource; +use crate::components::audio_source::AudioSource; use bevy::prelude::{debug, trace, Resource}; #[cfg(feature = "live-update")] use libfmod::ffi::FMOD_STUDIO_INIT_LIVEUPDATE; @@ -68,11 +68,11 @@ impl FmodStudio { studio } - pub fn build_audio_source_from_path(&self, path: &str) -> BevyFmodAudioSource { + pub fn build_audio_source(&self, path_or_id: &str) -> AudioSource { let event_description = self .0 - .get_event(path) - .expect("The event is expected to exist in the FMOD project."); - BevyFmodAudioSource::new(event_description) + .get_event(path_or_id) + .expect("Failed to get FMOD event from path or ID."); + AudioSource::new(event_description) } } From a057c250a3a15fd87440addd9e65743805e504bc Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Sun, 5 Nov 2023 17:57:45 -0500 Subject: [PATCH 4/6] add .idea folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 72d09be..9a47f34 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ assets/ demo_project/ Cargo.lock .vscode/ +.idea/ \ No newline at end of file From e7bd45c1d8c1876f0f9bbd01a3a80828ff842622 Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Sun, 5 Nov 2023 18:04:36 -0500 Subject: [PATCH 5/6] Updated examples with new build_audio_source helper --- examples/audio_control.rs | 4 +--- examples/minimal.rs | 4 +--- examples/parameters.rs | 8 ++------ examples/spatial.rs | 6 +++--- src/components/bundles.rs | 5 ++--- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/examples/audio_control.rs b/examples/audio_control.rs index 5c09469..f33784e 100644 --- a/examples/audio_control.rs +++ b/examples/audio_control.rs @@ -31,11 +31,9 @@ fn main() { struct MyMusicPlayer; fn startup(mut commands: Commands, studio: Res) { - let event_description = studio.0.get_event("event:/Music/Level 03").unwrap(); - commands .spawn(MyMusicPlayer) - .insert(AudioSource::new(event_description)); + .insert(studio.build_audio_source("event:/Music/Level 03")); } fn play_music(mut audio_sources: Query<&AudioSource, With>) { diff --git a/examples/minimal.rs b/examples/minimal.rs index 9048b1c..f097cd2 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -26,11 +26,9 @@ fn main() { struct MyMusicPlayer; fn startup(mut commands: Commands, studio: Res) { - let event_description = studio.0.get_event("event:/Music/Level 03").unwrap(); - commands .spawn(MyMusicPlayer) - .insert(AudioSource::new(event_description)); + .insert(studio.build_audio_source("event:/Music/Level 03")); } fn play_music(mut audio_sources: Query<&AudioSource, With>) { diff --git a/examples/parameters.rs b/examples/parameters.rs index 2f5bedc..aa9ef1c 100644 --- a/examples/parameters.rs +++ b/examples/parameters.rs @@ -63,17 +63,13 @@ struct ForestSfxPlayer; struct CountrySfxPlayer; fn startup(mut commands: Commands, studio: Res) { - let event_description = studio.0.get_event("event:/Ambience/Forest").unwrap(); - commands .spawn(ForestSfxPlayer) - .insert(AudioSource::new(event_description)); - - let event_description = studio.0.get_event("event:/Ambience/Country").unwrap(); + .insert(studio.build_audio_source("event:/Ambience/Forest")); commands .spawn(CountrySfxPlayer) - .insert(AudioSource::new(event_description)); + .insert(studio.build_audio_source("event:/Ambience/Country")); } fn play_music(audio_sources: Query<&AudioSource>) { diff --git a/examples/spatial.rs b/examples/spatial.rs index 3da71ac..dbcd8c8 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -66,10 +66,10 @@ fn setup_scene( Vec3::Y, )); // Audio source - let event_description = studio.0.get_event("event:/Music/Radio Station").unwrap(); - commands - .spawn(SpatialAudioBundle::new(event_description)) + .spawn(SpatialAudioBundle::new( + studio.build_audio_source("event:/Music/Radio Station"), + )) .insert(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), diff --git a/src/components/bundles.rs b/src/components/bundles.rs index 55c8ce4..a740f5c 100644 --- a/src/components/bundles.rs +++ b/src/components/bundles.rs @@ -1,6 +1,5 @@ use crate::prelude::{AudioListener, AudioSource, Velocity}; use bevy::prelude::{Bundle, Transform}; -use libfmod::EventDescription; #[derive(Bundle)] pub struct SpatialAudioBundle { @@ -10,9 +9,9 @@ pub struct SpatialAudioBundle { } impl SpatialAudioBundle { - pub fn new(event_description: EventDescription) -> Self { + pub fn new(audio_source: AudioSource) -> Self { SpatialAudioBundle { - audio_source: AudioSource::new(event_description), + audio_source, velocity: Velocity::default(), transform: Transform::default(), } From 0f4e11bbc7cbad37ecbec0042d01fb756f5cad92 Mon Sep 17 00:00:00 2001 From: Houssein Khafaja Date: Thu, 16 Nov 2023 16:59:37 -0500 Subject: [PATCH 6/6] undo changes to .gitignore --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9a47f34..fc69cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,4 @@ assets/ *.so *.so.* demo_project/ -Cargo.lock -.vscode/ -.idea/ \ No newline at end of file +Cargo.lock \ No newline at end of file