aboutsummaryrefslogtreecommitdiff
path: root/src/midifile.rs
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 23:56:03 -0500
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 23:56:03 -0500
commit6e5dc4eaee1ffb9474390dbd62a6dae4b90d8f5f (patch)
tree0d615f2287a4c5ffd10ba9f4a4bdf06950cd07f5 /src/midifile.rs
parent21d891b4a62b54651a92d5f1a6a79d98b9b30110 (diff)
downloadit2midi-6e5dc4eaee1ffb9474390dbd62a6dae4b90d8f5f.tar.xz
Remove duplicate midi tempo events.HEADdev
Diffstat (limited to 'src/midifile.rs')
-rw-r--r--src/midifile.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/midifile.rs b/src/midifile.rs
index 00e20f5..8210f70 100644
--- a/src/midifile.rs
+++ b/src/midifile.rs
@@ -137,6 +137,24 @@ fn write_track<W>(f: &mut W, trk: &MidiTrack) -> io::Result<()> where W: Write
Ok(())
}
+pub fn lint_tempo(trk: &MidiTrack) -> MidiTrack
+{
+ trk.iter().fold((f64::NAN, Vec::new()), |(last, mut t), e| {
+ match e.e
+ {
+ MidiEvent::MetaTempo(x) => {
+ if x != last
+ {
+ t.push(e.clone());
+ (x, t)
+ }
+ else { (last , t) }
+ },
+ _ => { t.push(e.clone()); (last, t) }
+ }
+ }).1
+}
+
pub fn lint_track(trk: &MidiTrack) -> bool
{
let mut ret = true;