diff options
author | Chris Xiong <chirs241097@gmail.com> | 2022-12-16 18:03:42 -0500 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2022-12-16 18:36:30 -0500 |
commit | 19560c3f39110fbff910091b5b25e69a044ed18e (patch) | |
tree | ba4b9cda58c2c9ef326401f3607e5cb1f0a6180f /src/convert.rs | |
parent | 7dfed69f5b181c6368ac55e50192b967c0bb4b80 (diff) | |
download | it2midi-19560c3f39110fbff910091b5b25e69a044ed18e.tar.xz |
Initial note volume handling.
Diffstat (limited to 'src/convert.rs')
-rw-r--r-- | src/convert.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/convert.rs b/src/convert.rs index 56ab4f7..d3e1a4b 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -39,6 +39,7 @@ struct ChannelMemory postnote: u8, inst: u8, postinst: u8, + initvol: u8, vol: u8, efxmem: [u8; 32], pitch: Rational @@ -53,6 +54,7 @@ impl Default for ChannelMemory postnote: 0xff, inst: 0xff, postinst: 0xff, + initvol: 0, vol: 0, efxmem: Default::default(), pitch: 0u32.into() @@ -60,12 +62,13 @@ impl Default for ChannelMemory } } -pub struct Converter<'a> +pub struct Converter<'a, 'b> where 'a: 'b { + it: &'a ITFile, miditick: Rational, chmem: Vec<Rc<RefCell<ChannelMemory>>>, trks: Vec<MidiTrack>, - fx_handlers: Vec<Box<RefCell<EfxHandlerFn<'a>>>> + fx_handlers: Vec<Box<RefCell<EfxHandlerFn<'b>>>> } impl<'a, 'b> Player<'a, 'b> @@ -201,12 +204,13 @@ impl<'a, 'b> Player<'a, 'b> } } -impl<'a> Converter<'a> +impl<'a, 'b> Converter<'a, 'b> { - pub fn new() -> Converter<'a> + pub fn new(it: &'a ITFile) -> Converter<'a, 'b> { let mut ret = Converter { + it, miditick: 0u32.into(), chmem: Vec::new(), trks: Vec::new(), @@ -220,15 +224,21 @@ impl<'a> Converter<'a> fn setup_fx_handlers<'x, 'y>(&mut self) { let nonfx = |ch: u8, cell, chmem: Rc<RefCell<ChannelMemory>>, ps: PlayerState, t: Rational| { - if !ch == 0 { return Vec::new(); } + if !ch == 0 || ps.in_rep { return Vec::new(); } let mut ret = Vec::new(); - let Cell { mask, note, mut inst, .. } = cell; + let Cell { mask, note, mut inst, mut vol, .. } = cell; if mask & 0x11 != 0 && ps.current_tick == 0 { if mask & 0x22 == 0 { inst = chmem.borrow().postinst; } + if mask & 0x44 == 0 && (0u8..0x78).contains(¬e) + { + 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 => @@ -237,16 +247,18 @@ impl<'a> Converter<'a> ret.push((TimedMidiEvent{t: t.as_int_trunc() as u32, e: MidiEvent::NoteOff{ch: 0, key: chmem.borrow().postnote, vel: 0x40}}, (ch, inst))); chmem.borrow_mut().postnote = 0xff; }, - 0 => (), _ => { if chmem.borrow().postnote != 0xff { 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))); } - ret.push((TimedMidiEvent{t: t.as_int_trunc() as u32, e: MidiEvent::NoteOn{ch: 0, key: note, vel: 0x40}}, (ch, inst))); + 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))); chmem.borrow_mut().postnote = note; chmem.borrow_mut().postinst = inst; + chmem.borrow_mut().initvol = vol; + chmem.borrow_mut().vol = vol; } } } @@ -278,8 +290,9 @@ impl<'a> Converter<'a> |(i, p)| { instch.insert(*p, i + 1); } ); instch } - pub fn convert(&mut self, it: &ITFile) + pub fn convert(&mut self) { + let it = self.it; let instch = Converter::pre_pass(it); println!("{:?}", instch); self.trks.resize_with(instch.len() + 1, Default::default); |