[][src]Struct tune::note::Note

pub struct Note { /* fields omitted */ }

A musical note encapsulating a clearly defined pitch.

The pitch can be derived using the Pitched impl on the Note type itself, assuming standard 440 Hz tuning, or on NoteAtConcertPitch, given a specific concert pitch.

Implementations

impl Note[src]

pub fn from_midi_number(midi_number: i32) -> Self[src]

pub fn from_letter_and_octave(
    note_letter: NoteLetter,
    octave: impl Into<Octave>
) -> Self
[src]

Creates a Note instance given a NoteLetter and an octave.

Examples

let a4 = Note::from_midi_number(69);
assert_eq!(Note::from_letter_and_octave(NoteLetter::A, 4), a4);
assert_eq!(Note::from_letter_and_octave(NoteLetter::A, Octave::from_octave_number(4)), a4);
assert_eq!(Note::from_letter_and_octave(NoteLetter::A, HelmholtzOctave::OneLined), a4);

pub fn from_piano_key(piano_key: PianoKey) -> Self[src]

Creates a Note instance from a PianoKey assuming standard 12-EDO tuning.

pub fn midi_number(self) -> i32[src]

pub fn letter_and_octave(self) -> (NoteLetter, Octave)[src]

Splits the current note into a NoteLetter and an Octave.

Examples

let a4 = Note::from_midi_number(69);
assert_eq!(a4.letter_and_octave(), (NoteLetter::A, Octave::from_octave_number(4)));

let midi_root = Note::from_midi_number(0);
assert_eq!(midi_root.letter_and_octave(), (NoteLetter::C, Octave::from_octave_number(-1)));

pub fn as_piano_key(self) -> PianoKey[src]

Retrieves the associated PianoKey assuming standard 12-EDO tuning.

pub fn at_pitch(self, pitched: impl Pitched) -> NoteAtConcertPitch[src]

Creates a NoteAtConcertPitch instance with self sounding at a different pitch.

Examples

use tune::pitch::Pitched;

let c4_at_260_hz = NoteLetter::C.in_octave(4).at_pitch(Pitch::from_hz(260.0));
assert_approx_eq!(c4_at_260_hz.pitch().as_hz(), 260.0);

let (_note, concert_pitch) = c4_at_260_hz;
assert_approx_eq!(concert_pitch.a4_pitch().as_hz(), 437.266136);

pub fn at_concert_pitch(self, concert_pitch: ConcertPitch) -> NoteAtConcertPitch[src]

Convenience function creating a NoteAtConcertPitch instance.

Examples

let a4 = NoteLetter::A.in_octave(4);
let concert_pitch = ConcertPitch::from_a4_pitch(Pitch::from_hz(435.0));
assert_eq!(a4.at_concert_pitch(concert_pitch), (a4, concert_pitch));

pub fn num_semitones_before(self, other: Note) -> i32[src]

Counts the number of semitones [left inclusive, right exclusive) between self and other.

pub fn plus_semitones(self, num_semitones: i32) -> Note[src]

Retrieves the Note instance num_semitones above self.

Trait Implementations

impl Clone for Note[src]

impl Copy for Note[src]

impl Debug for Note[src]

impl Display for Note[src]

Notes are rendered in scientific pitch notation.

Examples

assert_eq!(Note::from_midi_number(0).to_string(), "C -1");
assert_eq!(Note::from_midi_number(69).to_string(), "A 4");
assert_eq!(Note::from_midi_number(70).to_string(), "A#/Bb 4");
assert_eq!(Note::from_midi_number(71).to_string(), "B 4");
assert_eq!(Note::from_midi_number(72).to_string(), "C 5");
assert_eq!(Note::from_midi_number(127).to_string(), "G 9");

// Format flags
assert_eq!(format!("{:+}", Note::from_midi_number(70)), "A# 4");
assert_eq!(format!("{:-}", Note::from_midi_number(70)), "Bb 4");
assert_eq!(format!("{:10}", Note::from_midi_number(70)), "A#/Bb 4   ");
assert_eq!(format!("{:<10}", Note::from_midi_number(70)), "A#/Bb 4   ");
assert_eq!(format!("{:>10}", Note::from_midi_number(70)), "   A#/Bb 4");

impl Eq for Note[src]

impl Hash for Note[src]

impl Ord for Note[src]

impl PartialEq<Note> for Note[src]

impl PartialOrd<Note> for Note[src]

impl Pitched for Note[src]

impl PitchedNote for Note[src]

impl StructuralEq for Note[src]

impl StructuralPartialEq for Note[src]

impl Tuning<Note> for ConcertPitch[src]

impl Tuning<Note> for ()[src]

Convenience implementation enabling to write () instead of ConcertPitch::default().

Examples

assert_eq!(Pitch::from_hz(880.0).find_in(&()).approx_value, Note::from_midi_number(81));

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.