Skip to content

Commit

Permalink
Dynamically set tags on Fader Elements
Browse files Browse the repository at this point in the history
Because the profile uses .swap on memory locations when switching two faders, the originally read element name may no longer be valid when writing.

This used to work for everything (except scribbles) until 1.1.2 when the writing behaviour was changed.
  • Loading branch information
FrostyCoolSlug committed Aug 23, 2024
1 parent e5abf43 commit 4c082ff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
12 changes: 4 additions & 8 deletions profile/src/components/fader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub enum ParseError {

#[derive(Debug)]
pub struct Fader {
element_name: String,

colour_map: ColourMap,
channel: FullChannelList,
}
Expand All @@ -57,7 +55,6 @@ impl Fader {
};

Self {
element_name: context.to_string(),
colour_map,
channel,
}
Expand Down Expand Up @@ -92,10 +89,9 @@ impl Fader {
Ok(())
}

pub fn write_fader<W: Write>(&self, writer: &mut Writer<W>) -> Result<()> {
let element_name = &self.element_name;

let mut elem = BytesStart::new(element_name.as_str());
pub fn write_fader<W: Write>(&self, writer: &mut Writer<W>, fader: Faders) -> Result<()> {
let element_name = fader.get_str("faderContext").unwrap();
let mut elem = BytesStart::new(element_name);

let mut attributes: HashMap<String, String> = HashMap::default();
attributes.insert(
Expand All @@ -104,7 +100,7 @@ impl Fader {
);

self.colour_map
.write_colours_with_prefix(element_name.clone(), &mut attributes);
.write_colours_with_prefix(element_name.into(), &mut attributes);

for (key, value) in &attributes {
elem.push_attribute((key.as_str(), value.as_str()));
Expand Down
16 changes: 6 additions & 10 deletions profile/src/components/mute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub enum ParseError {

#[derive(Debug)]
pub struct MuteButton {
element_name: String,

colour_map: ColourMap,
mute_function: MuteFunction,
previous_volume: u8,
Expand All @@ -55,7 +53,6 @@ impl MuteButton {
colour_map.set_colour_group("muteGroup".to_string());

Self {
element_name: context.to_string(),
colour_map,
mute_function: MuteFunction::All,
previous_volume: 0,
Expand Down Expand Up @@ -118,20 +115,19 @@ impl MuteButton {
Ok(())
}

pub fn write_button<W: Write>(&self, writer: &mut Writer<W>) -> Result<()> {
let name = &self.element_name;

let mut elem = BytesStart::new(name.as_str());
pub fn write_button<W: Write>(&self, writer: &mut Writer<W>, fader: Faders) -> Result<()> {
let element_name = fader.get_str("muteContext").unwrap();
let mut elem = BytesStart::new(element_name);

let mut attributes: HashMap<String, String> = HashMap::default();
let mute_value = if self.mute_function == MuteFunction::ToVoiceChat {
String::from("Mute to Chat Mic")
} else {
self.mute_function.get_str("Value").unwrap().to_string()
};
attributes.insert(format!("{name}Function"), mute_value);
attributes.insert(format!("{element_name}Function"), mute_value);
attributes.insert(
format!("{name}prevLevel"),
format!("{element_name}prevLevel"),
format!("{}", self.previous_volume),
);

Expand All @@ -143,7 +139,7 @@ impl MuteButton {
}

self.colour_map
.write_colours_with_prefix(name.clone(), &mut attributes);
.write_colours_with_prefix(element_name.into(), &mut attributes);

for (key, value) in &attributes {
elem.push_attribute((key.as_str(), value.as_str()));
Expand Down
30 changes: 12 additions & 18 deletions profile/src/components/scribble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub enum ParseError {

#[derive(Debug)]
pub struct Scribble {
element_name: String,
colour_map: ColourMap,

// File provided to the GoXLR to handle (no path, just the filename)
Expand Down Expand Up @@ -74,7 +73,6 @@ impl Scribble {
};

Self {
element_name: element_name.to_string(),
colour_map,
icon_file: None,
text_top_left: "".to_string(),
Expand Down Expand Up @@ -140,46 +138,42 @@ impl Scribble {
Ok(())
}

pub fn write_scribble<W: Write>(&self, writer: &mut Writer<W>) -> Result<()> {
let mut elem = BytesStart::new(self.element_name.as_str());
pub fn write_scribble<W: Write>(&self, writer: &mut Writer<W>, fader: Faders) -> Result<()> {
let element_name = fader.get_str("scribbleContext").unwrap();
let mut elem = BytesStart::new(element_name);

let mut attributes: HashMap<String, String> = HashMap::default();
attributes.insert(
format!("{}iconFile", self.element_name),
format!("{}iconFile", element_name),
if self.icon_file.is_none() {
"".to_string()
} else {
self.icon_file.clone().unwrap()
},
);
attributes.insert(
format!("{}string0", self.element_name),
format!("{}string0", element_name),
self.text_top_left.clone(),
);
attributes.insert(
format!("{}string1", self.element_name),
format!("{}string1", element_name),
self.text_bottom_middle.clone(),
);
attributes.insert(format!("{}alpha", element_name), format!("{}", self.alpha));
attributes.insert(
format!("{}alpha", self.element_name),
format!("{}", self.alpha),
);
attributes.insert(
format!("{}inverted", self.element_name),
format!("{}inverted", element_name),
if self.style == Normal { "0" } else { "1" }
.parse()
.unwrap(),
);
attributes.insert(
format!("{}textSize", self.element_name),
format!("{}textSize", element_name),
format!("{}", self.text_size),
);
attributes.insert(
format!("{}bitmap", self.element_name),
self.bitmap_file.clone(),
);
attributes.insert(format!("{}bitmap", element_name), self.bitmap_file.clone());

self.colour_map.write_colours(&mut attributes);
self.colour_map
.write_colours_with_prefix(element_name.into(), &mut attributes);

for (key, value) in &attributes {
elem.push_attribute((key.as_str(), value.as_str()));
Expand Down
15 changes: 9 additions & 6 deletions profile/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,16 +666,19 @@ impl ProfileSettings {

self.mute_chat.write_mute_chat(&mut writer)?;

for fader in self.faders.values() {
fader.write_fader(&mut writer)?;
// The following three iters need the FaderName to be defined and passed
// forward, the tag names need to be dynamically generated to prevent breakage
// when .swap() is used to move them around.
for (faders, fader) in &self.faders {
fader.write_fader(&mut writer, faders)?;
}

for button in self.mute_buttons.values() {
button.write_button(&mut writer)?;
for (fader, button) in &self.mute_buttons {
button.write_button(&mut writer, fader)?;
}

for scribble in self.scribbles.values() {
scribble.write_scribble(&mut writer)?;
for (fader, scribble) in &self.scribbles {
scribble.write_scribble(&mut writer, fader)?;
}

for effect in self.effects.values() {
Expand Down

0 comments on commit 4c082ff

Please sign in to comment.