Skip to content

Commit

Permalink
Update Bevy to 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Woyten committed Dec 3, 2024
1 parent 68b25db commit 519d951
Show file tree
Hide file tree
Showing 16 changed files with 1,006 additions and 878 deletions.
1,745 changes: 929 additions & 816 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions magnetron/src/automation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ impl<Q: QueryInfo, T> Automated<Q> for &mut T
where
T: Automated<Q>,
{
type Output<'a> = T::Output<'a> where Self: 'a;
type Output<'a>
= T::Output<'a>
where
Self: 'a;

fn query(&mut self, render_window_secs: f64, context: Q::Context<'_>) -> Self::Output<'_> {
T::query(self, render_window_secs, context)
Expand Down Expand Up @@ -255,7 +258,10 @@ impl<Q: QueryInfo, T> Automated<Q> for Option<T>
where
T: Automated<Q>,
{
type Output<'a> = Option<T::Output<'a>> where Self: 'a;
type Output<'a>
= Option<T::Output<'a>>
where
Self: 'a;

fn query(&mut self, render_window_secs: f64, context: Q::Context<'_>) -> Self::Output<'_> {
self.as_mut()
Expand Down Expand Up @@ -308,7 +314,10 @@ impl<Q: QueryInfo, T, O> Automated<Q> for AutomatedSlice<T, O>
where
for<'a> T: Automated<Q, Output<'a> = O> + 'a,
{
type Output<'a> = &'a [O] where Self: 'a;
type Output<'a>
= &'a [O]
where
Self: 'a;

fn query(&mut self, render_window_secs: f64, context: Q::Context<'_>) -> Self::Output<'_> {
self.outputs.clear();
Expand All @@ -335,7 +344,10 @@ pub struct AutomatedValue<Q: QueryInfo> {
type AutomationFn<Q> = Box<dyn FnMut(f64, <Q as QueryInfo>::Context<'_>) -> f64 + Send>;

impl<Q: QueryInfo> Automated<Q> for AutomatedValue<Q> {
type Output<'a> = f64 where Self: 'a;
type Output<'a>
= f64
where
Self: 'a;

fn query(&mut self, render_window_secs: f64, context: Q::Context<'_>) -> Self::Output<'_> {
(self.automation_fn)(render_window_secs, context)
Expand Down
2 changes: 1 addition & 1 deletion magnetron/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Buffers<'_> {
.max(out_buffers.1.stage_activity())
}

fn get<'a>(&'a self, buffer: BufferIndex, zeros: &'a [f64]) -> &[f64] {
fn get<'a>(&'a self, buffer: BufferIndex, zeros: &'a [f64]) -> &'a [f64] {
match buffer {
BufferIndex::Internal(index) => &self.internal_buffers[index],
BufferIndex::External(index) => &self.external_buffers[index],
Expand Down
2 changes: 1 addition & 1 deletion microwave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sf3 = ["fluid-xenth/sf3"]

[dependencies]
async-std = "1.10.0"
bevy = "0.13.0"
bevy = "0.14.0"
chrono = "0.4.15"
clap = { version = "4.0.29", features = ["derive", "env"] }
cpal = { version = "0.15.0", features = ["wasm-bindgen"] }
Expand Down
27 changes: 15 additions & 12 deletions microwave/src/app/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use bevy::{
color::palettes::css,
prelude::*,
render::{camera::ScalingMode, render_resource::PrimitiveTopology},
sprite::{Anchor, MaterialMesh2dBundle},
Expand Down Expand Up @@ -57,7 +58,7 @@ pub struct ViewPlugin;

impl Plugin for ViewPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(ClearColor(Color::hex("222222").unwrap()))
app.insert_resource(ClearColor(Srgba::hex("222222").unwrap().into()))
.insert_resource(DynBackendInfo::from(NoAudioInfo))
.insert_resource(FontResource(default()))
.add_systems(
Expand Down Expand Up @@ -209,10 +210,11 @@ fn create_keyboards(
) {
fn get_12edo_key_color(key: i32) -> Color {
if [1, 3, 6, 8, 10].contains(&key.rem_euclid(12)) {
Color::WHITE * 0.2
css::WHITE * 0.2
} else {
Color::WHITE
css::WHITE
}
.into()
}

let kbm_root = state.kbm.kbm_root();
Expand Down Expand Up @@ -323,9 +325,10 @@ fn create_grid_lines(
let tuning = (&state.scl, state.kbm.kbm_root());
for (degree, pitch_coord) in iterate_grid_coords(main_view, &tuning) {
let line_color = match degree {
0 => Color::SALMON,
_ => Color::GRAY,
};
0 => css::SALMON,
_ => css::GRAY,
}
.into();

scale_grid.with_children(|commands| {
commands.spawn(MaterialMeshBundle {
Expand Down Expand Up @@ -404,7 +407,7 @@ fn create_pitch_lines_and_deviation_markers(
TextStyle {
font: font.clone(),
font_size: FONT_RESOLUTION,
color: Color::RED,
color: css::RED.into(),
},
),
text_anchor: Anchor::CenterLeft,
Expand All @@ -423,9 +426,9 @@ fn create_pitch_lines_and_deviation_markers(
let width = (approximation.deviation.as_octaves() / octave_range) as f32;

let color = if width > 0.0 {
Color::DARK_GREEN
css::DARK_GREEN
} else {
Color::MAROON
css::MAROON
};

scale_grid_canvas.with_children(|commands| {
Expand All @@ -437,7 +440,7 @@ fn create_pitch_lines_and_deviation_markers(
commands.spawn(MaterialMesh2dBundle {
mesh: square_mesh.clone().into(),
transform: transform.with_scale(Vec3::new(width.abs(), LINE_HEIGHT, 0.0)),
material: color_materials.add(color),
material: color_materials.add(ColorMaterial::from_color(color)),
..default()
});
transform.translation.z = z_index::DEVIATION_TEXT;
Expand Down Expand Up @@ -497,7 +500,7 @@ fn init_recording_indicator(
mesh: meshes.add(Circle::default()).into(),
transform: Transform::from_xyz(0.5 - 0.05, 0.25 - 0.05, z_index::RECORDING_INDICATOR)
.with_scale(Vec3::splat(0.05)),
material: materials.add(Color::RED),
material: materials.add(ColorMaterial::from_color(css::RED)),
..default()
},
));
Expand Down Expand Up @@ -554,7 +557,7 @@ fn update_hud(
TextStyle {
font: font.0.clone(),
font_size: FONT_RESOLUTION,
color: Color::GREEN,
color: css::GREEN.into(),
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion microwave/src/app/view/on_screen_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn add_key_marker(
) {
let material = StandardMaterial {
alpha_mode: AlphaMode::Blend,
..get_mesh_material(Color::rgba(1.0, 0.0, 0.0, 0.5))
..get_mesh_material(Color::srgba(1.0, 0.0, 0.0, 0.5))
};

let available_margin = available_width - parent_key_scale.x;
Expand Down
30 changes: 15 additions & 15 deletions microwave/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::render::color::Color;
use bevy::color::Color;
use magnetron::envelope::EnvelopeSpec;
use tune_cli::shared::midi::TuningMethod;

Expand Down Expand Up @@ -270,25 +270,25 @@ pub fn get_default_profile() -> MicrowaveProfile {
];

let color_palette = ColorPalette {
root_color: Color::rgb(1.0, 1.0, 0.5),
natural_color: Color::rgb(1.0, 1.0, 1.0),
root_color: Color::srgb(1.0, 1.0, 0.5),
natural_color: Color::srgb(1.0, 1.0, 1.0),
sharp_colors: vec![
Color::rgb(0.5, 0.0, 1.0),
Color::rgb(0.0, 0.0, 1.0),
Color::rgb(0.0, 0.5, 1.0),
Color::rgb(0.5, 0.5, 1.0),
Color::srgb(0.5, 0.0, 1.0),
Color::srgb(0.0, 0.0, 1.0),
Color::srgb(0.0, 0.5, 1.0),
Color::srgb(0.5, 0.5, 1.0),
],
flat_colors: vec![
Color::rgb(0.5, 1.0, 0.0),
Color::rgb(0.0, 1.0, 0.0),
Color::rgb(0.0, 1.0, 0.5),
Color::rgb(0.5, 1.0, 0.5),
Color::srgb(0.5, 1.0, 0.0),
Color::srgb(0.0, 1.0, 0.0),
Color::srgb(0.0, 1.0, 0.5),
Color::srgb(0.5, 1.0, 0.5),
],
enharmonic_colors: vec![
Color::rgb(0.0, 0.5, 0.5),
Color::rgb(1.0, 0.5, 0.5),
Color::rgb(1.0, 0.0, 1.0),
Color::rgb(1.0, 0.5, 1.0),
Color::srgb(0.0, 0.5, 0.5),
Color::srgb(1.0, 0.5, 0.5),
Color::srgb(1.0, 0.0, 1.0),
Color::srgb(1.0, 0.5, 1.0),
],
};

Expand Down
10 changes: 5 additions & 5 deletions microwave/src/lumatone.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use async_std::task;
use bevy::render::color::Color;
use bevy::color::Color;
use flume::Sender;
use rand::{rngs::SmallRng, seq::SliceRandom, SeedableRng};
use tune::math;
Expand Down Expand Up @@ -49,11 +49,11 @@ pub fn connect_lumatone(fuzzy_port_name: &str) -> MidiResult<Sender<LumatoneLayo
task::sleep(Duration::from_millis(15)).await;

// Set color

let color = color.to_srgba();
let (r, g, b) = (
(color.r() * 255.0) as u8,
(color.g() * 255.0) as u8,
(color.b() * 255.0) as u8,
(color.red * 255.0) as u8,
(color.green * 255.0) as u8,
(color.blue * 255.0) as u8,
);

connection
Expand Down
29 changes: 16 additions & 13 deletions microwave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr};
use ::magnetron::automation::AutomationFactory;
use app::{PhysicalKeyboardLayout, VirtualKeyboardResource};
use async_std::task;
use bevy::render::color::Color;
use bevy::color::{palettes::css, Color, Srgba};
use clap::{builder::ValueParserFactory, Parser};
use control::{LiveParameter, LiveParameterMapper, LiveParameterStorage, ParameterValue};
use piano::PianoEngine;
Expand Down Expand Up @@ -277,18 +277,21 @@ impl FromStr for KeyColors {

fn from_str(s: &str) -> Result<Self, Self::Err> {
s.chars()
.map(|c| match c {
'w' => Ok(Color::WHITE),
'r' => Ok(Color::MAROON),
'g' => Ok(Color::DARK_GREEN),
'b' => Ok(Color::BLUE),
'c' => Ok(Color::TEAL),
'm' => Ok(Color::rgb(0.5, 0.0, 1.0)),
'y' => Ok(Color::YELLOW),
'k' => Ok(Color::WHITE * 0.2),
c => Err(format!(
"Received an invalid character '{c}'. Only wrgbcmyk are allowed."
)),
.map(|c| {
match c {
'w' => Ok(css::WHITE),
'r' => Ok(css::MAROON),
'g' => Ok(css::DARK_GREEN),
'b' => Ok(css::BLUE),
'c' => Ok(css::TEAL),
'm' => Ok(Srgba::rgb(0.5, 0.0, 1.0)),
'y' => Ok(css::YELLOW),
'k' => Ok(css::WHITE * 0.2),
c => Err(format!(
"Received an invalid character '{c}'. Only wrgbcmyk are allowed."
)),
}
.map(Color::from)
})
.collect::<Result<Vec<_>, _>>()
.and_then(|key_colors| {
Expand Down
2 changes: 1 addition & 1 deletion microwave/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::render::color::Color;
use bevy::color::Color;
use cpal::SampleRate;
use flume::Sender;
use magnetron::{automation::AutomationFactory, envelope::EnvelopeSpec, stage::Stage};
Expand Down
2 changes: 0 additions & 2 deletions src/mts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ pub enum SingleNoteTuningChangeError {
/// create_tuning_message_for_program(128),
/// Err(SingleNoteTuningChangeError::TuningProgramOutOfRange)
/// ));
/// ```
TuningProgramOutOfRange,

Expand Down Expand Up @@ -496,7 +495,6 @@ pub enum SingleNoteTuningChangeError {
/// create_tuning_message_with_bank_select(128),
/// Err(SingleNoteTuningChangeError::TuningBankNumberOutOfRange)
/// ));
/// ```
TuningBankNumberOutOfRange,
}
Expand Down
4 changes: 2 additions & 2 deletions src/scala/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl Display for PitchValue {
/// Format / [`Display`] wrapper created by [`Scl::export`].
pub struct SclExport<'a>(&'a Scl);

impl<'a> Display for SclExport<'a> {
impl Display for SclExport<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let pitch_values_to_export = &self.0.pitch_values[1..];
writeln!(f, "{}", self.0.description())?;
Expand Down Expand Up @@ -990,7 +990,7 @@ pub enum KbmBuildError {
/// Format / [`Display`] wrapper created by [`Kbm::export`].
pub struct KbmExport<'a>(&'a Kbm);

impl<'a> Display for KbmExport<'a> {
impl Display for KbmExport<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let kbm_root = self.0.kbm_root();
writeln!(f, "{}", self.0.num_items())?;
Expand Down
2 changes: 0 additions & 2 deletions src/temperament.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ impl Val {
/// assert_approx_eq!(errors[3], 19.409388);
/// assert_approx_eq!(errors[4], 13.387940);
/// ```
pub fn errors(&self) -> impl Iterator<Item = Ratio> + '_ {
self.values
.iter()
Expand Down Expand Up @@ -223,7 +222,6 @@ impl Val {
/// assert_approx_eq!(errors_in_steps[3] * 100.0, 27.496633);
/// assert_approx_eq!(errors_in_steps[4] * 100.0, 18.966248);
/// ```
pub fn errors_in_steps(&self) -> impl Iterator<Item = f64> + '_ {
self.errors()
.map(move |error_abs| error_abs.num_equal_steps_of_size(self.step_size))
Expand Down
1 change: 0 additions & 1 deletion src/tuner/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ impl<K: Copy + Eq + Hash> JitTuningModel<K> {
///
/// If the key cannot be registered [`RegisterKeyResult::Rejected`] is returned.
/// If the new key requires a registered note to be stopped `stopped_note` is [`Option::Some`].
pub enum RegisterKeyResult {
Accepted {
channel: usize,
Expand Down
2 changes: 1 addition & 1 deletion tune-cli/src/est.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct EstPrinter<'a, 'b> {
catalog: CommaCatalog,
}

impl<'a, 'b> EstPrinter<'a, 'b> {
impl EstPrinter<'_, '_> {
fn print_newline(&mut self) -> io::Result<()> {
self.app.writeln("")
}
Expand Down
4 changes: 3 additions & 1 deletion tune-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ fn call_cli(args: &[&str]) -> Output {
}

fn call_cli_piped(first_args: &[&str], second_args: &[&str]) -> Output {
let first_command = Command::new(env!("CARGO_BIN_EXE_tune"))
let mut first_command = Command::new(env!("CARGO_BIN_EXE_tune"))
.args(first_args)
.stdout(Stdio::piped())
.spawn()
.unwrap();

first_command.wait().unwrap();

Command::new(env!("CARGO_BIN_EXE_tune"))
.args(second_args)
.stdin(first_command.stdout.unwrap())
Expand Down

0 comments on commit 519d951

Please sign in to comment.