Struct NotesMap

Source
pub struct NotesMap { /* private fields */ }
Expand description

Effectively maps notes to midi and backwards.

Example

use musical_note::{NotesMap, NoteName, Accidental};
let map = NotesMap::get();
assert_eq!(map.get_by_note(NoteName::F, Accidental::DoubleFlat), 3);

Implementations§

Source§

impl NotesMap

Source

pub fn get() -> &'static NotesMap

Source

pub fn get_by_midi(&self, midi: &u8) -> &HashMap<Accidental, NoteName>

Source

pub fn get_by_note(&self, note: NoteName, acc: Accidental) -> u8

Source

pub fn resolve_note_for_midi( &self, note: (NoteName, Accidental), midi: u8, ) -> Option<(NoteName, Accidental)>

Accidental of “root” is not counted.

For the given note and MIDI-byte finds only possible enharmonic variant, or returns None.

For example: with the given NoteName::C and midi 2, only possible enharmonic variant is (NoteName::C, Accidental::DoubleSharp), which will be returned.

If None is returned — something goes very wrong and it is better to panic.

Source

pub fn resolve_enharmonic( &self, accidental: Option<Accidental>, midi: u8, ) -> (NoteName, Accidental)

Trait Implementations§

Source§

impl Debug for NotesMap

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.