aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/convert.rs3
-rw-r--r--src/midifile.rs18
2 files changed, 20 insertions, 1 deletions
diff --git a/src/convert.rs b/src/convert.rs
index 125e687..a96c802 100644
--- a/src/convert.rs
+++ b/src/convert.rs
@@ -3,7 +3,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use crate::itfile::{ITFile, Cell};
use crate::utils::Rational;
-use crate::midifile::{MidiEvent, TimedMidiEvent, MidiTrack, MidiFile, lint_track};
+use crate::midifile::{MidiEvent, TimedMidiEvent, MidiTrack, MidiFile, lint_track, lint_tempo};
use crate::portmod::Effect;
#[derive(Debug)]
@@ -410,6 +410,7 @@ impl<'a, 'b> Converter<'a, 'b>
t: t.last().unwrap_or(&TimedMidiEvent{t: 0, e: MidiEvent::MetaEndOfTrack}).t,
e: MidiEvent::MetaEndOfTrack}));
+ self.trks[0] = lint_tempo(&self.trks[0]);
self.trks.iter().for_each(|t| { lint_track(t); });
}
pub fn result(self) -> MidiFile
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;