Skip to content

Commit 696a2b3

Browse files
committed
Bugfix
1 parent b6a10ea commit 696a2b3

File tree

8 files changed

+77
-59
lines changed

8 files changed

+77
-59
lines changed

SPDIFKA/App.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
</setting>
2525
<setting name="IsMinimizedOnClose" serializeAs="String">
2626
<value>False</value>
27-
</setting>
28-
<setting name="IsStartWithWindows" serializeAs="String">
29-
<value>False</value>
3027
</setting>
31-
<setting name="EnabledDeviceNames" serializeAs="Xml">
28+
<setting name="TargetedDeviceNames" serializeAs="Xml">
3229
<value>
3330
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3431
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3532
<string>Default playback device</string>
3633
</ArrayOfString>
3734
</value>
3835
</setting>
36+
<setting name="IsStartWithWindows" serializeAs="String">
37+
<value>False</value>
38+
</setting>
3939
</SPDIFKA.Properties.Settings>
4040
</userSettings>
4141
</configuration>

SPDIFKA/AudioControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void Start() {
111111

112112
private static List<ILoopAudioPlayer> PlaySoundAsync(UnmanagedMemoryStream sound) {
113113
var deviceIds = new HashSet<int>();
114-
foreach (var deviceName in SPDIFKAGUI.UserPrefs.EnabledDeviceNames) {
114+
foreach (var deviceName in SPDIFKAGUI.UserPrefs.TargetedDeviceNames) {
115115
if (deviceName == UserPreferences.DEFAULT_AUDIO_DEVICE) {
116116
deviceIds.Add(-1);
117117
}

SPDIFKA/Properties/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SPDIFKA/Properties/Settings.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Setting Name="IsMinimizedOnClose" Type="System.Boolean" Scope="User">
1818
<Value Profile="(Default)">False</Value>
1919
</Setting>
20-
<Setting Name="EnabledDeviceNames" Type="System.Collections.Specialized.StringCollection" Scope="User">
20+
<Setting Name="TargetedDeviceNames" Type="System.Collections.Specialized.StringCollection" Scope="User">
2121
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
2222
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
2323
&lt;string&gt;Default playback device&lt;/string&gt;

SPDIFKA/SPDIFGUI.Designer.cs

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SPDIFKA/SPDIFGUI.cs

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
namespace SPDIFKA {
99
public partial class SPDIFKAGUI : Form {
10-
private const string name = "SPDIF-KA";
11-
private const string stoppedMessage = "stopped";
12-
private const string startMessage = "running";
13-
private static string toolStripStartText = "Start " + name;
14-
private static string toolStripStopText = "Stop " + name;
10+
private const string AppName = "SPDIF-KA";
11+
private const string StoppedMessage = "stopped";
12+
private const string RunningMessage = "running";
13+
private static string ToolStripStartText = "Start " + AppName;
14+
private static string ToolStripStopText = "Stop " + AppName;
1515
private const string UNPLUGGED_SUFFIX = " (*Unplugged*)";
16-
private bool isAppVisible = true;
16+
private bool IsAppVisible = true;
17+
private bool IsAnyTargetedDevicesUnplugged;
1718

18-
private static readonly string version = System.Reflection.Assembly.GetExecutingAssembly()
19+
private static readonly string Version = System.Reflection.Assembly.GetExecutingAssembly()
1920
.GetName()
2021
.Version
2122
.ToString();
@@ -43,15 +44,15 @@ public SPDIFKAGUI() {
4344
this.MaximizeBox = false;
4445

4546
this.spdifka.BalloonTipIcon = ToolTipIcon.Info;
46-
this.spdifka.BalloonTipText = name + " - " + stoppedMessage;
47-
this.spdifka.BalloonTipTitle = name;
48-
this.spdifka.Text = name + " - " + stoppedMessage;
47+
this.spdifka.BalloonTipText = AppName + " - " + StoppedMessage;
48+
this.spdifka.BalloonTipTitle = AppName;
49+
this.spdifka.Text = AppName + " - " + StoppedMessage;
4950
this.spdifka.Icon = Properties.Resources.bar_chart_64_red;
5051

51-
this.toolStripStart.Text = toolStripStartText;
52+
this.toolStripStart.Text = ToolStripStartText;
5253
this.spdifka.ContextMenuStrip = this.RightClickMenuStrip;
5354
this.Resize += this.Form1_Resize;
54-
this.runningLabel.Text = stoppedMessage;
55+
this.runningLabel.Text = StoppedMessage;
5556
this.FormBorderStyle = FormBorderStyle.FixedSingle;
5657
this.LoadState();
5758
this.IsInitializing = false;
@@ -63,7 +64,7 @@ public SPDIFKAGUI() {
6364
/// </summary>
6465
/// <param name="isVisible"></param>
6566
protected override void SetVisibleCore(bool isVisible) {
66-
if (!this.isAppVisible) {
67+
if (!this.IsAppVisible) {
6768
isVisible = false;
6869
if (!this.IsHandleCreated) this.CreateHandle();
6970
}
@@ -98,6 +99,15 @@ private void OnPowerChange(object s, PowerModeChangedEventArgs e) {
9899
case PowerModes.Resume:
99100
this.ReloadDevices();
100101
this.RestartAudioControlIfRunning();
102+
if (this.IsAnyTargetedDevicesUnplugged) {
103+
var timer = new Timer { Interval = 5000 };
104+
timer.Tick += (s2, e2) => {
105+
this.ReloadDevices();
106+
this.RestartAudioControlIfRunning();
107+
timer.Dispose();
108+
};
109+
timer.Start();
110+
}
101111
break;
102112
case PowerModes.Suspend:
103113
break;
@@ -106,7 +116,7 @@ private void OnPowerChange(object s, PowerModeChangedEventArgs e) {
106116

107117
private bool IsRegisteredToUsbDeviceNotification = false;
108118
private void RegisterOrUnregisterUsbDeviceNotificationBasedOnEnabledDevices() {
109-
foreach (var deviceName in UserPrefs.EnabledDeviceNames) {
119+
foreach (var deviceName in UserPrefs.TargetedDeviceNames) {
110120
if (deviceName != UserPreferences.DEFAULT_AUDIO_DEVICE) {
111121
if (!this.IsRegisteredToUsbDeviceNotification) {
112122
this.IsRegisteredToUsbDeviceNotification = true;
@@ -138,22 +148,25 @@ protected override void WndProc(ref Message m) {
138148
}
139149

140150
private void ReloadDevices() {
141-
if (WaveOut.DeviceCount <= 0) return;
142151
this.comboBoxWaveOutDevice.Items.Clear();
143152
this.comboBoxWaveOutDevice.Items.Add(UserPreferences.DEFAULT_AUDIO_DEVICE);
153+
this.IsAnyTargetedDevicesUnplugged = false;
144154
for (var deviceId = -1; deviceId < WaveOut.DeviceCount; deviceId++) {
145155
var capabilities = WaveOut.GetCapabilities(deviceId);
146156
this.comboBoxWaveOutDevice.Items.Add(capabilities.ProductName);
147157
}
148-
foreach (var deviceName in UserPrefs.EnabledDeviceNames) {
149-
var found = false;
150-
for (int i = 0; i < this.comboBoxWaveOutDevice.Items.Count; i++) {
158+
foreach (var deviceName in UserPrefs.TargetedDeviceNames) {
159+
var plugged = false;
160+
for (var i = 0; i < this.comboBoxWaveOutDevice.Items.Count; i++) {
151161
if (this.comboBoxWaveOutDevice.Items[i].ToString().Replace(UNPLUGGED_SUFFIX, "") == deviceName) {
152162
this.comboBoxWaveOutDevice.SetItemChecked(i, true);
153-
found = true;
163+
plugged = true;
154164
}
155165
}
156-
if (!found) this.comboBoxWaveOutDevice.Items.Add(deviceName + UNPLUGGED_SUFFIX);
166+
if (!plugged) {
167+
this.comboBoxWaveOutDevice.Items.Add(deviceName + UNPLUGGED_SUFFIX);
168+
this.IsAnyTargetedDevicesUnplugged = true;
169+
}
157170
}
158171
}
159172

@@ -196,12 +209,12 @@ private void Minimize() {
196209

197210
private void minimized_to_notificaton_area() {
198211
if (UserPrefs.IsMinimizeToNotificationArea) {
199-
this.isAppVisible = false;
212+
this.IsAppVisible = false;
200213
this.ShowInTaskbar = false;
201214
this.Hide();
202215
}
203216
else {
204-
this.isAppVisible = true;
217+
this.IsAppVisible = true;
205218
this.WindowState = FormWindowState.Minimized;
206219
this.ShowInTaskbar = true;
207220
}
@@ -211,7 +224,7 @@ private void minimized_to_notificaton_area() {
211224
/// Restore the window to normal user operation mode.
212225
/// </summary>
213226
private void Restore() {
214-
this.isAppVisible = true;
227+
this.IsAppVisible = true;
215228
this.WindowState = FormWindowState.Normal;
216229
this.ShowInTaskbar = true;
217230
this.Show();
@@ -271,33 +284,33 @@ private void Exit_application() {
271284
/// <param name="sender"></param>
272285
/// <param name="e"></param>
273286
private void toolStripAbout_Click(object sender, EventArgs e) {
274-
MessageBox.Show("Copyright 2017 handruin.com - Version " + version, "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
287+
MessageBox.Show("Copyright 2017 handruin.com - Version " + Version, "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
275288
}
276289

277290
/// <summary>
278291
/// Generic method to handle the starting and stopping of the SPDIF keep alive audio clip playback.
279292
/// </summary>
280293
private void ToggleStartStop() {
281294
if (!AudioControl.Instance.Value.IsRunning) {
282-
this.spdifka.Text = name + " - " + startMessage;
283-
this.toolStripStart.Text = toolStripStopText;
284-
this.runningLabel.Text = startMessage;
285-
this.spdifka.BalloonTipText = name + " - " + startMessage;
295+
this.spdifka.Text = AppName + " - " + RunningMessage;
296+
this.toolStripStart.Text = ToolStripStopText;
297+
this.runningLabel.Text = RunningMessage;
298+
this.spdifka.BalloonTipText = AppName + " - " + RunningMessage;
286299
this.startStopButton.Text = "Stop";
287300
AudioControl.Instance.Value.Start();
288301
this.UpdateTrayIconWhenRunning(isRunning: true);
289302
}
290303
else {
291-
this.spdifka.Text = name + " - " + stoppedMessage;
304+
this.spdifka.Text = AppName + " - " + StoppedMessage;
292305
this.startStopButton.Text = "Start";
293-
this.toolStripStart.Text = toolStripStartText;
294-
this.runningLabel.Text = stoppedMessage;
295-
this.spdifka.BalloonTipText = name + " - " + stoppedMessage;
306+
this.toolStripStart.Text = ToolStripStartText;
307+
this.runningLabel.Text = StoppedMessage;
308+
this.spdifka.BalloonTipText = AppName + " - " + StoppedMessage;
296309
AudioControl.Instance.Value.Stop();
297310
this.UpdateTrayIconWhenRunning(isRunning: false);
298311
}
299-
}
300-
312+
}
313+
301314
/// <summary>
302315
/// Restart the audio control only if the audio was already running.
303316
/// </summary>
@@ -400,25 +413,30 @@ private void silent_sound_CheckedChanged(object sender, EventArgs e) {
400413

401414
private void comboBoxWaveOutDevice_SelectedIndexChanged(object sender, EventArgs e) {
402415
if (this.IsInitializing) return;
403-
if (UserPrefs.EnabledDeviceNames == null) {
404-
UserPrefs.EnabledDeviceNames = Properties.Settings.Default.EnabledDeviceNames;
416+
if (UserPrefs.TargetedDeviceNames == null) {
417+
UserPrefs.TargetedDeviceNames = Properties.Settings.Default.TargetedDeviceNames;
405418
UserPrefs.Save();
406419
}
407-
UserPrefs.EnabledDeviceNames.Clear();
420+
UserPrefs.TargetedDeviceNames.Clear();
408421
for (int i = 0; i < this.comboBoxWaveOutDevice.Items.Count; i++) {
409422
var deviceName = this.comboBoxWaveOutDevice.Items[i].ToString().Replace(UNPLUGGED_SUFFIX, "");
410423
if (this.comboBoxWaveOutDevice.GetItemChecked(i)) {
411-
if (!UserPrefs.EnabledDeviceNames.Contains(deviceName)) {
412-
UserPrefs.EnabledDeviceNames.Add(deviceName);
424+
if (!UserPrefs.TargetedDeviceNames.Contains(deviceName)) {
425+
UserPrefs.TargetedDeviceNames.Add(deviceName);
413426
}
414427
}
415428
else {
416-
UserPrefs.EnabledDeviceNames.Remove(deviceName);
429+
UserPrefs.TargetedDeviceNames.Remove(deviceName);
417430
}
418431
}
419432
UserPrefs.Save();
420433
this.RegisterOrUnregisterUsbDeviceNotificationBasedOnEnabledDevices();
421434
this.RestartAudioControlIfRunning();
422435
}
436+
437+
private void TabsMenu1_Click(object sender, EventArgs e) {
438+
this.ReloadDevices();
439+
this.RestartAudioControlIfRunning();
440+
}
423441
}
424442
}

SPDIFKA/SPDIFKA.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
<ItemGroup>
148148
<Content Include="ILMergeOrder.txt" />
149149
<Content Include="media\blank.wav" />
150-
<None Include="bar-chart-64-white.ico" />
151150
<None Include="media\inaudible.wav" />
152151
<Content Include="bar-chart-64-green.ico" />
153152
</ItemGroup>

SPDIFKA/UserPreferences.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum Sound { Silent, Inaudible }
1111
public bool IsMinimizeToNotificationArea { get; set; }
1212
public bool IsMinimizedOnClose { get; set; }
1313
public Sound SoundType { get; set; }
14-
public StringCollection EnabledDeviceNames { get; set; }
14+
public StringCollection TargetedDeviceNames { get; set; }
1515

1616
public UserPreferences() {
1717
this.Load();
@@ -24,7 +24,7 @@ public void Save() {
2424
Properties.Settings.Default.IsMinimizedNotification = this.IsMinimizeToNotificationArea;
2525
Properties.Settings.Default.IsMinimizedOnClose = this.IsMinimizedOnClose;
2626
Properties.Settings.Default.SoundType = this.SoundType.ToString();
27-
Properties.Settings.Default.EnabledDeviceNames = this.EnabledDeviceNames;
27+
Properties.Settings.Default.TargetedDeviceNames = this.TargetedDeviceNames;
2828
Properties.Settings.Default.Save();
2929
}
3030

@@ -41,7 +41,7 @@ public void Load() {
4141
if (Properties.Settings.Default.SoundType == "Inaudible") {
4242
this.SoundType = Sound.Inaudible;
4343
}
44-
this.EnabledDeviceNames = Properties.Settings.Default.EnabledDeviceNames ?? new StringCollection { DEFAULT_AUDIO_DEVICE };
44+
this.TargetedDeviceNames = Properties.Settings.Default.TargetedDeviceNames ?? new StringCollection { DEFAULT_AUDIO_DEVICE };
4545
}
4646
}
4747
}

0 commit comments

Comments
 (0)