#keyboard #keyboard-input #note #conversion #pitch #music

musical_keyboard

A small lib for converting keyboard input into musical notes

9 releases (5 breaking)

Uses old Rust 2015

0.6.0 Mar 22, 2017
0.5.0 Mar 22, 2017
0.4.0 Sep 2, 2016
0.3.1 Aug 2, 2016
0.1.0 Feb 13, 2015

#925 in Audio

Download history 1/week @ 2024-02-19 5/week @ 2024-02-26 153/week @ 2024-04-01

153 downloads per month

MIT license

8KB
131 lines

musical_keyboard Build Status Crates.io Crates.io docs.rs

A small lib for converting keyboard input into musical notes.

extern crate musical_keyboard;
use musical_keyboard::{Letter, MusicalKeyboard, NoteEvent, Key};

fn main() {
    let mut musical_keyboard = MusicalKeyboard::default();

    let on = musical_keyboard.key_pressed(Key::A);
    assert_eq!(Some(NoteOn { letter: Letter::C, octave: 2, velocity: 1.0 }), on);

    musical_keyboard.key_pressed(Key::X);
    let on = musical_keyboard.key_pressed(Key::D);
    assert_eq!(Some(NoteOn { letter: Letter::E, octave: 3, velocity: 1.0 }), on);

    let off = musical_keyboard.key_released(Key::D);
    assert_eq!(Some(NoteOff { letter: Letter::E, octave: 3 }), off);

    musical_keyboard.key_pressed(Key::C);
    let on = musical_keyboard.key_pressed(Key::Semicolon);
    assert_eq!(Some(NoteOn { letter: Letter::E, octave: 4, velocity: 0.95 }), on);
}

The behaviour is modelled on Logic Studio X's musical keyboard.

License

Licensed under either of

at your option.

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–0.8MB
~12K SLoC