Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
- update VmrAPI
- add macro buttons support
  • Loading branch information
PhoenixWyllow authored Nov 2, 2024
2 parents 2029641 + 31b8f6a commit acef7e5
Show file tree
Hide file tree
Showing 30 changed files with 594 additions and 53 deletions.
71 changes: 71 additions & 0 deletions Actions/MacroButtonAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using PW.VoicemeeterPlugin.Models;
using PW.VoicemeeterPlugin.Services;
using PW.VoicemeeterPlugin.ViewModels;
using SuchByte.MacroDeck.ActionButton;
using SuchByte.MacroDeck.GUI;
using SuchByte.MacroDeck.GUI.CustomControls;
using SuchByte.MacroDeck.Logging;
using SuchByte.MacroDeck.Plugins;
using SuchByte.MacroDeck.Variables;

using System.Diagnostics;

namespace PW.VoicemeeterPlugin.Actions;

public class MacroButtonAction : PluginAction
{
/// <summary>
/// Name of the action
/// </summary>
public override string Name => LocalizationManager.Instance.MacroButtonActionName;

/// <summary>
/// A short description what this action does
/// </summary>
public override string Description => LocalizationManager.Instance.MacroButtonActionDescription;

/// <summary>
/// Set true if the plugin can be configured.
/// </summary>
public override bool CanConfigure => true;

/// <summary>
/// Return the ActionConfigControl for this action.
/// </summary>
/// <returns></returns>
public override ActionConfigControl GetActionConfigControl(ActionConfigurator actionConfigurator)
{
return new Views.MacroButtonActionConfigView(new MacroButtonActionConfigViewModel(this));
}

/// <summary>
/// Gets called when the button with this action gets pressed.
/// </summary>
/// <param name="clientId">Returns the client id</param>
/// <param name="actionButton">Returns the pressed action button</param>
public override void Trigger(string clientId, ActionButton actionButton)
{
if (string.IsNullOrWhiteSpace(Configuration))
{
return;
}
var config = MacroButtonActionConfigModel.Deserialize(Configuration);
var value = VariableManager.GetVariable(PluginInstance.Plugin, config.AsVariable());
if (value is null)
{
MacroDeckLogger.Info(PluginInstance.Plugin, typeof(DeviceToggleAction), $"Please report a bug to the developer of the plugin. Expected value: {Configuration}");
return;
}
PluginInstance.VoicemeeterControl.SetButtonState(config.ButtonId, value.Value.Equals(bool.FalseString), config.ButtonType);
//if (config.ButtonType == ButtonType.Push)
//{
// var sw = Stopwatch.StartNew();
// var elapsed = sw.ElapsedMilliseconds;
// while (elapsed < 100)
// {
// elapsed = sw.ElapsedMilliseconds;
// }
// PluginInstance.VoicemeeterControl.SetButtonState(config.ButtonId, value.Value.Equals(bool.FalseString));
//}
}
}
4 changes: 2 additions & 2 deletions ExtensionManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"author": "PhoenixWyllow",
"repository": "https://github.com/PhoenixWyllow/MacroDeck.Voicemeeter",
"packageId": "PhoenixWyllow.VoicemeeterPlugin",
"version": "2.0.0",
"version": "2.1.0",
"target-plugin-api-version": 40,
"target-macro-deck-version": "2.13.0",
"target-macro-deck-version": "2.14.1",
"dll": "Voicemeeter Plugin.dll"
}
7 changes: 6 additions & 1 deletion Languages/Chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
"SliderActionName": "Slider control",
"SliderActionDescription": "Change a slider by a given amount",
"SliderValue": "Change slider by amount",
"ErrorZeroSliderValue": "Amount cannot be zero."
"ErrorZeroSliderValue": "Amount cannot be zero.",
"MacroButtonActionName": "Use Macro Button",
"MacroButtonActionDescription": "Use a Voicemeeter Macro Button",
"MacroButtonButtonId": "Logical ID",
"MacroButtonButtonType": "Button Type",
"MacroButtonIdError": "Button Id is not valid. Valid values are 0 to 79"
}
7 changes: 6 additions & 1 deletion Languages/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
"SliderActionName": "Slider control",
"SliderActionDescription": "Change a slider by a given amount",
"SliderValue": "Change slider by amount",
"ErrorZeroSliderValue": "Amount cannot be zero."
"ErrorZeroSliderValue": "Amount cannot be zero.",
"MacroButtonActionName": "Use Macro Button",
"MacroButtonActionDescription": "Use a Voicemeeter Macro Button",
"MacroButtonButtonId": "Logical ID",
"MacroButtonButtonType": "Button Type",
"MacroButtonIdError": "Button Id is not valid. Valid values are 0 to 79"
}
7 changes: 6 additions & 1 deletion Languages/Italian.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
"SliderActionName": "Controllo slider",
"SliderActionDescription": "Varia slider per una determinata quantità",
"SliderValue": "Variazione",
"ErrorZeroSliderValue": "La quantità non può essere pari a zero."
"ErrorZeroSliderValue": "La quantità non può essere pari a zero.",
"MacroButtonActionName": "Usa Macro Button",
"MacroButtonActionDescription": "Usa una macro di Voicemeeter",
"MacroButtonButtonId": "ID Logico",
"MacroButtonButtonType": "Tipo Bottone",
"MacroButtonIdError": "L'ID non è valido. I valori validi sono da 0 a 79"
}
33 changes: 33 additions & 0 deletions Languages/Polish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Attribution": "szopen",
"Language": "Polski",
"PluginDescription": "Plugin do Macro Deck'a",
"VoiceMeeterConnected": "Voicemeeter połączony",
"VoiceMeeterDisconnected": "Voicemeeter rozłączony",
"ToggleActionName": "Przełącz urządzenie",
"ToggleActionDescription": "Przełącz opcję na pasku lub szynie",
"Device": "Urządzenie",
"Action": "Akcja",
"AdvancedActionName": "Zaawansowane/Niestandardowe",
"AdvancedActionDescription": "Zaawansowane/Niestandardowe opcje do kontrolowania Voicemeeter'a przy użyciu Voicemeeter API.\nInstrukcje znajdziesz w dokumentacji Voicemeeter.",
"Commands": "Komendy (rozdzielone przez ',', ';' albo nową linią)",
"LabelParameter": "Parametr",
"ParameterError": "Wystąpił błąd podczas weryfikowania parametru.",
"ParameterExists": "Ten parametr już istnieje.",
"NoCommandsMsg": "Brak komend do wykonania",
"NCommandsMsg": "{0} komend",
"CommandActionName": "Wywołaj komendę",
"CommandActionDescription": "Wybierz komendę z Voicemeeter'a do wykonaia",
"Command": "Komenda",
"CommandValue": "Wartość komendy",
"CommandError": "Nastąpił błąd podczas weryfikowania komendy.",
"SliderActionName": "Sterowanie suwakiem",
"SliderActionDescription": "Przesuń suwak o daną wartość",
"SliderValue": "Przesuń suwak o wartość",
"ErrorZeroSliderValue": "Wartość nie może być równa zeru.",
"MacroButtonActionName": "Use Macro Button",
"MacroButtonActionDescription": "Use a Voicemeeter Macro Button",
"MacroButtonButtonId": "Logical ID",
"MacroButtonButtonType": "Button Type",
"MacroButtonIdError": "Button Id is not valid. Valid values are 0 to 79"
}
7 changes: 6 additions & 1 deletion Languages/Spanish.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@
"SliderActionName": "Slider control",
"SliderActionDescription": "Change a slider by a given amount",
"SliderValue": "Change slider by amount",
"ErrorZeroSliderValue": "Amount cannot be zero."
"ErrorZeroSliderValue": "Amount cannot be zero.",
"MacroButtonActionName": "Use Macro Button",
"MacroButtonActionDescription": "Use a Voicemeeter Macro Button",
"MacroButtonButtonId": "Logical ID",
"MacroButtonButtonType": "Button Type",
"MacroButtonIdError": "Button Id is not valid. Valid values are 0 to 79"
}
2 changes: 1 addition & 1 deletion Models/AdditionalVariablesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace PW.VoicemeeterPlugin.Models;
[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
public sealed class AdditionalVariablesModel : ISerializableConfiguration
{
public List<VmIoOptions> Options { get; init; } = new();
public List<VmIoOptions> Options { get; init; } = [];

public string Serialize()
{
Expand Down
5 changes: 5 additions & 0 deletions Models/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ internal sealed class Localization
public string SliderValue { get; set; } = "Change slider by amount";
public string ErrorZeroSliderValue { get; set; } = "Amount cannot be zero";
public string ErrorNoDeviceSelected { get; set; } = "No device selected";
public string MacroButtonActionName { get; set; } = "Use Macro Button";
public string MacroButtonActionDescription { get; set; } = "Use a Voicemeeter Macro Button";
public string MacroButtonButtonId { get; set; } = "Button ID";
public string MacroButtonButtonType { get; set; } = "Button Type";
public string MacroButtonIdError { get; set; } = "Button Id is not valid. Valid values are 0 to 79";
}
55 changes: 55 additions & 0 deletions Models/MacroButtonActionConfigModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Diagnostics;
using System.Text.Json;

namespace PW.VoicemeeterPlugin.Models;

public enum ButtonType
{
Push,
TwoPositions,
}

[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
internal class MacroButtonActionConfigModel : ISerializableConfiguration
{
public int ButtonId { get; set; } = -1;

public ButtonType ButtonType { get; set; }

public string Serialize()
{
return JsonSerializer.Serialize(this);
}

public static MacroButtonActionConfigModel Deserialize(string config)
{
return ISerializableConfiguration.Deserialize<MacroButtonActionConfigModel>(config);
}

public override string ToString()
{
if (ButtonType == ButtonType.Push)
{
return $"Button {ButtonId}: Press";
}
else
{
return $"Button {ButtonId}: Toggle";
}
}

private string GetDebuggerDisplay()
{
return ToString();
}

public string AsVariable()
{
return GetVariable(ButtonId);
}

public static string GetVariable(int buttonId)
{
return $"vm_macrobutton{buttonId:d2}_pressed";
}
}
1 change: 0 additions & 1 deletion Models/VmIOInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace PW.VoicemeeterPlugin.Models;

Expand Down
1 change: 0 additions & 1 deletion Models/VmIOOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using SuchByte.MacroDeck.Variables;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json.Serialization;

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Create a button and configure how you want to control Voicemeeter.
| Slider control | Change a slider by a given amount | Change slider by a relative amount (between -10 and +10) |
| Program commands | Execute Voicemeeter commands | Shutdown, Restart, Show, Reset/Load/Save configuration, Load/Eject cassette |
| Advanced/Custom | Send a custom command to Voicemeeter | This option allows configuring custom commands using the Voicemeeter API language. <br/> Please see the official [VoicemeeterRemoteAPI pdf](https://download.vb-audio.com/Download_CABLE/VoicemeeterRemoteAPI.pdf) for more info. |
| Use Macro Button | Activate/Toggle a Macro Button (Voicemeeter) | Activate or toggle a Voicemeeter Macro Button. Ids are 0-79 and you will need to find and confugure them separately, according to the documentation for your Voicemeeter version. |

#### Available parameters/variables

Expand All @@ -45,7 +46,15 @@ Clicking on an option that you've already included allows you to edit or delete
>- **Restart Macro Deck** to refresh with the variables you've added or removed
>- I can only provide minimal support for this since it's all your own stuff being added. Use it wisely.
*More features/actions coming soon...*
#### Use Voicemeeter Macro Buttons

Macro Buttons are a feature of Voicemeeter that allows you to execute a series of commands with a single button press.\
Some actions are only possible with Macro Buttons, like sending special commands (SendText, Wait, etc.).

To use a Macro Button, you must first create it in Voicemeeter and then configure the plugin to use it.\
The plugin will only activate or toggle the button, it will not create or edit the button for you.

The Macro Button ID is a number between 0 and 79, and you can find it in the Voicemeeter Macro Buttons editor window as "Logical ID".\

***
## Need this in your language?
Expand All @@ -60,6 +69,7 @@ Currently available languages:
- Italian
- Spanish (by Danivar)
- Chinese (by PENC)
- Polish (by szopen)

***
## Third party licenses
Expand Down
2 changes: 1 addition & 1 deletion Services/Voicemeeter/AvailableValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static void Reset()

public static List<VmIoInfo>? IoInfo { get; private set; }

internal static void InitIoInfo(AtgDev.Voicemeeter.RemoteApiExtender vmrApi)
internal static void InitIoInfo(AtgDev.Voicemeeter.RemoteApiWrapper vmrApi)
{
void AddChannel(ICollection<VmIoInfo> ioInfo, VmIoType type, int num)
{
Expand Down
7 changes: 6 additions & 1 deletion Services/Voicemeeter/Control.Connect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AtgDev.Voicemeeter;
using AtgDev.Voicemeeter.Extensions;
using AtgDev.Voicemeeter.Types;
using System;
using System.Timers;
Expand Down Expand Up @@ -91,7 +92,7 @@ private void Login()

private void StartPolling()
{
_timer ??= new()
_timer ??= new Timer
{
Interval = 300,
AutoReset = true,
Expand All @@ -118,6 +119,10 @@ private void Poll(object? sender, ElapsedEventArgs e)
{
UpdateVariables();
}
if (_connected && VmrApi.MacroButtonIsDirty() > 0)
{
UpdateButtonStates();
}
}

internal static event EventHandler? Polling;
Expand Down
Loading

0 comments on commit acef7e5

Please sign in to comment.