pub fn create_performance_engine(
numerator: u8,
denominator: u8,
bpm: f32,
) -> MusicTimerEngine
Expand description
Creates a new music timer performance engine.
§Arguments
numerator
- The upper part of a time signature. Must be none 0.denominator
- The lower part of a time signature. Only 2, 4, 8, 16, 32 are supported.bpm
- The beats per minute.
§Example
let mut performer = music_timer::create_performance_engine(3, 4, 155.0);
Examples found in repository?
examples/event_performance.rs (line 55)
39fn main() {
40 use std::thread;
41
42 // Create the performer_state with bunch of events
43 let mut performer_state = PerformanceState {
44 is_playing: true,
45 performance_end: MusicTime::new(4, 3, 8),
46 events: vec![
47 MusicTime::new(1, 1, 1),
48 MusicTime::new(2, 2, 5),
49 MusicTime::new(4, 3, 8),
50 ],
51 event_head: 0,
52 };
53
54 // Run our main loop
55 let mut performer = music_timer::create_performance_engine(3, 4, 155.0);
56
57 // We can set the delay to be half the trigger target. This will give
58 // us a resonable cycle speed with enough buffer to keep an accurate time.
59 // This of course is not needed if the application is managing thread sleeping.
60 // The shorter the sleep duration of the thread, the more accurate the
61 // time triggering will be. In most cases setting the sleep to 60fps is recommended for
62 // < 180bpm @ 4/4.
63 let sleep_duration = performer.get_beat_interval_duration() / 2;
64 println!("SLEEP_DURATION: {:?}", sleep_duration);
65
66 while performer_state.is_playing {
67 // Pass in our performance state to trigger our on event callback functions
68 performer.pulse(&mut performer_state);
69 thread::sleep(sleep_duration);
70 }
71}