1
0

Start Web UI

This commit is contained in:
Geraint 2025-06-25 10:25:57 +01:00
parent e295fadeb4
commit 2efd1de4e9
6 changed files with 101 additions and 4 deletions

View File

@ -39,8 +39,8 @@ set(CLAP_WRAPPER_DONT_ADD_TARGETS TRUE)
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
clap-wrapper clap-wrapper
GIT_REPOSITORY https://github.com/free-audio/clap-wrapper GIT_REPOSITORY https://github.com/geraintluff/clap-wrapper.git
GIT_TAG v0.12.1 # first version with WCLAP stuff GIT_TAG cd666f7d2291d47f810d9c8f123886026a631576
GIT_SHALLOW ON GIT_SHALLOW ON
) )
FetchContent_MakeAvailable(clap-wrapper) FetchContent_MakeAvailable(clap-wrapper)

View File

@ -9,6 +9,7 @@
#include "./param-info.h" #include "./param-info.h"
#include "../storage/storage.h" #include "../storage/storage.h"
#include "../ui/web-ui.h"
namespace stfx { namespace clap { namespace stfx { namespace clap {
@ -121,7 +122,7 @@ template<template<class> class EffectSTFX>
struct Plugin : public clap_plugin { struct Plugin : public clap_plugin {
const Plugins &plugins; const Plugins &plugins;
const clap_host *host; const clap_host *host;
using Effect = stfx::LibraryEffect<float, EffectSTFX>; using Effect = stfx::WebUILibraryEffect<float, EffectSTFX>;
Effect effect; Effect effect;
template<class ...Args> template<class ...Args>
@ -182,7 +183,6 @@ struct Plugin : public clap_plugin {
// CLAP plugin methods // CLAP plugin methods
static bool plugin_init(const clap_plugin *obj) { static bool plugin_init(const clap_plugin *obj) {
auto &plugin = *(Plugin *)obj; auto &plugin = *(Plugin *)obj;
LOG_EXPR(plugin.plugins.modulePath);
return true; return true;
} }
static void plugin_destroy(const clap_plugin *obj) { static void plugin_destroy(const clap_plugin *obj) {
@ -240,6 +240,12 @@ struct Plugin : public clap_plugin {
state_load state_load
}; };
return &ext; return &ext;
} else if (!std::strcmp(extId, CLAP_EXT_WEBVIEW)) {
static struct clap_plugin_webview ext{
webview_provide_starting_uri,
webview_receive
};
return &ext;
} }
return nullptr; return nullptr;
} }
@ -589,6 +595,27 @@ struct Plugin : public clap_plugin {
plugin.effect.state(storage); plugin.effect.state(storage);
return true; return true;
} }
// Just include the proposed draft structs here
static constexpr const char *CLAP_EXT_WEBVIEW = "clap.webview/1";
struct clap_plugin_webview {
bool(CLAP_ABI *provide_starting_uri)(const clap_plugin_t *plugin, char *out_buffer, uint32_t out_buffer_capacity);
bool(CLAP_ABI *receive)(const clap_plugin_t *plugin, const void *buffer, uint32_t size);
};
struct clap_host_webview {
bool(CLAP_ABI *send)(const clap_host_t *host, const void *buffer, uint32_t size);
};
static bool webview_provide_starting_uri(const clap_plugin_t *obj, char *startingUri, uint32_t capacity) {
auto &plugin = *(Plugin *)obj;
if (!plugin.effect.webPage.size() + 1 > capacity) return false;
std::strcpy(startingUri, plugin.effect.webPage.c_str());
return true;
}
static bool webview_receive(const clap_plugin_t *obj, const void *buffer, uint32_t size) {
auto &plugin = *(Plugin *)obj;
plugin.effect.webReceive(buffer, size);
return true;
}
}; };
}} // namespace }} // namespace

1
stfx/ui/html/cbor.min.js vendored Normal file

File diff suppressed because one or more lines are too long

46
stfx/ui/html/generic.html Normal file
View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Generic STFX UI</title>
<style>
body {
width: 100vw;
height: 100vh;
overflow: hidden;
background: linear-gradient(#FFF, #EEE, #CCC);
color: #000;
font-family: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, system-ui, sans-serif;
}
output {
font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
font-weight: normal;
}
</style>
</head>
<body>
{=}
<h1>{name}</h1>
<script src="cbor.min.js"></script>
<script src="matsui-bundle.min.js"></script>
<script>
addEventListener('message', e => {
let state = window.state = Matsui.replace(document.body, CBOR.decode(e.data));
state.trackMerges(merge => {
window.parent.postMessage(CBOR.encode(merge), '*');
}, true/*async*/, false/*include direct merges*/);
addEventListener('message', e => {
state.merge(CBOR.decode(e.data));
});
}, {once: true});
//*
window.dispatchEvent(new MessageEvent('message', {
data: CBOR.encode({name: "Hello 😀"})
}));//*/
window.parent.postMessage(CBOR.encode("ready"), '*');
</script>
</body>
</html>

2
stfx/ui/html/matsui-bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

21
stfx/ui/web-ui.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <string>
namespace stfx {
template<typename Sample, template<class, class...> class EffectSTFX, class... ExtraArgs>
struct WebUILibraryEffect : public LibraryEffect<Sample, EffectSTFX, ExtraArgs...> {
std::string webPage = "generic.html";
int webWidth = 640, webHeight = 480;
using LibraryEffect<Sample, EffectSTFX, ExtraArgs...>::LibraryEffect;
void webReceive(const void *message, size_t size) {
std::cout << "received " << size << " bytes from webview\n";
}
private:
using Super = LibraryEffect<Sample, EffectSTFX, ExtraArgs...>;
};
} // namespace