Struct music_theory::theory::note::Note

source ·
pub struct Note(_);
Expand description

The main note type. Does not take into account enharmonic spelling.

Example:

use music_theory::theory::*;
assert_eq!(Note::new(0), Note::A0);

Implementations§

source§

impl Note

source

pub const MAX: Note = _

Biggest valid Note value.

Example:

use music_theory::theory::*;
assert_eq!(Note::MAX + Note::C3, Note::MAX);
source

pub const MIN: Note = _

Smallest valid Note value.

Example:

use music_theory::theory::*;
assert_eq!(Note::MIN.shift_octave(-1), Note::MIN);
source

pub const ZERO: Note = _

The zeroth Note, the same as Note::MIN.

Example:

use music_theory::theory::*;
assert_eq!(Note::ZERO, Note::MIN);
source

pub const A0: Note = _

source

pub const AS0: Note = _

source

pub const B0: Note = _

source

pub const C0: Note = _

source

pub const CS0: Note = _

source

pub const D0: Note = _

source

pub const DS0: Note = _

source

pub const E0: Note = _

source

pub const F0: Note = _

source

pub const FS0: Note = _

source

pub const G0: Note = _

source

pub const GS0: Note = _

source

pub const A1: Note = _

source

pub const AS1: Note = _

source

pub const B1: Note = _

source

pub const C1: Note = _

source

pub const CS1: Note = _

source

pub const D1: Note = _

source

pub const DS1: Note = _

source

pub const E1: Note = _

source

pub const F1: Note = _

source

pub const FS1: Note = _

source

pub const G1: Note = _

source

pub const GS1: Note = _

source

pub const A2: Note = _

source

pub const AS2: Note = _

source

pub const B2: Note = _

source

pub const C2: Note = _

source

pub const CS2: Note = _

source

pub const D2: Note = _

source

pub const DS2: Note = _

source

pub const E2: Note = _

source

pub const F2: Note = _

source

pub const FS2: Note = _

source

pub const G2: Note = _

source

pub const GS2: Note = _

source

pub const A3: Note = _

source

pub const AS3: Note = _

source

pub const B3: Note = _

source

pub const C3: Note = _

source

pub const CS3: Note = _

source

pub const D3: Note = _

source

pub const DS3: Note = _

source

pub const E3: Note = _

source

pub const F3: Note = _

source

pub const FS3: Note = _

source

pub const G3: Note = _

source

pub const GS3: Note = _

source

pub const A4: Note = _

source

pub const AS4: Note = _

source

pub const B4: Note = _

source

pub const C4: Note = _

source

pub const CS4: Note = _

source

pub const D4: Note = _

source

pub const DS4: Note = _

source

pub const E4: Note = _

source

pub const F4: Note = _

source

pub const FS4: Note = _

source

pub const G4: Note = _

source

pub const GS4: Note = _

source

pub const A5: Note = _

source

pub const AS5: Note = _

source

pub const B5: Note = _

source

pub const C5: Note = _

source

pub const CS5: Note = _

source

pub const D5: Note = _

source

pub const DS5: Note = _

source

pub const E5: Note = _

source

pub const F5: Note = _

source

pub const FS5: Note = _

source

pub const G5: Note = _

source

pub const GS5: Note = _

source

pub const A6: Note = _

source

pub const AS6: Note = _

source

pub const B6: Note = _

source

pub const C6: Note = _

source

pub const CS6: Note = _

source

pub const D6: Note = _

source

pub const DS6: Note = _

source

pub const E6: Note = _

source

pub const F6: Note = _

source

pub const FS6: Note = _

source

pub const G6: Note = _

source

pub const GS6: Note = _

source

pub const A7: Note = _

source

pub const AS7: Note = _

source

pub const B7: Note = _

source

pub const C7: Note = _

source

pub const CS7: Note = _

source

pub const D7: Note = _

source

pub const DS7: Note = _

source

pub const E7: Note = _

source

pub const F7: Note = _

