Skip to content

Commit

Permalink
Merge pull request #126 from NiklasEi/bevy_main
Browse files Browse the repository at this point in the history
Update to Bevy 0.14
  • Loading branch information
NiklasEi authored Jul 5, 2024
2 parents dba0bb6 + 18a0710 commit 9fe5cf8
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 192 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.20.0 - 04.07.2024
- Update to Bevy `0.14`

## v0.19.0 - 17.02.2024
- Update to Bevy `0.13`

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_kira_audio"
version = "0.19.0"
version = "0.20.0"
authors = ["Niklas Eicker <hello@nikl.me>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,7 +22,7 @@ wav = ["kira/wav"]
settings_loader = ["dep:ron", "dep:serde", "kira/serde"]

[dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.14.0", default-features = false, features = ["bevy_asset"] }
anyhow = "1.0"
uuid = { version = "1", features = ["fast-rng"] }
kira = { version = "0.8", default-features = false, features = ["cpal"] }
Expand All @@ -32,7 +32,7 @@ parking_lot = "0.12"
thiserror = "1.0"

[dev-dependencies.bevy]
version = "0.13"
version = "0.14.0"
default-features = false
features = [
"bevy_asset",
Expand All @@ -49,7 +49,7 @@ features = [
"tonemapping_luts",
"ktx2",
"zstd",
"multi-threaded",
"multi_threaded"
]

[[example]]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Sound can be played in channels. Each channel has controls to pause or stop play

## Usage

*Note: the Bevy feature `bevy_audio` is enabled by default and not compatible with this plugin. Make sure to not have the `bevy_audio` feature enabled if you want to use `bevy_kira_audio`. The same goes for Bevy's `vorbis` feature. See [Bevys' Cargo file][bevy_default_features] for a list of all default features of version `0.12` and list them manually in your Cargo file excluding the ones you do not want. Make sure to set `default-features` to `false` for the Bevy dependency. You can take a look at [bevy_game_template's cargo file as an example](https://github.com/NiklasEi/bevy_game_template/blob/main/Cargo.toml).*
*Note: the Bevy feature `bevy_audio` is enabled by default and not compatible with this plugin. Make sure to not have the `bevy_audio` feature enabled if you want to use `bevy_kira_audio`. The same goes for Bevy's `vorbis` feature. See [Bevys' Cargo file][bevy_default_features] for a list of all default features of version `0.14` and list them manually in your Cargo file excluding the ones you do not want. Make sure to set `default-features` to `false` for the Bevy dependency. You can take a look at [bevy_game_template's cargo file as an example](https://github.com/NiklasEi/bevy_game_template/blob/main/Cargo.toml).*


To play audio, you usually want to load audio files as assets. This requires `AssetLoaders`. `bevy_kira_audio` comes with loaders for most common audio formats. You can enable them with the features `ogg` (enabled by default), `mp3`, `wav`, or `flac`. The following example assumes that the feature `ogg` is enabled.
Expand Down Expand Up @@ -91,6 +91,7 @@ Compatibility of `bevy_kira_audio` versions:

| Bevy version | `bevy_kira_audio` version |
|:-------------|:--------------------------|
| `0.14` | `0.20` |
| `0.13` | `0.19` |
| `0.12` | `0.18` |
| `0.11` | `0.16` - `0.17` |
Expand Down Expand Up @@ -124,4 +125,4 @@ additional terms or conditions.


[kira]: https://github.com/tesselode/kira
[bevy_default_features]: https://github.com/bevyengine/bevy/blob/v0.13.0/Cargo.toml#L55-L80
[bevy_default_features]: https://github.com/bevyengine/bevy/blob/v0.14.0/Cargo.toml#L56-L86
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
App::new()
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.run()
.run();
}

// `Audio` is an alias for `AudioChannel<MainTrack>`, which is the default channel added by the audio plugin
Expand Down
2 changes: 1 addition & 1 deletion examples/channel_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.add_systems(Update, channel_control)
.run()
.run();
}

fn channel_control(input: Res<ButtonInput<MouseButton>>, audio: Res<Audio>) {
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, start_background_audio)
.add_systems(Update, plop)
.run()
.run();
}

fn start_background_audio(
Expand Down
2 changes: 1 addition & 1 deletion examples/instance_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, play_loop)
.add_systems(Update, instance_control)
.run()
.run();
}

