use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize, Copy, Clone, Debug)]
pub struct SidVoice {
pub freq: u16,
pub pw: u16,
pub ctrl_noise: bool, pub ctrl_pulse: bool, pub ctrl_sawtooth: bool, pub ctrl_triangle: bool, pub ctrl_test: bool, pub ctrl_rm: bool, pub ctrl_sync: bool, pub ctrl_gate: bool, pub ad: u8,
pub sr: u8,
}
impl SidVoice {
pub fn update_from_ctrl_register(&mut self, ctrl: u8) {
if ctrl & 0b1000_0000 != 0 {
self.ctrl_noise = true;
}
if ctrl & 0b0100_0000 != 0 {
self.ctrl_pulse = true;
}
if ctrl & 0b0010_0000 != 0 {
self.ctrl_sawtooth = true;
}
if ctrl & 0b0001_0000 != 0 {
self.ctrl_triangle = true;
}
if ctrl & 0b0000_1000 != 0 {
self.ctrl_test = true;
}
if ctrl & 0b0000_0100 != 0 {
self.ctrl_rm = true;
}
if ctrl & 0b0000_0010 != 0 {
self.ctrl_sync = true;
}
if ctrl & 0b0000_0001 != 0 {
self.ctrl_gate = true;
}
}
pub fn generate_ctrl_register(&self) -> u8 {
let mut ctrl = 0;
if self.ctrl_noise {
ctrl |= 0b1000_0000;
}
if self.ctrl_pulse {
ctrl |= 0b0100_0000;
}
if self.ctrl_sawtooth {
ctrl |= 0b0010_0000;
}
if self.ctrl_triangle {
ctrl |= 0b0001_0000;
}
if self.ctrl_test {
ctrl |= 0b0000_1000;
}
if self.ctrl_rm {
ctrl |= 0b0000_0100;
}
if self.ctrl_sync {
ctrl |= 0b0000_0010;
}
if self.ctrl_gate {
ctrl |= 0b0000_0001;
}
ctrl
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InstrSid {
pub voice: [SidVoice; 3],
pub fc: u16, pub filter_resonance: u8, pub filter_gate: [bool; 4], pub low_pass: bool,
pub band_pass: bool,
pub high_pass: bool,
pub mute_voice3: bool,
pub main_volume: u8, }
impl Default for InstrSid {
fn default() -> Self {
Self {
voice: [SidVoice::default(); 3],
fc: 0,
filter_resonance: 0,
filter_gate: [false; 4],
low_pass: false,
band_pass: false,
high_pass: false,
mute_voice3: false,
main_volume: 15,
}
}
}