DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
DSParkWebViewEditor.h File Reference

WebView editor layer: plugin GUIs written in HTML/CSS/JS, embedded in the host window through the platform web engine. More...

#include "../DSParkPlugin.h"
#include <atomic>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
Include dependency graph for DSParkWebViewEditor.h:

Go to the source code of this file.

Classes

struct  dspark::plugin::webview_ui::PostArgs
 One decoded bridge message: [op, id?, value?]. More...
 
struct  dspark::plugin::webview_ui::HostCallbacks
 How the editor reaches back into the format wrapper. Plain function pointers + context (no std::function, no virtuals): the wrapper translates to its format's gesture/automation calls and to the user's setParameter. All calls arrive on the host's main/UI thread, in PLAIN parameter values. More...
 
class  dspark::plugin::webview_ui::Editor< P >
 One embedded WebView editor instance for plugin class P. Owned by the format backends (the VST3 IPlugView object, the CLAP gui extension); plugin authors never touch this class - they only provide editorHtml() and friends. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 
namespace  dspark::plugin
 
namespace  dspark::plugin::webview_ui
 

Macros

#define DSPARK_PLUGIN_WEBVIEW   1
 
#define DSPARK_WEBVIEW_BACKEND   0
 

Functions

void dspark::plugin::webview_ui::debugLog (const char *format,...) noexcept
 
void dspark::plugin::webview_ui::appendJsonString (std::string &out, const char *s)
 Appends a JSON string literal (quotes included, control chars escaped).
 
void dspark::plugin::webview_ui::appendJsonNumber (std::string &out, double v)
 Appends a JSON number, immune to the process locale.
 
const char * dspark::plugin::webview_ui::parseJsonNumber (const char *s, double &out) noexcept
 Locale-independent number parse; returns the end pointer or nullptr.
 
bool dspark::plugin::webview_ui::parsePostArgs (const char *s, PostArgs &out) noexcept
 Parses the bridge's JSON array of scalars (op + optional id/number).
 

Variables

constexpr const char * dspark::plugin::webview_ui::kBridgeJs
 

Detailed Description

WebView editor layer: plugin GUIs written in HTML/CSS/JS, embedded in the host window through the platform web engine.

Opt-in and additive: include this header BEFORE the format headers, set hasEditor = true and serve your page from editorHtml() - the VST3, CLAP and AU backends then embed it inside the window the host provides (AU through a Cocoa view factory announced via kAudioUnitProperty_CocoaUI). Nothing else in the plugin class changes; plugins without this header keep building exactly as before.

struct MyPlugin
{
// ... descriptor / parameters / prepare / setParameter / processBlock ...
static constexpr bool hasEditor = true;
static constexpr dspark::plugin::EditorSize editorSize { 560, 330 };
static constexpr bool editorResizable = true; // optional
static const char* editorHtml() { return R"(<!doctype html>...)"; }
};
Native CLAP backend: the same plugin class, one more macro.
Native VST3 backend: a complete plugin from one DSPark plugin class.
WebView editor layer: plugin GUIs written in HTML/CSS/JS, embedded in the host window through the pla...
Editor window size in logical pixels (physical = logical x host scale).

The page talks to the DSP through a tiny injected bridge (same stable text ids as state and automation):

dspark.onReady(params => { ... }); // parameter table + current values
dspark.setParam("drive", 6.0); // UI -> DSP (plain value)
dspark.onParam("drive", v => { ... }); // DSP/automation -> UI (~30 Hz)
dspark.beginEdit("drive"); // host automation gesture (undo)
dspark.endEdit("drive");
dspark.getParam("drive"); dspark.params; // cached value / metadata

Platform engines:

  • Windows - WebView2 (Edge runtime, present on Win10/11) through the vendored MIT webview library (webview/webview.h), embedded as a child window of the host's HWND. Requires exceptions enabled (plugins are).
  • macOS - WKWebView created directly through the Objective-C runtime (no headers, WebKit.framework loaded at runtime) and added as a subview of the host's NSView.
  • Linux - WebKitGTK (GTK3) resolved entirely through dlopen at runtime (no headers, no link-time dependency), embedded in the host's X11 window with GtkPlug/XEmbed - the same route LV2's suil takes. GTK is driven from the HOST's run loop through Editor::pump() (VST3 IRunLoop timers / CLAP timer-support); a plugin must never spin its own GTK main loop. Systems without WebKitGTK (or hosts without a usable run loop) keep the host's generic parameter UI - the same plugin binary, unchanged.

Threading: every editor call (create/destroy/resize/JS callbacks) runs on the host's main/UI thread. Values flow UI -> DSP through the wrapper's normalized shadows and the user's atomic setParameter (any-thread safe by contract), and DSP -> UI by polling those shadows at ~30 Hz from the page - no native timers, no locks, no allocation on the audio thread.

Definition in file DSParkWebViewEditor.h.

Macro Definition Documentation

◆ DSPARK_PLUGIN_WEBVIEW

#define DSPARK_PLUGIN_WEBVIEW   1

Definition at line 72 of file DSParkWebViewEditor.h.

◆ DSPARK_WEBVIEW_BACKEND

#define DSPARK_WEBVIEW_BACKEND   0

Definition at line 120 of file DSParkWebViewEditor.h.