1use std::sync::atomic::{AtomicBool, Ordering};
2
3use gpui::App;
4use settings::{Settings, SettingsStore};
5
6#[derive(Clone, Debug)]
7pub struct AudioSettings {
8 /// Opt into the new audio system.
9 pub rodio_audio: bool, // default is false
10 /// Requires 'rodio_audio: true'
11 ///
12 /// Use the new audio systems automatic gain control for your microphone.
13 /// This affects how loud you sound to others.
14 pub control_input_volume: bool,
15 /// Requires 'rodio_audio: true'
16 ///
17 /// Use the new audio systems automatic gain control on everyone in the
18 /// call. This makes call members who are too quite louder and those who are
19 /// too loud quieter. This only affects how things sound for you.
20 pub control_output_volume: bool,
21}
22
23/// Configuration of audio in Zed
24impl Settings for AudioSettings {
25 fn from_settings(content: &settings::SettingsContent, _cx: &mut App) -> Self {
26 let audio = &content.audio.as_ref().unwrap();
27 AudioSettings {
28 control_input_volume: audio.control_input_volume.unwrap(),
29 control_output_volume: audio.control_output_volume.unwrap(),
30 rodio_audio: audio.rodio_audio.unwrap(),
31 }
32 }
33
34 fn import_from_vscode(
35 _vscode: &settings::VsCodeSettings,
36 _current: &mut settings::SettingsContent,
37 ) {
38 }
39}
40
41/// See docs on [LIVE_SETTINGS]
42pub(crate) struct LiveSettings {
43 pub(crate) control_input_volume: AtomicBool,
44 pub(crate) control_output_volume: AtomicBool,
45}
46
47impl LiveSettings {
48 pub(crate) fn initialize(&self, cx: &mut App) {
49 cx.observe_global::<SettingsStore>(move |cx| {
50 LIVE_SETTINGS.control_input_volume.store(
51 AudioSettings::get_global(cx).control_input_volume,
52 Ordering::Relaxed,
53 );
54 LIVE_SETTINGS.control_output_volume.store(
55 AudioSettings::get_global(cx).control_output_volume,
56 Ordering::Relaxed,
57 );
58 })
59 .detach();
60
61 let init_settings = AudioSettings::get_global(cx);
62 LIVE_SETTINGS
63 .control_input_volume
64 .store(init_settings.control_input_volume, Ordering::Relaxed);
65 LIVE_SETTINGS
66 .control_output_volume
67 .store(init_settings.control_output_volume, Ordering::Relaxed);
68 }
69}
70
71/// Allows access to settings from the audio thread. Updated by
72/// observer of SettingsStore. Needed because audio playback and recording are
73/// real time and must each run in a dedicated OS thread, therefore we can not
74/// use the background executor.
75pub(crate) static LIVE_SETTINGS: LiveSettings = LiveSettings {
76 control_input_volume: AtomicBool::new(true),
77 control_output_volume: AtomicBool::new(true),
78};