iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugAPP.cpp
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#include "IPlugAPP.h"
12#include "IPlugAPP_host.h"
13
14#if defined OS_MAC || defined OS_LINUX
15#include <IPlugSWELL.h>
16#else
17extern float GetScaleForHWND(HWND hWnd);
18#endif
19
20using namespace iplug;
21
22extern HWND gHWND;
23
24IPlugAPP::IPlugAPP(const InstanceInfo& info, const Config& config)
25: IPlugAPIBase(config, kAPIAPP)
26, IPlugProcessor(config, kAPIAPP)
27{
28 mAppHost = (IPlugAPPHost*) info.pAppHost;
29
30 Trace(TRACELOC, "%s%s", config.pluginName, config.channelIOStr);
31
32 SetChannelConnections(ERoute::kInput, 0, MaxNChannels(ERoute::kInput), true);
33 SetChannelConnections(ERoute::kOutput, 0, MaxNChannels(ERoute::kOutput), true);
34
35 SetBlockSize(DEFAULT_BLOCK_SIZE);
36
37 CreateTimer();
38}
39
40bool IPlugAPP::EditorResize(int viewWidth, int viewHeight)
41{
42 bool parentResized = false;
43
44 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
45 {
46 #if defined OS_MAC || defined NO_IGRAPHICS
47 RECT rcClient, rcWindow;
48 POINT ptDiff;
49
50 GetClientRect(gHWND, &rcClient);
51 GetWindowRect(gHWND, &rcWindow);
52
53 ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
54 ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
55
56 int flags = 0;
57
58 #ifdef OS_WIN
59 flags = SWP_NOMOVE;
60 float ss = GetScaleForHWND(gHWND);
61 #else
62 float ss = 1.f;
63 #endif
64
65 SetWindowPos(gHWND, 0,
66 static_cast<LONG>(rcWindow.left * ss),
67 static_cast<LONG>((rcWindow.bottom - viewHeight - ptDiff.y) * ss),
68 static_cast<LONG>((viewWidth + ptDiff.x) * ss),
69 static_cast<LONG>((viewHeight + ptDiff.y) * ss), flags);
70 parentResized = true;
71 #endif
72
73 SetEditorSize(viewWidth, viewHeight);
74 }
75
76 return parentResized;
77}
78
80{
81 if (DoesMIDIOut() && mAppHost->mMidiOut)
82 {
83 //TODO: midi out channel
84// uint8_t status;
85//
86// // if the midi channel out filter is set, reassign the status byte appropriately
87// if(mAppHost->mMidiOutChannel > -1)
88// status = mAppHost->mMidiOutChannel-1 | ((uint8_t) msg.StatusMsg() << 4) ;
89
90 std::vector<uint8_t> message;
91 message.push_back(msg.mStatus);
92 message.push_back(msg.mData1);
93 message.push_back(msg.mData2);
94
95 mAppHost->mMidiOut->sendMessage(&message);
96
97 return true;
98 }
99
100 return false;
101}
102
104{
105 if (DoesMIDIOut() && mAppHost->mMidiOut)
106 {
107 //TODO: midi out channel
108 std::vector<uint8_t> message;
109
110 for (int i = 0; i < msg.mSize; i++)
111 {
112 message.push_back(msg.mData[i]);
113 }
114
115 mAppHost->mMidiOut->sendMessage(&message);
116 return true;
117 }
118
119 return false;
120}
121
122void IPlugAPP::SendSysexMsgFromUI(const ISysEx& msg)
123{
124 SendSysEx(msg);
125}
126
127void IPlugAPP::AppProcess(double** inputs, double** outputs, int nFrames)
128{
129 SetChannelConnections(ERoute::kInput, 0, MaxNChannels(ERoute::kInput), !IsInstrument()); //TODO: go elsewhere - enable inputs
130 SetChannelConnections(ERoute::kOutput, 0, MaxNChannels(ERoute::kOutput), true); //TODO: go elsewhere
131 AttachBuffers(ERoute::kInput, 0, NChannelsConnected(ERoute::kInput), inputs, GetBlockSize());
132 AttachBuffers(ERoute::kOutput, 0, NChannelsConnected(ERoute::kOutput), outputs, GetBlockSize());
133
134 if(mMidiMsgsFromCallback.ElementsAvailable())
135 {
136 IMidiMsg msg;
137
138 while (mMidiMsgsFromCallback.Pop(msg))
139 {
140 ProcessMidiMsg(msg);
141 mMidiMsgsFromProcessor.Push(msg); // queue incoming MIDI for UI
142 }
143 }
144
145 if(mSysExMsgsFromCallback.ElementsAvailable())
146 {
147 SysExData data;
148
149 while (mSysExMsgsFromCallback.Pop(data))
150 {
151 ISysEx msg { data.mOffset, data.mData, data.mSize };
152 ProcessSysEx(msg);
153 mSysExDataFromProcessor.Push(data); // queue incoming Sysex for UI
154 }
155 }
156
157 if(mMidiMsgsFromEditor.ElementsAvailable())
158 {
159 IMidiMsg msg;
160
161 while (mMidiMsgsFromEditor.Pop(msg))
162 {
163 ProcessMidiMsg(msg);
164 }
165 }
166
167 //Do not handle Sysex messages here - SendSysexMsgFromUI overridden
168
169 ENTER_PARAMS_MUTEX
170 ProcessBuffers(0.0, GetBlockSize());
171 LEAVE_PARAMS_MUTEX
172}
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
A class that hosts an IPlug as a standalone app and provides Audio/Midi I/O.
Definition: IPlugAPP_host.h:82
bool SendSysEx(const ISysEx &msg) override
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
Definition: IPlugAPP.cpp:103
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!
Definition: IPlugAPP.cpp:79
bool EditorResize(int viewWidth, int viewHeight) override
Implementations call into the APIs resize hooks returns a bool to indicate whether the DAW or plugin ...
Definition: IPlugAPP.cpp:40
The base class for IPlug Audio Processing.
virtual void ProcessMidiMsg(const IMidiMsg &msg)
Override this method to handle incoming MIDI messages.
bool IsInstrument() const
int NChannelsConnected(ERoute direction) const
int GetBlockSize() const
virtual void ProcessSysEx(const ISysEx &msg)
Override this method to handle incoming MIDI System Exclusive (SysEx) messages.
int MaxNChannels(ERoute direction) const
bool DoesMIDIOut() const
bool Pop(T &item)
Definition: IPlugQueue.h:74
size_t ElementsAvailable() const
Definition: IPlugQueue.h:106
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:539
This structure is used when queueing Sysex messages.
Definition: IPlugStructs.h:45