Skip to content

Commit

Permalink
Update 0.5 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
harudagondi committed Aug 14, 2023
1 parent b7ed5b4 commit 1e287ec
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 69 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hound = { version = "3.4", optional = true }
lewton = { version = "0.10", optional = true }
claxon = { version = "0.4", optional = true }
minimp3 = { version = "0.5", optional = true }
bevy_math = { version = "0.10", features = ["mint"] }
bevy_math = { version = "0.11", features = ["mint"] }

[features]
wav = ["hound"]
Expand All @@ -29,7 +29,7 @@ ogg = ["lewton"]
flac = ["claxon"]

[dependencies.bevy]
version = "0.10"
version = "0.11"
default-features = false
features = ["bevy_asset"]

Expand All @@ -38,7 +38,7 @@ fastrand = "2.0"

[dev-dependencies.bevy]
# git = "https://github.com/bevyengine/bevy.git"
version = "0.10"
version = "0.11"
default-features = false
features = [
# "render",
Expand Down
20 changes: 11 additions & 9 deletions examples/gain.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use {
bevy::{
prelude::{
App, Assets, Commands, Deref, Handle, IntoSystemConfig, Res, ResMut, Resource,
StartupSet,
App, Assets, Commands, Deref, Handle, PostStartup, Res, ResMut, Resource, Startup,
Update,
},
reflect::TypeUuid,
reflect::{TypePath, TypeUuid},
time::Time,
DefaultPlugins,
},
bevy_oddio::{builtins::sine, output::AudioSink, Audio, AudioApp, AudioPlugin, ToSignal},
oddio::Sample,
};

#[derive(TypeUuid)]
#[derive(TypeUuid, TypePath)]
#[uuid = "54498976-f7db-4ee7-a2e6-5fee0fcadbfb"]
struct SineWithGain;

Expand All @@ -28,11 +28,11 @@ impl ToSignal for SineWithGain {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_plugins(AudioPlugin::new())
.add_audio_source::<_, SineWithGain>()
.add_startup_system(init_assets)
.add_startup_system(play_sine_with_gain.in_base_set(StartupSet::PostStartup))
.add_system(change_volume)
.add_systems(Startup, init_assets)
.add_systems(PostStartup, play_sine_with_gain)
.add_systems(Update, change_volume)
.run();
}

Expand Down Expand Up @@ -60,7 +60,9 @@ fn change_volume(
mut sinks: ResMut<Assets<AudioSink<SineWithGain>>>,
time: Res<Time>,
) {
let Some(sink) = sinks.get_mut(&sink_handle.0) else { return };
let Some(sink) = sinks.get_mut(&sink_handle.0) else {
return;
};

let factor = (time.elapsed_seconds_wrapped().sin() + 1.0) / 2.0;

Expand Down
13 changes: 6 additions & 7 deletions examples/noise.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use {
bevy::{
prelude::{
App, Assets, Commands, Deref, Handle, IntoSystemConfig, Res, ResMut, Resource,
StartupSet,
App, Assets, Commands, Deref, Handle, PostStartup, Res, ResMut, Resource, Startup,
},
reflect::TypeUuid,
reflect::{TypePath, TypeUuid},
DefaultPlugins,
},
bevy_oddio::{output::AudioSink, Audio, AudioApp, AudioPlugin, ToSignal},
oddio::{Sample, Signal},
};

#[derive(TypeUuid)]
#[derive(TypeUuid, TypePath)]
#[uuid = "7cc24057-b499-4f7a-8f8a-e37dfa64be32"]
struct Noise;
#[derive(Resource)]
Expand Down Expand Up @@ -41,10 +40,10 @@ impl ToSignal for Noise {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_plugins(AudioPlugin::new())
.add_audio_source::<_, Noise>()
.add_startup_system(init_assets)
.add_startup_system(play_noise.in_base_set(StartupSet::PostStartup))
.add_systems(Startup, init_assets)
.add_systems(PostStartup, play_noise)
.run();
}

Expand Down
9 changes: 4 additions & 5 deletions examples/sine.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use {
bevy::{
prelude::{
App, Assets, Commands, Deref, Handle, IntoSystemConfig, Res, ResMut, Resource,
StartupSet,
App, Assets, Commands, Deref, Handle, PostStartup, Res, ResMut, Resource, Startup,
},
DefaultPlugins,
},
Expand All @@ -17,9 +16,9 @@ use {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_startup_system(init_assets)
.add_startup_system(play_sine.in_base_set(StartupSet::PostStartup))
.add_plugins(AudioPlugin::new())
.add_systems(Startup, init_assets)
.add_systems(PostStartup, play_sine)
.run();
}

Expand Down
16 changes: 9 additions & 7 deletions examples/spatial_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use {
bevy::{
prelude::{
default, App, Assets, BuildChildren, Camera2dBundle, Color, Commands, Component, Deref,
Handle, IntoSystemConfig, Query, Res, ResMut, Resource, SpatialBundle, StartupSet,
Transform, Vec2, Vec3, With,
Handle, PostStartup, Query, Res, ResMut, Resource, SpatialBundle, Startup, Transform,
Update, Vec2, Vec3, With,
},
sprite::{Sprite, SpriteBundle},
time::Time,
Expand All @@ -20,10 +20,10 @@ use {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_startup_system(init_assets)
.add_startup_system(setup.in_base_set(StartupSet::PostStartup))
.add_system(change_velocity)
.add_plugins(AudioPlugin::new())
.add_systems(Startup, init_assets)
.add_systems(PostStartup, setup)
.add_systems(Update, change_velocity)
.run();
}

Expand Down Expand Up @@ -86,7 +86,9 @@ fn change_velocity(
let normalized_time = time.elapsed_seconds_wrapped().sin() * 5.0;
let delta = time.delta_seconds();

let Some(sink) = sinks.get_mut(&sink.0) else { return };
let Some(sink) = sinks.get_mut(&sink.0) else {
return;
};

let prev_pos = emitter.translation;
let position = Vec3::new(normalized_time, prev_pos.y, prev_pos.z);
Expand Down
16 changes: 9 additions & 7 deletions examples/spatial_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use {
bevy::{
prelude::{
default, shape, App, Assets, Camera3dBundle, Color, Commands, Component, Deref, Handle,
IntoSystemConfig, Mesh, PbrBundle, PointLight, PointLightBundle, Query, Res, ResMut,
Resource, StandardMaterial, StartupSet, Transform, Vec3, With,
Mesh, PbrBundle, PointLight, PointLightBundle, PostStartup, Query, Res, ResMut,
Resource, StandardMaterial, Startup, Transform, Update, Vec3, With,
},
time::Time,
DefaultPlugins,
Expand All @@ -19,10 +19,10 @@ use {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_startup_system(init_assets)
.add_startup_system(setup.in_base_set(StartupSet::PostStartup))
.add_system(change_velocity)
.add_plugins(AudioPlugin::new())
.add_systems(Startup, init_assets)
.add_systems(PostStartup, setup)
.add_systems(Update, change_velocity)
.run();
}

Expand Down Expand Up @@ -111,7 +111,9 @@ fn change_velocity(
let z = time.elapsed_seconds_wrapped().cos() * 3.0;
let delta = time.delta_seconds();

let Some(sink) = sinks.get_mut(&sink.0) else { return };
let Some(sink) = sinks.get_mut(&sink.0) else {
return;
};

let prev_pos = emitter.translation;
let position = Vec3::new(x, prev_pos.y, z);
Expand Down
16 changes: 9 additions & 7 deletions examples/stop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use {
bevy::{
prelude::{
App, Assets, Commands, Deref, Handle, Input, IntoSystemConfig, KeyCode, Res, ResMut,
Resource, StartupSet,
App, Assets, Commands, Deref, Handle, Input, KeyCode, PostStartup, Res, ResMut,
Resource, Startup, Update,
},
DefaultPlugins,
},
Expand All @@ -17,10 +17,10 @@ use {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AudioPlugin::new())
.add_startup_system(init_assets)
.add_startup_system(play_sine.in_base_set(StartupSet::PostStartup))
.add_system(get_input)
.add_plugins(AudioPlugin::new())
.add_systems(Startup, init_assets)
.add_systems(PostStartup, play_sine)
.add_systems(Update, get_input)
.run();
}

Expand Down Expand Up @@ -49,7 +49,9 @@ fn get_input(
sink: Res<SineSink>,
mut sinks: ResMut<Assets<AudioSink<Sine>>>,
) {
let Some(sink) = sinks.get_mut(&sink.0) else { return };
let Some(sink) = sinks.get_mut(&sink.0) else {
return;
};

let control = sink.control::<oddio::Stop<_>, _>();

Expand Down
8 changes: 6 additions & 2 deletions src/builtins/constant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use {crate::ToSignal, bevy::reflect::TypeUuid, std::marker::PhantomData};
use {
crate::ToSignal,
bevy::reflect::{TypePath, TypeUuid},
std::marker::PhantomData,
};

/// [`Asset`](bevy::asset::Asset) form of [`Constant`](oddio::Constant)
#[derive(TypeUuid, Default)]
#[derive(TypeUuid, TypePath, Default)]
#[uuid = "6bcf912a-91d0-46d3-bd55-e81123bbc591"]
pub struct Constant<T> {
_phantom: PhantomData<T>,
Expand Down
4 changes: 2 additions & 2 deletions src/builtins/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use {
crate::ToSignal,
bevy::reflect::TypeUuid,
bevy::reflect::{TypePath, TypeUuid},
oddio::{Frame, Frames},
std::{marker::PhantomData, sync::Arc},
};

/// [`Asset`](bevy::asset::Asset) form of [`Constant`](oddio::Constant)
#[derive(TypeUuid, Default)]
#[derive(TypeUuid, TypePath, Default)]
#[uuid = "f391d20f-7654-403a-b7c9-3f3c7991138a"]
pub struct Cycle<T> {
_phantom: PhantomData<T>,
Expand Down
7 changes: 5 additions & 2 deletions src/builtins/sine.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use {crate::ToSignal, bevy::reflect::TypeUuid};
use {
crate::ToSignal,
bevy::reflect::{TypePath, TypeUuid},
};

/// [`Asset`](bevy::asset::Asset) form of [`Sine`](oddio::Sine)
#[derive(TypeUuid)]
#[derive(TypeUuid, TypePath)]
#[uuid = "14597aba-d411-4bfc-b227-09cf5f88202f"]
pub struct Sine;

Expand Down
7 changes: 5 additions & 2 deletions src/builtins/spatial_scene.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use {crate::ToSignal, bevy::reflect::TypeUuid};
use {
crate::ToSignal,
bevy::reflect::{TypePath, TypeUuid},
};

/// [`Asset`](bevy::asset::Asset) form of [`SpatialScene`](oddio::SpatialScene)
#[derive(TypeUuid)]
#[derive(TypeUuid, TypePath)]
#[uuid = "4c5ea5bb-293e-485e-93d9-7a4f69d2130a"]
pub struct SpatialScene;

Expand Down
9 changes: 7 additions & 2 deletions src/builtins/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use {crate::ToSignal, bevy::reflect::TypeUuid, oddio::Frame, std::marker::PhantomData};
use {
crate::ToSignal,
bevy::reflect::{TypePath, TypeUuid},
oddio::Frame,
std::marker::PhantomData,
};

/// [`Asset`](bevy::asset::Asset) form of [`Stream`](oddio::Stream)
#[derive(TypeUuid, Default)]
#[derive(TypeUuid, TypePath, Default)]
#[uuid = "f391d20f-7654-403a-b7c9-3f3c7991138a"]
pub struct Stream<T> {
_phantom: PhantomData<T>,
Expand Down
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use {
bevy::{
asset::{Asset, HandleId},
prelude::{
AddAsset, App, CoreSet, Handle as BevyHandle, IntoSystemConfig, Plugin, Resource,
},
prelude::{AddAsset, App, Handle as BevyHandle, Plugin, Resource},
reflect::TypeUuid,
},
cpal::SupportedStreamConfigRange,
Expand Down Expand Up @@ -42,6 +40,7 @@ pub mod builtins;
/// Newtypes for working around [bevyengine/bevy#5432](https://github.com/bevyengine/bevy/issues/5432)
pub mod frames;

use bevy::{prelude::PostUpdate, reflect::TypePath};
pub use frames::*;

mod loader;
Expand Down Expand Up @@ -121,7 +120,7 @@ where
/// Source of audio data.
///
/// Accepts an atomically reference-counted [`Frames`] with two channels.
#[derive(Clone, TypeUuid)]
#[derive(Clone, TypeUuid, TypePath)]
#[uuid = "2b024eb6-88f1-4001-b678-0446f2fab0f4"]
pub struct AudioSource<F: Frame> {
/// Raw audio data. See [`Frames`].
Expand Down Expand Up @@ -257,7 +256,7 @@ impl AudioApp for App {
.add_asset::<AudioSink<Source>>()
.init_resource::<Audio<F, Source>>()
.init_resource::<AudioSinks<Source>>()
.add_system(play_queued_audio::<F, Source>.in_base_set(CoreSet::PostUpdate))
.add_systems(PostUpdate, play_queued_audio::<F, Source>)
}

fn add_spatial_audio_source<Source>(&mut self) -> &mut Self
Expand All @@ -269,7 +268,7 @@ impl AudioApp for App {
.add_asset::<SpatialAudioSink<Source>>()
.init_resource::<Audio<Sample, Source>>()
.init_resource::<SpatialAudioSinks<Source>>()
.add_system(play_queued_spatial_audio::<Source>.in_base_set(CoreSet::PostUpdate))
.add_systems(PostUpdate, play_queued_spatial_audio::<Source>)
}

fn add_spatial_buffered_audio_source<Source>(&mut self) -> &mut Self
Expand All @@ -281,9 +280,7 @@ impl AudioApp for App {
.add_asset::<SpatialBufferedAudioSink<Source>>()
.init_resource::<Audio<Sample, Source>>()
.init_resource::<SpatialBufferedAudioSinks<Source>>()
.add_system(
play_queued_spatial_buffered_audio::<Source>.in_base_set(CoreSet::PostUpdate),
)
.add_systems(PostUpdate, play_queued_spatial_buffered_audio::<Source>)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
bevy::{
asset::{Asset, Handle as BevyHandle, HandleId},
prelude::{Assets, Deref, DerefMut, FromWorld, Res, ResMut, Resource},
reflect::TypeUuid,
reflect::{TypePath, TypeUuid},
tasks::AsyncComputeTaskPool,
utils::HashMap,
},
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn play_queued_audio<F, Source>(
}

/// Asset that controls the playback of the sound.
#[derive(TypeUuid, Deref, DerefMut)]
#[derive(TypeUuid, TypePath, Deref, DerefMut)]
#[uuid = "82317ee9-8f2d-4973-bb7f-8f4a5b74cc55"]
pub struct AudioSink<Source: ToSignal + Asset>(
ManuallyDrop<OddioHandle<Stop<<Source as ToSignal>::Signal>>>,
Expand Down
Loading

0 comments on commit 1e287ec

Please sign in to comment.