generated from webern/rust-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin separating code out into separate files and modules.
- Loading branch information
Showing
19 changed files
with
888 additions
and
815 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 +1,20 @@ | ||
[package] | ||
name = "midi" | ||
name = "midi_file" | ||
version = "0.0.0" | ||
authors = ["Matthew James Briggs <[email protected]>"] | ||
edition = "2018" | ||
exclude = ["tests/", ".gitignore"] | ||
exclude = [ | ||
".gitignore", | ||
".run", | ||
"examples/", | ||
"tests/", | ||
] | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
description = "For reading and writing MIDI files." | ||
repository = "https://github.com/webern/midi_file" | ||
keywords = ["MIDI"] | ||
categories = ["encoding"] | ||
|
||
[dependencies] | ||
log = "0.4" | ||
|
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// There are 24 MIDI Clocks in every quarter note. (12 MIDI Clocks in an eighth note, 6 MIDI Clocks in a 16th, etc). | ||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] | ||
pub enum Clocks { | ||
DottedWhole, | ||
Whole, | ||
DottedHalf, | ||
Half, | ||
DottedQuarter, | ||
Quarter, | ||
DottedEighth, | ||
Eighth, | ||
DottedSixteenth, | ||
Sixteenth, | ||
Other(u8), | ||
} | ||
|
||
impl Default for Clocks { | ||
fn default() -> Self { | ||
Clocks::Quarter | ||
} | ||
} | ||
|
||
impl Clocks { | ||
pub(crate) fn from_u8(v: u8) -> Clocks { | ||
match v { | ||
142 => Clocks::DottedWhole, | ||
96 => Clocks::Whole, | ||
72 => Clocks::DottedHalf, | ||
48 => Clocks::Half, | ||
32 => Clocks::DottedQuarter, | ||
24 => Clocks::Quarter, | ||
18 => Clocks::DottedEighth, | ||
12 => Clocks::Eighth, | ||
9 => Clocks::DottedSixteenth, | ||
6 => Clocks::Sixteenth, | ||
_ => Clocks::Other(v), | ||
} | ||
} | ||
|
||
pub(crate) fn to_u8(&self) -> u8 { | ||
match self { | ||
Clocks::DottedWhole => 142, | ||
Clocks::Whole => 96, | ||
Clocks::DottedHalf => 72, | ||
Clocks::Half => 48, | ||
Clocks::DottedQuarter => 32, | ||
Clocks::Quarter => 24, | ||
Clocks::DottedEighth => 18, | ||
Clocks::Eighth => 12, | ||
Clocks::DottedSixteenth => 9, | ||
Clocks::Sixteenth => 6, | ||
Clocks::Other(v) => *v, | ||
} | ||
} | ||
|
||
pub fn new(clocks: u8) -> Self { | ||
Self::from_u8(clocks) | ||
} | ||
|
||
pub fn resolve(&mut self) { | ||
*self = Self::from_u8(self.to_u8()) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::error::LibResult; | ||
use crate::Error; | ||
use std::convert::TryFrom; | ||
|
||
#[repr(u8)] | ||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] | ||
pub enum DurationName { | ||
/// Whole Note / Semibreve | ||
Whole = 0, | ||
|
||
/// Half Note / Minim | ||
Half = 1, | ||
|
||
/// Quarter Note / Crotchet | ||
Quarter = 2, | ||
|
||
/// Eighth Note / Quaver | ||
Eighth = 3, | ||
|
||
/// Sixteenth note / Semiquaver | ||
Sixteenth = 4, | ||
|
||
/// Thirty-Second Note / Demisemiquaver | ||
D32 = 5, | ||
|
||
/// Sixty-Fourth Note / Hemidemisemiquaver | ||
D64 = 6, | ||
|
||
/// One-Twenty-Eighth Note / Semihemidemisemiquaver | ||
D128 = 7, | ||
|
||
/// Two-Fifty-Sixth Note / Demisemihemidemisemiquaver | ||
D256 = 8, | ||
|
||
/// Five-Twelfth Note | ||
D512 = 9, | ||
|
||
/// One Thousand, Twenty-Fourth Note | ||
D1024 = 10, | ||
} | ||
|
||
impl Default for DurationName { | ||
fn default() -> Self { | ||
DurationName::Quarter | ||
} | ||
} | ||
|
||
impl DurationName { | ||
pub(crate) fn from_u8(v: u8) -> LibResult<Self> { | ||
match v { | ||
v if DurationName::Whole as u8 == v => Ok(DurationName::Whole), | ||
v if DurationName::Half as u8 == v => Ok(DurationName::Half), | ||
v if DurationName::Quarter as u8 == v => Ok(DurationName::Quarter), | ||
v if DurationName::Eighth as u8 == v => Ok(DurationName::Eighth), | ||
v if DurationName::Sixteenth as u8 == v => Ok(DurationName::Sixteenth), | ||
v if DurationName::D32 as u8 == v => Ok(DurationName::D32), | ||
v if DurationName::D64 as u8 == v => Ok(DurationName::D64), | ||
v if DurationName::D128 as u8 == v => Ok(DurationName::D128), | ||
v if DurationName::D256 as u8 == v => Ok(DurationName::D256), | ||
v if DurationName::D512 as u8 == v => Ok(DurationName::D512), | ||
v if DurationName::D1024 as u8 == v => Ok(DurationName::D1024), | ||
_ => crate::error::Other { site: site!() }.fail(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<u8> for DurationName { | ||
type Error = Error; | ||
|
||
fn try_from(value: u8) -> crate::Result<Self> { | ||
Ok(Self::from_u8(value)?) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#[repr(u8)] | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub enum GeneralMidi { | ||
AcousticGrandPiano = 1, | ||
BrightAcousticPiano = 2, | ||
ElectricGrandPiano = 3, | ||
HonkyTonkPiano = 4, | ||
ElectricPiano1 = 5, | ||
ElectricPiano2 = 6, | ||
Harpsichord = 7, | ||
Clavi = 8, | ||
Celesta = 9, | ||
Glockenspiel = 10, | ||
MusicBox = 11, | ||
Vibraphone = 12, | ||
Marimba = 13, | ||
Xylophone = 14, | ||
TubularBells = 15, | ||
Dulcimer = 16, | ||
DrawbarOrgan = 17, | ||
PercussiveOrgan = 18, | ||
RockOrgan = 19, | ||
ChurchOrgan = 20, | ||
ReedOrgan = 21, | ||
Accordion = 22, | ||
Harmonica = 23, | ||
TangoAccordion = 24, | ||
AcousticGuitarNylon = 25, | ||
AcousticGuitarSteel = 26, | ||
ElectricGuitarJazz = 27, | ||
ElectricGuitarClean = 28, | ||
ElectricGuitarMuted = 29, | ||
OverdrivenGuitar = 30, | ||
DistortionGuitar = 31, | ||
GuitarHarmonics = 32, | ||
AcousticBass = 33, | ||
ElectricBassFinger = 34, | ||
ElectricBassPick = 35, | ||
FretlessBass = 36, | ||
SlapBass1 = 37, | ||
SlapBass2 = 38, | ||
SynthBass1 = 39, | ||
SynthBass2 = 40, | ||
Violin = 41, | ||
Viola = 42, | ||
Cello = 43, | ||
Contrabass = 44, | ||
TremoloStrings = 45, | ||
PizzicatoStrings = 46, | ||
OrchestralHarp = 47, | ||
Timpani = 48, | ||
StringEnsemble1 = 49, | ||
StringEnsemble2 = 50, | ||
SynthStrings1 = 51, | ||
SynthStrings2 = 52, | ||
ChoirAahs = 53, | ||
VoiceOohs = 54, | ||
SynthVoice = 55, | ||
OrchestraHit = 56, | ||
Trumpet = 57, | ||
Trombone = 58, | ||
Tuba = 59, | ||
MutedTrumpet = 60, | ||
FrenchHorn = 61, | ||
BrassSection = 62, | ||
SynthBrass1 = 63, | ||
SynthBrass2 = 64, | ||
SopranoSax = 65, | ||
AltoSax = 66, | ||
TenorSax = 67, | ||
BaritoneSax = 68, | ||
Oboe = 69, | ||
EnglishHorn = 70, | ||
Bassoon = 71, | ||
Clarinet = 72, | ||
Piccolo = 73, | ||
Flute = 74, | ||
Recorder = 75, | ||
PanFlute = 76, | ||
BlownBottle = 77, | ||
Shakuhachi = 78, | ||
Whistle = 79, | ||
Ocarina = 80, | ||
Lead1Square = 81, | ||
Lead2Sawtooth = 82, | ||
Lead3Calliope = 83, | ||
Lead4Chiff = 84, | ||
Lead5Charang = 85, | ||
Lead6Voice = 86, | ||
Lead7Fifths = 87, | ||
Lead8BassPlusLead = 88, | ||
Pad1Newage = 89, | ||
Pad2Warm = 90, | ||
Pad3Polysynth = 91, | ||
Pad4Choir = 92, | ||
Pad5Bowed = 93, | ||
Pad6Metallic = 94, | ||
Pad7Halo = 95, | ||
Pad8Sweep = 96, | ||
Fx1Rain = 97, | ||
Fx2Soundtrack = 98, | ||
Fx3Crystal = 99, | ||
Fx4Atmosphere = 100, | ||
Fx5Brightness = 101, | ||
Fx6Goblins = 102, | ||
Fx7Echoes = 103, | ||
Fx8SciFi = 104, | ||
Sitar = 105, | ||
Banjo = 106, | ||
Shamisen = 107, | ||
Koto = 108, | ||
Kalimba = 109, | ||
Bagpipe = 110, | ||
Fiddle = 111, | ||
Shanai = 112, | ||
TinkleBell = 113, | ||
Agogo = 114, | ||
SteelDrums = 115, | ||
Woodblock = 116, | ||
TaikoDrum = 117, | ||
MelodicTom = 118, | ||
SynthDrum = 119, | ||
ReverseCymbal = 120, | ||
GuitarFretNoise = 121, | ||
BreathNoise = 122, | ||
Seashore = 123, | ||
BirdTweet = 124, | ||
TelephoneRing = 125, | ||
Helicopter = 126, | ||
Applause = 127, | ||
Gunshot = 128, | ||
} | ||
|
||
impl Into<u8> for GeneralMidi { | ||
fn into(self) -> u8 { | ||
self as u8 | ||
} | ||
} |
Oops, something went wrong.