11#include "IPlugWasmUI.h"
15#include <emscripten.h>
16#include <emscripten/bind.h>
19using namespace emscripten;
21#if defined OS_WEB && defined NO_IGRAPHICS
22void StartMainLoopTimer()
27IPlugWasmUI::IPlugWasmUI(
const InstanceInfo& info,
const Config& config)
30 mControllerName.SetFormatted(32,
"%s_Hybrid", GetPluginName());
33void IPlugWasmUI::SendParameterValueFromUI(
int paramIdx,
double value)
37 if (typeof window.iPlugController !==
'undefined') {
38 window.iPlugController.setParam($0, $1);
40 console.warn(
'IPlugWasmUI: controller not ready');
45 IPlugAPIBase::SendParameterValueFromUI(paramIdx, value);
48void IPlugWasmUI::SendMidiMsgFromUI(
const IMidiMsg& msg)
51 if (typeof window.iPlugController !==
'undefined') {
52 window.iPlugController.sendMidi($0, $1, $2);
54 console.warn(
'IPlugWasmUI: controller not ready');
56 }, msg.mStatus, msg.mData1, msg.mData2);
59void IPlugWasmUI::SendSysexMsgFromUI(
const ISysEx& msg)
62 if (typeof window.iPlugController !==
'undefined') {
63 var data = new Uint8Array($1);
64 data.set(HEAPU8.subarray($0, $0 + $1));
65 window.iPlugController.sendSysex(data);
67 console.warn(
'IPlugWasmUI: controller not ready');
69 },
reinterpret_cast<intptr_t
>(msg.mData), msg.mSize);
72void IPlugWasmUI::SendArbitraryMsgFromUI(
int msgTag,
int ctrlTag,
int dataSize,
const void* pData)
74 if (dataSize > 0 && pData)
77 if (typeof window.iPlugController !==
'undefined') {
78 var data = new Uint8Array($2);
79 data.set(HEAPU8.subarray($3, $3 + $2));
80 window.iPlugController.sendArbitraryMsg($0, $1, data);
82 console.warn(
'IPlugWasmUI: controller not ready');
84 }, msgTag, ctrlTag, dataSize,
reinterpret_cast<intptr_t
>(pData));
89 if (typeof window.iPlugController !==
'undefined') {
90 window.iPlugController.sendArbitraryMsg($0, $1, null);
95 IPlugAPIBase::SendArbitraryMsgFromUI(msgTag, ctrlTag, dataSize, pData);
98void IPlugWasmUI::SendDSPIdleTick()
101 if (typeof window.iPlugController !==
'undefined') {
102 window.iPlugController.sendIdleTick();
107bool IPlugWasmUI::EditorResize(
int width,
int height)
109 SetEditorSize(width, height);
112 if (typeof window.__iPlugWasmEditorResize ===
'function') {
113 window.__iPlugWasmEditorResize($0, $1);
121extern std::unique_ptr<iplug::IPlugWasmUI> gPlug;
130static int gPendingParentWindowW = 0;
131static int gPendingParentWindowH = 0;
133extern "C" EMSCRIPTEN_KEEPALIVE
void IPlugWasmUI_ApplyPendingParentWindowResize()
135 if (gPlug && gPendingParentWindowW > 0 && gPendingParentWindowH > 0)
137 gPlug->OnParentWindowResize(gPendingParentWindowW, gPendingParentWindowH);
138 gPendingParentWindowW = 0;
139 gPendingParentWindowH = 0;
144static void _SendParameterValueFromDelegate(
int paramIdx,
double normalizedValue)
146 gPlug->SendParameterValueFromDelegate(paramIdx, normalizedValue,
true);
149static void _SendControlValueFromDelegate(
int ctrlTag,
double normalizedValue)
151 gPlug->SendControlValueFromDelegate(ctrlTag, normalizedValue);
154static void _SendControlMsgFromDelegate(
int ctrlTag,
int msgTag,
int dataSize, uintptr_t pData)
156 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
157 gPlug->SendControlMsgFromDelegate(ctrlTag, msgTag, dataSize, pDataPtr);
160static void _SendArbitraryMsgFromDelegate(
int msgTag,
int dataSize, uintptr_t pData)
162 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
163 gPlug->SendArbitraryMsgFromDelegate(msgTag, dataSize, pDataPtr);
166static void _SendMidiMsgFromDelegate(
int status,
int data1,
int data2)
168 IMidiMsg msg{0, (uint8_t)status, (uint8_t)data1, (uint8_t)data2};
169 gPlug->SendMidiMsgFromDelegate(msg);
172static void _SendSysexMsgFromDelegate(
int dataSize, uintptr_t pData)
174 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
175 ISysEx msg(0, pDataPtr, dataSize);
176 gPlug->SendSysexMsgFromDelegate(msg);
179static void _StartIdleTimer()
181 gPlug->CreateTimer();
184static void _OnParentWindowResize(
int width,
int height)
188 gPlug->OnParentWindowResize(width, height);
194 gPendingParentWindowW = width;
195 gPendingParentWindowH = height;
200 function(
"SPVFD", &_SendParameterValueFromDelegate);
201 function(
"SCVFD", &_SendControlValueFromDelegate);
202 function(
"SCMFD", &_SendControlMsgFromDelegate);
203 function(
"SAMFD", &_SendArbitraryMsgFromDelegate);
204 function(
"SMMFD", &_SendMidiMsgFromDelegate);
205 function(
"SSMFD", &_SendSysexMsgFromDelegate);
206 function(
"StartIdleTimer", &_StartIdleTimer);
207 function(
"OnParentWindowResize", &_OnParentWindowResize);
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Hybrid UI class - IGraphics side for split DSP/UI builds.
Encapsulates a MIDI message and provides helper functions.
A struct for dealing with SysEx messages.