[][src]Struct minstrel::Note

pub struct Note {
    pub value: usize,
}

A note, represented as a single positive integer (called it's value). A value of 0 = C0, 1 = Db0 etc.

You can create a Note by either parsing from a string or directly inputting a number value:

use minstrel::Note;
use std::str::FromStr;

// Directly
let A0 = Note::new(9);

// From a string
let Eb100 = Note::from_str("Eb100");

Notes have a number of useful features. For example, you can easily transpose one by using the addition or subtraction operators:

use minstrel::Note;

let C1 = Note::new(12);
assert_eq!(C1 + 5, Note::new(17));
assert_eq!(C1 - 2, Note::new(10));

You can also get the semitone difference between two Notes just by subtracting them:

use minstrel::Note;

let C0 = Note::new(0);
let E0 = Note::new(4);

// It doesn't matter which order the notes are in
assert_eq!(C0 - E0, 4);
assert_eq!(E0 - C0, 4);

Finally, you can call into_iter on a Note to iterate over it:

use minstrel::Note;

// Prints the chromatic scale
for note in Note::new(0).into_iter().take(12) {
   println!("{}", note);
}

Fields

value: usize

Implementations

impl Note[src]

pub fn new(value: usize) -> Self[src]

Creates a new Note with the given value.

Examples

use minstrel::Note;

let C0 = Note::new(0);
let F4 = Note::new(53);
let Ab5 = Note::new(68);

pub fn disregard_octave(self) -> Self[src]

Returns a new Note where the inner value holds no octave information i.e. it is constrained between 0 and 11.

Examples

use minstrel::Note;

let F = Note::new(53).disregard_octave();

let Ab5 = Note::new(68);
let Ab = Ab5.disregard_octave();

Trait Implementations

impl Add<usize> for Note[src]

type Output = Self

The resulting type after applying the + operator.

impl Clone for Note[src]

impl Copy for Note[src]

impl Debug for Note[src]

impl Display for Note[src]

impl Eq for Note[src]

impl FromStr for Note[src]

type Err = Error

The associated error which can be returned from parsing.

impl IntoIterator for Note[src]

type Item = Self

The type of the elements being iterated over.

type IntoIter = NoteIter

Which kind of iterator are we turning this into?

impl PartialEq<Note> for Note[src]

impl StructuralEq for Note[src]

impl StructuralPartialEq for Note[src]

impl Sub<Note> for Note[src]

type Output = usize

The resulting type after applying the - operator.

impl Sub<usize> for Note[src]

type Output = Self

The resulting type after applying the - operator.

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.