diff options
author | Chris Xiong <chirs241097@gmail.com> | 2022-12-14 21:11:12 -0500 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2022-12-14 21:11:12 -0500 |
commit | dc9c8833ec7d4181251740354e8a4893ab277423 (patch) | |
tree | d40b28591f02717bd5d096d3357f5b56298f7ff3 /src/midifile.rs | |
parent | f8cf52fa4b2bbaff5627fa397a26589070084d3e (diff) | |
download | it2midi-dc9c8833ec7d4181251740354e8a4893ab277423.tar.xz |
Fix an ancient bug that dates back to the old C++ version.
Use old tracks naming scheme.
Diffstat (limited to 'src/midifile.rs')
-rw-r--r-- | src/midifile.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/midifile.rs b/src/midifile.rs index 219a931..aaa2dfd 100644 --- a/src/midifile.rs +++ b/src/midifile.rs @@ -134,6 +134,37 @@ fn write_track<W>(f: &mut W, trk: &MidiTrack) -> io::Result<()> where W: Write Ok(()) } +pub fn lint_track(trk: &MidiTrack) -> bool +{ + let mut ret = true; + let mut notest = [false; 128]; + for te in trk + { + let TimedMidiEvent{t, e} = te; + match e + { + MidiEvent::NoteOff{ch: _, key: n, vel: _} | MidiEvent::NoteOn{ch: _, key: n, vel: 0} => { + if !notest[*n as usize] { ret = false; println!("Invalid note off {} @ {}", n, t); } + notest[*n as usize] = false; + }, + MidiEvent::NoteOn{ch: _, key: n, vel: _} => { + if notest[*n as usize] { ret = false; println!("Unterminated note {} @ {}", n, t); } + notest[*n as usize] = true; + }, + MidiEvent::MetaTrackName(s) => { + println!("Linting track {}", s); + }, + _ => {} + } + } + if ! matches!(trk.last().unwrap_or(&TimedMidiEvent{t: 0, e: MidiEvent::NoteOn{ch: 0, key: 0, vel: 0}}).e , MidiEvent::MetaEndOfTrack) + { + println!("Missing end of track event"); + ret = false; + } + ret +} + pub fn write_file(filename: &str, mf: &MidiFile) -> io::Result<()> { let mut f = File::create(filename)?; |