Enum wmidi::Note

source ·
#[repr(u8)]
pub enum Note {
Show 128 variants CMinus1 = 0, DbMinus1 = 1, DMinus1 = 2, EbMinus1 = 3, EMinus1 = 4, FMinus1 = 5, GbMinus1 = 6, GMinus1 = 7, AbMinus1 = 8, AMinus1 = 9, BbMinus1 = 10, BMinus1 = 11, C0 = 12, Db0 = 13, D0 = 14, Eb0 = 15, E0 = 16, F0 = 17, Gb0 = 18, G0 = 19, Ab0 = 20, A0 = 21, Bb0 = 22, B0 = 23, C1 = 24, Db1 = 25, D1 = 26, Eb1 = 27, E1 = 28, F1 = 29, Gb1 = 30, G1 = 31, Ab1 = 32, A1 = 33, Bb1 = 34, B1 = 35, C2 = 36, Db2 = 37, D2 = 38, Eb2 = 39, E2 = 40, F2 = 41, Gb2 = 42, G2 = 43, Ab2 = 44, A2 = 45, Bb2 = 46, B2 = 47, C3 = 48, Db3 = 49, D3 = 50, Eb3 = 51, E3 = 52, F3 = 53, Gb3 = 54, G3 = 55, Ab3 = 56, A3 = 57, Bb3 = 58, B3 = 59, C4 = 60, Db4 = 61, D4 = 62, Eb4 = 63, E4 = 64, F4 = 65, Gb4 = 66, G4 = 67, Ab4 = 68, A4 = 69, Bb4 = 70, B4 = 71, C5 = 72, Db5 = 73, D5 = 74, Eb5 = 75, E5 = 76, F5 = 77, Gb5 = 78, G5 = 79, Ab5 = 80, A5 = 81, Bb5 = 82, B5 = 83, C6 = 84, Db6 = 85, D6 = 86, Eb6 = 87, E6 = 88, F6 = 89, Gb6 = 90, G6 = 91, Ab6 = 92, A6 = 93, Bb6 = 94, B6 = 95, C7 = 96, Db7 = 97, D7 = 98, Eb7 = 99, E7 = 100, F7 = 101, Gb7 = 102, G7 = 103, Ab7 = 104, A7 = 105, Bb7 = 106, B7 = 107, C8 = 108, Db8 = 109, D8 = 110, Eb8 = 111, E8 = 112, F8 = 113, Gb8 = 114, G8 = 115, Ab8 = 116, A8 = 117, Bb8 = 118, B8 = 119, C9 = 120, Db9 = 121, D9 = 122, Eb9 = 123, E9 = 124, F9 = 125, Gb9 = 126, G9 = 127,
}
Expand description

A midi note.

The format for the enum is $NOTE $MODIFIER? $OCTAVE. Note can be a note from A to G. Modifier can be b for flat or Sharp for sharp. Octave is the number. The octave -1 is represented as Minus1.

Example

use wmidi::Note;
let ab7_chord = [Note::AbMinus1, Note::C4, Note::Gb4]; // We omit the 5th for a jazzier sound
let dmaj_chord = [Note::D2, Note::FSharp3, Note::A3];
assert_eq!(u8::from(Note::C3), 48u8);
assert_eq!(Note::from_u8_lossy(48), Note::C3);

Variants§

§

CMinus1 = 0

§

DbMinus1 = 1

§

DMinus1 = 2

§

EbMinus1 = 3

§

EMinus1 = 4

§

FMinus1 = 5

§

GbMinus1 = 6

§

GMinus1 = 7

§

AbMinus1 = 8

§

AMinus1 = 9

§

BbMinus1 = 10

§

BMinus1 = 11

§

C0 = 12

§

Db0 = 13

§

D0 = 14

§

Eb0 = 15

§

E0 = 16

§

F0 = 17

§

Gb0 = 18

§

G0 = 19

§

Ab0 = 20

§

A0 = 21

§

Bb0 = 22

§

B0 = 23

§

C1 = 24

§

Db1 = 25

§

D1 = 26

§

Eb1 = 27

§

E1 = 28

§

F1 = 29

§

Gb1 = 30

§

G1 = 31

§

Ab1 = 32

§

A1 = 33

