[−][src]Struct music_timer::music_timer_engine::MusicTimerEngine
The engine uses all of this crate's utilities to allow to use of a music performance state system that triggers callbacks. Its aims are to allow for an easy interface for changes in music time.
Methods
impl MusicTimerEngine[src]
pub fn new(time_signature: TimeSignature, bpm: f32) -> Self[src]
Create a new MusicTimerEngine with a TimeSignature and bpm.
Arguments
time_signature- The time signature for the performance.bpm- The beats per minute used for the performance.
Example
use music_timer::{music_timer_engine::MusicTimerEngine, time_signature::TimeSignature}; let mut performer = MusicTimerEngine::new(TimeSignature::new(3, 4), 155.0);
pub fn pulse<TimerState: MusicTimerState>(&mut self, state: &mut TimerState)[src]
Pulse the engine. The time since the last pulse is used to evaluate if there is a change in music time. It is suggested to call this from a loop.
Arguments
state- The traitMusicTimerStateused for changes in music time callbacks.TimeSignature
Example
use music_timer::{music_timer_engine::{MusicTimerEngine, MusicTimerState}, music_time::MusicTime}; struct PerformanceState; impl MusicTimerState for PerformanceState { fn on_beat_interval(&mut self, current_time: &MusicTime) { // Do something on the beat interval } fn on_beat(&mut self, current_time: &MusicTime) { // Do something on the beat } fn on_bar(&mut self, current_time: &MusicTime) { // Do something on the bar } } let mut performer_state = PerformanceState{}; let mut performer = music_timer::create_performance_engine(3, 4, 155.0); performer.pulse(&mut performer_state);
pub fn get_beat_interval_duration(&self) -> Duration[src]
Gets the duration of time between beat intervals. Handy for sleeping threads.
Example
let mut performer = music_timer::create_performance_engine(3, 4, 155.0); // We can set the delay to be half the trigger target. This will give // us a reasonable cycle speed with enough buffer to keep an accurate time. // This of course is not needed if the application is managing thread sleeping. // The shorter the sleep duration of the thread, the more accurate the // time triggering will be. In most cases setting the sleep to 60fps is recommended for // < 180bpm @ 4/4. let sleep_duration = performer.get_beat_interval_duration() / 2; println!("SLEEP_DURATION: {:?}", sleep_duration); std::thread::sleep(sleep_duration);
Auto Trait Implementations
impl Send for MusicTimerEngine
impl Sync for MusicTimerEngine
impl Unpin for MusicTimerEngine
impl UnwindSafe for MusicTimerEngine
impl RefUnwindSafe for MusicTimerEngine
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,