Skip to content

Commit

Permalink
Start clap.web draft
Browse files Browse the repository at this point in the history
  • Loading branch information
geraintluff committed Nov 21, 2024
1 parent 50f004f commit 926d15e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/clap/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
#include "ext/draft/tuning.h"
#include "ext/draft/undo.h"
#include "ext/draft/scratch-memory.h"
#include "ext/draft/web.h"
52 changes: 52 additions & 0 deletions include/clap/ext/draft/web.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

static CLAP_CONSTEXPR const char CLAP_EXT_WEB[] = "clap.web/1";

#ifdef __cplusplus
extern "C" {
#endif

/// @page Web
///
/// This extension enables the plugin to provide the start-page for a webview UI, and exchange
/// messages back and forth.
///
/// Messages are received in the webview using a standard MessageEvent, with the data in an
/// ArrayBuffer. They are posted back to the plugin using window.parent.postMessage(), with the
/// data in an ArrayBuffer or TypedArray.

typedef struct clap_plugin_web {
// Returns the URL for the webview's initial navigation, as a null-terminated UTF-8 string.
// If this URL is relative, it is resolved relative to the plugin (bundle) directory, and
// cannot be outside it. The host may use any protocol to serve this content, and the page
// must not assume that the root of the domain is the root of the bundle. The URL may also be
// absolute, including a `file://` URL.
// Returns true on success.
// [main-thread]
bool(CLAP_ABI *get_start)(const clap_plugin_t *plugin,
char *out_buffer,
uint32_t out_buffer_capacity);

// Receives a single message from the webview.
// Returns true on success.
// [main-thread]
bool(CLAP_ABI *receive)(const clap_plugin_t *plugin, const void *buffer, uint32_t size);

} clap_plugin_web_t;

typedef struct clap_host_web {
// Checks whether the webview is open (and ready to receive messages)
// [thread-safe]
bool(CLAP_ABI *is_open)(const clap_host_t *host);

// Sends a single message to the webview.
// It must not allocate or block if called from the audio thread.
// Returns true on success.
// [thread-safe]
bool(CLAP_ABI *send)(const clap_host_t *host, const void *buffer, uint32_t size);

} clap_host_web_t;

#ifdef __cplusplus
}
#endif

0 comments on commit 926d15e

Please sign in to comment.