Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Allow specification of target plugin for --parameter argument while r…
Browse files Browse the repository at this point in the history
…etaining backwards compatibility.
  • Loading branch information
CrushedPixel committed Dec 27, 2016
1 parent 281c10c commit e7d9075
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
9 changes: 4 additions & 5 deletions source/MrsWatsonOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,10 @@ Use '-' to write to stdout..",
options,
newProgramOptionWithName(
OPTION_PARAMETER, "parameter",
"Set a parameter in a plugin. May be specified multiple times, but can only \
set parameters for the first plugin in a chain. Parameter indexes for plugins \
can be found with the --display-info option. Use comma-separated arguments for \
index/value, for example:\n\n\
\t--parameter 1,0.3 --parameter 0,0.75",
"Set a parameter in a plugin. May be specified multiple times. Parameter indexes for plugins \
can be found with the --display-info option. Use arguments for \
plugin:index,value, for example:\n\n\
\t--parameter 0:1,0.3 --parameter 2:0,0.75",
NO_SHORT_FORM, kProgramOptionTypeList,
kProgramOptionArgumentTypeRequired));

Expand Down
30 changes: 25 additions & 5 deletions source/plugin/PluginChain.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ unsigned long pluginChainGetProcessingDelay(PluginChain self) {
}

typedef struct {
Plugin plugin;
PluginChain self;
boolByte success;
} _PluginChainSetParameterPassData;

Expand All @@ -283,11 +283,32 @@ void _pluginChainSetParameter(void *item, void *userData) {
char *parameterValue = (char *)item;
_PluginChainSetParameterPassData *passData =
(_PluginChainSetParameterPassData *)userData;
Plugin plugin = passData->plugin;
PluginChain self = passData->self;

char *comma = NULL;
char *colon = NULL;
int pluginIndex;
int index;
float value;

colon = strchr(parameterValue, ':');

if (colon == NULL) {
logWarn("No plugin index set for parameter argument %s, defaulting to plugin chain head", parameterValue);
pluginIndex = 0;
} else {
pluginIndex = (int)strtod(parameterValue, NULL);

if (pluginIndex < 0 || pluginIndex >= self->numPlugins) {
logWarn("Plugin index for parameter argument %s is out of bounds, skipping parameter", parameterValue);
return;
}

parameterValue = colon + 1;
}

Plugin plugin = self->plugins[pluginIndex];

// If a previous attempt to set a parameter failed, then return right away
// since this method will return false anyways.
if (!passData->success) {
Expand All @@ -306,16 +327,15 @@ void _pluginChainSetParameter(void *item, void *userData) {
*comma = '\0';
index = (int)strtod(parameterValue, NULL);
value = (float)strtod(comma + 1, NULL);
logDebug("Set parameter %d to %f", index, value);
logDebug("Set parameter %d of plugin %d to %f", index, pluginIndex, value);
passData->success = plugin->setParameter(plugin, (unsigned int)index, value);
}

boolByte pluginChainSetParameters(PluginChain self,
const LinkedList parameters) {
_PluginChainSetParameterPassData passData;
passData.plugin = self->plugins[0];
passData.self = self;
passData.success = true;
logDebug("Setting parameters on head plugin in chain");
linkedListForeach(parameters, _pluginChainSetParameter, &passData);
return passData.success;
}
Expand Down

0 comments on commit e7d9075

Please sign in to comment.