Skip to content

Commit

Permalink
Midi track debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jeudine committed Sep 27, 2024
1 parent 4505d07 commit 36a5a4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Binary file modified examples/res/track_0.mid
Binary file not shown.
9 changes: 6 additions & 3 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,27 @@ impl DeteTrack {
let mut notes_map: HashMap<u8, (u8, u32, u32)> = HashMap::new();
let mut notes: Vec<(MidiNote, u32, u32)> = vec![];
let mut step = 0;

// 24 comes from the TimeSignature (number of clocks per beat)
let step_size = u16::from(if let midly::Timing::Metrical(s) = smf.header.timing {
s
} else {
return Err(TrackError::BadTiming);
}) as u32
/ 6;
/ 24;

debug!("{:?}", smf.header.timing);
let track = smf.tracks.first().ok_or(TrackError::BadFormat)?;

for event in track {
debug!("step: {}, event: {:?}", step, event);
let nb_clocks = u32::from(event.delta) / step_size;

// Increase duration of all the current notes
notes_map
.values_mut()
.for_each(|(_vel, _start, dur)| *dur += u32::from(event.delta));
step += u32::from(event.delta) / step_size;
.for_each(|(_vel, _start, dur)| *dur += nb_clocks);
step += nb_clocks;

match event.kind {
midly::TrackEventKind::Midi {
Expand Down

0 comments on commit 36a5a4f

Please sign in to comment.