Skip to content

Commit b2e9b2d

Browse files
committed
fixes #38, trigger midi tick with fixed timestamp, not using thread yet, better than before, so leave it for now
1 parent e6c16e2 commit b2e9b2d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

crates/notation_midi/src/midi_plugin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ use crate::prelude::{
22
JumpToBarEvent, MidiHub, MidiSettings, MidiState, PlayControlEvent, SwitchTabEvent,
33
};
44
use bevy::prelude::*;
5+
use bevy::core::FixedTimestep;
56
use notation_model::prelude::{PlayClock};
67

78
pub struct MidiPlugin;
89

10+
const DO_TICK_TIMESTEP: f64 = 1.0 / 60.0;
11+
912
impl Plugin for MidiPlugin {
1013
fn build(&self, app: &mut AppBuilder) {
1114
app.add_event::<SwitchTabEvent>();
@@ -18,8 +21,11 @@ impl Plugin for MidiPlugin {
1821
app.add_system(on_switch_tab.system());
1922
app.add_system(on_jump_to_bar.system());
2023
app.add_system(on_play_control_evt.system());
21-
app.add_system(do_tick.system());
22-
24+
app.add_system_set(
25+
SystemSet::new()
26+
.with_run_criteria(FixedTimestep::step(DO_TICK_TIMESTEP))
27+
.with_system(do_tick.system())
28+
);
2329
#[cfg(not(target_arch = "wasm32"))]
2430
self.build_native(app);
2531
}
@@ -112,6 +118,7 @@ fn do_tick(
112118
mut play_control_evts: EventWriter<PlayControlEvent>,
113119
) {
114120
clock.tick();
121+
println!("do_tick() -> {}", clock.delta_seconds());
115122
_do_tick(
116123
&settings,
117124
&mut state,

crates/notation_midi/src/native/audio_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};
22

33
use bevy_kira_audio::{AudioStream, Frame};
44

5-
pub const AUDIO_BUFFER_SIZE: usize = 2048 * 2;
5+
pub const AUDIO_BUFFER_SIZE: usize = 4096 * 2;
66

77
pub type AudioBuffer = [f32; AUDIO_BUFFER_SIZE];
88

0 commit comments

Comments
 (0)