From 9649b10a5714832ce2d74ab30af29efaca213870 Mon Sep 17 00:00:00 2001 From: dsgallups Date: Fri, 26 Sep 2025 05:33:55 -0400 Subject: [PATCH 01/13] fix: add micros to prelude --- Cargo.toml | 2 +- src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54fd5b7..4f40d4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "midix" -version = "4.0.0-alpha.2" +version = "4.0.0-alpha.3" authors = ["dsgallups "] edition = "2024" description = "MIDI structures designed for humans" diff --git a/src/lib.rs b/src/lib.rs index be2d5ae..fb503ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,7 @@ pub mod prelude { file::*, file_repr::{chunk::*, meta::*, track::*, *}, message::{MidiMessage, channel::*, system::*, time::*}, + micros::*, note, }; @@ -72,7 +73,4 @@ pub mod prelude { pub(crate) use crate::reader::inv_data; pub use core::fmt::Display; - - //#[cfg(feature = "bevy")] - //pub use crate::bevy::prelude::*; } From 5d08487c5a3a2b00ccff2d0ad72abc8388c0a6f6 Mon Sep 17 00:00:00 2001 From: dsgallups Date: Fri, 26 Sep 2025 05:44:17 -0400 Subject: [PATCH 02/13] fix: update docs --- README.md | 124 ++-------------------------------------------------- src/note.rs | 46 +++++++++---------- 2 files changed, 26 insertions(+), 144 deletions(-) diff --git a/README.md b/README.md index d2086ce..258be02 100644 --- a/README.md +++ b/README.md @@ -71,135 +71,17 @@ let Ok(LiveEvent::ChannelVoice(channel_voice_msg)) = LiveEvent::from_bytes(¬e panic!("Expected a channel voice event"); }; -let VoiceEvent::NoteOn { key, velocity } = channel_voice_msg.event() else { +let VoiceEvent::NoteOn { note, velocity } = channel_voice_msg.event() else { panic!("Expected a note on event"); }; assert_eq!(channel_voice_msg.channel(), Channel::Three); -assert_eq!(key.note(), Note::C); -assert_eq!(key.octave(), Octave::new(4)); +assert_eq!(note.key(), Key::C); +assert_eq!(note.octave(), Octave::new(4)); assert_eq!(velocity.byte(), 96); ``` - - - -## Bevy Support - -Midix has been built with the bevy engine in mind. this feature uses `rustysynth` to play midi sounds under the hood! - -### Note -When running the examples, try using `cargo run --example --features example --release` for the best results! - -### Example -```rust, no_run -use bevy_platform::prelude::*; -use std::time::Duration; -use bevy::{ - log::{Level, LogPlugin}, - prelude::*, -}; -use midix::prelude::*; -fn main() { - App::new() - .add_plugins(( - DefaultPlugins.set(LogPlugin { - level: Level::INFO, - ..default() - }), - MidiPlugin { - input: None, - ..Default::default() - }, - )) - .add_systems(Startup, load_sf2) - .add_systems(Update, scale_me) - .run(); -} -/// Take a look here for some soundfonts: -/// -/// -fn load_sf2(asset_server: Res, mut synth: ResMut) { - synth.use_soundfont(asset_server.load("soundfont.sf2")); -} - -struct Scale { - timer: Timer, - current_key: Key, - note_on: bool, - forward: bool, - incremented_by: u8, - max_increment: u8, -} - -impl Scale { - pub fn calculate_next_key(&mut self) { - if self.forward { - if self.incremented_by == self.max_increment { - self.forward = false; - self.incremented_by -= 1; - self.current_key -= 1; - } else { - self.incremented_by += 1; - self.current_key += 1; - } - } else if self.incremented_by == 0 { - self.forward = true; - self.incremented_by += 1; - self.current_key += 1; - } else { - self.incremented_by -= 1; - self.current_key -= 1; - } - } -} - -impl Default for Scale { - fn default() -> Self { - let timer = Timer::new(Duration::from_millis(200), TimerMode::Repeating); - Scale { - timer, - current_key: Key::new(Note::C, Octave::new(2)), - note_on: true, - forward: true, - incremented_by: 0, - max_increment: 11, - } - } -} - -fn scale_me(synth: Res, time: Res