aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 13:31:58 -0500
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-12-21 13:31:58 -0500
commit09b01cef6389b1354073c2846303d027e4a73043 (patch)
treea1d27133e77865eb344780c6b5900542b3c74c63
parent4b6230c31890a9c7c2a45590863577f8f83629c2 (diff)
downloadit2midi-09b01cef6389b1354073c2846303d027e4a73043.tar.xz
Use stuff in portmod for vol column. Sort tracks by instruments first.
-rw-r--r--src/convert.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/convert.rs b/src/convert.rs
index d3e1a4b..a8aeb1a 100644
--- a/src/convert.rs
+++ b/src/convert.rs
@@ -226,19 +226,23 @@ impl<'a, 'b> Converter<'a, 'b>
let nonfx = |ch: u8, cell, chmem: Rc<RefCell<ChannelMemory>>, ps: PlayerState, t: Rational| {
if !ch == 0 || ps.in_rep { return Vec::new(); }
let mut ret = Vec::new();
- let Cell { mask, note, mut inst, mut vol, .. } = cell;
+ let Cell { mask, note, mut inst, vol, .. } = cell;
+ let vole = Effect::from_it_vol(vol);
+ let mut vel = 0xffu8;
+ if mask & 0x44 != 0
+ {
+ match vole
+ {
+ Effect::SetVolume(vol) => vel = vol,
+ _ => ()
+ }
+ }
if mask & 0x11 != 0 && ps.current_tick == 0
{
if mask & 0x22 == 0
{
inst = chmem.borrow().postinst;
}
- if mask & 0x44 == 0 && (0u8..0x78).contains(&note)
- {
- let samp = if self.it.inst_mode() { self.it.insts[(inst - 1) as usize].samp_for_key(note) } else { inst };
- if samp != 0
- { vol = self.it.samps[(samp - 1) as usize].default_vol(); }
- }
match note
{
0x78..=0xff =>
@@ -253,8 +257,13 @@ impl<'a, 'b> Converter<'a, 'b>
{
ret.push((TimedMidiEvent{t: t.as_int_trunc() as u32, e: MidiEvent::NoteOff{ch: 0, key: chmem.borrow().postnote, vel: 0x40}}, (ch, chmem.borrow().postinst)));
}
- if vol == 0 { vol = 1; } //TODO: investigate
- ret.push((TimedMidiEvent{t: t.as_int_trunc() as u32, e: MidiEvent::NoteOn{ch: 0, key: note, vel: vol}}, (ch, inst)));
+ if vel == 0xff
+ {
+ let samp = if self.it.inst_mode() { self.it.insts[(inst - 1) as usize].samp_for_key(note) } else { inst };
+ if samp != 0
+ { vel = self.it.samps[(samp - 1) as usize].default_vol(); }
+ }
+ ret.push((TimedMidiEvent{t: t.as_int_trunc() as u32, e: MidiEvent::NoteOn{ch: 0, key: note, vel}}, (ch, inst)));
chmem.borrow_mut().postnote = note;
chmem.borrow_mut().postinst = inst;
chmem.borrow_mut().initvol = vol;
@@ -279,7 +288,7 @@ impl<'a, 'b> Converter<'a, 'b>
else
{ inst = chinst[ch as usize]; }
if mask & 0x11 != 0
- { instchmap.insert((ch, inst)); }
+ { instchmap.insert((inst, ch)); }
ps
};
let p = Player::new(Box::new(RefCell::new(h)), it);
@@ -301,7 +310,7 @@ impl<'a, 'b> Converter<'a, 'b>
let inittpo = it.header.tempo as f64;
let rpb = it.time_signature().unwrap_or((4, 4)).0 as f64;
self.trks[0].push(TimedMidiEvent{ t: 0, e: MidiEvent::MetaTempo(inittpo * 24. / rpb / initspd)});
- for ((ch, inst), trkn) in instch.iter()
+ for ((inst, ch), trkn) in instch.iter()
{
let tn = format!("{} (instr #{}) @ ch{}", it.insts[(inst - 1) as usize].inst_name() , *inst, *ch);
self.trks[*trkn].push(TimedMidiEvent{ t:0, e: MidiEvent::MetaTrackName(tn) });
@@ -322,7 +331,7 @@ impl<'a, 'b> Converter<'a, 'b>
let ev = (h.borrow_mut())(ch, cell, self.chmem[ch as usize].clone(), ps.clone(), self.miditick);
ev.iter().for_each(
|(e, (ch, inst))| {
- let target_track = instch.get(&(*ch, *inst)).unwrap_or(&0);
+ let target_track = instch.get(&(*inst, *ch)).unwrap_or(&0);
self.trks[*target_track].push(e.clone());
}
);