fn instance_control(
Expand Down
82 changes: 41 additions & 41 deletions examples/multiple_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ fn play_pause_button<T: Component + Default>(
mut channel_state: ResMut<ChannelAudioState<T>>,
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), With<PlayPauseButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<PlayPauseButton<T>>>,
mut play_pause_text: Query<&mut Text, With<PlayPauseButton<T>>>,
) {
let (interaction, mut color) = interaction_query.single_mut();
*color = if channel_state.stopped {
DISABLED_BUTTON.into()
let (interaction, mut image) = interaction_query.single_mut();
image.color = if channel_state.stopped {
DISABLED_BUTTON
} else if interaction == &Interaction::Hovered {
HOVERED_BUTTON.into()
HOVERED_BUTTON
} else {
NORMAL_BUTTON.into()
NORMAL_BUTTON
};
let mut text = play_pause_text.single_mut();
text.sections.first_mut().unwrap().value = if channel_state.paused {
Expand Down Expand Up @@ -74,15 +74,15 @@ fn stop_button<T: Component + Default>(
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), With<StopButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<StopButton<T>>>,
) {
let (interaction, mut color) = interaction_query.single_mut();
*color = if channel_state.stopped {
DISABLED_BUTTON.into()
let (interaction, mut image) = interaction_query.single_mut();
image.color = if channel_state.stopped {
DISABLED_BUTTON
} else if interaction == &Interaction::Hovered {
HOVERED_BUTTON.into()
HOVERED_BUTTON
} else {
NORMAL_BUTTON.into()
NORMAL_BUTTON
};
if channel_state.stopped {
return;
Expand All @@ -102,17 +102,17 @@ fn loop_button<T: Component + Default>(
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
audio_handles: Res<AudioHandles>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), With<StartLoopButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<StartLoopButton<T>>>,
) {
let (interaction, mut color) = interaction_query.single_mut();
*color = if !channel_state.loop_started {
let (interaction, mut image) = interaction_query.single_mut();
image.color = if !channel_state.loop_started {
if interaction == &Interaction::Hovered {
HOVERED_BUTTON.into()
HOVERED_BUTTON
} else {
NORMAL_BUTTON.into()
NORMAL_BUTTON
}
} else {
DISABLED_BUTTON.into()
DISABLED_BUTTON
};
if channel_state.loop_started {
return;
Expand All @@ -133,13 +133,13 @@ fn play_sound_button<T: Component + Default>(
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
audio_handles: Res<AudioHandles>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor), With<PlaySoundButton<T>>>,
mut interaction_query: Query<(&Interaction, &mut UiImage), With<PlaySoundButton<T>>>,
) {
let (interaction, mut color) = interaction_query.single_mut();
*color = if interaction == &Interaction::Hovered {
HOVERED_BUTTON.into()
let (interaction, mut image) = interaction_query.single_mut();
image.color = if interaction == &Interaction::Hovered {
HOVERED_BUTTON
} else {
NORMAL_BUTTON.into()
NORMAL_BUTTON
};
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
Expand All @@ -156,13 +156,13 @@ fn volume_buttons<T: Component + Default>(
time: Res<Time>,
mut last_action: ResMut<LastAction>,
mut channel_state: ResMut<ChannelAudioState<T>>,
mut interaction_query: Query<(&Interaction, &mut BackgroundColor, &ChangeVolumeButton<T>)>,
mut interaction_query: Query<(&Interaction, &mut UiImage, &ChangeVolumeButton<T>)>,
) {
for (interaction, mut color, volume) in &mut interaction_query {
*color = if interaction == &Interaction::Hovered {
HOVERED_BUTTON.into()
for (interaction, mut image, volume) in &mut interaction_query {
image.color = if interaction == &Interaction::Hovered {
HOVERED_BUTTON
} else {
NORMAL_BUTTON.into()
NORMAL_BUTTON
};
if interaction == &Interaction::Pressed {
if !last_action.action(&time) {
Expand Down Expand Up @@ -252,9 +252,9 @@ impl<T> Default for ChannelAudioState<T> {
}
}

const NORMAL_BUTTON: Color = Color::rgb(0.15, 0.15, 0.15);
const HOVERED_BUTTON: Color = Color::rgb(0.25, 0.25, 0.25);
const DISABLED_BUTTON: Color = Color::rgb(0.5, 0.5, 0.5);
const NORMAL_BUTTON: Color = Color::linear_rgb(0.15, 0.15, 0.15);
const HOVERED_BUTTON: Color = Color::linear_rgb(0.25, 0.25, 0.25);
const DISABLED_BUTTON: Color = Color::linear_rgb(0.5, 0.5, 0.5);

fn prepare_audio_and_ui(mut commands: Commands, asset_server: ResMut<AssetServer>) {
let loop_handle = asset_server.load("sounds/loop.ogg");
Expand Down Expand Up @@ -327,7 +327,7 @@ fn build_button_row<T: Component + Default + Clone>(
value: format!("Channel {}", 4 - channel_index),
style: TextStyle {
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
font: font.clone(),
},
}],
Expand All @@ -339,28 +339,28 @@ fn build_button_row<T: Component + Default + Clone>(
spawn_button(
parent,
"Sound",
DISABLED_BUTTON.into(),
DISABLED_BUTTON,
PlaySoundButton::<T>::default(),
font.clone(),
);
spawn_button(
parent,
"Loop",
DISABLED_BUTTON.into(),
DISABLED_BUTTON,
StartLoopButton::<T>::default(),
font.clone(),
);
spawn_button(
parent,
"Pause",
DISABLED_BUTTON.into(),
DISABLED_BUTTON,
PlayPauseButton::<T>::default(),
font.clone(),
);
spawn_button(
parent,
"Vol. up",
NORMAL_BUTTON.into(),
NORMAL_BUTTON,
ChangeVolumeButton::<T> {
louder: true,
_marker: PhantomData,
Expand All @@ -370,7 +370,7 @@ fn build_button_row<T: Component + Default + Clone>(
spawn_button(
parent,
"Vol. down",
NORMAL_BUTTON.into(),
NORMAL_BUTTON,
ChangeVolumeButton::<T> {
louder: false,
_marker: PhantomData,
Expand All @@ -380,7 +380,7 @@ fn build_button_row<T: Component + Default + Clone>(
spawn_button(
parent,
"Stop",
DISABLED_BUTTON.into(),
DISABLED_BUTTON,
StopButton::<T>::default(),
font.clone(),
);
Expand All @@ -390,7 +390,7 @@ fn build_button_row<T: Component + Default + Clone>(
fn spawn_button<T: Component + Clone>(
parent: &mut ChildBuilder,
text: &str,
background_color: BackgroundColor,
color: Color,
marker: T,
font: Handle<Font>,
) {
Expand All @@ -404,7 +404,7 @@ fn spawn_button<T: Component + Clone>(
align_items: AlignItems::Center,
..Default::default()
},
background_color,
image: UiImage::default().with_color(color),
..Default::default()
})
.insert(marker.clone())
Expand All @@ -416,7 +416,7 @@ fn spawn_button<T: Component + Clone>(
value: text.to_string(),
style: TextStyle {
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
font: font.clone(),
},
}],
Expand Down
6 changes: 3 additions & 3 deletions examples/spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.insert_resource(SpatialAudio { max_distance: 25. })
.add_plugins((DefaultPlugins, AudioPlugin, CameraPlugin))
.add_systems(Startup, setup)
.run()
.run();
}

fn setup(
Expand Down Expand Up @@ -73,7 +73,7 @@ fn setup(
style: TextStyle {
font: asset_server.load("fonts/monogram.ttf"),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
}],
..default()
Expand All @@ -88,7 +88,7 @@ fn setup(
mesh: meshes.add(Cuboid {
half_size: Vec3::new(25., 0., 25.),
}),
material: materials.add(Color::DARK_GREEN),
material: materials.add(StandardMaterial::from_color(LinearRgba::GREEN)),
..default()
});
}
Expand Down
10 changes: 5 additions & 5 deletions examples/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn display_help_text(mut commands: Commands, asset_server: Res<AssetServer>) {
align_items: AlignItems::Center,
..Default::default()
},
background_color: Color::rgba(0., 0., 0., 0.).into(),
background_color: Color::linear_rgba(0., 0., 0., 0.).into(),
..Default::default()
})
.with_children(|parent| {
Expand All @@ -71,31 +71,31 @@ fn display_help_text(mut commands: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: monogram.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
},
TextSection {
value: "Press 'R' to resume\n".to_string(),
style: TextStyle {
font: monogram.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
},
TextSection {
value: "Press 'S' to stop\n\n".to_string(),
style: TextStyle {
font: monogram.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
},
TextSection {
value: "Check your console for the audio state".to_string(),
style: TextStyle {
font: monogram.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
color: Color::linear_rgb(0.9, 0.9, 0.9),
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
.add_plugins((DefaultPlugins, AudioPlugin))
.add_systems(Startup, prepare)
.add_systems(Update, (check, play))
.run()
.run();
}

#[derive(Resource)]
Expand Down
Loading

0 comments on commit 9fe5cf8

Please sign in to comment.