12#include "IPlugAPP_host.h"
17#include "IPlugSWELLTimer.h"
18#if defined WEBVIEW_EDITOR_DELEGATE
19extern "C" void IPlugLinuxWebViewPump();
23#if defined OS_MAC || defined OS_LINUX
24#include <IPlugSWELL.h>
26extern float GetScaleForHWND(HWND hWnd);
33IPlugAPP::IPlugAPP(
const InstanceInfo& info,
const Config& config)
39 Trace(TRACELOC,
"%s%s", config.pluginName, config.channelIOStr);
41 SetChannelConnections(ERoute::kInput, 0, MaxNChannels(ERoute::kInput),
true);
42 SetChannelConnections(ERoute::kOutput, 0, MaxNChannels(ERoute::kOutput),
true);
44 SetBlockSize(DEFAULT_BLOCK_SIZE);
47 mTimer.reset(SWELLTimer::Create([
this](
Timer&) {
49 CloseWindowIfRequested();
52#if defined WEBVIEW_EDITOR_DELEGATE
53 IPlugLinuxWebViewPump();
63 bool parentResized =
false;
65 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
67 #if defined OS_MAC || defined OS_LINUX || defined NO_IGRAPHICS
68 RECT rcClient, rcWindow;
71 GetClientRect(gHWND, &rcClient);
72 GetWindowRect(gHWND, &rcWindow);
74 ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
75 ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
81 float ss = GetScaleForHWND(gHWND);
82 #elif defined OS_LINUX
83 flags = SWP_NOMOVE | SWP_NOZORDER;
86 const float containerScale = IPlugAPPHost::ResolveLinuxScreenScale(gHWND);
87 const int containerWidth =
static_cast<int>(std::lround(viewWidth * containerScale));
88 const int containerHeight =
static_cast<int>(std::lround(viewHeight * containerScale));
94 const int containerWidth = viewWidth;
95 const int containerHeight = viewHeight;
98 SetWindowPos(gHWND, 0,
99 static_cast<LONG
>(rcWindow.left * ss),
100 static_cast<LONG
>((rcWindow.bottom - containerHeight - ptDiff.y) * ss),
101 static_cast<LONG
>((containerWidth + ptDiff.x) * ss),
102 static_cast<LONG
>((containerHeight + ptDiff.y) * ss), flags);
103 parentResized =
true;
106 SetEditorSize(viewWidth, viewHeight);
109 return parentResized;
123 std::vector<uint8_t> message;
124 message.push_back(msg.mStatus);
125 message.push_back(msg.mData1);
126 message.push_back(msg.mData2);
128 mAppHost->mMidiOut->sendMessage(&message);
141 std::vector<uint8_t> message;
143 for (
int i = 0; i < msg.mSize; i++)
145 message.push_back(msg.mData[i]);
148 mAppHost->mMidiOut->sendMessage(&message);
155void IPlugAPP::SendSysexMsgFromUI(
const ISysEx& msg)
160void IPlugAPP::AppProcess(
double** inputs,
double** outputs,
int nFrames)
165 bool allInputsConnected =
true;
167 for (
int i = 0; i < nInputs; i++)
169 const bool connected = inputs[i] !=
nullptr;
170 allInputsConnected &= connected;
173 SetChannelConnections(ERoute::kInput, i, 1, connected);
176 if (!allInputsConnected)
177 ZeroScratchBuffers();
179 for (
int i = 0; i < nInputs; i++)
182 AttachBuffers(ERoute::kInput, i, 1, &inputs[i],
GetBlockSize());
185 SetChannelConnections(ERoute::kOutput, 0,
MaxNChannels(ERoute::kOutput),
true);
189 if (mAppHost->mSendAllNotesOff.exchange(
false))
191 for (
int chan = 0; chan < 16; chan++)
203 while (mMidiMsgsFromCallback.
Pop(msg))
206 mMidiMsgsFromProcessor.Push(msg);
214 while (mSysExMsgsFromCallback.
Pop(data))
216 ISysEx msg { data.mOffset, data.mData, data.mSize };
218 mSysExDataFromProcessor.Push(data);
222 if (mMidiMsgsFromEditor.ElementsAvailable())
226 while (mMidiMsgsFromEditor.Pop(msg))
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
A class that hosts an IPlug as a standalone app and provides Audio/Midi I/O.
bool SendSysEx(const ISysEx &msg) override
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
bool SendMidiMsg(const IMidiMsg &msg) override
Send a single MIDI message // TODO: info about what thread should this be called on or not called on!
bool EditorResize(int viewWidth, int viewHeight) override
Implementations call into the APIs resize hooks returns a bool to indicate whether the DAW or plugin ...
The base class for IPlug Audio Processing.
virtual void ProcessMidiMsg(const IMidiMsg &msg)
Override this method to handle incoming MIDI messages.
bool IsChannelConnected(ERoute direction, int chIdx) const
virtual void ProcessSysEx(const ISysEx &msg)
Override this method to handle incoming MIDI System Exclusive (SysEx) messages.
int MaxNChannels(ERoute direction) const
bool Pop(T &item)
Removes and retrieves an item from the queue.
size_t ElementsAvailable() const
Returns the number of elements currently in the queue.
Encapsulates a MIDI message and provides helper functions.
void MakeControlChangeMsg(EControlChangeMsg idx, double value, int channel=0, int offset=0)
Create a CC message.
A struct for dealing with SysEx messages.
This structure is used when queueing Sysex messages.