[][src]Struct simple_tones::Player

pub struct Player { /* fields omitted */ }

The Player is a struct used to play an Iterator of types implementing Play.

Example

use simple_tones::{Note, NoteDuration, Player};

let song = vec![
        Note::new("C4".parse().unwrap(), NoteDuration::Quarter),
        Note::new("C4".parse().unwrap(), NoteDuration::Quarter),
        Note::new("D4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("Eb4".parse().unwrap(), NoteDuration::Eighth),
        // |
        Note::new("D4".parse().unwrap(), NoteDuration::HalfDotted),
        // |
        Note::new("C4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("G3".parse().unwrap(), NoteDuration::Eighth),
        Note::new("Ab4".parse().unwrap(), NoteDuration::Quarter),
        Note::new("G3".parse().unwrap(), NoteDuration::Eighth),
        Note::new("F3".parse().unwrap(), NoteDuration::Eighth),
        // |
        Note::new("G3".parse().unwrap(), NoteDuration::HalfDotted),
        // |
        Note::new("C4".parse().unwrap(), NoteDuration::Quarter),
        Note::new("C4".parse().unwrap(), NoteDuration::Quarter),
        Note::new("D4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("Eb4".parse().unwrap(), NoteDuration::Eighth),
        // |
        Note::new("F4".parse().unwrap(), NoteDuration::HalfDotted),
        // |
        Note::new("G4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("Eb4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("D4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("C4".parse().unwrap(), NoteDuration::Eighth),
        Note::new("Bb4".parse().unwrap(), NoteDuration::Quarter),
        // |
        Note::new("C4".parse().unwrap(), NoteDuration::HalfDotted),
        // |
        Note::new("F3".parse().unwrap(), NoteDuration::Half),
    ];
let np = Player::from_bpm(55);
np.play(song.iter());

Implementations

impl Player[src]

pub fn new(bar_duration: Duration) -> Self[src]

Constructs a new Player from the given bar duration, which describes how much time one whole note takes to play.

Example

use simple_tones::Player;

let np = Player::new(std::time::Duration::from_secs_f64(0.5));

pub fn from_bpm(bpm: u32) -> Self[src]

Constructs a new Player from the given beats per minute. One beat is considered a quarter note. Therefore, the formula to determine the duration of one bar d is: d = 60 / bpm * 4

Example

use simple_tones::Player;

let np = Player::from_bpm(120);

pub fn play<P: Play, N: Iterator<Item = P>>(&self, notes: N)[src]

Plays an Iterator of types implementing Play on the standard audio device.

Auto Trait Implementations

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