Skip to content

Commit

Permalink
bump appconfig version, remove bad session sync implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Nov 6, 2023
1 parent e24aefe commit f75cf27
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 174 deletions.
4 changes: 3 additions & 1 deletion VolumeControl.Core/VolumeControl.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="radj307.AppReconfig" Version="2.3.0" />
<PackageReference Include="radj307.AppReconfig" Version="2.3.1">
<PrivateAssets>Resources</PrivateAssets>
</PackageReference>
<PackageReference Include="SharpDX.DirectInput" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
Expand Down
15 changes: 11 additions & 4 deletions VolumeControl.CoreAudio/AudioSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,37 @@ public float NativeVolume
else if (value > 1.0f)
value = 1.0f;

if (value == NativeVolume) return;

SimpleAudioVolume.MasterVolume = value;
if (isNotifying) return; //< don't duplicate propertychanged notifications
isNotifying = true;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(Volume));
NotifyVolumeChanged(value, Mute);
NotifyPropertyChanged();
isNotifying = false;
}
}
/// <inheritdoc/>
public int Volume
{
get => VolumeLevelConverter.FromNativeVolume(NativeVolume);
set => NativeVolume = VolumeLevelConverter.ToNativeVolume(value);
set
{
NativeVolume = VolumeLevelConverter.ToNativeVolume(value);
NotifyPropertyChanged();
}
}
/// <inheritdoc/>
public bool Mute
{
get => SimpleAudioVolume.Mute;
set
{
if (value == Mute) return;

SimpleAudioVolume.Mute = value;
NotifyPropertyChanged();
NotifyVolumeChanged(NativeVolume, value);
NotifyPropertyChanged();
}
}
#endregion Properties
Expand Down
12 changes: 6 additions & 6 deletions VolumeControl.CoreAudio/Events/VolumeChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace VolumeControl.CoreAudio.Events
/// <summary>
/// Contains event data for the <see cref="VolumeChangedEventHandler"/> event type.
/// </summary>
public sealed class VolumeChangedEventArgs : EventArgs, IReadOnlyAudioControl
public sealed class VolumeChangedEventArgs : EventArgs
{
#region Constructor
/// <summary>
Expand All @@ -16,8 +16,8 @@ public sealed class VolumeChangedEventArgs : EventArgs, IReadOnlyAudioControl
/// <param name="data">The <see cref="AudioVolumeNotificationData"/> object from the underlying event.</param>
internal VolumeChangedEventArgs(AudioVolumeNotificationData data)
{
NativeVolume = data.MasterVolume;
Volume = VolumeLevelConverter.FromNativeVolume(NativeVolume);
NewNativeVolume = data.MasterVolume;
Volume = VolumeLevelConverter.FromNativeVolume(NewNativeVolume);
Mute = data.Muted;
}
/// <summary>
Expand All @@ -27,15 +27,15 @@ internal VolumeChangedEventArgs(AudioVolumeNotificationData data)
/// <param name="newMute">The new mute state.</param>
internal VolumeChangedEventArgs(float newVolume, bool newMute)
{
NativeVolume = newVolume;
Volume = VolumeLevelConverter.FromNativeVolume(NativeVolume);
NewNativeVolume = newVolume;
Volume = VolumeLevelConverter.FromNativeVolume(NewNativeVolume);
Mute = newMute;
}
#endregion Constructor

#region Properties
/// <inheritdoc/>
public float NativeVolume { get; }
public float NewNativeVolume { get; }
/// <inheritdoc/>
public int Volume { get; }
/// <inheritdoc/>
Expand Down
13 changes: 0 additions & 13 deletions VolumeControl.CoreAudio/Helpers/AudioControlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using VolumeControl.CoreAudio.Interfaces;
using VolumeControl.CoreAudio.Structs;

namespace VolumeControl.CoreAudio.Helpers
{
Expand Down Expand Up @@ -50,18 +49,6 @@ public static void SetMute(this IAudioControl audioControl, bool muteState)
public static void ToggleMute(this IAudioControl audioControl)
=> audioControl.Mute = !audioControl.Mute;
/// <summary>
/// Sets the volume level &amp; mute state to the values in the specified <paramref name="volumeState"/>, if they're set.
/// </summary>
/// <param name="audioControl">(implicit) <see cref="IAudioControl"/> instance.</param>
/// <param name="volumeState"><see cref="VolumeState"/> instance containing the values to set.</param>
public static void SetState(this IAudioControl audioControl, VolumeState volumeState)
{
if (volumeState.HasVolume)
audioControl.Volume = volumeState.Volume;
if (volumeState.HasMute)
audioControl.Mute = volumeState.Mute;
}
/// <summary>
/// Sets the volume level &amp; mute state to the values in the specified <paramref name="other"/> instance.
/// </summary>
/// <param name="audioControl">(implicit) <see cref="IAudioControl"/> instance.</param>
Expand Down
14 changes: 5 additions & 9 deletions VolumeControl.CoreAudio/Interfaces/IReadOnlyAudioControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
public interface IReadOnlyAudioControl
{
/// <summary>
/// Gets the volume level of the audio instance, in the native float format.
/// Gets the volume level, in the native float format.
/// </summary>
/// <remarks>
/// Range: <b>0.0</b> - <b>1.0</b>
/// </remarks>
/// <returns>A <see cref="float"/> between <b>0.0</b> and <b>1.0</b>.</returns>
float NativeVolume { get; }
/// <summary>
/// Gets the volume level of the audio instance.
/// Gets the volume level.
/// </summary>
/// <remarks>
/// Range: <b>0</b> - <b>100</b>
/// </remarks>
/// <returns>An <see cref="int"/> between <b>0</b> and <b>100</b>.</returns>
int Volume { get; }
/// <summary>
/// Gets the mute state of the audio instance.
/// Gets the mute state.
/// </summary>
bool Mute { get; }
}
Expand Down
7 changes: 6 additions & 1 deletion VolumeControl.SDK/VolumeControl.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<Version>6.5.1</Version>
<Copyright>Copyright © 2023 by $(Authors)</Copyright>
</PropertyGroup>
<ItemGroup>
<Content Remove="C:\Users\Administrator\.nuget\packages\radj307.appreconfig\2.3.0\contentFiles\any\net6.0\Resources\gear-split.ico" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
Expand All @@ -44,7 +47,9 @@
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="radj307.AppReconfig" Version="2.3.0" />
<PackageReference Include="radj307.AppReconfig" Version="2.3.1">
<PrivateAssets>Resources</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VolumeControl.CoreAudio\VolumeControl.CoreAudio.csproj">
Expand Down
21 changes: 21 additions & 0 deletions VolumeControl.TypeExtensions/BoolExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace VolumeControl.TypeExtensions
{
/// <summary>
/// Extension methods for the <see cref="bool"/> type.
/// </summary>
public static class BoolExtensions
{
/// <summary>
/// Converts the <see cref="bool"/> value to <see cref="int"/>.
/// </summary>
/// <param name="value">(implicit) A boolean value.</param>
/// <returns>1 when <paramref name="value"/> was <see langword="true"/>; 0 when <paramref name="value"/> was <see langword="false"/>.</returns>
public static int ToInt32(this bool value) => value ? 1 : 0;
/// <summary>
/// Converts the <see cref="bool"/> value to <see cref="uint"/>.
/// </summary>
/// <param name="value">(implicit) A boolean value.</param>
/// <returns>1 when <paramref name="value"/> was <see langword="true"/>; 0 when <paramref name="value"/> was <see langword="false"/>.</returns>
public static uint ToUInt32(this bool value) => value ? 1u : 0u;
}
}
2 changes: 1 addition & 1 deletion VolumeControl/Helpers/LocalizationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StreamLoader
/// <param name="sourceFileName">Optional source file name.</param>
public void LoadFromStream(Stream stream, LocalizationLoader loader, string resourceName)
{
using var reader = new StreamReader(stream, System.Text.Encoding.UTF8, true, leaveOpen: true);
using var reader = new StreamReader(stream, System.Text.Encoding.UTF8, true);
string content = reader.ReadToEnd();
LoadFromString(content, loader, resourceName);
}
Expand Down
20 changes: 5 additions & 15 deletions VolumeControl/ViewModels/AudioDeviceManagerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public AudioDeviceManagerVM()
};

// setup the session synchronizer
SessionSync = new(this);
SessionSync.PropertyChanged += this.SessionSync_PropertyChanged;
//SessionSync = new(this, initialState: false);

// populate the sessions lists
Devices.Select(d => d.AudioDevice.SessionManager).ForEach(AudioSessionManager.AddSessionManager);
Expand All @@ -105,6 +104,9 @@ public AudioDeviceManagerVM()
AudioSessionMultiSelector.SessionDeselected += this.AudioSessionMultiSelector_SessionDeselected;
AudioSessionMultiSelector.CurrentSessionChanged += this.AudioSessionMultiSelector_CurrentSessionChanged;

// enable session sync
//SessionSync.IsEnabled = Settings.EnableSessionSync;

if (doDebugLogging) FLog.Debug($"Successfully initialized {AudioSessionManager.Sessions.Count + AudioSessionManager.HiddenSessions.Count} {(AudioSessionManager.HiddenSessions.Count == 0 ? "" : $"({AudioSessionManager.HiddenSessions.Count} hidden)")} audio sessions.");

if (doDebugLogging) FLog.Debug("Finished initializing CoreAudio APIs.");
Expand All @@ -130,7 +132,7 @@ public AudioDeviceManagerVM()
public AudioDeviceSelector AudioDeviceSelector { get; }
public AudioDeviceVM? SelectedDevice { get; set; }
public AudioSessionMultiSelector AudioSessionMultiSelector { get; }
public SessionSyncVM SessionSync { get; }
// public SessionSyncVM SessionSync { get; }
public bool? AllSessionsSelected
{
get
Expand Down Expand Up @@ -284,18 +286,6 @@ private void AudioDeviceSelector_PropertyChanged(object? sender, PropertyChanged
}
#endregion AudioDeviceSelector

#region SessionSync
private void SessionSync_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == null) return;

if (e.PropertyName.Equals(nameof(SessionSyncVM.IsEnabled), StringComparison.Ordinal))
{
Settings.EnableSessionSync = SessionSync.IsEnabled;
}
}
#endregion SessionSync

