Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
clap_webview.hpp
Go to the documentation of this file.
1#pragma once
2
3// CLAP Draft Webview Extension for Pulp
4// Implements clap.ext.draft.webview (CLAP v1.2.7+) for WCLAP UIs.
5//
6// This is the primary way WCLAPs provide a GUI, since it requires no
7// platform-specific view handles or headers. The host provides a webview,
8// and the plugin provides HTML/JS/CSS content to render in it.
9//
10// The webview extension works alongside clap.gui:
11// - Plugins implement clap_plugin_webview to provide content
12// - Hosts implement clap_host_webview to provide the webview
13// - WCLAP bridge translates webview → clap.gui for native hosts
14//
15// Reference: https://github.com/free-audio/clap/blob/main/include/clap/ext/draft/webview.h
16
17#include <cstdint>
18#include <string>
19#include <functional>
20
22
23// Extension ID (from CLAP draft spec)
24static constexpr const char* CLAP_EXT_WEBVIEW = "clap.webview/1";
25static constexpr const char* CLAP_WINDOW_API_WEBVIEW = "webview";
26
27// Plugin-side webview extension
28// Provides content for the host's webview
30 std::string url; // URL to navigate to (for remote content)
31 std::string html; // Inline HTML (alternative to URL)
32 uint32_t preferred_width = 400;
33 uint32_t preferred_height = 300;
34 bool resizable = true;
35};
36
37// Callback for JS→C++ communication from the webview
38using WebviewMessageCallback = std::function<void(const std::string& message_json)>;
39
40// Plugin webview interface
41// Implement this on your Processor to provide webview-based UI
43public:
44 virtual ~WebviewProvider() = default;
45
46 // Return the webview content (HTML or URL)
48
49 // Called when the webview sends a message to the plugin
50 virtual void on_webview_message(const std::string& message_json) {
51 (void)message_json;
52 }
53
54 // Called when the webview is shown/hidden
55 virtual void on_webview_show(bool visible) { (void)visible; }
56
57 // Send a message from the plugin to the webview
58 // (Set by the host when the webview is created)
60 send_to_webview_ = std::move(cb);
61 }
62
63protected:
64 // Call this to send a JSON message to the webview
65 void send_message(const std::string& json) {
66 if (send_to_webview_) send_to_webview_(json);
67 }
68
69private:
70 WebviewMessageCallback send_to_webview_;
71};
72
73// Auto-generate a simple webview UI from parameters
74// Returns HTML that creates knobs/sliders for each parameter
75// and communicates via postMessage for parameter changes
76std::string generate_webview_html(const std::string& plugin_name,
77 const std::string& params_json);
78
79} // namespace pulp::format::wclap
Definition clap_webview.hpp:42
void send_message(const std::string &json)
Definition clap_webview.hpp:65
virtual void on_webview_show(bool visible)
Definition clap_webview.hpp:55
virtual WebviewContent get_webview_content() const =0
virtual void on_webview_message(const std::string &message_json)
Definition clap_webview.hpp:50
void set_message_callback(WebviewMessageCallback cb)
Definition clap_webview.hpp:59
Definition clap_webview.hpp:21
std::string generate_webview_html(const std::string &plugin_name, const std::string &params_json)
static constexpr const char * CLAP_WINDOW_API_WEBVIEW
Definition clap_webview.hpp:25
static constexpr const char * CLAP_EXT_WEBVIEW
Definition clap_webview.hpp:24
std::function< void(const std::string &message_json)> WebviewMessageCallback
Definition clap_webview.hpp:38
Definition clap_webview.hpp:29
uint32_t preferred_height
Definition clap_webview.hpp:33
std::string html
Definition clap_webview.hpp:31
bool resizable
Definition clap_webview.hpp:34
uint32_t preferred_width
Definition clap_webview.hpp:32
std::string url
Definition clap_webview.hpp:30