musical_keyboard icon indicating copy to clipboard operation
musical_keyboard copied to clipboard

A small lib for converting keyboard input into musical notes.

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

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

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.