Skip to content

Commit

Permalink
Add Recording configuration. See #19
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aflalo committed Sep 2, 2015
1 parent 9b1e5a3 commit c92865c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
24 changes: 12 additions & 12 deletions SoundSwitch.Tests/AppModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void TestUnionSelectedDeviceWithActiveDevice()
public void TestCycleConsoleAudioDevice()
{
var configurationMoq = new Mock<ISoundSwitchConfiguration> { Name = "Configuration mock" };
configurationMoq.SetupGet(conf => conf.LastActiveDevice).Returns("");
configurationMoq.SetupGet(conf => conf.LastPlaybackActive).Returns("");

var audioMoqI = new Mock<IAudioDevice> { Name = "first audio dev" };
audioMoqI.SetupGet(a => a.FriendlyName).Returns("Speakers (Test device)");
Expand All @@ -185,8 +185,8 @@ public void TestCycleConsoleAudioDevice()
audioMoqI.VerifyGet(a => a.FriendlyName);
audioMoqII.VerifyGet(a => a.FriendlyName);
listerMoq.Verify(l => l.GetPlaybackDevices());
configurationMoq.VerifyGet(config => config.LastActiveDevice);
configurationMoq.VerifySet(config => config.LastActiveDevice = "Headphones (Test device)");
configurationMoq.VerifyGet(config => config.LastPlaybackActive);
configurationMoq.VerifySet(config => config.LastPlaybackActive = "Headphones (Test device)");
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
Assert.That(audioMoqII.Object.Equals(audioDevice));
}
Expand All @@ -195,7 +195,7 @@ public void TestCycleConsoleAudioDevice()
public void TestCycleCommunicationsAudioDevice()
{
var configurationMoq = new Mock<ISoundSwitchConfiguration> { Name = "Configuration mock" };
configurationMoq.SetupGet(conf => conf.LastActiveDevice).Returns("");
configurationMoq.SetupGet(conf => conf.LastPlaybackActive).Returns("");
configurationMoq.SetupGet(conf => conf.ChangeCommunications).Returns(true);

var audioMoqI = new Mock<IAudioDevice> { Name = "first audio dev" };
Expand Down Expand Up @@ -224,8 +224,8 @@ public void TestCycleCommunicationsAudioDevice()
audioMoqI.VerifyGet(a => a.FriendlyName);
audioMoqII.VerifyGet(a => a.FriendlyName);
listerMoq.Verify(l => l.GetPlaybackDevices());
configurationMoq.VerifyGet(config => config.LastActiveDevice);
configurationMoq.VerifySet(config => config.LastActiveDevice = "Headphones (Test device)");
configurationMoq.VerifyGet(config => config.LastPlaybackActive);
configurationMoq.VerifySet(config => config.LastPlaybackActive = "Headphones (Test device)");
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
audioMoqII.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Communications)));
Assert.That(audioMoqII.Object.Equals(audioDevice));
Expand All @@ -235,7 +235,7 @@ public void TestCycleCommunicationsAudioDevice()
public void TestCycleAudioDeviceIsACycleThatReturnToFirstWhenReachEnd()
{
var configurationMoq = new Mock<ISoundSwitchConfiguration> { Name = "Configuration mock" };
configurationMoq.SetupGet(conf => conf.LastActiveDevice).Returns("");
configurationMoq.SetupGet(conf => conf.LastPlaybackActive).Returns("");

var audioMoqI = new Mock<IAudioDevice> { Name = "first audio dev" };
audioMoqI.SetupGet(a => a.FriendlyName).Returns("Speakers (Test device)");
Expand All @@ -262,8 +262,8 @@ public void TestCycleAudioDeviceIsACycleThatReturnToFirstWhenReachEnd()
audioMoqI.VerifyGet(a => a.FriendlyName);
audioMoqII.VerifyGet(a => a.FriendlyName);
listerMoq.Verify(l => l.GetPlaybackDevices());
configurationMoq.VerifyGet(config => config.LastActiveDevice);
configurationMoq.VerifySet(config => config.LastActiveDevice = "Speakers (Test device)");
configurationMoq.VerifyGet(config => config.LastPlaybackActive);
configurationMoq.VerifySet(config => config.LastPlaybackActive = "Speakers (Test device)");
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
Assert.That(audioMoqI.Object.Equals(audioDevice));
}
Expand All @@ -272,7 +272,7 @@ public void TestCycleAudioDeviceIsACycleThatReturnToFirstWhenReachEnd()
public void TestSetActiveDeviceNull()
{
var configurationMoq = new Mock<ISoundSwitchConfiguration> {Name = "Configuration mock"};
configurationMoq.SetupGet(conf => conf.LastActiveDevice).Returns("");
configurationMoq.SetupGet(conf => conf.LastPlaybackActive).Returns("");


//Setup
Expand All @@ -295,7 +295,7 @@ public void TestSetActiveDeviceNull()
public void TestSetAudioDeviceSetAudioDeviceAsDefault()
{
var configurationMoq = new Mock<ISoundSwitchConfiguration> { Name = "Configuration mock" };
configurationMoq.SetupGet(conf => conf.LastActiveDevice).Returns("");
configurationMoq.SetupGet(conf => conf.LastPlaybackActive).Returns("");

var audioMoqI = new Mock<IAudioDevice> { Name = "first audio dev" };
audioMoqI.SetupGet(a => a.FriendlyName).Returns("Speakers (Test device)");
Expand All @@ -309,7 +309,7 @@ public void TestSetAudioDeviceSetAudioDeviceAsDefault()
AppModel.Instance.SetActiveDevice(audioMoqI.Object);

//Asserts
configurationMoq.VerifySet(config => config.LastActiveDevice = "Speakers (Test device)");
configurationMoq.VerifySet(config => config.LastPlaybackActive = "Speakers (Test device)");
audioMoqI.Verify(a => a.SetAsDefault(It.Is<Role>(role => role == Role.Console)));
Assert.That(audioMoqI.Object.Equals(audioDevice));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ namespace SoundSwitch.Framework.Configuration
public interface ISoundSwitchConfiguration : IConfiguration
{
HashSet<string> SelectedPlaybackDeviceList { get; set; }
string LastActiveDevice { get; set; }
HashSet<string> SelectedRecordingDeviceList { get; set; }
string LastPlaybackActive { get; set; }
string LastRecordingActive { get; set; }
bool FirstRun { get; set; }
HotKeys HotKeysCombinaison { get; set; }
bool ChangeCommunications { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ public SoundSwitchConfiguration()
FirstRun = true;
ChangeCommunications = false;
SelectedPlaybackDeviceList = new HashSet<string>();
SelectedRecordingDeviceList = new HashSet<string>();
HotKeysCombinaison = new HotKeys(Keys.F11, HotKeys.ModifierKeys.Alt | HotKeys.ModifierKeys.Control);
//12 hours
UpdateCheckInterval = 3600*12;
}

public HashSet<string> SelectedPlaybackDeviceList { get; set; }
public string LastActiveDevice { get; set; }
public HashSet<string> SelectedRecordingDeviceList { get; set; }
public string LastPlaybackActive { get; set; }
public string LastRecordingActive { get; set; }
public bool FirstRun { get; set; }
public HotKeys HotKeysCombinaison { get; set; }
public bool ChangeCommunications { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions SoundSwitch/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ICollection<IAudioDevice> AvailablePlaybackDevices
}
}

public HashSet<string> SelectedRecordingDevicesList { get; }
public HashSet<string> SelectedRecordingDevicesList => AppConfigs.Configuration.SelectedRecordingDeviceList;

public ICollection<IAudioDevice> AvailableRecordingDevices
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public bool SetActiveDevice(IAudioDevice device)
device.SetAsDefault(Role.Communications);
}
DefaultPlaybackDeviceChanged?.Invoke(this, new AudioChangeEvent(device));
AppConfigs.Configuration.LastActiveDevice = device.FriendlyName;
AppConfigs.Configuration.LastPlaybackActive = device.FriendlyName;
AppConfigs.Configuration.Save();
return true;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public bool CycleActiveDevice()
}
AppLogger.Log.Info("Cycle Audio Devices", list);
var defaultDev =
list.FirstOrDefault(device => device.FriendlyName == AppConfigs.Configuration.LastActiveDevice) ??
list.FirstOrDefault(device => device.FriendlyName == AppConfigs.Configuration.LastPlaybackActive) ??
list.FirstOrDefault(device => device.IsDefault(Role.Console)) ??
list.ElementAt(0);

Expand Down

0 comments on commit c92865c

Please sign in to comment.