Volume slides - ish

This commit is contained in:
Gwilym Inzani 2023-07-17 00:45:58 +01:00
parent 203b1a4026
commit 4d699e9000
3 changed files with 25 additions and 0 deletions

View file

@ -46,6 +46,7 @@ pub enum PatternEffect {
Arpeggio(Num<u16, 8>, Num<u16, 8>), Arpeggio(Num<u16, 8>, Num<u16, 8>),
Panning(Num<i16, 4>), Panning(Num<i16, 4>),
Volume(Num<i16, 4>), Volume(Num<i16, 4>),
VolumeSlide(Num<i16, 4>),
} }
#[cfg(feature = "quote")] #[cfg(feature = "quote")]
@ -185,6 +186,10 @@ impl quote::ToTokens for PatternEffect {
let volume = volume.to_raw(); let volume = volume.to_raw();
quote! { Volume(agb_tracker::__private::Num::from_raw(#volume))} quote! { Volume(agb_tracker::__private::Num::from_raw(#volume))}
} }
PatternEffect::VolumeSlide(amount) => {
let amount = amount.to_raw();
quote! { VolumeSlide(agb_tracker::__private::Num::from_raw(#amount))}
}
}; };
tokens.append_all(quote! { tokens.append_all(quote! {

View file

@ -40,6 +40,7 @@ pub struct Tracker {
struct TrackerChannel { struct TrackerChannel {
channel_id: Option<ChannelId>, channel_id: Option<ChannelId>,
base_speed: Num<u32, 8>, base_speed: Num<u32, 8>,
volume: Num<i16, 4>,
} }
impl Tracker { impl Tracker {
@ -48,6 +49,7 @@ impl Tracker {
channels.resize_with(track.num_channels, || TrackerChannel { channels.resize_with(track.num_channels, || TrackerChannel {
channel_id: None, channel_id: None,
base_speed: 0.into(), base_speed: 0.into(),
volume: 0.into(),
}); });
Self { Self {
@ -183,6 +185,14 @@ impl TrackerChannel {
} }
PatternEffect::Volume(volume) => { PatternEffect::Volume(volume) => {
channel.volume(*volume); channel.volume(*volume);
self.volume = *volume;
}
PatternEffect::VolumeSlide(amount) => {
self.volume += *amount;
if self.volume < 0.into() {
self.volume = 0.into();
}
channel.volume(self.volume);
} }
} }
} }

View file

@ -188,6 +188,16 @@ pub fn parse_module(module: &Module) -> TokenStream {
0x8 => { 0x8 => {
PatternEffect::Panning(Num::new(slot.effect_parameter as i16 - 128) / 128) PatternEffect::Panning(Num::new(slot.effect_parameter as i16 - 128) / 128)
} }
0xA => {
let first = slot.effect_parameter >> 4;
let second = slot.effect_parameter & 0xF;
if first == 0 {
PatternEffect::VolumeSlide(-Num::new(second as i16) / 16)
} else {
PatternEffect::VolumeSlide(Num::new(first as i16) / 16)
}
}
0xC => PatternEffect::Volume(Num::new(slot.effect_parameter as i16) / 255), 0xC => PatternEffect::Volume(Num::new(slot.effect_parameter as i16) / 255),
_ => PatternEffect::None, _ => PatternEffect::None,
}; };