§

Bb1 = 34

§

B1 = 35

§

C2 = 36

§

Db2 = 37

§

D2 = 38

§

Eb2 = 39

§

E2 = 40

§

F2 = 41

§

Gb2 = 42

§

G2 = 43

§

Ab2 = 44

§

A2 = 45

§

Bb2 = 46

§

B2 = 47

§

C3 = 48

§

Db3 = 49

§

D3 = 50

§

Eb3 = 51

§

E3 = 52

§

F3 = 53

§

Gb3 = 54

§

G3 = 55

§

Ab3 = 56

§

A3 = 57

§

Bb3 = 58

§

B3 = 59

§

C4 = 60

Middle C.

§

Db4 = 61

§

D4 = 62

§

Eb4 = 63

§

E4 = 64

§

F4 = 65

§

Gb4 = 66

§

G4 = 67

§

Ab4 = 68

§

A4 = 69

A440.

§

Bb4 = 70

§

B4 = 71

§

C5 = 72

§

Db5 = 73

§

D5 = 74

§

Eb5 = 75

§

E5 = 76

§

F5 = 77

§

Gb5 = 78

§

G5 = 79

§

Ab5 = 80

§

A5 = 81

§

Bb5 = 82

§

B5 = 83

§

C6 = 84

§

Db6 = 85

§

D6 = 86

§

Eb6 = 87

§

E6 = 88

§

F6 = 89

§

Gb6 = 90

§

G6 = 91

§

Ab6 = 92

§

A6 = 93

§

Bb6 = 94

§

B6 = 95

§

C7 = 96

§

Db7 = 97

§

D7 = 98

§

Eb7 = 99

§

E7 = 100

§

F7 = 101

§

Gb7 = 102

§

G7 = 103

§

Ab7 = 104

§

A7 = 105

§

Bb7 = 106

§

B7 = 107

§

C8 = 108

§

Db8 = 109

§

D8 = 110

§

Eb8 = 111

§

E8 = 112

§

F8 = 113

§

Gb8 = 114

§

G8 = 115

§

Ab8 = 116

§

A8 = 117

§

Bb8 = 118

§

B8 = 119

§

C9 = 120

§

Db9 = 121

§

D9 = 122

§

Eb9 = 123

§

E9 = 124

§

F9 = 125

§

Gb9 = 126

§

G9 = 127

Implementations§

source§

impl Note

source

pub const CSharpMinus1: Note = Note::DbMinus1

source

pub const DSharpMinus1: Note = Note::EbMinus1

source

pub const FSharpMinus1: Note = Note::GbMinus1

source

pub const GSharpMinus1: Note = Note::AbMinus1

source

pub const ASharpMinus1: Note = Note::BbMinus1

source

pub const CSharp0: Note = Note::Db0

source

pub const DSharp0: Note = Note::Eb0

source

pub const FSharp0: Note = Note::Gb0

source

pub const GSharp0: Note = Note::Ab0

source

pub const ASharp0: Note = Note::Bb0

source

pub const CSharp1: Note = Note::Db1

source

pub const DSharp1: Note = Note::Eb1

source

pub const FSharp1: Note = Note::Gb1

source

pub const GSharp1: Note = Note::Ab1

source

pub const ASharp1: Note = Note::Bb1

source

pub const CSharp2: Note = Note::Db2

source

pub const DSharp2: Note = Note::Eb2

source

pub const FSharp2: Note = Note::Gb2

source

pub const GSharp2: Note = Note::Ab2

source

pub const ASharp2: Note = Note::Bb2

source

pub const CSharp3: Note = Note::Db3

source

pub const DSharp3: Note = Note::Eb3

source

pub const FSharp3: Note = Note::Gb3

source

pub const GSharp3: Note = Note::Ab3

source

pub const ASharp3: Note = Note::Bb3

source

pub const CSharp4: Note = Note::Db4

source

pub const DSharp4: Note = Note::Eb4

source

pub const FSharp4: Note = Note::Gb4

source

pub const GSharp4: Note = Note::Ab4

source

pub const ASharp4: Note = Note::Bb4

source

pub const CSharp5: Note = Note::Db5

source

pub const DSharp5: Note = Note::Eb5

source

