Add a command with a parameter
Overview
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 the console 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.
Plugin service 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
Steps
-
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
ButtonSwitchesCommand
class opens for editing. -
Inherit the
ButtonSwitchesCommand
class from thePluginDynamicCommand
class: -
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
AddParameter
method: -
Add
_switches
Boolean array that keeps the current state of switches: -
Overwrite the
RunCommand
method that is called every time a user presses the touch or the physical button to which this command is assigned: -
Overwrite the
GetCommandDisplayName
method that is called every time Plugin Service 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. Plugin Service uses display names that the plugin specifies with the
ActionImageChanged
method in the class constructor. -
Start debugging and wait until the software is loaded.
-
Open the configuration UI.
-
Switch the Adapt to App to OFF Options+ or Dynamic mode to OFF in Loupedeck Software.
-
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 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.