use std::error::Error;
use verovio::lookup::sounding_at_into;
use verovio::Toolkit;
const SAMPLE_PAE: &str = "\
@start:s
@clef:G-2
@keysig:xF
@key:
@timesig:
@data:'4G/4-
@end:s
";
const PLAYBACK_TICK_MS: f64 = 100.0;
fn main() -> Result<(), Box<dyn Error>> {
let mut tk = Toolkit::from_data(SAMPLE_PAE)?;
let timemap = tk.timemap()?;
let end_ms = timemap.last().map(|e| e.tstamp).unwrap_or(0.0);
println!(
"verovio {}: playing back {:.0} ms in {:.0} ms ticks…",
tk.version(),
end_ms,
PLAYBACK_TICK_MS
);
let mut active = Vec::with_capacity(16);
let mut t = 0.0;
while t <= end_ms {
sounding_at_into(&timemap, t, &mut active);
if active.is_empty() {
println!(" [{t:>5.0} ms] (silence)");
} else {
println!(" [{t:>5.0} ms] sounding={active:?}");
}
t += PLAYBACK_TICK_MS;
}
Ok(())
}