66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
import re
|
|
|
|
with open("src/app/mod.rs", "r") as f:
|
|
text = f.read()
|
|
|
|
# 1. Add to AppMessage
|
|
text = text.replace(
|
|
" OutputDeviceSelected(AudioDevice),\n EventOccurred(Event),",
|
|
" OutputDeviceSelected(AudioDevice),\n NoiseGateChanged(f32),\n EventOccurred(Event),"
|
|
)
|
|
|
|
# 2. Add to AppState (already has config, so we can just read from config.noise_gate_threshold, but state needs it too if we don't want to use state.config everywhere)
|
|
# Let's just use state.config.noise_gate_threshold
|
|
|
|
# 3. Add to update() match
|
|
update_old = """ AppMessage::OutputDeviceSelected(dev) => {
|
|
state.config.output_device = dev.name.clone();
|
|
state.config.save();
|
|
state.selected_output = Some(dev);
|
|
}"""
|
|
update_new = """ AppMessage::OutputDeviceSelected(dev) => {
|
|
state.config.output_device = dev.name.clone();
|
|
state.config.save();
|
|
state.selected_output = Some(dev);
|
|
}
|
|
AppMessage::NoiseGateChanged(val) => {
|
|
state.config.noise_gate_threshold = val;
|
|
state.config.save();
|
|
let _ = state.controller.send(CoreCommand::SetNoiseGateThreshold(val));
|
|
}"""
|
|
text = text.replace(update_old, update_new)
|
|
|
|
# 4. We also need to send the initial noise gate value to the controller on Join/Create,
|
|
# but wait! CoreController receives it async. Maybe we send it right after controller is created?
|
|
# Or just in AppState::default() we can't send because it's async? No, controller.send() is async? Actually it's non-blocking channel send.
|
|
# Let's just add it to Join message or send it when RoomJoined occurs.
|
|
# Wait, let's just send it when creating the controller? No, `state.controller.send()` returns Result, it's non-blocking.
|
|
default_old = """ let controller = Arc::new(CoreController::new(ui_tx));
|
|
let _ = UI_RX.set(Mutex::new(Some(ui_rx)));
|
|
|
|
let config = AppConfig::load();"""
|
|
default_new = """ let controller = Arc::new(CoreController::new(ui_tx));
|
|
let _ = UI_RX.set(Mutex::new(Some(ui_rx)));
|
|
|
|
let config = AppConfig::load();
|
|
let _ = controller.send(CoreCommand::SetNoiseGateThreshold(config.noise_gate_threshold));"""
|
|
text = text.replace(default_old, default_new)
|
|
|
|
# 5. Add slider to view_settings
|
|
settings_old = """ ].spacing(10),
|
|
vertical_space(30.0),
|
|
button("""
|
|
|
|
settings_new = """ ].spacing(10),
|
|
vertical_space(20.0),
|
|
column![
|
|
text(&format!("Mic Sensitivity (Noise Gate): {:.1}%", state.config.noise_gate_threshold * 100.0)).size(14).color(color_subtext),
|
|
slider(0.0..=0.1, state.config.noise_gate_threshold, AppMessage::NoiseGateChanged)
|
|
].spacing(10).width(iced::Length::Fixed(320.0)),
|
|
vertical_space(30.0),
|
|
button("""
|
|
text = text.replace(settings_old, settings_new)
|
|
|
|
with open("src/app/mod.rs", "w") as f:
|
|
f.write(text)
|