Skip to content

Commit

Permalink
- fixed OSC callback id parameter being always undefined
Browse files Browse the repository at this point in the history
- added GlobalRoutingManager.removeOSCCallback() / Cable.deregisterCallback()
  • Loading branch information
christoph-hart committed Sep 17, 2024
1 parent 9949058 commit a418284
Show file tree
Hide file tree
Showing 6 changed files with 4,942 additions and 4,892 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5dde56a05d1aa211d7989a78b44093c6f45b921d
9949058d7f8a0ed2ea865fd27d6e4bff74df6bc2
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "5dde56a05d1aa211d7989a78b44093c6f45b921d"
#define PREVIOUS_HISE_COMMIT "9949058d7f8a0ed2ea865fd27d6e4bff74df6bc2"
37 changes: 37 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7677,6 +7677,7 @@ struct ScriptingObjects::GlobalRoutingManagerReference::Wrapper
API_METHOD_WRAPPER_2(GlobalRoutingManagerReference, connectToOSC);
API_METHOD_WRAPPER_2(GlobalRoutingManagerReference, sendOSCMessage);
API_VOID_METHOD_WRAPPER_2(GlobalRoutingManagerReference, addOSCCallback);
API_METHOD_WRAPPER_1(GlobalRoutingManagerReference, removeOSCCallback);
API_VOID_METHOD_WRAPPER_3(GlobalRoutingManagerReference, setEventData);
API_METHOD_WRAPPER_2(GlobalRoutingManagerReference, getEventData);
};
Expand All @@ -7694,6 +7695,7 @@ ScriptingObjects::GlobalRoutingManagerReference::GlobalRoutingManagerReference(P
ADD_API_METHOD_2(connectToOSC);
ADD_API_METHOD_2(sendOSCMessage);
ADD_API_METHOD_2(addOSCCallback);
ADD_API_METHOD_2(removeOSCCallback);
ADD_API_METHOD_3(setEventData);
ADD_API_METHOD_2(getEventData);
}
Expand Down Expand Up @@ -7856,6 +7858,23 @@ void ScriptingObjects::GlobalRoutingManagerReference::OSCCallback::callForMessag
callback.call(args, 2);
}

bool ScriptingObjects::GlobalRoutingManagerReference::removeOSCCallback(String oscSubAddress)
{
if (auto m = dynamic_cast<scriptnode::routing::GlobalRoutingManager*>(manager.getObject()))
{
for(auto c: callbacks)
{
if(c->subDomain == oscSubAddress)
{
callbacks.removeObject(c);
return true;
}
}
}

return false;
}

void ScriptingObjects::GlobalRoutingManagerReference::addOSCCallback(String oscSubAddress, var callback)
{
if (auto m = dynamic_cast<scriptnode::routing::GlobalRoutingManager*>(manager.getObject()))
Expand Down Expand Up @@ -7913,6 +7932,8 @@ ScriptingObjects::GlobalRoutingManagerReference::OSCCallback::OSCCallback(Global
subDomain(sd),
fullAddress("/*")
{
args[0] = subDomain;

callback.incRefCount();
callback.setHighPriority();
}
Expand All @@ -7927,6 +7948,7 @@ struct ScriptingObjects::GlobalCableReference::Wrapper
API_VOID_METHOD_WRAPPER_3(GlobalCableReference, setRangeWithSkew);
API_VOID_METHOD_WRAPPER_3(GlobalCableReference, setRangeWithStep);
API_VOID_METHOD_WRAPPER_2(GlobalCableReference, registerCallback);
API_METHOD_WRAPPER_1(GlobalCableReference, deregisterCallback);
API_VOID_METHOD_WRAPPER_3(GlobalCableReference, connectToMacroControl);
API_VOID_METHOD_WRAPPER_2(GlobalCableReference, connectToGlobalModulator);
API_VOID_METHOD_WRAPPER_3(GlobalCableReference, connectToModuleParameter);
Expand Down Expand Up @@ -7994,6 +8016,7 @@ ScriptingObjects::GlobalCableReference::GlobalCableReference(ProcessorWithScript
ADD_API_METHOD_3(setRangeWithSkew);
ADD_API_METHOD_3(setRangeWithStep);
ADD_API_METHOD_2(registerCallback);
ADD_API_METHOD_1(deregisterCallback);
ADD_API_METHOD_3(connectToMacroControl);
ADD_API_METHOD_2(connectToGlobalModulator);
ADD_API_METHOD_3(connectToModuleParameter);
Expand Down Expand Up @@ -8178,6 +8201,20 @@ void ScriptingObjects::GlobalCableReference::registerCallback(var callbackFuncti
}
}

bool ScriptingObjects::GlobalCableReference::deregisterCallback(var callbackFunction)
{
for(auto c: callbacks)
{
if(c->callback.matches(callbackFunction))
{
callbacks.removeObject(c);
return true;
}
}

return false;
}

struct MacroCableTarget : public scriptnode::routing::GlobalRoutingManager::CableTargetBase,
public ControlledObject
{
Expand Down
6 changes: 6 additions & 0 deletions hi_scripting/scripting/api/ScriptingApiObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,9 @@ namespace ScriptingObjects
/** Register a scripting callback to be executed when a OSC message that matches the subAddress is received. */
void addOSCCallback(String oscSubAddress, var callback);

/** Removes a OSC callback for the given address. */
bool removeOSCCallback(String oscSubAddress);

/** Send an OSC message to the output port. */
bool sendOSCMessage(String oscSubAddress, var data);

Expand Down Expand Up @@ -2607,6 +2610,9 @@ namespace ScriptingObjects
/** Registers a function that will be executed whenever a value is sent through the cable. */
void registerCallback(var callbackFunction, var synchronous);

/** Deregisteres a callback from the cable. */
bool deregisterCallback(var callbackFunction);

/** Connects the cable to a macro control. */
void connectToMacroControl(int macroIndex, bool macroIsTarget, bool filterRepetitions);

Expand Down
Loading

1 comment on commit a418284

@aaronventure
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're looking at the GlobalRoutingManager, there's one outstanding breaking bug:

#537

Please sign in to comment.