launcher/pages/audio/
types.rs1use midas_audio::types::Channels;
2#[cfg(target_os = "windows")]
3use rodio::{MixerDeviceSink, Player};
4use supreme_config::models::SoundConfig;
5
6use crate::tasks::TaskHandle;
7
8#[cfg(target_os = "windows")]
12pub type StreamSink = MixerDeviceSink;
13#[cfg(not(target_os = "windows"))]
14pub type StreamSink = ();
15
16#[cfg(target_os = "windows")]
18pub type PlayerHandle = Player;
19#[cfg(not(target_os = "windows"))]
20pub type PlayerHandle = ();
21
22pub struct MusicPageState {
23 pub target_channels: Channels,
24 pub target_sample_rate: TargetSampleRate,
25 pub target_bit_depth: TargetBitDepth,
26 pub _stream: Option<StreamSink>,
28 pub current_sink: Option<PlayerHandle>,
29 pub current_playing_file: Option<String>,
30 pub metadata_cache: std::collections::HashMap<String, midas_audio::types::AudioMetadata>,
32 pub status_cache: std::collections::HashMap<String, supreme_music::MusicFileStatus>,
33 pub is_scanned: bool,
34
35 pub task_handle: Option<TaskHandle<supreme_music::MusicConfig>>,
37 pub import_status: String,
38}
39
40impl Default for MusicPageState {
41 fn default() -> Self {
42 Self {
43 target_channels: Channels::Stereo,
44 target_sample_rate: TargetSampleRate::Hz44100,
45 target_bit_depth: TargetBitDepth::Adpcm,
46 _stream: None,
47 current_sink: None,
48 current_playing_file: None,
49 metadata_cache: std::collections::HashMap::new(),
50 status_cache: std::collections::HashMap::new(),
51 is_scanned: false,
52 task_handle: None,
53 import_status: String::new(),
54 }
55 }
56}
57
58#[derive(Debug, Clone, Copy, PartialEq)]
59pub enum TargetBitDepth {
60 Adpcm,
61 EightBit,
62 SixteenBit,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq)]
66pub enum TargetSampleRate {
67 Original,
68 Hz11025,
69 Hz22050,
70 Hz44100,
71}
72
73impl TargetSampleRate {
74 #[must_use]
75 pub fn to_u32(self, original: Option<u32>) -> u32 {
76 match self {
77 TargetSampleRate::Original => original.unwrap_or(22050),
78 TargetSampleRate::Hz11025 => 11025,
79 TargetSampleRate::Hz22050 => 22050,
80 TargetSampleRate::Hz44100 => 44100,
81 }
82 }
83}
84
85#[derive(PartialEq, Clone, Copy, Debug)]
86pub enum SoundMode {
87 Disabled = 0,
88 WithoutMusic = 1,
89 Full = 2,
90}
91
92impl SoundMode {
93 #[must_use]
94 pub fn from_config(config: &SoundConfig) -> Self {
95 if config.enable_sound_system == 0 {
96 SoundMode::Disabled
97 } else if config.enable_music == 0 {
98 SoundMode::WithoutMusic
99 } else {
100 SoundMode::Full
101 }
102 }
103
104 pub fn apply_to_config(self, config: &mut SoundConfig) {
105 match self {
106 SoundMode::Disabled => {
107 config.enable_sound_system = 0;
108 }
109 SoundMode::WithoutMusic => {
110 config.enable_sound_system = 1;
111 config.enable_music = 0;
112 }
113 SoundMode::Full => {
114 config.enable_sound_system = 1;
115 config.enable_music = 1;
116 }
117 }
118 }
119}