33#include "IPlugWebView.h" 
   34#include "wdl_base64.h" 
   51  static constexpr int kDefaultMaxJSStringLength = 8192;
 
   68    str.SetFormatted(mMaxJSStringLength, 
"SCVFD(%i, %f)", ctrlTag, normalizedValue);
 
   75    std::vector<char> base64;
 
   76    base64.resize(GetBase64Length(dataSize) + 1);
 
   77    wdl_base64encode(
reinterpret_cast<const unsigned char*
>(pData), base64.data(), dataSize);
 
   78    str.SetFormatted(mMaxJSStringLength, 
"SCMFD(%i, %i, %i, '%s')", ctrlTag, msgTag, dataSize, base64.data());
 
   91    str.SetFormatted(mMaxJSStringLength, 
"SPVFD(%i, %f)", paramIdx, value);
 
   98    std::vector<char> base64;
 
  101      base64.resize(GetBase64Length(dataSize) + 1);
 
  102      wdl_base64encode(
reinterpret_cast<const unsigned char*
>(pData), base64.data(), dataSize);
 
  104    str.SetFormatted(mMaxJSStringLength, 
"SAMFD(%i, %i, '%s')", msgTag, 
static_cast<int>(base64.size()), base64.data());
 
  111    str.SetFormatted(mMaxJSStringLength, 
"SMMFD(%i, %i, %i)", msg.mStatus, msg.mData1, msg.mData2);
 
  120  void SendJSONFromDelegate(
const nlohmann::json& jsonMessage)
 
  127    auto json = nlohmann::json::parse(jsonStr, 
nullptr, 
false);
 
  129    if (json[
"msg"] == 
"SPVFUI")
 
  131      assert(json[
"paramIdx"] > -1);
 
  134    else if (json[
"msg"] == 
"BPCFUI")
 
  136      assert(json[
"paramIdx"] > -1);
 
  139    else if (json[
"msg"] == 
"EPCFUI")
 
  141      assert(json[
"paramIdx"] > -1);
 
  144    else if (json[
"msg"] == 
"SAMFUI")
 
  146      std::vector<unsigned char> base64;
 
  148      if(json.count(
"data") > 0 && json[
"data"].is_string())
 
  150        auto dStr = json[
"data"].get<std::string>();
 
  151        int dSize = 
static_cast<int>(dStr.size());
 
  154        int numPaddingBytes = 0;
 
  156        if(dSize >= 2 && dStr[dSize-2] == 
'=')
 
  158        else if(dSize >= 1 && dStr[dSize-1] == 
'=')
 
  161        base64.resize((dSize * 3) / 4 - numPaddingBytes);
 
  162        wdl_base64decode(dStr.c_str(), base64.data(), 
static_cast<int>(base64.size()));
 
  167    else if(json[
"msg"] == 
"SMMFUI")
 
  169      IMidiMsg msg {0, json[
"statusByte"].get<uint8_t>(),
 
  170                       json[
"dataByte1"].get<uint8_t>(),
 
  171                       json[
"dataByte2"].get<uint8_t>()};
 
  174    else if(json[
"msg"] == 
"SKPFUI")
 
  176      IKeyPress keyPress = ConvertToIKeyPress(json[
"keyCode"].get<uint32_t>(), json[
"utf8"].get<std::string>().c_str(), json[
"S"].get<bool>(), json[
"C"].get<bool>(), json[
"A"].get<bool>());
 
  181  void Resize(
int width, 
int height);
 
  197    msg[
"id"] = 
"params";
 
  198    std::vector<nlohmann::json> params;
 
  199    for (
int idx = 0; idx < 
NParams(); idx++)
 
  204      nlohmann::json paramMsg = nlohmann::json::parse(jsonStr.Get(), 
nullptr, 
true);
 
  205      params.push_back(paramMsg);
 
  207    msg[
"params"] = params;
 
  209    SendJSONFromDelegate(msg);
 
  214  void SetMaxJSStringLength(
int length)
 
  216    mMaxJSStringLength = length;
 
  228#if !defined OS_IOS && defined _DEBUG 
  229    namespace fs = std::filesystem;
 
  231    fs::path mainPath(pathOfPluginSrc);
 
  232    fs::path indexRelativePath = mainPath.parent_path() / 
"Resources" / 
"web" / 
"index.html";
 
  234    LoadFile(indexRelativePath.string().c_str(), 
nullptr);
 
  241  int mMaxJSStringLength = kDefaultMaxJSStringLength;
 
  242  std::function<void()> mEditorInitFunc = 
nullptr;
 
  243  void* mView = 