source

pub const FS7: Note = _

source

pub const G7: Note = _

source

pub const GS7: Note = _

source

pub const A8: Note = _

source

pub const AS8: Note = _

source

pub const B8: Note = _

source

pub const C8: Note = _

source

pub const CS8: Note = _

source

pub const D8: Note = _

source

pub const DS8: Note = _

source

pub const E8: Note = _

source

pub const F8: Note = _

source

pub const FS8: Note = _

source

pub const G8: Note = _

source

pub const GS8: Note = _

source

pub const A9: Note = _

source

pub const AS9: Note = _

source

pub const B9: Note = _

source

pub const C9: Note = _

source

pub const CS9: Note = _

source

pub const D9: Note = _

source

pub const DS9: Note = _

source

pub const E9: Note = _

source

pub const F9: Note = _

source

pub const FS9: Note = _

source

pub const G9: Note = _

source

pub const GS9: Note = _

source

pub fn new(note: u32) -> Self

Create a new valid note. Will be clamped if nessesary.

Example:

use music_theory::theory::*;
assert_eq!(Note::new(12), Note::A1);
source

pub fn inside(&self) -> u32

Returns the inner value. You can not set the inner value directly to prevent invalid notes.

Example:

use music_theory::theory::*;
assert_eq!(Note::A2.inside(), 24);
source

pub fn to_pitch(&self) -> f32

Return the pitch in hertz. Note::A4 has an inner value of 48 and a pitch of 440 hz.

Example:

use music_theory::theory::*;
assert_eq!(Note::A4.to_pitch(), 440.0);
source

pub fn to_midi_note(&self) -> u8

Return the equivalent MIDI note. Note::A4 has an inner value of 48 and a MIDI note number of 69.

Example:

use music_theory::theory::*;
assert_eq!(Note::A4.to_midi_note(), 69);

Trait Implementations§

source§

impl Add<Note> for Note

§

type Output = Note

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<Note> for Note

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl AddInterval for Note

source§

fn add_interval(self, interval: Interval) -> Option<Self>

Add an Interval.
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 Default for Note

source§

fn default() -> Note

Returns the “default value” for a type. 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 GeneratablePartialOrder for Note

source§

fn next(self) -> Option<Note>

Generate the next item.
source§

fn prev(self) -> Option<Note>

Generate the previous item.
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 Mul<Note> for Note

§

type Output = Note

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<Note> for Note

source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
source§

impl OctaveShiftable for Note

source§

fn with_octave(self, octave: Octave) -> Note

Have the value with everything the same except change the octave to the given one.
source§

fn shift_octave(self, shift: OctaveShift) -> Note

Have the value with everything the same except shift the octave from the current one with the given shift.
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) -> Selfwhere Self: Sized,

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

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

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

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

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

impl PartialEq<Note> 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<Note> 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 RangeBounds<Note> for Note

source§

fn start_bound(&self) -> Bound<&Self>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&Self>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> boolwhere T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl Rem<Note> for Note

§

type Output = Note

The resulting type after applying the % operator.
source§

fn rem(self, other: Self) -> Self::Output

Performs the % operation. Read more
source§

impl RemAssign<Note> for Note

source§

fn rem_assign(&mut self, other: Self)

Performs the %= operation. Read more
source§

impl Sub<Note> for Note

§

type Output = Interval

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Interval

Performs the - operation. Read more
source§

impl ToEnharmonicNote for Note

source§

impl ToLetterTry for Note

source§

fn to_letter_try(&self) -> Option<Letter>

Take self and try to return Letter.
source§

impl ToPC for Note

source§

fn to_pc(self) -> PC

Take self and return PC.
source§

impl Wrapper for Note

§

type Inner = u32

The type the new type wraps.
source§

fn wrap(note: Self::Inner) -> Option<Self>

Try to wrap a Self::Inner type into the Self type.
source§

fn unwrap(self) -> Self::Inner

Unwrap a Self type into a Self::Inner type.
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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.