-
Notifications
You must be signed in to change notification settings - Fork 1
protoPTCH
The PTCH protocol sends a json encoded object, and is typically used to represent settings in your module. The json settings object is sent along with an address comprising two slugs. By convention you should use your manufacture slug for the first, and this should ensure that there are no conflicts. Avoiding conflicts in the second slug is then your responsibility. The received method delivers both slugs as parameters, so you can examine these to determine if you understand and choose to handle any given message. The message object can be constructed using the same jansson libraries that VCVRack already uses for loading and saving patches.
The payload of the PTCH protocol is a json encoded object comprising the two slugs and the message object
{
"plugin": "ManufacturerSlug",
"module": "ModuleSlug",
"patch": {
"param1": "paramValue",
"param2": "paramValue"
}
}
You can send in the PTCH protocol using a PatchOutputPort
Torpedo::PatchOutputPort outPort = Torpedo::PatchOutputPort(module, OUTPUT_TOR);
json_t *rootJ = json_object();
json_object_set_new(rootJ, "param1", json_real(params[PARAM_1].value));
json_object_set_new(rootJ, "param2", json_real(params[PARAM_2].value));
outPort.send(std::string(TOSTRING(SLUG)), std::string("MyModule"), rootJ);
You can receive the PTCH protocol using a PatchInputPort
void mySubclassedInputPort::received(std::string pluginName, std::string moduleName, json_t *rootJ) {
if (pluginName.compare(TOSTRING(SLUG))) return;
if (pluginName.compare("MyModule")) return;
MyModule *myMod = dynamic_cast<MyModule *>(this->module);
json_t *p1 = json_object_get(rootJ, "param1");
if (p1) {
engineSetParam(myMod, MyModule::PARAM_1, json_number_value(p1));
}
json_t *p2 = json_object_get(rootJ, "param2");
if (p2) {
engineSetParam(myMod, MyModule::PARAM_2, json_number_value(p2));
}
return;
}