From 1c9685c3e2d1a96cb76f5c3cd839243355a53f9a Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 9 Jul 2023 23:35:33 +0200 Subject: [PATCH 01/15] Update cargo.toml to bevy 0.11 --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 828ce8c..0fe466a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,20 +25,20 @@ midir = "0.9" crossbeam-channel = "0.5.6" [dev-dependencies] -bevy_egui = { version = "0.20", features = ["immutable_ctx"]} -strum = { version = "0.24", features = ["derive"] } -bevy_mod_picking = "0.12" +#bevy_egui = { version = "0.20", features = ["immutable_ctx"]} +strum = { version = "0.25.0", features = ["derive"] } +bevy_mod_picking = "0.14.0" [dependencies.bevy] -version = "0.10" +version = "0.11.0" default-features = false [dev-dependencies.bevy] -version = "0.10" +version = "0.11.0" features = ["bevy_core_pipeline","bevy_asset", "bevy_scene", "bevy_render", "bevy_winit", "bevy_gltf", "bevy_ui", "bevy_text"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] -version = "0.10" +version = "0.11.0" features = ["x11", "wayland"] default-features = false From 9d5928f88129ff446d1f53abdcbf33ccb4be53d9 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 9 Jul 2023 23:37:15 +0200 Subject: [PATCH 02/15] Re-add bevy_egui --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0fe466a..316800b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ midir = "0.9" crossbeam-channel = "0.5.6" [dev-dependencies] -#bevy_egui = { version = "0.20", features = ["immutable_ctx"]} +bevy_egui = { version = "0.20", features = ["immutable_ctx"]} strum = { version = "0.25.0", features = ["derive"] } bevy_mod_picking = "0.14.0" From 4367db79e75e85bd4a869c94f97d42971b72d542 Mon Sep 17 00:00:00 2001 From: Mason Smith Date: Mon, 23 Oct 2023 19:49:27 -0700 Subject: [PATCH 03/15] update library, dependencies to bevy 0.11 --- Cargo.toml | 12 ++++++------ src/input.rs | 9 ++++++--- src/output.rs | 5 +++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 828ce8c..f6508aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,23 +22,23 @@ name = "bevy_midi" [dependencies] midir = "0.9" -crossbeam-channel = "0.5.6" +crossbeam-channel = "0.5.8" [dev-dependencies] -bevy_egui = { version = "0.20", features = ["immutable_ctx"]} +bevy_egui = { version = "0.22", features = ["immutable_ctx"]} strum = { version = "0.24", features = ["derive"] } -bevy_mod_picking = "0.12" +bevy_mod_picking = "0.15" [dependencies.bevy] -version = "0.10" +version = "0.11" default-features = false [dev-dependencies.bevy] -version = "0.10" +version = "0.11" features = ["bevy_core_pipeline","bevy_asset", "bevy_scene", "bevy_render", "bevy_winit", "bevy_gltf", "bevy_ui", "bevy_text"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] -version = "0.10" +version = "0.11" features = ["x11", "wayland"] default-features = false diff --git a/src/input.rs b/src/input.rs index 5afb09d..b26c90c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -17,9 +17,9 @@ impl Plugin for MidiInputPlugin { .init_resource::() .add_event::() .add_event::() - .add_startup_system(setup) - .add_system(reply.in_base_set(CoreSet::PreUpdate)) - .add_system(debug); + .add_systems(Startup, setup) + .add_systems(PreUpdate, reply) + .add_systems(Update, debug); } } @@ -113,6 +113,8 @@ pub struct MidiData { pub message: MidiMessage, } +impl bevy::prelude::Event for MidiData {} + /// The [`Error`] type for midi input operations, accessible as an [`Event`](bevy::ecs::event::Event). #[derive(Clone, Debug)] pub enum MidiInputError { @@ -121,6 +123,7 @@ pub enum MidiInputError { } impl Error for MidiInputError {} +impl Event for MidiInputError {} impl Display for MidiInputError { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { match self { diff --git a/src/output.rs b/src/output.rs index 7f0774f..2c43138 100644 --- a/src/output.rs +++ b/src/output.rs @@ -14,8 +14,8 @@ impl Plugin for MidiOutputPlugin { app.init_resource::() .init_resource::() .add_event::() - .add_startup_system(setup) - .add_system(reply.in_base_set(CoreSet::PreUpdate)); + .add_systems(Startup, setup) + .add_systems(PreUpdate, reply); } } @@ -107,6 +107,7 @@ pub enum MidiOutputError { } impl Error for MidiOutputError {} +impl Event for MidiOutputError {} impl Display for MidiOutputError { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { match self { From 88d09cccc2f20fce228def9d2dae4b020cfd34cd Mon Sep 17 00:00:00 2001 From: Mason Smith Date: Mon, 23 Oct 2023 20:19:42 -0700 Subject: [PATCH 04/15] update input, output examples --- examples/input.rs | 21 +++++++++++++-------- examples/output.rs | 21 +++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/examples/input.rs b/examples/input.rs index 4932aba..0a0f4d3 100644 --- a/examples/input.rs +++ b/examples/input.rs @@ -28,14 +28,19 @@ fn main() { level: Level::WARN, filter: "bevy_midi=debug".to_string(), })) - .add_plugin(MidiInputPlugin) - .add_system(refresh_ports) - .add_system(connect) - .add_system(disconnect) - .add_system(show_ports) - .add_system(show_connection) - .add_system(show_last_message) - .add_startup_system(setup) + .add_plugins(MidiInputPlugin) + .add_systems( + Update, + ( + refresh_ports, + connect, + disconnect, + show_ports, + show_connection, + show_last_message, + ), + ) + .add_systems(Startup, setup) .run(); } diff --git a/examples/output.rs b/examples/output.rs index 2f210f1..433c837 100644 --- a/examples/output.rs +++ b/examples/output.rs @@ -30,14 +30,19 @@ fn main() { .insert_resource(MidiOutputSettings { port_name: "output", }) - .add_plugin(MidiOutputPlugin) - .add_system(refresh_ports) - .add_system(connect) - .add_system(disconnect) - .add_system(play_notes) - .add_system(show_ports) - .add_system(show_connection) - .add_startup_system(setup) + .add_plugins(MidiOutputPlugin) + .add_systems( + Update, + ( + refresh_ports, + connect, + disconnect, + play_notes, + show_ports, + show_connection, + ), + ) + .add_systems(Startup, setup) .run(); } From ba0ce3c61924ddb4a6528d3798d92a387ddb01a2 Mon Sep 17 00:00:00 2001 From: Mason Smith Date: Mon, 23 Oct 2023 20:20:00 -0700 Subject: [PATCH 05/15] update egui example --- examples/egui.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/egui.rs b/examples/egui.rs index 16626be..3e75748 100644 --- a/examples/egui.rs +++ b/examples/egui.rs @@ -2,7 +2,10 @@ use std::iter::{Cycle, Peekable}; use bevy::prelude::*; use bevy_egui::{ - egui::{self, Color32, ColorImage, ImageButton, Key, TextureHandle, TextureOptions, Ui}, + egui::{ + self, load::SizedTexture, Color32, ColorImage, ImageButton, Key, TextureHandle, + TextureOptions, Ui, + }, EguiContext, EguiPlugin, }; use bevy_midi::prelude::*; @@ -14,10 +17,10 @@ use strum::{EnumCount, EnumIter, IntoEnumIterator}; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(EguiPlugin) + .add_plugins(EguiPlugin) // Systems that create Egui widgets should be run during the `CoreStage::Update` stage, // or after the `EguiSystem::BeginFrame` system (which belongs to the `CoreStage::PreUpdate` stage). - .add_system(ui_example) + .add_systems(Update, ui_example) .init_resource::() .run(); } @@ -214,7 +217,6 @@ impl PianoRoll { }); self.key_states = next_keys; - drop(input); } fn get_key_texture_tint(&self, note: NoteName, index: usize) -> Color32 { @@ -257,6 +259,7 @@ impl PianoRoll { ) }) .id(); + // Draw the actual piano keys for clicking ui.vertical(|ui| { ui.spacing_mut().item_spacing = bevy_egui::egui::Vec2 { @@ -271,7 +274,8 @@ impl PianoRoll { all_notes_iter.for_each(|(index, (note, _octave))| { let color = self.get_key_texture_tint(note, index); - let button_top = ImageButton::new(texture_id, TOP_KEY_SIZE).tint(color); + let button_top = + ImageButton::new(SizedTexture::new(texture_id, TOP_KEY_SIZE)).tint(color); if ui.add(button_top).clicked() { //sync.trigger_note(index, selected_instrument); println!("Pressed {}{}", KEY_RANGE[index % 12], index / 12); @@ -291,7 +295,8 @@ impl PianoRoll { let tint = self.get_key_texture_tint(note, index); let button_bottom = - ImageButton::new(texture_id, BOTTOM_KEY_SIZE).tint(tint); + ImageButton::new(SizedTexture::new(texture_id, BOTTOM_KEY_SIZE)) + .tint(tint); if ui.add(button_bottom).clicked() { //sync.trigger_note(index, selected_instrument); From 0d2b1a93537718e3712a4bbd572a82ef0882da75 Mon Sep 17 00:00:00 2001 From: Mason Smith Date: Mon, 23 Oct 2023 20:49:57 -0700 Subject: [PATCH 06/15] update piano example --- Cargo.toml | 2 +- examples/piano.rs | 68 +++++++++++++++++++---------------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f6508aa..78db548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ default-features = false [dev-dependencies.bevy] version = "0.11" -features = ["bevy_core_pipeline","bevy_asset", "bevy_scene", "bevy_render", "bevy_winit", "bevy_gltf", "bevy_ui", "bevy_text"] +features = ["bevy_core_pipeline","bevy_asset", "bevy_scene", "bevy_render", "bevy_winit", "bevy_gltf", "bevy_ui", "bevy_text", "zstd", "tonemapping_luts", "ktx2", "hdr"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] diff --git a/examples/piano.rs b/examples/piano.rs index 8b27d45..6316985 100644 --- a/examples/piano.rs +++ b/examples/piano.rs @@ -4,10 +4,7 @@ use bevy::{ prelude::*, }; use bevy_midi::prelude::*; -use bevy_mod_picking::{ - DefaultPickingPlugins, HoverEvent, PickableBundle, PickingCameraBundle, PickingEvent, - SelectionEvent, -}; +use bevy_mod_picking::prelude::*; fn main() { App::new() @@ -21,17 +18,21 @@ fn main() { filter: "bevy_midi=debug".to_string(), })) .add_plugins(DefaultPickingPlugins) - .add_plugin(MidiInputPlugin) + .add_plugins(MidiInputPlugin) .init_resource::() - .add_plugin(MidiOutputPlugin) + .add_plugins(MidiOutputPlugin) .init_resource::() - .add_startup_system(setup) - .add_system(handle_midi_input) - .add_system(connect_to_first_input_port) - .add_system(connect_to_first_output_port) - .add_system(print_events.in_base_set(CoreSet::PostUpdate)) - .add_system(display_press) - .add_system(display_release) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + handle_midi_input, + connect_to_first_input_port, + connect_to_first_output_port, + display_press, + display_release, + ), + ) .run(); } @@ -41,28 +42,6 @@ struct Key { y_reset: f32, } -pub fn print_events( - mut events: EventReader, - mut commands: Commands, - mouse_button_input: Res>, -) { - for event in events.iter() { - let entity = match event { - PickingEvent::Selection(SelectionEvent::JustSelected(e)) => e, - PickingEvent::Selection(SelectionEvent::JustDeselected(e)) => e, - PickingEvent::Hover(HoverEvent::JustEntered(e)) => e, - PickingEvent::Hover(HoverEvent::JustLeft(e)) => e, - PickingEvent::Clicked(e) => e, - }; - - if mouse_button_input.pressed(MouseButton::Left) { - commands.entity(*entity).insert(PressedKey); - } else { - commands.entity(*entity).remove::(); - } - } -} - #[derive(Component)] struct PressedKey; @@ -86,7 +65,7 @@ fn setup( transform: Transform::from_xyz(8., 5., mid).looking_at(Vec3::new(0., 0., mid), Vec3::Y), ..Default::default() }, - PickingCameraBundle::default(), + RaycastPickCamera::default(), )); let pos: Vec3 = Vec3::new(0., 0., 0.); @@ -103,16 +82,16 @@ fn setup( for i in 0..8 { spawn_note(&mut commands, &w_mat, 0.00, pos, &mut white_key_0, i, "C"); - spawn_note(&mut commands, &b_mat, 0.15, pos_black, &mut black_key, i, "C#"); + spawn_note(&mut commands, &b_mat, 0.15, pos_black, &mut black_key, i, "C#/Db"); spawn_note(&mut commands, &w_mat, 0.27, pos, &mut white_key_1, i, "D"); - spawn_note(&mut commands, &b_mat, 0.39, pos_black, &mut black_key, i, "D#"); + spawn_note(&mut commands, &b_mat, 0.39, pos_black, &mut black_key, i, "D#/Eb"); spawn_note(&mut commands, &w_mat, 0.54, pos, &mut white_key_2, i, "E"); spawn_note(&mut commands, &w_mat, 0.69, pos, &mut white_key_0, i, "F"); - spawn_note(&mut commands, &b_mat, 0.85, pos_black, &mut black_key, i, "F#"); + spawn_note(&mut commands, &b_mat, 0.85, pos_black, &mut black_key, i, "F#/Gb"); spawn_note(&mut commands, &w_mat, 0.96, pos, &mut white_key_1, i, "G"); - spawn_note(&mut commands, &b_mat, 1.08, pos_black, &mut black_key, i, "G#"); + spawn_note(&mut commands, &b_mat, 1.08, pos_black, &mut black_key, i, "G#/Ab"); spawn_note(&mut commands, &w_mat, 1.19, pos, &mut white_key_1, i, "A"); - spawn_note(&mut commands, &b_mat, 1.31, pos_black, &mut black_key, i, "A#"); + spawn_note(&mut commands, &b_mat, 1.31, pos_black, &mut black_key, i, "A#/Bb"); spawn_note(&mut commands, &w_mat, 1.46, pos, &mut white_key_2, i, "B"); } } @@ -142,6 +121,13 @@ fn spawn_note( y_reset: pos.y, }, PickableBundle::default(), + RaycastPickTarget::default(), + On::>::target_commands_mut(|_click, entity_commands| { + entity_commands.insert(PressedKey); + }), + On::>::target_commands_mut(|_click, entity_commands| { + entity_commands.remove::(); + }), )); } From 46e7c8fa68be22fdd67095125cae63bd7b000765 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 12:57:51 +0100 Subject: [PATCH 07/15] Shortened param --- examples/piano.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/piano.rs b/examples/piano.rs index 6316985..158fe33 100644 --- a/examples/piano.rs +++ b/examples/piano.rs @@ -47,20 +47,20 @@ struct PressedKey; #[rustfmt::skip] fn setup( - mut commands: Commands, + mut cmds: Commands, mut materials: ResMut>, asset_server: Res, ) { let mid = -6.3; // light - commands.spawn(PointLightBundle { + cmds.spawn(PointLightBundle { transform: Transform::from_xyz(0.0, 6.0, mid), ..Default::default() }); //Camera - commands.spawn(( + cmds.spawn(( Camera3dBundle { transform: Transform::from_xyz(8., 5., mid).looking_at(Vec3::new(0., 0., mid), Vec3::Y), ..Default::default() @@ -81,18 +81,18 @@ fn setup( let pos_black = pos + Vec3::new(0., 0.06, 0.); for i in 0..8 { - spawn_note(&mut commands, &w_mat, 0.00, pos, &mut white_key_0, i, "C"); - spawn_note(&mut commands, &b_mat, 0.15, pos_black, &mut black_key, i, "C#/Db"); - spawn_note(&mut commands, &w_mat, 0.27, pos, &mut white_key_1, i, "D"); - spawn_note(&mut commands, &b_mat, 0.39, pos_black, &mut black_key, i, "D#/Eb"); - spawn_note(&mut commands, &w_mat, 0.54, pos, &mut white_key_2, i, "E"); - spawn_note(&mut commands, &w_mat, 0.69, pos, &mut white_key_0, i, "F"); - spawn_note(&mut commands, &b_mat, 0.85, pos_black, &mut black_key, i, "F#/Gb"); - spawn_note(&mut commands, &w_mat, 0.96, pos, &mut white_key_1, i, "G"); - spawn_note(&mut commands, &b_mat, 1.08, pos_black, &mut black_key, i, "G#/Ab"); - spawn_note(&mut commands, &w_mat, 1.19, pos, &mut white_key_1, i, "A"); - spawn_note(&mut commands, &b_mat, 1.31, pos_black, &mut black_key, i, "A#/Bb"); - spawn_note(&mut commands, &w_mat, 1.46, pos, &mut white_key_2, i, "B"); + spawn_note(&mut cmds, &w_mat, 0.00, pos, &mut white_key_0, i, "C"); + spawn_note(&mut cmds, &b_mat, 0.15, pos_black, &mut black_key, i, "C#/Db"); + spawn_note(&mut cmds, &w_mat, 0.27, pos, &mut white_key_1, i, "D"); + spawn_note(&mut cmds, &b_mat, 0.39, pos_black, &mut black_key, i, "D#/Eb"); + spawn_note(&mut cmds, &w_mat, 0.54, pos, &mut white_key_2, i, "E"); + spawn_note(&mut cmds, &w_mat, 0.69, pos, &mut white_key_0, i, "F"); + spawn_note(&mut cmds, &b_mat, 0.85, pos_black, &mut black_key, i, "F#/Gb"); + spawn_note(&mut cmds, &w_mat, 0.96, pos, &mut white_key_1, i, "G"); + spawn_note(&mut cmds, &b_mat, 1.08, pos_black, &mut black_key, i, "G#/Ab"); + spawn_note(&mut cmds, &w_mat, 1.19, pos, &mut white_key_1, i, "A"); + spawn_note(&mut cmds, &b_mat, 1.31, pos_black, &mut black_key, i, "A#/Bb"); + spawn_note(&mut cmds, &w_mat, 1.46, pos, &mut white_key_2, i, "B"); } } From a58497670fee2dbf1c918e95970b20119315b424 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 14:48:14 +0100 Subject: [PATCH 08/15] Prevent hang from TaskPool but now no data is sent --- .gitignore | 1 + Cargo.toml | 14 +++++++------- README.md | 1 + examples/input.rs | 4 ++-- examples/piano.rs | 2 -- src/input.rs | 24 ++++++++++++++---------- src/output.rs | 15 +++++++++++++++ 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 4bc4b9d..fbd5be5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Cargo.lock **/*.rs.bk package-lock.json +.vscode/launch.json diff --git a/Cargo.toml b/Cargo.toml index 78db548..63fb72a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_midi" -version = "0.6.0" +version = "0.7.0" authors = ["Black Phlox "] edition = "2021" license = "MIT OR Apache-2.0" @@ -25,20 +25,20 @@ midir = "0.9" crossbeam-channel = "0.5.8" [dev-dependencies] -bevy_egui = { version = "0.22", features = ["immutable_ctx"]} -strum = { version = "0.24", features = ["derive"] } -bevy_mod_picking = "0.15" +bevy_egui = { version = "0.23", features = ["immutable_ctx"]} +strum = { version = "0.25", features = ["derive"] } +bevy_mod_picking = "0.17" [dependencies.bevy] -version = "0.11" +version = "0.12" default-features = false [dev-dependencies.bevy] -version = "0.11" +version = "0.12" features = ["bevy_core_pipeline","bevy_asset", "bevy_scene", "bevy_render", "bevy_winit", "bevy_gltf", "bevy_ui", "bevy_text", "zstd", "tonemapping_luts", "ktx2", "hdr"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] -version = "0.11" +version = "0.12" features = ["x11", "wayland"] default-features = false diff --git a/README.md b/README.md index bfb86bb..0cca25d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ See examples |0.7|0.4.X| |0.8|0.5.X| |0.10|0.6.X| +|0.12|0.7.X| # Licensing The project is under dual license MIT and Apache 2.0, so joink to your hearts content, just remember the license agreements. diff --git a/examples/input.rs b/examples/input.rs index 0a0f4d3..a25caf4 100644 --- a/examples/input.rs +++ b/examples/input.rs @@ -29,6 +29,7 @@ fn main() { filter: "bevy_midi=debug".to_string(), })) .add_plugins(MidiInputPlugin) + .add_systems(Startup, setup) .add_systems( Update, ( @@ -40,7 +41,6 @@ fn main() { show_last_message, ), ) - .add_systems(Startup, setup) .run(); } @@ -101,7 +101,7 @@ fn show_last_message( mut midi_data: EventReader, mut instructions: Query<&mut Text, With>, ) { - for data in midi_data.iter() { + for data in midi_data.read() { let text_section = &mut instructions.single_mut().sections[3]; text_section.value = format!( "Last Message: {} - {:?}", diff --git a/examples/piano.rs b/examples/piano.rs index 158fe33..b6bc6b7 100644 --- a/examples/piano.rs +++ b/examples/piano.rs @@ -65,7 +65,6 @@ fn setup( transform: Transform::from_xyz(8., 5., mid).looking_at(Vec3::new(0., 0., mid), Vec3::Y), ..Default::default() }, - RaycastPickCamera::default(), )); let pos: Vec3 = Vec3::new(0., 0., 0.); @@ -121,7 +120,6 @@ fn spawn_note( y_reset: pos.y, }, PickableBundle::default(), - RaycastPickTarget::default(), On::>::target_commands_mut(|_click, entity_commands| { entity_commands.insert(PressedKey); }), diff --git a/src/input.rs b/src/input.rs index b26c90c..f682990 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,5 +1,6 @@ use super::{MidiMessage, KEY_RANGE}; use bevy::prelude::Plugin; +use bevy::tasks::TaskPool; use bevy::{prelude::*, tasks::IoTaskPool}; use crossbeam_channel::{Receiver, Sender}; use midir::ConnectErrorKind; // XXX: do we expose this? @@ -173,16 +174,19 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded::(); let (r_sender, r_receiver) = crossbeam_channel::unbounded::(); - let thread_pool = IoTaskPool::get(); - thread_pool - .spawn(MidiInputTask { - receiver: m_receiver, - sender: r_sender, - settings: settings.clone(), - input: None, - connection: None, + //Got issues with the rewrite : https://github.com/bevyengine/bevy/pull/10008 + let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); + thread_pool.scope(|s|{ + s.spawn(async { + MidiInputTask { + receiver: m_receiver, + sender: r_sender, + settings: settings.clone(), + input: None, + connection: None, + } }) - .detach(); + }); commands.insert_resource(MidiInput { sender: m_sender, @@ -342,7 +346,7 @@ fn get_available_ports(input: &midir::MidiInput) -> Reply { // A system which debug prints note events fn debug(mut midi: EventReader) { - for data in midi.iter() { + for data in midi.read() { let pitch = data.message.msg[1]; let octave = pitch / 12; let key = KEY_RANGE[pitch as usize % 12]; diff --git a/src/output.rs b/src/output.rs index 2c43138..29e54d7 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,4 +1,5 @@ use super::MidiMessage; +use bevy::tasks::TaskPool; use bevy::{prelude::*, tasks::IoTaskPool}; use crossbeam_channel::{Receiver, Sender}; use midir::ConnectErrorKind; @@ -135,6 +136,19 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded(); let (r_sender, r_receiver) = crossbeam_channel::unbounded(); + let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); + thread_pool.scope(|s|{ + s.spawn(async { + MidiOutputTask { + receiver: m_receiver, + sender: r_sender, + settings: settings.clone(), + output: None, + connection: None, + } + }) + }); + /* let thread_pool = IoTaskPool::get(); thread_pool .spawn(MidiOutputTask { @@ -145,6 +159,7 @@ fn setup(mut commands: Commands, settings: Res) { connection: None, }) .detach(); + */ commands.insert_resource(MidiOutput { sender: m_sender, From 41c6521a3897ad2894b5cea7b77dbef1b3631141 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:00:26 +0100 Subject: [PATCH 09/15] Reverted back TaskPool changes --- src/input.rs | 20 +++++++++----------- src/output.rs | 15 +-------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/input.rs b/src/input.rs index f682990..1795c56 100644 --- a/src/input.rs +++ b/src/input.rs @@ -174,18 +174,16 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded::(); let (r_sender, r_receiver) = crossbeam_channel::unbounded::(); - //Got issues with the rewrite : https://github.com/bevyengine/bevy/pull/10008 + //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); - thread_pool.scope(|s|{ - s.spawn(async { - MidiInputTask { - receiver: m_receiver, - sender: r_sender, - settings: settings.clone(), - input: None, - connection: None, - } - }) + thread_pool.spawn({ + MidiInputTask { + receiver: m_receiver, + sender: r_sender, + settings: settings.clone(), + input: None, + connection: None, + } }); commands.insert_resource(MidiInput { diff --git a/src/output.rs b/src/output.rs index 29e54d7..00665de 100644 --- a/src/output.rs +++ b/src/output.rs @@ -136,20 +136,8 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded(); let (r_sender, r_receiver) = crossbeam_channel::unbounded(); + //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); - thread_pool.scope(|s|{ - s.spawn(async { - MidiOutputTask { - receiver: m_receiver, - sender: r_sender, - settings: settings.clone(), - output: None, - connection: None, - } - }) - }); - /* - let thread_pool = IoTaskPool::get(); thread_pool .spawn(MidiOutputTask { receiver: m_receiver, @@ -159,7 +147,6 @@ fn setup(mut commands: Commands, settings: Res) { connection: None, }) .detach(); - */ commands.insert_resource(MidiOutput { sender: m_sender, From 8bb90410ee8bcdbfb6b1b1ee37aa00223845ce50 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:02:04 +0100 Subject: [PATCH 10/15] clippy --- src/input.rs | 2 +- src/output.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input.rs b/src/input.rs index 1795c56..ab15d81 100644 --- a/src/input.rs +++ b/src/input.rs @@ -175,7 +175,7 @@ fn setup(mut commands: Commands, settings: Res) { let (r_sender, r_receiver) = crossbeam_channel::unbounded::(); //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 - let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); + let thread_pool = IoTaskPool::get_or_init(TaskPool::new); thread_pool.spawn({ MidiInputTask { receiver: m_receiver, diff --git a/src/output.rs b/src/output.rs index 00665de..bd9306d 100644 --- a/src/output.rs +++ b/src/output.rs @@ -137,7 +137,7 @@ fn setup(mut commands: Commands, settings: Res) { let (r_sender, r_receiver) = crossbeam_channel::unbounded(); //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 - let thread_pool = IoTaskPool::get_or_init(|| TaskPool::new()); + let thread_pool = IoTaskPool::get_or_init(TaskPool::new); thread_pool .spawn(MidiOutputTask { receiver: m_receiver, From f6e554ba6121c1c1466d3ece46ac9f26916617a2 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:15:30 +0100 Subject: [PATCH 11/15] More clippy --- examples/egui.rs | 2 +- examples/piano.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/egui.rs b/examples/egui.rs index 3e75748..429a187 100644 --- a/examples/egui.rs +++ b/examples/egui.rs @@ -186,7 +186,7 @@ impl PianoRoll { } fn update_key_states(&mut self, ui: &mut Ui) { - let input = ui.input(|i| i.key_pressed(egui::Key::A)); + let _input = ui.input(|i| i.key_pressed(egui::Key::A)); let next_keys = std::array::from_fn(|index| ui.input(|i| i.key_down(KEYS[index]))); self.key_states diff --git a/examples/piano.rs b/examples/piano.rs index b6bc6b7..84c8dc0 100644 --- a/examples/piano.rs +++ b/examples/piano.rs @@ -146,7 +146,7 @@ fn handle_midi_input( mut midi_events: EventReader, query: Query<(Entity, &Key)>, ) { - for data in midi_events.iter() { + for data in midi_events.read() { let [_, index, _value] = data.message.msg; let off = index % 12; let oct = index.overflowing_div(12).0; From 88e82da4f9ea80c3a1fd0afae4dc3faaaf469201 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:26:25 +0100 Subject: [PATCH 12/15] Removed unused init --- src/input.rs | 3 +-- src/output.rs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/input.rs b/src/input.rs index ab15d81..1779ba9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,6 +1,5 @@ use super::{MidiMessage, KEY_RANGE}; use bevy::prelude::Plugin; -use bevy::tasks::TaskPool; use bevy::{prelude::*, tasks::IoTaskPool}; use crossbeam_channel::{Receiver, Sender}; use midir::ConnectErrorKind; // XXX: do we expose this? @@ -175,7 +174,7 @@ fn setup(mut commands: Commands, settings: Res) { let (r_sender, r_receiver) = crossbeam_channel::unbounded::(); //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 - let thread_pool = IoTaskPool::get_or_init(TaskPool::new); + let thread_pool = IoTaskPool::get(); thread_pool.spawn({ MidiInputTask { receiver: m_receiver, diff --git a/src/output.rs b/src/output.rs index bd9306d..035a72c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,6 +1,6 @@ use super::MidiMessage; -use bevy::tasks::TaskPool; -use bevy::{prelude::*, tasks::IoTaskPool}; +use bevy::prelude::*; +use bevy::tasks::IoTaskPool; use crossbeam_channel::{Receiver, Sender}; use midir::ConnectErrorKind; pub use midir::MidiOutputPort; @@ -137,7 +137,7 @@ fn setup(mut commands: Commands, settings: Res) { let (r_sender, r_receiver) = crossbeam_channel::unbounded(); //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 - let thread_pool = IoTaskPool::get_or_init(TaskPool::new); + let thread_pool = IoTaskPool::get(); thread_pool .spawn(MidiOutputTask { receiver: m_receiver, From c7472e855b84c9b16ba2cf9390796b7a38dbdfe6 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:35:15 +0100 Subject: [PATCH 13/15] Added detach --- src/input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input.rs b/src/input.rs index 1779ba9..65c950b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -183,7 +183,7 @@ fn setup(mut commands: Commands, settings: Res) { input: None, connection: None, } - }); + }).detach(); commands.insert_resource(MidiInput { sender: m_sender, From 7bbac6c162ab143ef6458ed3826583c5b014e731 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sat, 11 Nov 2023 15:35:44 +0100 Subject: [PATCH 14/15] fmt --- src/input.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/input.rs b/src/input.rs index 65c950b..bdca0eb 100644 --- a/src/input.rs +++ b/src/input.rs @@ -175,15 +175,17 @@ fn setup(mut commands: Commands, settings: Res) { //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 let thread_pool = IoTaskPool::get(); - thread_pool.spawn({ - MidiInputTask { - receiver: m_receiver, - sender: r_sender, - settings: settings.clone(), - input: None, - connection: None, - } - }).detach(); + thread_pool + .spawn({ + MidiInputTask { + receiver: m_receiver, + sender: r_sender, + settings: settings.clone(), + input: None, + connection: None, + } + }) + .detach(); commands.insert_resource(MidiInput { sender: m_sender, From 1d17b916318f6d2e3a94c6600aea867d0b776a36 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 12 Nov 2023 02:00:31 +0100 Subject: [PATCH 15/15] Fixed TaskPool hanging --- Cargo.toml | 1 + src/input.rs | 15 ++++++--------- src/output.rs | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63fb72a..17910df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ bevy_mod_picking = "0.17" [dependencies.bevy] version = "0.12" default-features = false +features = ["multi-threaded"] [dev-dependencies.bevy] version = "0.12" diff --git a/src/input.rs b/src/input.rs index bdca0eb..cb10c2b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -173,17 +173,14 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded::(); let (r_sender, r_receiver) = crossbeam_channel::unbounded::(); - //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 let thread_pool = IoTaskPool::get(); thread_pool - .spawn({ - MidiInputTask { - receiver: m_receiver, - sender: r_sender, - settings: settings.clone(), - input: None, - connection: None, - } + .spawn(MidiInputTask { + receiver: m_receiver, + sender: r_sender, + settings: settings.clone(), + input: None, + connection: None, }) .detach(); diff --git a/src/output.rs b/src/output.rs index 035a72c..3d49568 100644 --- a/src/output.rs +++ b/src/output.rs @@ -136,7 +136,6 @@ fn setup(mut commands: Commands, settings: Res) { let (m_sender, m_receiver) = crossbeam_channel::unbounded(); let (r_sender, r_receiver) = crossbeam_channel::unbounded(); - //Got issues with the taskpool rewrite : https://github.com/bevyengine/bevy/pull/10008 let thread_pool = IoTaskPool::get(); thread_pool .spawn(MidiOutputTask {