Skip to content

Commit

Permalink
Explicitly label things which aren't used by RD300NX
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlang42 committed Feb 15, 2023
1 parent 3714a28 commit ee025a3
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/roland/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct LogicalLayer {
pub external: ExternalLayer,
pub tone: ToneLayer,
pub piano: PianoLayer,
pub e_piano: EPianoLayer,
pub tone_wheel: ToneWheelLayer
pub unused_e_piano: EPianoLayer,
pub unused_tone_wheel: ToneWheelLayer
}

impl LogicalLayer {
Expand All @@ -39,8 +39,8 @@ impl LogicalLayer {
external: ext.remove(0),
tone: tone.remove(0),
piano: pno.remove(0),
e_piano: ep.remove(0),
tone_wheel: tw.remove(0),
unused_e_piano: ep.remove(0),
unused_tone_wheel: tw.remove(0),
});
}
Box::new(layers.try_into().unwrap())
Expand Down
18 changes: 9 additions & 9 deletions src/roland/live_set/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Common {
s2_assign: ButtonFunction, // 0-17
s1_state: bool,
s2_state: bool,
eq_settings: Bits<68>,
unused_eq_settings: Bits<68>,
key_touch_velocity: KeyTouchVelocity,
key_touch_curve_type: KeyTouchCurveType,
key_touch_curve_offset: OffsetU8<10>, // 0-19 (-10 - +9)
Expand All @@ -39,8 +39,8 @@ pub struct Common {
split_switch_internal: bool,
split_switch_external: bool,
#[serde(with = "serialize_map_keys_in_order")]
harmonic_bar_assign: HashMap<Layer, StateMap<HarmonicBar>>, // index=(LOWER2:ON, LOWER2:OFF, LOWER1:ON, LOWER1:OFF, UPPER2:ON, UPPER2:OFF, UPPER1:ON, UPPER1:OFF)
mfx_control_destination: Layer,
unused_harmonic_bar_assign: HashMap<Layer, StateMap<HarmonicBar>>, // index=(LOWER2:ON, LOWER2:OFF, LOWER1:ON, LOWER1:OFF, UPPER2:ON, UPPER2:OFF, UPPER1:ON, UPPER1:OFF)
unused_mfx_control_destination: Layer,
#[serde(skip_serializing_if="Bits::is_zero", default="Bits::zero")]
unused: Bits<7>
}
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Bytes<56> for Common {
bits.set_u8::<5>(self.s2_assign.into(), 0, 17)?;
bits.set_bool(self.s1_state);
bits.set_bool(self.s2_state);
bits.set_bits(&self.eq_settings);
bits.set_bits(&self.unused_eq_settings);
bits.set_u8::<7>(self.key_touch_velocity.into(), 0, 127)?;
bits.set_u8::<3>(self.key_touch_curve_type.into(), 1, 5)?;
bits.set_u8::<5>(self.key_touch_curve_offset.into(), 0, 19)?;
Expand All @@ -82,11 +82,11 @@ impl Bytes<56> for Common {
bits.set_bool(self.split_switch_internal);
bits.set_bool(self.split_switch_external);
for layer in Layer::iter().rev() {
let state_map = self.harmonic_bar_assign.get(&layer).unwrap();
let state_map = self.unused_harmonic_bar_assign.get(&layer).unwrap();
bits.set_u8::<4>(state_map.on.into(), 1, 9)?;
bits.set_u8::<4>(state_map.off.into(), 1, 9)?;
}
bits.set_u8::<2>(self.mfx_control_destination.into(), 0, 3)?;
bits.set_u8::<2>(self.unused_mfx_control_destination.into(), 0, 3)?;
bits.set_bits(&self.unused);
Ok(())
})
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Bytes<56> for Common {
s2_assign,
s1_state,
s2_state,
eq_settings,
unused_eq_settings: eq_settings,
key_touch_velocity,
key_touch_curve_type,
key_touch_curve_offset,
Expand All @@ -160,8 +160,8 @@ impl Bytes<56> for Common {
slider_assign,
split_switch_internal,
split_switch_external,
harmonic_bar_assign,
mfx_control_destination: data.get_u8::<2>(0, 3)?.into(),
unused_harmonic_bar_assign: harmonic_bar_assign,
unused_mfx_control_destination: data.get_u8::<2>(0, 3)?.into(),
unused: data.get_bits()
})
})
Expand Down
66 changes: 48 additions & 18 deletions src/roland/live_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ mod song_rhythm;
mod mfx;
mod resonance;

