-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAudioSessionElement.cs
More file actions
81 lines (68 loc) · 2.26 KB
/
AudioSessionElement.cs
File metadata and controls
81 lines (68 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using CSCore.CoreAudioAPI;
using System;
namespace WindowsAudioVolumeManager {
public class AudioSessionElement : ObservablePropertyObject {
public float ScalarVolume;
private readonly MainWindow MainWindow;
private readonly AudioSessionControl SessionControl;
private SavedAudioSession SavedSession;
public string Name { get; set; }
public int Volume {
get => (int)Math.Round(ScalarVolume * MainWindow.MasterSlider.Value);
set {
float newScalar = (float)(value / MainWindow.MasterSlider.Value);
bool isDefault = Name.Equals(MainWindow.DEFAULT_APP_NAME);
if (newScalar <= 1) {
ScalarVolume = newScalar;
NotifyVolumeUpdate();
if (SessionControl != null) {
using SimpleAudioVolume volume = SessionControl.QueryInterface<SimpleAudioVolume>();
volume.MasterVolume = ScalarVolume;
}
if (!isDefault) {
if (SavedSession != null) {
SavedSession.ScalarVolume = ScalarVolume;
} else {
MainWindow.Invoke(() => MainWindow.SavedSessions.Add(SavedSession = new SavedAudioSession(Name, ScalarVolume)));
OnPropertyChanged("Saved");
}
}
if (MainWindow.Parser != null) {
MainWindow.Parser.Dirty = true;
if (MainWindow.Parser.SavedConfigObject != null && isDefault) {
MainWindow.Parser.SavedConfigObject.DefaultVolumeScalar = ScalarVolume;
}
}
}
}
}
public string VolumeText => Volume + " (" + (int)(ScalarVolume * 100f) + "%)";
public bool Saved {
get => SavedSession != null;
set {
if (!value) { // checkbox unchecked
MainWindow.Invoke(() => {
if (MainWindow.SavedSessions.Contains(SavedSession)) {
MainWindow.SavedSessions.Remove(SavedSession);
}
if (MainWindow.Parser != null) {
MainWindow.Parser.Dirty = true;
}
});
SavedSession = null;
OnPropertyChanged("Saved");
}
}
}
public AudioSessionElement(string name, float scalarVolume, MainWindow mainWindow, AudioSessionControl sessionControl = null, SavedAudioSession savedSession = null) {
Name = name;
ScalarVolume = scalarVolume;
MainWindow = mainWindow;
SessionControl = sessionControl;
SavedSession = savedSession;
}
public void NotifyVolumeUpdate() {
OnPropertyChanged("Volume", "VolumeText");
}
}
}