diff --git a/assets/settings/default.json b/assets/settings/default.json index 5dcb418184f592e941d23763f7fe39898413cb79..fc53e2c3e8cd07db8eb133c90809fd23f35be307 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -408,6 +408,21 @@ // Whether to show the menus in the titlebar. "show_menus": false }, + "audio": { + /// Opt into the new audio system. + "experimental.rodio_audio": false, + /// Requires 'rodio_audio: true' + /// + /// Use the new audio systems automatic gain control for your microphone. + /// This affects how loud you sound to others. + "experimental.control_input_volume": false, + /// Requires 'rodio_audio: true' + /// + /// Use the new audio systems automatic gain control on everyone in the + /// call. This makes call members who are too quite louder and those who are + /// too loud quieter. This only affects how things sound for you. + "experimental.control_output_volume": false + }, // Scrollbar related settings "scrollbar": { // When to show the scrollbar in the editor. diff --git a/crates/audio/src/audio_settings.rs b/crates/audio/src/audio_settings.rs index ea0ea5f3558e015f5579cca43eeb8c529273cb52..0c66cf08c4c0959c65df6b3554de8012137d897a 100644 --- a/crates/audio/src/audio_settings.rs +++ b/crates/audio/src/audio_settings.rs @@ -1,62 +1,53 @@ use std::sync::atomic::{AtomicBool, Ordering}; -use anyhow::Result; use gpui::App; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsKey, SettingsSources, SettingsStore, SettingsUi}; +use settings::{Settings, SettingsStore}; +use util::MergeFrom as _; -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi)] +#[derive(Clone, Default, Debug)] pub struct AudioSettings { /// Opt into the new audio system. - #[serde(rename = "experimental.rodio_audio", default)] pub rodio_audio: bool, // default is false /// Requires 'rodio_audio: true' /// /// Use the new audio systems automatic gain control for your microphone. /// This affects how loud you sound to others. - #[serde(rename = "experimental.control_input_volume", default)] pub control_input_volume: bool, /// Requires 'rodio_audio: true' /// /// Use the new audio systems automatic gain control on everyone in the /// call. This makes call members who are too quite louder and those who are /// too loud quieter. This only affects how things sound for you. - #[serde(rename = "experimental.control_output_volume", default)] - pub control_output_volume: bool, -} - -/// Configuration of audio in Zed. -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)] -#[serde(default)] -#[settings_key(key = "audio")] -pub struct AudioSettingsContent { - /// Opt into the new audio system. - #[serde(rename = "experimental.rodio_audio", default)] - pub rodio_audio: bool, // default is false - /// Requires 'rodio_audio: true' - /// - /// Use the new audio systems automatic gain control for your microphone. - /// This affects how loud you sound to others. - #[serde(rename = "experimental.control_input_volume", default)] - pub control_input_volume: bool, - /// Requires 'rodio_audio: true' - /// - /// Use the new audio systems automatic gain control on everyone in the - /// call. This makes call members who are too quite louder and those who are - /// too loud quieter. This only affects how things sound for you. - #[serde(rename = "experimental.control_output_volume", default)] pub control_output_volume: bool, } +/// Configuration of audio in Zed impl Settings for AudioSettings { - type FileContent = AudioSettingsContent; + fn from_default(content: &settings::SettingsContent, _cx: &mut App) -> Option { + let audio = &content.audio.as_ref()?; + Some(AudioSettings { + control_input_volume: audio.control_input_volume?, + control_output_volume: audio.control_output_volume?, + rodio_audio: audio.rodio_audio?, + }) + } - fn load(sources: SettingsSources, _cx: &mut App) -> Result { - sources.json_merge() + fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) { + let Some(audio) = content.audio.as_ref() else { + return; + }; + self.control_input_volume + .merge_from(&audio.control_input_volume); + self.control_output_volume + .merge_from(&audio.control_output_volume); + self.rodio_audio.merge_from(&audio.rodio_audio); } - fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} + fn import_from_vscode( + _vscode: &settings::VsCodeSettings, + _current: &mut settings::SettingsContent, + ) { + } } /// See docs on [LIVE_SETTINGS] diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index b5022c5c4172b3fa5bc52a92a044eccd9a242cae..e93cd2fb05ea2c6331bda90e363d90b5265674ef 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -36,6 +36,9 @@ pub struct SettingsContent { /// /// Default: false pub helix_mode: Option, + + /// Configuration of audio in Zed. + pub audio: Option, } impl SettingsContent { @@ -165,3 +168,24 @@ pub enum TitleBarVisibilityContent { Never, HideInFullScreen, } + +/// Configuration of audio in Zed. +#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)] +pub struct AudioSettingsContent { + /// Opt into the new audio system. + #[serde(rename = "experimental.rodio_audio", default)] + pub rodio_audio: Option, + /// Requires 'rodio_audio: true' + /// + /// Use the new audio systems automatic gain control for your microphone. + /// This affects how loud you sound to others. + #[serde(rename = "experimental.control_input_volume", default)] + pub control_input_volume: Option, + /// Requires 'rodio_audio: true' + /// + /// Use the new audio systems automatic gain control on everyone in the + /// call. This makes call members who are too quite louder and those who are + /// too loud quieter. This only affects how things sound for you. + #[serde(rename = "experimental.control_output_volume", default)] + pub control_output_volume: Option, +}