//TODO (LAST) modify live set to separate real and unused layers/parameters in 300nx vs 700nx

#[derive(Serialize, Deserialize, Debug)]
pub struct LiveSet {
common: Common, // 56 bytes
song_rhythm: SongRhythm, // 6 bytes
chorus: Chorus, // 42 bytes
reverb: Reverb, // 42 bytes
mfx: Box<[Mfx; 8]>, // 608 bytes
resonance: Resonance, // 76 bytes
layers: Box<[LogicalLayer; 4]>, // 332*4=1328 bytes
mfx: Mfx, // 76 bytes
unused_mfx: Box<[Mfx; 7]>, // 532 bytes
unused_resonance: Resonance, // 76 bytes
layers: Box<[LogicalLayer; 3]>, // 332*3=996 bytes
unused_layer: LogicalLayer, // 332 bytes
#[serde(skip_serializing_if="Bits::is_unit", default="Bits::unit")]
padding: Bits<8>, // 1 byte
// checksum: 1 byte
Expand All @@ -47,15 +47,30 @@ impl Bytes<2160> for LiveSet {
let song_rhythm = SongRhythm::from_bytes(data.get_bytes())?;
let chorus = Chorus::from_bytes(data.get_bytes())?;
let reverb = Reverb::from_bytes(data.get_bytes())?;
let mfx = Mfx::array_from_bytes(data)?;
let resonance = Resonance::from_bytes(data.get_bytes())?;
let mfx = Mfx::from_bytes(data.get_bytes())?;
let unused_mfx = Mfx::array_from_bytes(data)?;
let unused_resonance = Resonance::from_bytes(data.get_bytes())?;
let internal_layers = InternalLayer::array_from_bytes(data)?;
let unused_internal_layer = InternalLayer::from_bytes(data.get_bytes())?;
let external_layers = ExternalLayer::array_from_bytes(data)?;
let unused_external_layer = ExternalLayer::from_bytes(data.get_bytes())?;
let tone_layers = ToneLayer::array_from_bytes(data)?;
let unused_tone_layer = ToneLayer::from_bytes(data.get_bytes())?;
let piano_layers = PianoLayer::array_from_bytes(data)?;
let unused_piano_layer = PianoLayer::from_bytes(data.get_bytes())?;
let e_piano_layers = EPianoLayer::array_from_bytes(data)?;
let unused_e_piano_layer = EPianoLayer::from_bytes(data.get_bytes())?;
let tone_wheel_layers = ToneWheelLayer::array_from_bytes(data)?;
let unused_tone_wheel_layer = ToneWheelLayer::from_bytes(data.get_bytes())?;
let layers = LogicalLayer::from_layers(internal_layers, external_layers, tone_layers, piano_layers, e_piano_layers, tone_wheel_layers);
let unused_layer = LogicalLayer {
internal: unused_internal_layer,
external: unused_external_layer,
tone: unused_tone_layer,
piano: unused_piano_layer,
unused_e_piano: unused_e_piano_layer,
unused_tone_wheel: unused_tone_wheel_layer,
};
let padding = data.get_bits();
let expected_sum_to_zero = sum_to_zero(data.sum_previous_bytes());
let found_sum_to_zero = data.get_full_u8();
Expand All @@ -71,8 +86,10 @@ impl Bytes<2160> for LiveSet {
chorus,
reverb,
mfx,
resonance,
unused_mfx,
unused_resonance,
layers,
unused_layer,
padding
})
})
Expand All @@ -84,28 +101,35 @@ impl Bytes<2160> for LiveSet {
bs.set_bytes(self.song_rhythm.to_bytes()?);
bs.set_bytes(self.chorus.to_bytes()?);
bs.set_bytes(self.reverb.to_bytes()?);
for mfx in self.mfx.iter() {
bs.set_bytes(self.mfx.to_bytes()?);
for mfx in self.unused_mfx.iter() {
bs.set_bytes(mfx.to_bytes()?);
}
bs.set_bytes(self.resonance.to_bytes()?);
bs.set_bytes(self.unused_resonance.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.internal.to_bytes()?);
}
bs.set_bytes(self.unused_layer.internal.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.external.to_bytes()?);
}
bs.set_bytes(self.unused_layer.external.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.tone.to_bytes()?);
}
bs.set_bytes(self.unused_layer.tone.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.piano.to_bytes()?);
}
bs.set_bytes(self.unused_layer.piano.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.e_piano.to_bytes()?);
bs.set_bytes(layer.unused_e_piano.to_bytes()?);
}
bs.set_bytes(self.unused_layer.unused_e_piano.to_bytes()?);
for layer in self.layers.iter() {
bs.set_bytes(layer.tone_wheel.to_bytes()?);
bs.set_bytes(layer.unused_tone_wheel.to_bytes()?);
}
bs.set_bytes(self.unused_layer.unused_tone_wheel.to_bytes()?);
bs.set_bits(&self.padding);
let sum_to_zero = sum_to_zero(bs.sum_previous_bytes());
bs.set_full_u8(sum_to_zero);
Expand All @@ -124,9 +148,11 @@ impl Json for LiveSet {
("song_rhythm".to_string(), self.song_rhythm.to_structured_json()),
("chorus".to_string(), self.chorus.to_structured_json()),
("reverb".to_string(), self.reverb.to_structured_json()),
("mfx".to_string(), StructuredJson::from_collection(self.mfx.as_slice(), |_| None)),
("resonance".to_string(), self.resonance.to_structured_json()),
("layers".to_string(), StructuredJson::from_collection(self.layers.as_slice(), |l| Some(l.tone.tone_name())))
("mfx".to_string(), self.mfx.to_structured_json()),
("unused_mfx".to_string(), StructuredJson::from_collection(self.unused_mfx.as_slice(), |_| None)),
("unused_resonance".to_string(), self.unused_resonance.to_structured_json()),
("layers".to_string(), StructuredJson::from_collection(self.layers.as_slice(), |l| Some(l.tone.tone_name()))),
("unused_layer".to_string(), self.unused_layer.to_structured_json())
])
}

