Skip to content

Commit

Permalink
- add support for custom automation ID when modifying macro connectio…
Browse files Browse the repository at this point in the history
…ns using Scripting API
  • Loading branch information
christoph-hart committed Mar 3, 2024
1 parent 3f3d501 commit b166597
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8456,6 +8456,7 @@ namespace MacroIds
DECLARE_ID(MacroIndex);
DECLARE_ID(Processor);
DECLARE_ID(Attribute);
DECLARE_ID(CustomAutomation);
#undef DECLARE_ID
}

Expand Down Expand Up @@ -8497,16 +8498,51 @@ void ScriptingObjects::ScriptedMacroHandler::setFromCallbackArg(const var& obj)
{
auto pId = obj[MacroIds::Processor].toString();

auto isCustomId = (bool)obj[MacroIds::CustomAutomation];

if (auto p = ProcessorHelpers::getFirstProcessorWithName(getScriptProcessor()->getMainController_()->getMainSynthChain(), pId))
{
auto param = obj[MacroIds::Attribute];
int parameterIndex;

String pString;

if (param.isString())
parameterIndex = var(p->getParameterIndexForIdentifier(param.toString()));
{
pString = param.toString();

if(isCustomId)
{
if(auto ptr = getScriptProcessor()->getMainController_()->getUserPresetHandler().getCustomAutomationData(Identifier(param.toString())))
{
parameterIndex = ptr->index;
}
else
reportScriptError("Can't find custom automation with ID " + param.toString());
}
else
parameterIndex = var(p->getParameterIndexForIdentifier(param.toString()));
}
else
{
parameterIndex = (int)param;

if(isCustomId)
{
if(auto ptr = getScriptProcessor()->getMainController_()->getUserPresetHandler().getCustomAutomationData(parameterIndex))
{
pString = ptr->id;
}
else
reportScriptError("Can't find custom automation with ID " + param.toString());
}
else
{
pString = p->getIdentifierForParameterIndex(parameterIndex).toString();
}
}


auto& mm = getScriptProcessor()->getMainController_()->getMacroManager();

auto fr = RangeHelpers::getDoubleRange(obj, RangeHelpers::IdSet::MidiAutomationFull);
Expand All @@ -8515,7 +8551,7 @@ void ScriptingObjects::ScriptedMacroHandler::setFromCallbackArg(const var& obj)
if (fr.getRange().isEmpty())
fr = nr;

mm.getMacroChain()->getMacroControlData(mIndex)->addParameter(p, parameterIndex, p->getIdentifierForParameterIndex(parameterIndex).toString(), fr.rng, true, false, dontSendNotification);
mm.getMacroChain()->getMacroControlData(mIndex)->addParameter(p, parameterIndex, pString, fr.rng, true, isCustomId, dontSendNotification);

auto pd = mm.getMacroChain()->getMacroControlData(mIndex)->getParameterWithProcessorAndIndex(p, parameterIndex);

Expand Down Expand Up @@ -8565,6 +8601,18 @@ var ScriptingObjects::ScriptedMacroHandler::getCallbackArg(int macroIndex, Proce
nr.rng = md->getParameter(i)->getParameterRange();
nr.inv = md->getParameter(i)->isInverted();

if(md->getParameter(i)->isCustomAutomation())
{
obj->setProperty(MacroIds::CustomAutomation, true);

auto automationId = md->getParameter(i)->getParameter();

if(auto ptr = getScriptProcessor()->getMainController_()->getUserPresetHandler().getCustomAutomationData(automationId))
{
obj->setProperty(MacroIds::Attribute, ptr->id);
}
}

scriptnode::InvertableParameterRange fr;
fr.rng = md->getParameter(i)->getTotalRange();

Expand Down

0 comments on commit b166597

Please sign in to comment.