15#include <emscripten.h>
16#include <emscripten/bind.h>
19using namespace emscripten;
21static const int kNumMsgHeaderBytes = 6;
22static const int kNumSPVFUIBytes = 18;
23static const int kNumSMMFUIBytes = 9;
24static const int kNumSSMFUIBytes = 10;
25static const int kNumSAMFUIBytes = 18;
27IPlugWeb::IPlugWeb(
const InstanceInfo& info,
const Config& config)
30 mSPVFUIBuf.Resize(kNumSPVFUIBytes); memcpy(mSPVFUIBuf.GetData(),
"SPVFUI", kNumMsgHeaderBytes);
31 mSMMFUIBuf.Resize(kNumSMMFUIBytes); memcpy(mSMMFUIBuf.GetData(),
"SMMFUI", kNumMsgHeaderBytes);
32 mSSMFUIBuf.Resize(kNumSSMFUIBytes); memcpy(mSSMFUIBuf.GetData(),
"SSMFUI", kNumMsgHeaderBytes);
33 mSAMFUIBuf.Resize(kNumSAMFUIBytes); memcpy(mSAMFUIBuf.GetData(),
"SAMFUI", kNumMsgHeaderBytes);
35 mWAMCtrlrJSObjectName.SetFormatted(32,
"%s_WAM", GetPluginName());
38void IPlugWeb::SendParameterValueFromUI(
int paramIdx,
double value)
41 int pos = kNumMsgHeaderBytes;
42 *((
int*)(mSPVFUIBuf.
GetData() + pos)) = paramIdx; pos +=
sizeof(int);
43 *((
double*)(mSPVFUIBuf.
GetData() + pos)) = value; pos +=
sizeof(double);
46 var jsbuff = Module.HEAPU8.subarray($0, $0 + $1);
48 }, (int) mSPVFUIBuf.
GetData(), kNumSPVFUIBytes);
51 val::global(mWAMCtrlrJSObjectName.Get()).call<
void>(
"setParam", paramIdx, value);
53 IPlugAPIBase::SendParameterValueFromUI(paramIdx, value);
56void IPlugWeb::SendMidiMsgFromUI(
const IMidiMsg& msg)
59 int pos = kNumMsgHeaderBytes;
60 mSMMFUIBuf.
GetData()[pos] = msg.mStatus; pos++;
61 mSMMFUIBuf.
GetData()[pos] = msg.mData1; pos++;
62 mSMMFUIBuf.
GetData()[pos] = msg.mData2; pos++;
65 var jsbuff = Module.HEAPU8.subarray($0, $0 + $1);
67 }, (int) mSMMFUIBuf.
GetData(), kNumSMMFUIBytes);
71 dataStr.SetFormatted(16,
"%i:%i:%i", msg.mStatus, msg.mData1, msg.mData2);
72 val::global(mWAMCtrlrJSObjectName.Get()).call<
void>(
"sendMessage", std::string(
"SMMFUI"), std::string(dataStr.Get()));
76void IPlugWeb::SendSysexMsgFromUI(
const ISysEx& msg)
78 DBGMSG(
"TODO: SendSysexMsgFromUI");
103void IPlugWeb::SendArbitraryMsgFromUI(
int msgTag,
int ctrlTag,
int dataSize,
const void* pData)
105 mSAMFUIBuf.
Resize(kNumSAMFUIBytes + dataSize);
106 int pos = kNumMsgHeaderBytes;
108 *((
int*)(mSAMFUIBuf.
GetData() + pos)) = msgTag; pos +=
sizeof(int);
109 *((
int*)(mSAMFUIBuf.
GetData() + pos)) = ctrlTag; pos +=
sizeof(int);
110 *((
int*)(mSAMFUIBuf.
GetData() + pos)) = dataSize; pos +=
sizeof(int);
112 memcpy(mSAMFUIBuf.
GetData() + pos, pData, dataSize);
116 var jsbuff = Module.HEAPU8.subarray($0, $0 + $1);
121 if(typeof window[Module.UTF8ToString($0)] ===
'undefined' ) {
122 console.log(
"warning - SAMFUI called before controller exists");
125 window[Module.UTF8ToString($0)].sendMessage(
'SAMFUI',
"", Module.HEAPU8.slice($1, $1 + $2).buffer);
127 }, mWAMCtrlrJSObjectName.Get(), (
int) mSAMFUIBuf.
GetData() + kNumMsgHeaderBytes, mSAMFUIBuf.
Size() - kNumMsgHeaderBytes);
131void IPlugWeb::SendDSPIdleTick()
134 if(typeof window[Module.UTF8ToString($0)] ===
'undefined' ) {
135 console.log(
"warning - SendDSPIdleTick called before controller exists");
138 window[Module.UTF8ToString($0)].sendMessage(
"TICK",
"", 0.);
140 }, mWAMCtrlrJSObjectName.Get());
143extern std::unique_ptr<IPlugWeb> gPlug;
147static void _SendArbitraryMsgFromDelegate(
int msgTag,
int dataSize, uintptr_t pData)
149 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
150 gPlug->SendArbitraryMsgFromDelegate(msgTag, dataSize, pDataPtr);
153static void _SendControlMsgFromDelegate(
int ctrlTag,
int msgTag,
int dataSize, uintptr_t pData)
155 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
156 gPlug->SendControlMsgFromDelegate(ctrlTag, msgTag, dataSize, pDataPtr);
159static void _SendControlValueFromDelegate(
int ctrlTag,
double normalizedValue)
161 gPlug->SendControlValueFromDelegate(ctrlTag, normalizedValue);
164static void _SendParameterValueFromDelegate(
int paramIdx,
double normalizedValue)
166 gPlug->SendParameterValueFromDelegate(paramIdx, normalizedValue,
true);
169static void _SendMidiMsgFromDelegate(
int status,
int data1,
int data2)
171 IMidiMsg msg {0, (uint8_t) status, (uint8_t) data1, (uint8_t) data2};
172 gPlug->SendMidiMsgFromDelegate(msg);
175static void _SendSysexMsgFromDelegate(
int dataSize, uintptr_t pData)
177 const uint8_t* pDataPtr =
reinterpret_cast<uint8_t*
>(pData);
178 ISysEx msg(0, pDataPtr, dataSize);
179 gPlug->SendSysexMsgFromDelegate(msg);
182static void _StartIdleTimer()
184 gPlug->CreateTimer();
188 function(
"SPVFD", &_SendParameterValueFromDelegate);
189 function(
"SAMFD", &_SendArbitraryMsgFromDelegate);
190 function(
"SCMFD", &_SendControlMsgFromDelegate);
191 function(
"SCVFD", &_SendControlValueFromDelegate);
192 function(
"SMMFD", &_SendMidiMsgFromDelegate);
193 function(
"SSMFD", &_SendSysexMsgFromDelegate);
194 function(
"StartIdleTimer", &_StartIdleTimer);
uint8_t * GetData()
Gets a ptr to the chunk data.
int Size() const
Returns the current size of the chunk.
int Resize(int newSize)
Resizes the chunk.
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
This is used for the UI "editor" - controller side of a WAM or remote editors that communicate with d...
Encapsulates a MIDI message and provides helper functions.
A struct for dealing with SysEx messages.