Expand All @@ -135,18 +161,22 @@ impl Json for LiveSet {
let song_rhythm = structured_json.extract("song_rhythm")?.to()?;
let chorus = structured_json.extract("chorus")?.to()?;
let reverb = structured_json.extract("reverb")?.to()?;
let mfx = structured_json.extract("mfx")?.to_array()?;
let resonance = structured_json.extract("resonance")?.to()?;
let mfx = structured_json.extract("mfx")?.to()?;
let unused_mfx = structured_json.extract("unused_mfx")?.to_array()?;
let unused_resonance = structured_json.extract("unused_resonance")?.to()?;
let layers = structured_json.extract("layers")?.to_array()?;
let unused_layer = structured_json.extract("unused_layer")?.to()?;
structured_json.done()?;
Ok(Self {
common,
song_rhythm,
chorus,
reverb,
mfx,
resonance,
unused_mfx,
unused_resonance,
layers,
unused_layer,
padding: Bits::unit()
})
}
Expand Down
50 changes: 36 additions & 14 deletions src/roland/system/favorites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use crate::roland::types::numeric::{OneIndexedU16, OneIndexedU8};

#[derive(Serialize, Deserialize, Debug)]
pub struct Favorites {
one_touch_piano_current_number: [OneIndexedU8; 3],
one_touch_e_piano_current_number: [OneIndexedU8; 3],
one_touch_piano_current_number: OneIndexedU8,
unused_one_touch_piano_current_number: [OneIndexedU8; 2],
one_touch_e_piano_current_number: OneIndexedU8,
unused_one_touch_e_piano_current_number: [OneIndexedU8; 2],
bank_a: Bank,
bank_b: Bank,
bank_c: Bank,
Expand All @@ -31,10 +33,12 @@ impl Favorites {
impl Bytes<76> for Favorites {
fn to_bytes(&self) -> Result<Box<[u8; Self::BYTE_SIZE]>, BytesError> {
BitStream::write_fixed(|bits| {
for value in self.one_touch_piano_current_number {
bits.set_u8::<7>(self.one_touch_piano_current_number.into(), 0, 127)?;
for value in self.unused_one_touch_piano_current_number {
bits.set_u8::<7>(value.into(), 0, 127)?;
}
for value in self.one_touch_e_piano_current_number {
bits.set_u8::<7>(self.one_touch_e_piano_current_number.into(), 0, 127)?;
for value in self.unused_one_touch_e_piano_current_number {
bits.set_u8::<7>(value.into(), 0, 127)?;
}
for bank in self.all_banks() {
Expand All @@ -46,21 +50,25 @@ impl Bytes<76> for Favorites {

fn from_bytes(bytes: Box<[u8; Self::BYTE_SIZE]>) -> Result<Self, BytesError> where Self: Sized {
BitStream::read_fixed(bytes, |bs| {
let mut one_touch_piano_current_number = [OneIndexedU8::default(); 3];
for i in 0..one_touch_piano_current_number.len() {
one_touch_piano_current_number[i] = bs.get_u8::<7>(0, 127)?.into();
let one_touch_piano_current_number = bs.get_u8::<7>(0, 127)?.into();
let mut unused_one_touch_piano_current_number = [OneIndexedU8::default(); 2];
for i in 0..unused_one_touch_piano_current_number.len() {
unused_one_touch_piano_current_number[i] = bs.get_u8::<7>(0, 127)?.into();
}
let mut one_touch_e_piano_current_number = [OneIndexedU8::default(); 3];
for i in 0..one_touch_e_piano_current_number.len() {
one_touch_e_piano_current_number[i] = bs.get_u8::<7>(0, 127)?.into();
let one_touch_e_piano_current_number = bs.get_u8::<7>(0, 127)?.into();
let mut unused_one_touch_e_piano_current_number = [OneIndexedU8::default(); 2];
for i in 0..unused_one_touch_e_piano_current_number.len() {
unused_one_touch_e_piano_current_number[i] = bs.get_u8::<7>(0, 127)?.into();
}
let bank_a = Bank::from_bits(bs.get_bits())?;
let bank_b = Bank::from_bits(bs.get_bits())?;
let bank_c = Bank::from_bits(bs.get_bits())?;
let bank_d = Bank::from_bits(bs.get_bits())?;
Ok(Self {
one_touch_piano_current_number,
unused_one_touch_piano_current_number,
one_touch_e_piano_current_number,
unused_one_touch_e_piano_current_number,
bank_a,
bank_b,
bank_c,
Expand Down Expand Up @@ -90,28 +98,42 @@ impl Json for Favorites {
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Bank([Favorite; Self::FAVORITES_PER_BANK]);
pub struct Bank {
favorites: [Favorite; Self::USED_FAVORITES],
unused_favorites: [Favorite; Self::FAVORITES_PER_BANK - Self::USED_FAVORITES]
}

impl Bank {
const USED_FAVORITES: usize = 6;
const FAVORITES_PER_BANK: usize = 10;
const BITS_SIZE: usize = Favorite::BITS_SIZE * Self::FAVORITES_PER_BANK;

fn to_bits(&self) -> Result<Bits<{Self::BITS_SIZE}>, BytesError> {
BitStream::write_fixed_bits(|bits| {
for favorite in &self.0 {
for favorite in &self.favorites {
bits.set_bits(&favorite.to_bits()?);
}
for unused_favorite in &self.unused_favorites {
bits.set_bits(&unused_favorite.to_bits()?);
}
Ok(())
})
}

fn from_bits(bits: Bits<{Self::BITS_SIZE}>) -> Result<Self, BytesError> where Self: Sized {
BitStream::read_fixed_bits(bits, |data| {
let mut favorites = Vec::new();
for _ in 0..Self::FAVORITES_PER_BANK {
for _ in 0..Self::USED_FAVORITES {
favorites.push(Favorite::from_bits(data.get_bits())?);
}
Ok(Self(favorites.try_into().unwrap()))
let mut unused_favorites = Vec::new();
for _ in 0..Self::FAVORITES_PER_BANK - Self::USED_FAVORITES {
unused_favorites.push(Favorite::from_bits(data.get_bits())?);
}
Ok(Self {
favorites: favorites.try_into().unwrap(),
unused_favorites: unused_favorites.try_into().unwrap()
})
})
}
}
Expand Down
Loading

0 comments on commit ee025a3

Please sign in to comment.