#endregion EventHandlers
}
}
121 changes: 0 additions & 121 deletions VolumeControl/ViewModels/SessionSyncVM.cs

This file was deleted.

1 change: 0 additions & 1 deletion VolumeControl/ViewModels/VolumeControlVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public VolumeControlVM() : base()
if (Settings.CheckForUpdates) Updater.CheckForUpdateNow();

this.AudioAPI = new();
AudioAPI.SessionSync.IsEnabled = true;

TargetBoxVM = new(AudioAPI.AudioSessionManager, AudioAPI.AudioSessionMultiSelector);

Expand Down
7 changes: 5 additions & 2 deletions VolumeControl/VolumeControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<NeutralLanguage>en-CA</NeutralLanguage>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/radj307/volume-control</RepositoryUrl>
<Copyright>Copyright © 2023 by $(Authors)</Copyright>
<Copyright>Copyright © 2023 $(Authors)</Copyright>
<ApplicationIcon>Resources\icons\iconSilvered.ico</ApplicationIcon>
<Company>radj307</Company>
<Product>Volume Control</Product>
Expand All @@ -36,6 +36,9 @@
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<EmbeddedResource Include="Localization\zz.loc.json" />
</ItemGroup>
<ItemGroup>
<Content Remove="C:\Users\Administrator\.nuget\packages\radj307.appreconfig\2.3.0\contentFiles\any\net6.0\Resources\gear-split.ico" />
</ItemGroup>
<ItemGroup>
<None Remove="Localization\de.loc.json" />
<None Remove="Localization\en.loc.json" />
Expand Down Expand Up @@ -160,4 +163,4 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>

0 comments on commit f75cf27

Please sign in to comment.