midi_input/
midi_input.rs

1#[cfg(feature = "midi")]
2fn main() -> humster::Result<()> {
3    use humster::prelude::*;
4
5    let mut track = Track::Midi(MidiTrack::new(vec![
6        MidiEvent::new(60, 80),
7        MidiEvent::new(64, 90),
8    ]));
9
10    struct VelocityBoost(f32);
11
12    impl Processor for VelocityBoost {
13        fn process_midi(&self, track: &mut MidiTrack) {
14            for event in track.events.iter_mut() {
15                let boosted = (event.velocity as f32 * self.0).round() as u32;
16                event.velocity = boosted.min(127) as u8;
17            }
18        }
19    }
20
21    let boost = VelocityBoost(1.25);
22    track.apply(&boost);
23
24    if let Some(midi) = track.as_midi() {
25        for (idx, event) in midi.events().iter().enumerate() {
26            println!("Event #{idx}: note {}, velocity {}", event.note, event.velocity);
27        }
28    }
29
30    Ok(())
31}
32
33#[cfg(not(feature = "midi"))]
34fn main() {
35    eprintln!("Enable the `midi` feature to run this example.");
36}