-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from masonium/midly-owned
Midly owned
- Loading branch information
Showing
8 changed files
with
287 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,16 @@ | ||
/// Re-export [`midly::num`] module . | ||
pub mod num { | ||
pub use midly::num::{u14, u15, u24, u28, u4, u7}; | ||
} | ||
|
||
pub mod input; | ||
pub mod output; | ||
pub mod types; | ||
|
||
pub mod prelude { | ||
pub use crate::{input::*, output::*, *}; | ||
pub use crate::{input::*, output::*, types::*, *}; | ||
} | ||
|
||
pub const KEY_RANGE: [&str; 12] = [ | ||
"C", "C#/Db", "D", "D#/Eb", "E", "F", "F#/Gb", "G", "G#/Ab", "A", "A#/Bb", "B", | ||
]; | ||
|
||
const NOTE_ON_STATUS: u8 = 0b1001_0000; | ||
const NOTE_OFF_STATUS: u8 = 0b1000_0000; | ||
|
||
#[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
pub struct MidiMessage { | ||
pub msg: [u8; 3], | ||
} | ||
|
||
impl From<[u8; 3]> for MidiMessage { | ||
fn from(msg: [u8; 3]) -> Self { | ||
MidiMessage { msg } | ||
} | ||
} | ||
|
||
impl MidiMessage { | ||
#[must_use] | ||
pub fn is_note_on(&self) -> bool { | ||
(self.msg[0] & 0b1111_0000) == NOTE_ON_STATUS | ||
} | ||
|
||
#[must_use] | ||
pub fn is_note_off(&self) -> bool { | ||
(self.msg[0] & 0b1111_0000) == NOTE_OFF_STATUS | ||
} | ||
|
||
/// Get the channel of a message, assuming the message is not a system message. | ||
#[must_use] | ||
pub fn channel(&self) -> u8 { | ||
self.msg[0] & 0b0000_1111 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.