CabbageRack icon indicating copy to clipboard operation
CabbageRack copied to clipboard

How to allow multiple modules in CabbageRack project?

Open brylie opened this issue 3 years ago • 9 comments

When exporting for VCV Rack, CabbageRack prepares a directory structure that contains a single module:

  • module.csd
  • LICENSE
  • plugin.json
  • plugin.so
  • README

It is conventional for Rack modules to be distributed in "packs" of multiple modules, as can be seen in plugin.json:

...
"modules": [ ... ]
...

When modifying the modules array in plugin.json, the CabbageRack module fails to register with VCV Rack.

Steps to reproduce

  1. export a module for VCV Rack (e.g. cabbage_test)
  2. open Rack and verify that the plugin loads
  3. duplicate the cabbage_test.csd as cabbage_test_two.csd
  4. modify the modules array in plugin.json to include the new cabbage_test_two
  5. open Rack and look for the plugins which are now missing
plugin.json
{
  "slug": "cabbage_test",
  "name": "Cabbage Test",
  "version": "1.0.0",
  "license": "GPL",
  "brand": "Cabbage Test",
  "author": "Rory Walsh",
  "authorEmail": "",
  "authorUrl": "cabbageaudio.com",
  "pluginUrl": "",
  "manualUrl": "",
  "sourceUrl": "",
  "donateUrl": "",
  "modules": [
    {
      "slug": "cabbage_test",
      "name": "cabbage_test",
      "description": "VCV Rack interface for Cabbage",
      "tags": [
        "Csound",
        "Cabbage"
      ]
    },
    {
      "slug": "cabbage_test_two",
      "name": "cabbage_test_two",
      "description": "VCV Rack interface for Cabbage",
      "tags": [
        "Csound",
        "Cabbage"
      ]
    }
  ]
}

brylie avatar Nov 03 '21 08:11 brylie

I'm happy to take a pull request on this..

rorywalsh avatar Nov 03 '21 09:11 rorywalsh

Understandable. I just don't know where to begin, hence the question in the issue title.

What prevents the module from loading the second cabage_test_two.csd file? Is the plugin.so unique only to the initial cabbage_test.csd?

brylie avatar Nov 03 '21 09:11 brylie

Yes, each 'module' currently deals with a single .csd file. But I think it's probably something here that needs changing: https://github.com/rorywalsh/CabbageRack/blob/master/src/plugin.cpp#L15 When I wrote this interface I don't think it was possible to define multiple modules. The problem is getting the the correct .csd file to be loaded..

rorywalsh avatar Nov 03 '21 09:11 rorywalsh

One possible solution might be:

  • parse the plugin.json modules array
  • for each module object,
    1. look for a corresponding .csd file based on the slug field <slug>.csd
    2. initialize the module

Then, we would just need to update:

  1. the exporter UX so it somehow allows a developer to export just the .csd file without the other package files
  2. the documentation to clarify the importance of the <slug>.csd naming convention

brylie avatar Nov 03 '21 09:11 brylie

Do you have any recommendations for a C++ JSON parser? Is there one in the C++ standard library? I've searched but only seem to find recommendations on Stack Overflow for third-party libraries.

brylie avatar Nov 03 '21 09:11 brylie

Hmm, it looks like there is at least one proposal for JSON parsing support in the C++ standard library. The lack of JSON support in the C++ standard library is somewhat surprising given the ubiquity of JSON.

brylie avatar Nov 03 '21 10:11 brylie

There is no in-built support for parsing JSON files in C++ afaik. You can write your own parser or use a 3rd party one. https://github.com/nlohmann/json is definitely one of the better ones. I've used quite a bit before and never had an issues, although I'm by no means an expert. If you can hack together something that works on the CabbageRack side I can update the Cabbage stuff. Aporpos, the idea would be that users export all .csd file to a single CabbageRack folder? That sounds like a nice solution. In fact, it would be trivial to place a CabbageRack folder into the VCV Plugins dir when installing Cabbage. And each time a user exports, it automatically get places into that very folder.

rorywalsh avatar Nov 03 '21 10:11 rorywalsh

it would be trivial to place a CabbageRack folder into the VCV Plugins dir when installing Cabbage. And each time a user exports, it automatically get places into that very folder.

Consider the use case of a module developer who wants to package multiple modules potentially under separate packages. In their case, the folder should be flexible, within reason, and not make too many hard-coded assumptions.

Perhaps, the "Export as VCV Rack module" workflow could be something like:

  1. prompt user to select a directory (and possibly create an empty directory in the selection process)
  2. if the directory is empty, scaffold a boilerplate plugin with the .csd file
  3. if the folder contains an existing CabbageRack export, place only the .csd file into an existing project

The plugin.so would dynamically register all local .csd files at runtime, perhaps by parsing the contents of plugin.json for the module slugs (as described above).

brylie avatar Nov 03 '21 10:11 brylie

Yes, this sounds good. :+1:

rorywalsh avatar Nov 03 '21 10:11 rorywalsh