Skip to content

Commit

Permalink
feat(Profile::RecordingCommunication): Add possibility to set communi…
Browse files Browse the repository at this point in the history
…cation device for recording device in Profile.cs

Fixes #793
  • Loading branch information
Belphemur committed Jan 7, 2023
1 parent 7881f16 commit 2ef778b
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 43 deletions.
7 changes: 6 additions & 1 deletion SoundSwitch/Framework/Profile/Profile.cs
Expand Up @@ -31,6 +31,8 @@ internal DeviceRoleWrapper(DeviceInfo deviceInfo, ERole role)
public DeviceInfo? Playback { get; set; }
public DeviceInfo? Communication { get; set; }
public DeviceInfo? Recording { get; set; }

public DeviceInfo? RecordingCommunication { get; set; }

public string Name { get; set; } = "";
public IList<Trigger.Trigger> Triggers { get; set; } = new List<Trigger.Trigger>();
Expand Down Expand Up @@ -75,6 +77,7 @@ public Profile Copy()
Name = Name,
Playback = Playback,
Recording = Recording,
RecordingCommunication = RecordingCommunication,
RestoreDevices = RestoreDevices,
Triggers = Triggers.Select(trigger => new Trigger.Trigger(trigger.Type)
{
Expand All @@ -96,7 +99,9 @@ internal IEnumerable<DeviceRoleWrapper> Devices
if (Communication != null)
yield return new DeviceRoleWrapper(Communication, ERole.eCommunications);
if (Recording != null)
yield return new DeviceRoleWrapper(Recording, ERole.ERole_enum_count);
yield return new DeviceRoleWrapper(Recording, RecordingCommunication == null ? ERole.ERole_enum_count : ERole.eConsole | ERole.eMultimedia);
if (RecordingCommunication != null)
yield return new DeviceRoleWrapper(RecordingCommunication, ERole.eCommunications);
}
}

Expand Down
2 changes: 2 additions & 0 deletions SoundSwitch/Framework/Profile/ProfileManager.cs
Expand Up @@ -265,6 +265,7 @@ private bool SaveCurrentState(User32.NativeMethods.HWND windowHandle, Profile pr
var communication = _audioSwitcher.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eCommunications);
var playback = _audioSwitcher.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
var recording = _audioSwitcher.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia);
var recordingCommunication = _audioSwitcher.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eCommunications);

var currentState = new Profile
{
Expand All @@ -273,6 +274,7 @@ private bool SaveCurrentState(User32.NativeMethods.HWND windowHandle, Profile pr
Communication = communication,
Playback = playback,
Recording = recording,
RecordingCommunication = recordingCommunication,
NotifyOnActivation = profile.NotifyOnActivation
};
_activeWindowsTrigger.Add(windowHandle, currentState);
Expand Down
11 changes: 10 additions & 1 deletion SoundSwitch/UI/Forms/Settings.cs
Expand Up @@ -225,7 +225,8 @@ ListViewItem ProfileToListViewItem(Profile profile)
DeviceFullInfo recording = null;
DeviceFullInfo playback = null;
DeviceFullInfo communication = null;

DeviceFullInfo recordingCommunication = null;

var applicationTrigger = profile.Triggers.FirstOrDefault(trig => trig.Type == TriggerFactory.Enum.Process);
var hotkeyTrigger = profile.Triggers.FirstOrDefault(trig => trig.Type == TriggerFactory.Enum.HotKey);

Expand Down Expand Up @@ -258,6 +259,12 @@ ListViewItem ProfileToListViewItem(Profile profile)
communication = _audioDeviceLister.PlaybackDevices.FirstOrDefault(info =>
info.Equals(profile.Communication));
}

if (profile.RecordingCommunication != null)
{
recordingCommunication = _audioDeviceLister.RecordingDevices.FirstOrDefault(info =>
info.Equals(profile.RecordingCommunication));
}

listViewItem.SubItems.AddRange(new[]
{
Expand All @@ -270,6 +277,8 @@ ListViewItem ProfileToListViewItem(Profile profile)
recording?.NameClean ?? profile.Recording?.ToString() ?? "") {Tag = recording?.SmallIcon},
new ListViewItem.ListViewSubItem(listViewItem,
communication?.NameClean ?? profile.Communication?.ToString() ?? "") {Tag = communication?.SmallIcon},
new ListViewItem.ListViewSubItem(listViewItem,
recordingCommunication?.NameClean ?? profile.RecordingCommunication?.ToString() ?? "") {Tag = recordingCommunication?.SmallIcon},
});

return listViewItem;
Expand Down

0 comments on commit 2ef778b

Please sign in to comment.