VCV Prototype

I probably won’t add a Python engine due to the difficulty of embedding Python into an application.

  • Handling multiple interpreter contexts being called from arbitrary threads is not a well-supported use-case of Python, and the Global Interpreter Lock is an imperfect, sparsely-documented, and complex solution.
  • Python shared objects such as the math.cpython*.so module call libpython functions, but Rack dlopen()s plugins with RTLD_LOCAL, so the module can’t find the libpython symbols. This might be worked around, but it would be a nasty solution. This issue has been discovered by many, such as https://bugs.python.org/issue4434 and https://bugs.python.org/issue36753.
  • If Numpy and Scipy were included, the package would be ~100MB larger and 10,000+ files.

Regardless, I’ve added PythonEngine.cpp to the repo in case anyone wants to pick up the work. It might even be easier to add Julia, which would also be a mess.

2 Likes

I’ve been a Python programmer for over 20 years. I love Python. I applaud your choice here though; Python is good at a lot of things, but not everything, and it’s not a good fit here.

1 Like

Python/Scipy would be a good fit for script writers, but CPython is not designed to be embedded. The ability was added as an afterthought so it’s priority #10000 for the project, not #1 like Duktape or QuickJS.

I agree, Python the language would be nice, but as you indicate, the CPython implementation can’t play well here. I’m looking forward to learning something new anyway :slight_smile:

Is there a tutorial for JavaScript that is specific to VCV Prototype? Some more sample code would be nice as well.
I want to use it to replace the arcane arrangements of adders, comparators and Frank Buss Formulas that I used here: https://youtu.be/KyBrSXecYmE?t=4289 (I linked to the end of that piece because the rest of the video only shows a small amount of the patch)
Thanks.

while not a tutorial, the README has a well documented simple script that shows all of the variables available and how to access them:

I wrote some for a project similar to VCV-Prototype a while back, I’ll see about getting them ported. you might find VCV Prototype: Share your prototypes interesting, as others have been sharing what they’ve come up with.

1 Like

I’ve started working with prototype and for the most part it’s going okay. There are certain workflow issues that I need to sort out (I’m using notepad to code with and that’s not great) and the familiar sensation of dealing with bugs (“wait, what? Why isn’t that working”) is returning to me.
One thing that doesn’t appear to be explained in the docs is the bufferindex parameter. In fact, i’m not really clear on what “buffers” are for in this context?
Other than that i’ve replaced about three rows of modules with one module and it’s looking okay so far.

If you can stand a new tool, Visual Studio Code (free, of course) will be a much better editor for JS. You won’t have to learn many/any features to just start using it.

2 Likes

process() is called every N samples, where N is set by config.bufferSize and read from block.bufferSize. It stores the last N samples received in the array block.inputs[i], and your goal is to fill the array block.outputs[i]. Buffers are easier to work with and better performance than sample-by-sample state.

1 Like

Added the Lua script engine. Will be available in the next Prototype release.

8 Likes

I think what I want is just a fairly simple text editor that has auto indent and syntax highlighting. I’m somewhat “old school”.
Anyway, all the stuff that I did with Formulas, adders and comparitors (amoungst other stuff) I’m doing with Prototype and it works okay. Problems?

  • Please let me send several separate lines of text to the display.
  • I’m tempted to ask for polyphonic ports but I’m not sure how that would work. However…
  • Please can we have either more ports or a simple extension module that gives you another 6 sets of things and lets you keep adding more extensions. The problem being that there is no amount of ports that is “enough”.
  • Minor thing: I was expecting the buttons to be slightly simpler to use. Like, they’d toggle on and off and give me a true or false value.

Thanks

7 posts were split to a new topic: Text editors

Isolated sub-interpretes in embedded python can be challenging … I also had a look at https://pybind11.readthedocs.io/en/stable/advanced/embedding.html Maybe its easier embedding with CFFI https://cffi.readthedocs.io/en/latest/embedding.html I’ll have a look at it. I’m a little bit rusty with C++ …but I’ll get along.

GIL isn’t really the blocker here. Various crashes with Numpy, and the build system on Mac/Windows is. See https://github.com/VCVRack/VCV-Prototype/blob/master/src/PythonEngine.cpp#L13 and propose patches in the issue tracker if you want to push this along.

Any plans to support polyphony? After writing my script I realized that Prototype isn’t polyphonic so I will try switching to Formula.

How would that work? outputs[i][blockIndex][channel]? What about backwards compatibility? What about performance being 16x worse?

1 Like

in the case of javascript, it wouldn’t be 16x worse, given that the transition between c++ and javascript is still fairly expensive, even with quickjs (though not as expensive as v8). if I had to make an educated guess, I’d say 4x worse. I can’t make those guesses for other languages though.

that said, for backward compatibility, it could be a configuration option:

config.polyphonic = true

where default would be false. someone could make a proposal and if it made sense across enough languages and were performant enough, it might be doable.

What I’m doing is inexpensive and isn’t audio rate (calculations based on the notes being played on a keyboard), so I’m not too concerned about performance.

But presumably there would a config variable with the number of channels currently in use, so you wouldn’t pay the cost for computing channels you’re not using?

I have added support for Vult language. If anyone wants to test it, you can find it in my fork https://github.com/modlfo/VCV-Prototype

15 Likes

I’ve added preliminary support for Csound, but there is an issue. Csound is LGPL licensed. As far as I know this means it can’t be statically linked. Does that mean Csound support is a no-no in this case or is there some way we can make it work?