diff options
author | Chris Xiong <chirs241097@gmail.com> | 2022-12-21 23:42:11 -0500 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2022-12-21 23:42:11 -0500 |
commit | 21d891b4a62b54651a92d5f1a6a79d98b9b30110 (patch) | |
tree | 25b1d2bfd2b4c482914e4ef612b59be60d6b3f01 | |
parent | a1823d3f9568aac9eeafc91e444744906440ded8 (diff) | |
download | it2midi-21d891b4a62b54651a92d5f1a6a79d98b9b30110.tar.xz |
Turn auto swing into force speed.
-rw-r--r-- | src/convert.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/convert.rs b/src/convert.rs index c864400..125e687 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -18,7 +18,7 @@ struct PlayerState speed: u8, tempo: u8, rpb: u8, - swing_speed: Option<Rational>, + force_speed: Option<Rational>, loop_start: u8, loop_ctr: u8, row_extension: u8, @@ -93,7 +93,7 @@ impl<'a, 'b> Player<'a, 'b> Effect::PattLoopStart => PlayerState{loop_start: ps.current_row, ..ps}, Effect::SetTempo(t) => PlayerState{tempo: t, ..ps}, Effect::RowExtention(t) => PlayerState{row_extension: ps.row_extension + t, ..ps}, - Effect::SetVibWaveform(0xe) => { //proprietary command: enter swing mode + Effect::SetVibWaveform(0xe) => { //it2midi-specific command: enter swing mode let mut ticks = 0; let mut ts = ps.speed; for r in ps.current_row..ps.current_row + ps.rpb @@ -115,9 +115,15 @@ impl<'a, 'b> Player<'a, 'b> ticks += ts; } let swing_speed = Some(Rational::from(ticks) / Rational::from(ps.rpb)); - PlayerState{swing_speed, ..ps} + PlayerState{force_speed: swing_speed, ..ps} }, - Effect::SetVibWaveform(0xf) => PlayerState{swing_speed: None, ..ps}, //proprietary command: exit swing mode + Effect::SetTremWaveform(0x4) => { //it2midi-specific command: force current speed + PlayerState{force_speed: Some(Rational::from(ps.speed)), ..ps} + }, + Effect::SetTremWaveform(x @ 0x5..=0xf) => { //it2midi-specific command: force speed + PlayerState{force_speed: Some(Rational::from(x - 0x3)), ..ps} + }, + Effect::SetVibWaveform(0xf) => PlayerState{force_speed: None, ..ps}, //it2midi-specific command: exit swing mode _ => ps } } @@ -204,7 +210,7 @@ impl<'a, 'b> Player<'a, 'b> speed: self.it.header.speed, tempo: self.it.header.tempo, rpb: self.it.time_signature().unwrap_or((4, 16)).0 as u8, - swing_speed: None, + force_speed: None, loop_start: 0, loop_ctr: !0, row_extension: 0, @@ -311,9 +317,10 @@ impl<'a, 'b> Converter<'a, 'b> { Effect::SetSpeed(_) | Effect::SetTempo(_) | Effect::TempoSlideDown(_) | Effect::TempoSlideUp(_) | - Effect::SetVibWaveform(0xe) | Effect::SetVibWaveform(0xf) => + Effect::SetVibWaveform(0xe) | Effect::SetVibWaveform(0xf) | + Effect::SetTremWaveform(0x4..=0xf) => { - match ps.swing_speed + match ps.force_speed { None => ret.push((TimedMidiEvent{ t: t.as_int_trunc() as u32, e: MidiEvent::MetaTempo(ps.tempo as f64 * 24. / ps.rpb as f64 / ps.speed as f64)}, (!0, !0))), Some(ss) => ret.push((TimedMidiEvent{ t: t.as_int_trunc() as u32, e: MidiEvent::MetaTempo((Rational::from(ps.tempo as u16 * 24) / Rational::from(ps.rpb) / ss).into())}, (!0, !0))) @@ -375,7 +382,7 @@ impl<'a, 'b> Converter<'a, 'b> let Cell{mask, note, inst, vol: _, efx: _, fxp: _} = cell; if !ch == 0 { - match ps.swing_speed + match ps.force_speed { None => self.miditick += Rational::from(960u32) / (ps.rpb as u16).into(), Some(ss) => self.miditick += Rational::from(960u32) / (ps.rpb as u16).into() * (Rational::from(ps.speed) / ss) |