1
0
mirror of synced 2024-11-16 13:33:50 +00:00
MassiveKnob/Windows/MassiveKnob.Plugin.VoiceMeeter/InstanceRegister.cs
Mark van Renswoude cae557e7e1 Implemented default device switching
Added VoiceMeeter plugin (run macro and get status)
Added Inno Setup script
Added Fusion 360 files for housing designs
2021-03-06 10:53:38 +01:00

70 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Voicemeeter;
namespace MassiveKnob.Plugin.VoiceMeeter
{
public static class InstanceRegister
{
private static readonly object InstancesLock = new object();
private static readonly HashSet<IVoiceMeeterAction> Instances = new HashSet<IVoiceMeeterAction>();
private static Task initializeTask;
// The VoiceMeeter Remote only connects to one instance, so all actions need to be in sync
private static RunVoicemeeterParam version;
public static RunVoicemeeterParam Version
{
get => version;
set
{
if (value == version)
return;
version = value;
Notify(action => action.VoiceMeeterVersionChanged());
initializeTask = Task.Run(async () =>
{
await global::VoiceMeeter.Remote.Initialize(version);
});
}
}
public static Task InitializeVoicemeeter()
{
return initializeTask ?? Task.CompletedTask;
}
public static void Register(IVoiceMeeterAction instance)
{
lock (InstancesLock)
{
Instances.Add(instance);
}
}
public static void Unregister(IVoiceMeeterAction instance)
{
lock (InstancesLock)
{
Instances.Remove(instance);
}
}
public static void Notify(Action<IVoiceMeeterAction> action)
{
lock (InstancesLock)
{
foreach (var instance in Instances)
action(instance);
}
}
}
}