Skip to content

Commit

Permalink
Use a new Sound for notification. See #49
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aflalo committed Dec 29, 2015
1 parent 530eb35 commit 4629316
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 17 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ http://creativecommons.org/licenses/by-nc-sa/4.0/

### Disabling notification
[@adamblackburn](https://github.com/adamblackburn) with merge request [#33](https://github.com/Belphemur/SoundSwitch/pull/33)

### Notification Sound
[Music box notification sound by Robinhood76](https://www.freesound.org/people/Robinhood76/sounds/216676/)
1 change: 1 addition & 0 deletions SoundSwitch/Framework/Audio/AudioPlaybackEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void NotifyDefaultChanged(IAudioDevice audioDevice)
{
if (audioDevice.Type != AudioDeviceType.Playback)
return;

new AudioPlaybackEngine().PlaySoundWav(_sound);
}
}
Expand Down
24 changes: 20 additions & 4 deletions SoundSwitch/Framework/NotificationManager/NotificationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using AudioEndPointControllerWrapper;
using System;
using AudioEndPointControllerWrapper;
using SoundSwitch.Framework.NotificationManager.Notification;
using SoundSwitch.Model;

namespace SoundSwitch.Framework.NotificationManager
Expand All @@ -7,27 +9,41 @@ public class NotificationManager
{
private readonly IAppModel _model;
private string _lastDeviceId;
private INotification _notification;

public NotificationManager(IAppModel model)
{
_model = model;
}

public void Init()
{
_model.DefaultDeviceChanged += ModelOnDefaultDeviceChanged;
_model.NotificationSettingsChanged += ModelOnNotificationSettingsChanged;
_notification = NotificationFactory.CreateNotification(_model.NotificationSettings, _model.NotifyIcon,
_model.NotificationSound);
}

private void ModelOnNotificationSettingsChanged(object sender, NotificationSettingsUpdatedEvent notificationSettingsUpdatedEvent)
{
_notification = NotificationFactory.CreateNotification(notificationSettingsUpdatedEvent.NewSettings, _model.NotifyIcon,
_model.NotificationSound);
}

private void ModelOnDefaultDeviceChanged(object sender, DeviceDefaultChangedEvent deviceDefaultChangedEvent)
{
if (_lastDeviceId == deviceDefaultChangedEvent.device.Id)
return;

var notification = NotificationFactory.CreateNotification(_model.NotificationSettings, _model.NotifyIcon,
_model.NotificationSound);
notification.NotifyDefaultChanged(deviceDefaultChangedEvent.device);

_notification.NotifyDefaultChanged(deviceDefaultChangedEvent.device);
_lastDeviceId = deviceDefaultChangedEvent.device.Id;
}

~NotificationManager()
{
_model.DefaultDeviceChanged -= ModelOnDefaultDeviceChanged;
_model.NotificationSettingsChanged -= ModelOnNotificationSettingsChanged;
}
}
}
8 changes: 7 additions & 1 deletion SoundSwitch/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public NotificationTypeEnum NotificationSettings
{
AppConfigs.Configuration.NotificationSettings = value;
AppConfigs.Configuration.Save();
NotificationSettingsChanged?.Invoke(this,
new NotificationSettingsUpdatedEvent(NotificationSettings, value));
}
}
public HashSet<string> SelectedPlaybackDevicesList => AppConfigs.Configuration.SelectedPlaybackDeviceListId;
Expand Down Expand Up @@ -122,9 +124,12 @@ public bool RunAtStartup
}

public IAudioDeviceLister ActiveAudioDeviceLister { get; set; }
public event EventHandler<NotificationSettingsUpdatedEvent> NotificationSettingsChanged;

#endregion



/// <summary>
/// Initialize the Main class with Updater and Hotkeys
/// </summary>
Expand All @@ -140,10 +145,11 @@ public void InitializeMain()
}
SetHotkeyCombination(AppConfigs.Configuration.PlaybackHotKeys, AudioDeviceType.Playback);
SetHotkeyCombination(AppConfigs.Configuration.RecordingHotKeys, AudioDeviceType.Recording);
NotificationSound = new CachedWavSound(Properties.Resources.dingdong);
NotificationSound = new CachedWavSound(Properties.Resources.NotificationSound);
/*TODO: Remove in next VERSION (3.6.6)*/
MigrateSelectedDeviceLists();
InitUpdateChecker();
_notificationManager.Init();
_initialized = true;
}

Expand Down
13 changes: 13 additions & 0 deletions SoundSwitch/Model/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
using AudioEndPointControllerWrapper;
using SoundSwitch.Framework.NotificationManager;

namespace SoundSwitch.Model
{
Expand All @@ -40,4 +41,16 @@ public DeviceListChanged(IEnumerable<string> seletedDevicesList, AudioDeviceType
public IEnumerable<string> SeletedDevicesList { get; private set; }
public AudioDeviceType Type { get; private set; }
}

public class NotificationSettingsUpdatedEvent : EventArgs
{
public NotificationTypeEnum PrevSettings { get;}
public NotificationTypeEnum NewSettings { get; }

public NotificationSettingsUpdatedEvent(NotificationTypeEnum prevSettings, NotificationTypeEnum newSettings)
{
PrevSettings = prevSettings;
NewSettings = newSettings;
}
}
}
5 changes: 5 additions & 0 deletions SoundSwitch/Model/IAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public interface IAppModel
/// If a device is added in the system
/// </summary>
event EventHandler<DeviceAddedEvent> DeviceAdded;

/// <summary>
/// If the NotificationSettings has been modified
/// </summary>
event EventHandler<NotificationSettingsUpdatedEvent> NotificationSettingsChanged;
#endregion

#region Methods
Expand Down
18 changes: 9 additions & 9 deletions SoundSwitch/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions SoundSwitch/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<data name="defaultSpeakers" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\defaultSpeakers.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="dingdong" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\33244__ljudman__dingding.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="NotificationSound" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\216676__robinhood76__04864-notification-music-box.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file not shown.
Binary file removed SoundSwitch/Resources/33244__ljudman__dingding.wav
Binary file not shown.
1 change: 1 addition & 0 deletions SoundSwitch/SoundSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
<None Include="Resources\arrow-switch-16.png" />
<None Include="Resources\arrow-switch-48.png" />
<None Include="Resources\33244__ljudman__dingding.wav" />
<None Include="Resources\216676__robinhood76__04864-notification-music-box.wav" />
<Content Include="Resources\arrow_switch.ico" />
<None Include="Resources\cog.png" />
<None Include="Resources\exit.png" />
Expand Down

0 comments on commit 4629316

Please sign in to comment.