pub struct Player<T: Timer, C: Connection> {
pub con: C,
/* private fields */
}Expand description
A type that orchestrates playing of MIDI tracks.
Player is a struct with two requirements:
- A Timer for properly timing a sleep.
- A Connection to send the MIDI events when they are ready to play.
So, Player is the glue that binds timing and playback.
This type is more of a convenience struct; it cannot possibly satisfy all use cases.
§Implementation Details
In this section, the "track" refers to either a Sheet or a slice of Moments.
This type orchestrates playback of tracks. There are some things that are assumed:
- Every moment in the given sheet is offset by exactly 1 MIDI tick.
- The provided Timer is assumed to be aware of #1 above.
The implementation of Player::play is roughly as follows:
- Initialize a counter that increments by 1 every tick and resets to 0 wwhenever there is a non-empty Moment.
- Start iterating over the provided track, incrementing the counter every iteration (tick).
- Whenever the iterated value is a non-empty Moment, check to see if there are any tempo change events.
- If the event is a tempo change, call Timer::change_tempo, if it’s a MIDI event, call Connection::play.
- Repeat until the iteration is complete.
Fields§
§con: CAn active midi connection.
Implementations§
Source§impl<T: Timer, C: Connection> Player<T, C>
impl<T: Timer, C: Connection> Player<T, C>
Sourcepub fn new(timer: T, con: C) -> Self
pub fn new(timer: T, con: C) -> Self
Creates a new Player with the given Timer and Connection.
Auto Trait Implementations§
impl<T, C> Freeze for Player<T, C>
impl<T, C> RefUnwindSafe for Player<T, C>where
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, C> Send for Player<T, C>
impl<T, C> Sync for Player<T, C>
impl<T, C> Unpin for Player<T, C>
impl<T, C> UnwindSafe for Player<T, C>where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more