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, rcWindow.left * ss,
66 (rcWindow.bottom - viewHeight - ptDiff.y) * ss,
67 (viewWidth + ptDiff.x) * ss,
68 (viewHeight + ptDiff.y) * ss, flags);
69 parentResized = true;
70 #endif
71
72 SetEditorSize(viewWidth, viewHeight);
73 }
74
75 return parentResized;
76}
77
79{
80 if (DoesMIDIOut() && mAppHost->mMidiOut)
81 {
82 //TODO: midi out channel
83// uint8_t status;
84//
85// // if the midi channel out filter is set, reassign the status byte appropriately
86// if(mAppHost->mMidiOutChannel > -1)
87// status = mAppHost->mMidiOutChannel-1 | ((uint8_t) msg.StatusMsg() << 4) ;
88
89 std::vector<uint8_t> message;
90 message.push_back(msg.mStatus);
91 message.push_back(msg.mData1);
92 message.push_back(msg.mData2);
93
94 mAppHost->mMidiOut->sendMessage(&message);
95
96 return true;
97 }
98
99 return false;
100}
101
103{
104 if (DoesMIDIOut() && mAppHost->mMidiOut)
105 {
106 //TODO: midi out channel
107 std::vector<uint8_t> message;
108
109 for (int i = 0; i < msg.mSize; i++)
110 {
111 message.push_back(msg.mData[i]);
112 }
113
114 mAppHost->mMidiOut->sendMessage(&message);
115 return true;
116 }
117
118 return false;
119}
120
121void IPlugAPP::SendSysexMsgFromUI(const ISysEx& msg)
122{
123 SendSysEx(msg);
124}
125
126void IPlugAPP::AppProcess(double** inputs, double** outputs, int nFrames)
127{
128 SetChannelConnections(ERoute::kInput, 0, MaxNChannels(ERoute::kInput), !IsInstrument()); //TODO: go elsewhere - enable inputs
129 SetChannelConnections(ERoute::kOutput, 0, MaxNChannels(ERoute::kOutput), true); //TODO: go elsewhere
130 AttachBuffers(ERoute::kInput, 0, NChannelsConnected(ERoute::kInput), inputs, GetBlockSize());
131 AttachBuffers(ERoute::kOutput, 0, NChannelsConnected(ERoute::kOutput), outputs, GetBlockSize());
132
133 if(mMidiMsgsFromCallback.ElementsAvailable())
134 {
135 IMidiMsg msg;
136
137 while (mMidiMsgsFromCallback.Pop(msg))
138 {
139 ProcessMidiMsg(msg);
140 mMidiMsgsFromProcessor.Push(msg); // queue incoming MIDI for UI
141 }
142 }
143
144 if(mSysExMsgsFromCallback.ElementsAvailable())
145 {
146 SysExData data;
147
148 while (mSysExMsgsFromCallback.Pop(data))
149 {
150 ISysEx msg { data.mOffset, data.mData, data.mSize };
151 ProcessSysEx(msg);
152 mSysExDataFromProcessor.Push(data); // queue incoming Sysex for UI
153 }
154 }
155
156 if(mMidiMsgsFromEditor.ElementsAvailable())
157 {
158 IMidiMsg msg;
159
160 while (mMidiMsgsFromEditor.Pop(msg))
161 {
162 ProcessMidiMsg(msg);
163 }
164 }
165
166 //Do not handle Sysex messages here - SendSysexMsgFromUI overridden
167
168 ENTER_PARAMS_MUTEX
169 ProcessBuffers(0.0, GetBlockSize());
170 LEAVE_PARAMS_MUTEX
171}
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:102
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:78
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
int MaxNChannels(ERoute direction) const
virtual void ProcessSysEx(ISysEx &msg)
Override this method to handle incoming MIDI System Exclusive (SysEx) messages.
bool DoesMIDIOut() const
bool Pop(T &item)
Definition: IPlugQueue.h:74
size_t ElementsAvailable() const
Definition: IPlugQueue.h:88
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