aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/midifile.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/midifile.rs b/src/midifile.rs
index aaa2dfd..00e20f5 100644
--- a/src/midifile.rs
+++ b/src/midifile.rs
@@ -105,14 +105,16 @@ fn write_varlen<W>(f: &mut W, v: u32) -> io::Result<()> where W: Write
f.write_all(&buf[..])
}
-fn write_raw_event<W>(f: &mut W, re: &RawMidiEvent) -> io::Result<()> where W: Write
+fn write_raw_event<W>(f: &mut W, re: &RawMidiEvent, runst: u8) -> io::Result<u8> where W: Write
{
let mut buf: Vec<u8> = Vec::new();
- buf.push(re.ty);
+ if re.ty != runst || runst >= 0xf0 || re.ty >= 0xf0
+ { buf.push(re.ty); }
buf.push(re.p1);
if re.p2 < 0x80 { buf.push(re.p2); }
for d in &re.data { buf.push(*d); }
- f.write_all(&buf[..])
+ f.write_all(&buf[..])?;
+ Ok(re.ty)
}
fn write_track<W>(f: &mut W, trk: &MidiTrack) -> io::Result<()> where W: Write
@@ -121,13 +123,14 @@ fn write_track<W>(f: &mut W, trk: &MidiTrack) -> io::Result<()> where W: Write
f.write_all(header)?;
let mut buf: Vec<u8> = Vec::new();
let mut curt = 0u32;
+ let mut runst = 0u8;
for te in trk
{
let TimedMidiEvent{t, e} = te;
write_varlen(&mut buf, t - curt)?;
curt = *t;
let re = RawMidiEvent::from(e);
- write_raw_event(&mut buf, &re)?;
+ runst = write_raw_event(&mut buf, &re, runst)?;
}
write_u32be(f, buf.len() as u32)?;
f.write_all(&buf[..])?;