11 #import <AudioToolbox/AudioToolbox.h> 12 #include <CoreMIDI/CoreMIDI.h> 15 #import "IPlugAUAudioUnit.h" 17 #if !__has_feature(objc_arc) 18 #error This file must be compiled with Arc. Use -fobjc-arc flag 21 using namespace iplug;
23 IPlugAUv3::IPlugAUv3(
const InstanceInfo& instanceInfo,
const Config& config)
27 Trace(TRACELOC,
"%s", config.pluginName);
30 void IPlugAUv3::SetAUAudioUnit(
void* pAUAudioUnit)
32 mAUAudioUnit = pAUAudioUnit;
37 const AUParameterAddress address = GetParamAddress(paramIdx);
38 [(__bridge IPlugAUAudioUnit*) mAUAudioUnit beginInformHostOfParamChange:address];
43 const AUParameterAddress address = GetParamAddress(paramIdx);
45 [(__bridge IPlugAUAudioUnit*) mAUAudioUnit informHostOfParamChange:address :(
float) GetParam(paramIdx)->FromNormalized(normalizedValue)];
50 const AUParameterAddress address = GetParamAddress(paramIdx);
51 [(__bridge IPlugAUAudioUnit*) mAUAudioUnit endInformHostOfParamChange:address];
56 uint8_t data[3] = { msg.mStatus, msg.mData1, msg.mData2 };
58 int64_t sampleTime = mLastTimeStamp.mSampleTime + msg.mOffset;
60 return [(__bridge IPlugAUAudioUnit*) mAUAudioUnit sendMidiData: sampleTime :
sizeof(data) : data];
70 int64_t sampleTime = mLastTimeStamp.mSampleTime + msg.mOffset;
72 return [(__bridge IPlugAUAudioUnit*) mAUAudioUnit sendMidiData: sampleTime : msg.mSize : msg.mData];
121 void IPlugAUv3::ProcessWithEvents(AudioTimeStamp
const* pTimestamp, uint32_t frameCount, AURenderEvent
const* pEvents,
ITimeInfo& timeInfo)
123 SetTimeInfo(timeInfo);
126 while (mMidiMsgsFromEditor.Pop(midiMsg))
131 mLastTimeStamp = *pTimestamp;
132 AUEventSampleTime now = AUEventSampleTime(pTimestamp->mSampleTime);
133 uint32_t framesRemaining = frameCount;
135 for (
const AURenderEvent* pEvent = pEvents; pEvent !=
nullptr; pEvent = pEvent->head.next)
137 switch (pEvent->head.eventType)
139 case AURenderEventMIDI:
141 const AUMIDIEvent& midiEvent = pEvent->MIDI;
143 midiMsg = {
static_cast<int>(midiEvent.eventSampleTime - now), midiEvent.data[0], midiEvent.data[1], midiEvent.data[2] };
145 mMidiMsgsFromProcessor.Push(midiMsg);
149 case AURenderEventParameter:
150 case AURenderEventParameterRamp:
152 const AUParameterEvent& paramEvent = pEvent->parameter;
153 const int paramIdx = GetParamIdx(paramEvent.parameterAddress);
154 const double value = (double) paramEvent.value;
155 const int sampleOffset = (
int) (paramEvent.eventSampleTime - now);
157 GetParam(paramIdx)->Set(value);
159 OnParamChange(paramIdx, EParamSource::kHost, sampleOffset);
170 ProcessBuffers(0.f, framesRemaining);
174 while (mSysExDataFromEditor.Pop(mSysexBuf))
176 ISysEx smsg {mSysexBuf.mOffset, mSysexBuf.mData, mSysexBuf.mSize};
214 void IPlugAUv3::SetParameterFromValueObserver(uint64_t address,
float value)
216 const int paramIdx = GetParamIdx(address);
219 IParam* pParam = GetParam(paramIdx);
221 pParam->Set((
double) value);
223 OnParamChange(paramIdx, kHost, -1);
226 void IPlugAUv3::SendParameterValueFromObserver(uint64_t address,
float value)
228 const int paramIdx = GetParamIdx(address);
233 float IPlugAUv3::GetParameter(uint64_t address)
235 const int paramIdx = GetParamIdx(address);
238 const float val = (float) GetParam(paramIdx)->Value();
243 const char* IPlugAUv3::GetParamDisplay(uint64_t address,
float value)
245 const int paramIdx = GetParamIdx(address);
248 GetParam(paramIdx)->GetDisplay(value,
false, mParamDisplayStr);
250 return (
const char*) mParamDisplayStr.Get();
253 float IPlugAUv3::GetParamStringToValue(uint64_t address,
const char* str)
255 const int paramIdx = GetParamIdx(address);
258 float val = (float) GetParam(paramIdx)->StringToValue(str);
263 void IPlugAUv3::SetBuffers(AudioBufferList* pInBufList, AudioBufferList* pOutBufList, uint32_t outBusNumber)
268 for(
int i = 0; i < pInBufList->mNumberBuffers; i++)
270 int nConnected = pInBufList->mBuffers[i].mNumberChannels;
271 SetChannelConnections(ERoute::kInput, chanIdx, nConnected,
true);
272 AttachBuffers(ERoute::kInput, chanIdx, nConnected, (
float**) &(pInBufList->mBuffers[i].mData),
GetBlockSize());
273 chanIdx += nConnected;
281 int numChannelsInBus = pOutBufList->mNumberBuffers;
283 for(
int i = 0; i < pOutBufList->mNumberBuffers; i++)
285 int nConnected = pOutBufList->mBuffers[i].mNumberChannels;
286 SetChannelConnections(ERoute::kOutput, (outBusNumber * numChannelsInBus) + chanIdx, nConnected,
true);
287 AttachBuffers(ERoute::kOutput, (outBusNumber * numChannelsInBus) + chanIdx, nConnected, (
float**) &(pOutBufList->mBuffers[i].mData),
GetBlockSize());
288 chanIdx += nConnected;
293 void IPlugAUv3::Prepare(
double sampleRate, uint32_t blockSize)
295 SetBlockSize(blockSize);
296 SetSampleRate(sampleRate);
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Encapsulates a MIDI message and provides helper functions.
virtual void SendParameterValueFromAPI(int paramIdx, double value, bool normalized)
This is called from the plug-in API class in order to update UI controls linked to plug-in parameters...
IPlug's parameter class.
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!...
virtual void ProcessMidiMsg(const IMidiMsg &msg)
Override this method to handle incoming MIDI messages.
The base class for IPlug Audio Processing.
void InformHostOfParamChange(int idx, double normalizedValue) override
Implemented by the API class, called by the UI via SetParameterValue() with the value of a parameter ...
AudioUnit v3 API base class for an IPlug plug-in.
A struct for dealing with SysEx messages.
void BeginInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the beginning of a parameter cha...
void EndInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the end of a parameter change ge...
Encapsulates information about the host transport state.