mrg icon indicating copy to clipboard operation
mrg copied to clipboard

Automatic binding events to parsed SVG nodes

Open frink opened this issue 6 years ago • 2 comments

So I'm looking to build some an audio plugin construction environment with Faust (compiles to C or C++) and I'm looking for a better way to do interfaces than their ugly defaults. Mrg seems near perfect for my use case...

My idea is that each plugin will be compiled from a few files:

  • plugin_name/index.dsp
  • plugin_name/index.svg
  • plugin_name/index.css
  • plugin_name/.

Theses would all get built into a single file VST or LV2 by encapsulating everything in C

I'd like to write some glue code that auto detects names in SVG and binds them to the Faust program defining knobs, sliders, buttons, and graph interfaces. This is where I'm running into problems as buttons get pressed, knobs get turned, sliders get slid etc...

Am I barking up the wrong tree here or is this the sort of thing that mrg is trying to solve? It there a way to automatically bind events based on id/class?

frink avatar May 16 '19 05:05 frink

Binding events automatically to id's is not something I have attempted. The primary architectural point of mrg is interleaving action callback registration with drawing commands. The SVG rendering capabilities has received little attention; they mostly came for free with implementing the rest close to how CSS layout works with single pass HTML layout.

The current simple XML parser do some hooking up of events for <a href=..> in HTML and not more, as it is translating from XML to immediate mode drawing while driving the immediate mode renderer/layout engine of mrg. To make what you outline above work you'd have to implement your own inspired by how mrg does it itself. Doing it ad-hoc for a domain specific use, like property updates seem easier than coming up with a generic way of handling this, that also would work with bindings to dynamic languages.

Automatically binding events would be interesting and I'd merge patches for doing that - I'd be particularly thrilled if this ended up being possible to use both from C and dynamic languages binding it like lua (which I am currently using).

hodefoting avatar May 16 '19 09:05 hodefoting

I'm a big fan of Lua myself and love the concept of what you're doing with leveraging web UI design with more low level C while not bringing in the entire bloated browser stack as a dependency. My thought is binding events to XML/HTML/SVG ids allows a familiar paradigm. (like the browser does in JavaScript) While I'd expect the binding to be done in C.

Here's how I think the flow should work:

  1. Application Thread Spawns Display Thread
  2. Display Thread Loads and Parses the XML
  3. Display Thread Adds Events to Parsed XML
  4. Display Thread Loads and Parses CSS
  5. Display Thread Starts Render Loop
  6. Application Thread Sends Values to Display Thread
  7. Display Thread Sends Updated Values to Application Thread

Obviously, one of my goals is complete process separation from Application and Display to avoid blocking. Besides audio, there are a ton of fields where this is needed in real time monitoring applications. For a while I was looking at Dear Imgui for the simplicity of doing this. Then I looked for a while at Nuklear because it draws cleaner from vectors. But ultimately, the conclusion was some XML+CSS combo that handled events more efficient than a browser. That's how I found you.

I'm also trying to find a simple versatile process for GUIs based on vector rendering with as little dependencies as possible. Looking at PUGL as a possible alternate backend. Ideally, I'd be able to bring entire dependency tree into one .dll/.so. If it wasn't LGPL I could statically compile but linked it probably better for most use cases...

Bottom line: I need to fork Mrg and add the automatic binding code...

frink avatar May 16 '19 14:05 frink