pub const FSharp5: Note = Note::Gb5

source

pub const GSharp5: Note = Note::Ab5

source

pub const ASharp5: Note = Note::Bb5

source

pub const CSharp6: Note = Note::Db6

source

pub const DSharp6: Note = Note::Eb6

source

pub const FSharp6: Note = Note::Gb6

source

pub const GSharp6: Note = Note::Ab6

source

pub const ASharp6: Note = Note::Bb6

source

pub const CSharp7: Note = Note::Db7

source

pub const DSharp7: Note = Note::Eb7

source

pub const FSharp7: Note = Note::Gb7

source

pub const GSharp7: Note = Note::Ab7

source

pub const ASharp7: Note = Note::Bb7

source

pub const CSharp8: Note = Note::Db8

source

pub const DSharp8: Note = Note::Eb8

source

pub const FSharp8: Note = Note::Gb8

source

pub const GSharp8: Note = Note::Ab8

source

pub const ASharp8: Note = Note::Bb8

source

pub const CSharp9: Note = Note::Db9

source

pub const DSharp9: Note = Note::Eb9

source

pub const FSharp9: Note = Note::Gb9

source

pub const LOWEST_NOTE: Note = Note::CMinus1

The lowest representable note.

source

pub const HIGHEST_NOTE: Note = Note::G9

The highest representable note.

source

pub unsafe fn from_u8_unchecked(note: u8) -> Note

Creates a note from a u8. note must be between [0, 127] inclusive to create a valid note.

Example
 let parsed_note = 60;
 let note = unsafe { wmidi::Note::from_u8_unchecked(parsed_note) };
Safety

note must be less than or equal to 127.

source

pub fn from_u8_lossy(note: u8) -> Note

Create a note from a u8. Only the 7 least significant bits of note are used.

source

pub fn to_freq_f32(self) -> f32

The frequency using the standard 440Hz tuning.

Example
let note = wmidi::Note::A3;
sing(note.to_freq_f32());
source

pub fn to_freq_f64(self) -> f64

The frequency using the standard 440Hz tuning.

Example
let note = wmidi::Note::A3;
sing(note.to_freq_f64());
source

pub fn step(self, half_steps: i8) -> Result<Note, Error>

Get the note relative to self.

Example
use wmidi::Note;
fn minor_chord(root: Note) -> Result<[Note; 3], wmidi::Error> {
    Ok([root, root.step(3)?, root.step(7)?])
}
assert_eq!(minor_chord(Note::C2), Ok([Note::C2, Note::Eb2, Note::G2]));
source

pub fn to_str(self) -> &'static str

Get a str representation of the note. For example: "C3" or "A#/Bb2".

Trait Implementations§

source§

impl Clone for Note

source§

fn clone(&self) -> Note

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Note

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Note

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Note> for u8

Convert from a Note to a u8.

source§

fn from(note: Note) -> u8

Example
 use std::convert::TryFrom;
 fn encode_note(note: wmidi::Note) -> u8 {
     u8::from(note)
 }
source§

impl From<U7> for Note

source§

fn from(note: U7) -> Note

Converts to this type from the input type.
source§

impl Hash for Note

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Note

source§

fn cmp(&self, other: &Note) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Note

source§

fn eq(&self, other: &Note) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Note

source§

fn partial_cmp(&self, other: &Note) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<u8> for Note

Convert from a u8 to a Note. The u8 must be in the range [0, 127] inclusive.

source§

fn try_from(note: u8) -> Result<Note, Error>

Creates a note from a u8. note must be between [0, 127] inclusive to create a valid note.

Example
 use std::convert::TryFrom;
 fn decode_note(number: u8) -> Result<wmidi::Note, wmidi::Error> {
     let parsed_note = 60;
     let note = wmidi::Note::try_from(parsed_note)?;
     Ok(note)
 }
§

type Error = FromBytesError

The type returned in the event of a conversion error.
source§

impl Copy for Note

source§

impl Eq for Note

source§

impl StructuralEq for Note

source§

impl StructuralPartialEq for Note

Auto Trait Implementations§

§

impl RefUnwindSafe for Note

§

impl Send for Note

§

impl Sync for Note

§

impl Unpin for Note

§

impl UnwindSafe for Note

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.