nullptr;
 
  246  IKeyPress ConvertToIKeyPress(uint32_t keyCode, 
const char* utf8, 
bool shift, 
bool ctrl, 
bool alt)
 
  251  static int GetBase64Length(
int dataSize)
 
  253    return static_cast<int>(4. * std::ceil((
static_cast<double>(dataSize) / 3.)));
 
  256#if defined OS_MAC || defined OS_IOS 
  257  void ResizeWebViewAndHelper(
float width, 
float height);
 
This pure virtual interface delegates communication in both directions between a UI editor and someth...
 
virtual void BeginInformHostOfParamChangeFromUI(int paramIdx)=0
Called by the UI at the beginning of a parameter change gesture, in order to notify the host (via a c...
 
IParam * GetParam(int paramIdx)
Get a pointer to one of the delegate's IParam objects.
 
virtual void SendParameterValueFromUI(int paramIdx, double normalizedValue)
SPVFUI Called by the UI during a parameter change gesture, in order to notify the host of the new val...
 
virtual void EndInformHostOfParamChangeFromUI(int paramIdx)=0
Called by the user interface at the end of a parameter change gesture, in order to notify the host (v...
 
virtual void SendMidiMsgFromUI(const IMidiMsg &msg)
SendMidiMsgFromUI (Abbreviation: SMMFUI) This method should be used when sending a MIDI message from ...
 
virtual void SendArbitraryMsgFromUI(int msgTag, int ctrlTag=kNoTag, int dataSize=0, const void *pData=nullptr)
SendArbitraryMsgFromUI (Abbreviation: SAMFUI)
 
virtual void OnUIOpen()
Override this method to do something before the UI is opened.
 
double ToNormalized(double nonNormalizedValue) const
Convert a real value to normalized value for this parameter.
 
void GetJSON(WDL_String &json, int idx) const
Get a JSON description of the parameter.
 
IWebView is a base interface for hosting a platform web view inside an IPlug plug-in's UI.
 
void EvaluateJavaScript(const char *scriptStr, completionHandlerFunc func=nullptr)
Runs some JavaScript in the webview.
 
void LoadFile(const char *fileName, const char *bundleID="")
Load a file on disk into the web view.
 
An editor delegate base class that uses a platform native webview for the UI.
 
bool OnKeyDown(const IKeyPress &key) override
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
 
void OnMessageFromWebView(const char *jsonStr) override
When a script in the web view posts a message, it will arrive as a UTF8 json string here.
 
void SendArbitraryMsgFromDelegate(int msgTag, int dataSize, const void *pData) override
SendArbitraryMsgFromDelegate (Abbreviation: SAMFD) WARNING: should not be called on the realtime audi...
 
void SendMidiMsgFromDelegate(const IMidiMsg &msg) override
SendMidiMsgFromDelegate (Abbreviation: SMMFD) WARNING: should not be called on the realtime audio thr...
 
void CloseWindow() override
If you are not using IGraphics you can if you need to free resources etc when the window closes.
 
bool OnKeyUp(const IKeyPress &key) override
KeyDown handler, in order to get keystrokes from certain hosts/plugin formats that send key press mes...
 
void SendControlValueFromDelegate(int ctrlTag, double normalizedValue) override
SendControlValueFromDelegate (Abbreviation: SCVFD) WARNING: should not be called on the realtime audi...
 
void LoadIndexHtml(const char *pathOfPluginSrc, const char *bundleid)
Load index.html (from plugin src dir in debug builds, and from bundle in release builds) on desktop N...
 
void OnWebViewReady() override
Called when the web view is ready to receive navigation instructions.
 
void OnParentWindowResize(int width, int height) override
Called by app wrappers when the OS window scaling buttons/resizers are used.
 
void * OpenWindow(void *pParent) override
If you are not using IGraphics, you can implement this method to attach to the native parent view e....
 
void SendControlMsgFromDelegate(int ctrlTag, int msgTag, int dataSize, const void *pData) override
SendControlMsgFromDelegate (Abbreviation: SCMFD) WARNING: should not be called on the realtime audio ...
 
void OnWebContentLoaded() override
Called after navigation instructions have been exectued and e.g.
 
void SendParameterValueFromDelegate(int paramIdx, double value, bool normalized) override
SendParameterValueFromDelegate (Abbreviation: SPVFD) WARNING: should not be called on the realtime au...
 
int DOMKeyToVirtualKey(uint32_t domKeyCode)
Converts a DOM virtual key code to an iPlug2 virtual key code.
 
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
 
Encapsulates a MIDI message and provides helper functions.