Skip to content

protoPTCH

David O'Rourke edited this page Jun 8, 2018 · 1 revision

PTCH protocol

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.

Structure

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"
      }
    }

Sending

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);

Receiving

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;
    }
Clone this wiki locally