Add a command with a parameter
Commands and adjustments can contain parameters. As an example, the "apply develop profile" command in the Lightroom plugin takes the preset file name as a parameter.
Parameters are especially useful when you cannot determine the number of similar commands or adjustments at the development stage. Consider Windows 10/11 Volume Mixer - you cannot predict how many channels it will have on different PCs. However, a plugin can implement a single "toggle mute" command (or "change volume" adjustment) that takes the channel name as a parameter - and serve them all.
The plugin needs to indicate that the action has a parameter, and provide a list of available parameters.
The list of parameters can change at any moment (for example if a user started Spotify that added a channel to Volume Mixer), and there is a way to notify Loupedeck about the change.
A command or adjustment can have only one string parameter. If the plugin needs to store more data associated with a parameter, it should treat the parameter as an ID and keep an internal dictionary that links this ID to any related data.
Loupedeck treats a parameter as a random string. It is the plugin's responsibility to keep these parameters unique for every action.
To create a command with a parameter, add to the plugin project a class inherited from the
PluginDynamicCommand class (same as for a simple command). However, commands with parameters use a different base constructor.
As an example, let's add a simple command to the Demo plugin that toggles 12 switches.
The full source code for this topic is at: DemoPlugin/Step06
You can find the
ButtonSwitchesCommand class here: ButtonSwitchesCommand.cs
Open the Demo plugin solution in Visual Studio.
In the Solution Explorer, right-click on the DemoPlugin project and select Add > Class.
Enter ButtonSwitchesCommand.cs as the file name and click Add. The
ButtonSwitchesCommandclass opens for editing.
ButtonSwitchesCommandclass from the
Create an empty, parameterless constructor that calls the parameterless constructor of the base class. You need to define the display name, description, and group name separately for each parameter.
Add 12 parameters in the constructor using the
_switchesBoolean array that keeps the current state of switches:
RunCommandmethod that is called every time a user presses the touch or the physical button to which this command is assigned:
GetCommandDisplayNamemethod that is called every time Loupedeck needs to show a command on the console or the configuration UI.
Note that if your command does not change the display name during runtime, you don't need to override this method. Loupedeck uses display names that the plugin specifies with the
ActionImageChangedmethod in the class constructor.
Start debugging and wait until the Loupedeck software is loaded.
Open the Loupedeck configuration UI.
Switch the Dynamic mode to OFF position in the profile dropdown menu in the middle.
From the applications dropdown list, select Demo.
On the right pane, under Press Actions, expand the Demo node, then expand the Switches group and ensure that it contains 12 Switch commands.
Drag and drop more than one Switch command to any touch button.
Connect a Loupedeck console to your computer.
Check that the console shows the Switch commands on the touch screen.
Press the buttons and check how their text changes.