17#include "host-proxy.hxx"
24void ClapNameCopy(
char* destination,
const char* source)
26 strncpy(destination, source, CLAP_NAME_SIZE);
27 destination[CLAP_NAME_SIZE - 1] = 0;
30IPlugCLAP::IPlugCLAP(
const InstanceInfo& info,
const Config& config)
33 , ClapPluginHelper(info.mDesc, info.mHost)
35 Trace(TRACELOC,
"%s", config.pluginName);
39 if (CStringHasContents(info.mHost->version))
43 sscanf(info.mHost->version,
"%d.%d.%d", &ver, &rmaj, &rmin);
44 version = (ver << 16) + (rmaj << 8) + rmin;
48 int nChans = RequiredChannels();
49 mAudioIO32.Resize(nChans);
50 mAudioIO64.Resize(nChans);
52 SetHost(info.mHost->name, version);
56uint32_t IPlugCLAP::tailGet() const noexcept
61void IPlugCLAP::FlushParamsIfNeeded()
64 runOnMainThread([&](){
if (!isBeingDestroyed()) GetClapHost().paramsRequestFlush(); });
69 mParamValuesToHost.
PushFromArgs(ParamToHost::Type::Begin, idx, 0.0);
70 FlushParamsIfNeeded();
75 const IParam* pParam = GetParam(idx);
76 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
77 const double value = isDoubleType ? normalizedValue : pParam->
FromNormalized(normalizedValue);
79 mParamValuesToHost.
PushFromArgs(ParamToHost::Type::Value, idx, value);
80 FlushParamsIfNeeded();
85 mParamValuesToHost.
PushFromArgs(ParamToHost::Type::End, idx, 0.0);
86 FlushParamsIfNeeded();
93 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
95 GetClapHost().guiRequestResize(viewWidth, viewHeight);
98 SetEditorSize(viewWidth, viewHeight);
109 if (GetClapHost().canUseTail())
117 if (GetClapHost().canUseLatency())
122 mLatencyUpdate =
true;
124 runOnMainThread([&](){
if (!isBeingDestroyed()) GetClapHost().requestRestart(); });
130 mMidiToHost.Add(msg);
137 SysExData data(msg.mOffset, msg.mSize, msg.mData);
138 mSysExToHost.Add(data);
143bool IPlugCLAP::init() noexcept
150bool IPlugCLAP::activate(
double sampleRate, uint32_t minFrameCount, uint32_t maxFrameCount)
noexcept
152 SetBlockSize(maxFrameCount);
153 SetSampleRate(sampleRate);
155 OnParamReset(kReset);
160 GetClapHost().latencyChanged();
161 mLatencyUpdate =
false;
164 mHostHasTail = GetClapHost().canUseTail();
170void IPlugCLAP::deactivate() noexcept
178const T* ClapEventCast(
const clap_event_header_t* event)
180 return reinterpret_cast<const T*
>(event);
184bool InputIsSilent(
const T* data,
int nFrames)
187 auto isZero = [](T x) {
return x == T(0); };
189 return std::find_if_not(data, data + nFrames, isZero) == (data + nFrames);
192clap_process_status IPlugCLAP::process(
const clap_process* pProcess)
noexcept
198 if (pProcess->transport)
202 auto pTransport = pProcess->transport;
204 constexpr double beatFactor =
static_cast<double>(CLAP_BEATTIME_FACTOR);
205 constexpr double secFactor =
static_cast<double>(CLAP_SECTIME_FACTOR);
207 if (pTransport->flags & CLAP_TRANSPORT_HAS_TEMPO)
208 timeInfo.mTempo = pTransport->tempo;
211 if (pTransport->flags & CLAP_TRANSPORT_HAS_SECONDS_TIMELINE)
212 timeInfo.mSamplePos = (GetSampleRate() *
static_cast<double>(pTransport->song_pos_seconds) / secFactor);
214 if (pTransport->flags & CLAP_TRANSPORT_HAS_BEATS_TIMELINE)
216 timeInfo.mPPQPos =
static_cast<double>(pTransport->song_pos_beats) / beatFactor;
217 timeInfo.mLastBar =
static_cast<double>(pTransport->bar_start) / beatFactor;
218 timeInfo.mCycleStart =
static_cast<double>(pTransport->loop_start_beats) / beatFactor;
219 timeInfo.mCycleEnd =
static_cast<double>(pTransport->loop_end_beats) / beatFactor;
222 if (pTransport->flags & CLAP_TRANSPORT_HAS_TIME_SIGNATURE)
224 timeInfo.mNumerator =
static_cast<int>(pTransport->tsig_num);
225 timeInfo.mDenominator =
static_cast<int>(pTransport->tsig_denom);
228 timeInfo.mTransportIsRunning = pTransport->flags & CLAP_TRANSPORT_IS_PLAYING;
229 timeInfo.mTransportLoopEnabled = pTransport->flags & CLAP_TRANSPORT_IS_LOOP_ACTIVE;
231 SetTimeInfo(timeInfo);
235 ProcessInputEvents(pProcess->in_events);
237 while (mMidiMsgsFromEditor.Pop(msg))
242 while (mSysExDataFromEditor.Pop(sysEx))
244 SendSysEx(
ISysEx(sysEx.mOffset, sysEx.mData, sysEx.mSize));
250 int nFrames = pProcess->frames_count;
253 bool localTail = !mHostHasTail && !GetTailIsInfinite() && GetTailSize();
254 bool insQuiet =
true;
257 for (uint32_t i = 0; i < pProcess->audio_inputs_count; i++)
258 nIns +=
static_cast<int>(pProcess->audio_inputs[i].channel_count);
260 for (uint32_t i = 0; i < pProcess->audio_outputs_count; i++)
261 nOuts +=
static_cast<int>(pProcess->audio_outputs[i].channel_count);
264 bool format64 =
false;
266 if (pProcess->audio_inputs_count && pProcess->audio_inputs && pProcess->audio_inputs[0].channel_count)
267 format64 = pProcess->audio_inputs[0].data64;
268 else if (pProcess->audio_outputs_count && pProcess->audio_outputs && pProcess->audio_outputs[0].channel_count)
269 format64 = pProcess->audio_outputs[0].data64;
273 for (uint32_t i = 0; i < pProcess->audio_inputs_count; i++)
275 auto bus = pProcess->audio_inputs[i];
276 assert(!bus.channel_count || format64 ==
static_cast<bool>(bus.data64));
279 for (uint32_t i = 0; i < pProcess->audio_outputs_count; i++)
281 auto bus = pProcess->audio_outputs[i];
282 assert(!bus.channel_count || format64 ==
static_cast<bool>(bus.data64));
286 SetChannelConnections(ERoute::kInput, 0, MaxNChannels(ERoute::kInput),
false);
287 SetChannelConnections(ERoute::kInput, 0, nIns,
true);
294 for (uint32_t i = 0, k = 0; i < pProcess->audio_inputs_count; i++)
296 auto bus = pProcess->audio_inputs[i];
298 for (uint32_t j = 0; j < bus.channel_count; j++, k++)
300 mAudioIO64.Get()[k] = bus.data64[j];
304 if (localTail && insQuiet)
305 insQuiet = InputIsSilent(bus.data64[j], nFrames);
309 AttachBuffers(ERoute::kInput, 0, nIns, mAudioIO64.Get(), nFrames);
313 for (uint32_t i = 0, k = 0; i < pProcess->audio_inputs_count; i++)
315 auto bus = pProcess->audio_inputs[i];
317 for (uint32_t j = 0; j < bus.channel_count; j++, k++)
319 mAudioIO32.Get()[k] = bus.data32[j];
322 if (localTail && insQuiet)
323 insQuiet = InputIsSilent(bus.data32[j], nFrames);
327 AttachBuffers(ERoute::kInput, 0, nIns, mAudioIO32.Get(), nFrames);
331 SetChannelConnections(ERoute::kOutput, 0, MaxNChannels(ERoute::kOutput),
false);
332 SetChannelConnections(ERoute::kOutput, 0, nOuts,
true);
339 for (uint32_t i = 0, k = 0; i < pProcess->audio_outputs_count; i++)
341 auto bus = pProcess->audio_outputs[i];
342 for (uint32_t j = 0; j < bus.channel_count; j++, k++)
343 mAudioIO64.Get()[k] = bus.data64[j];
346 AttachBuffers(ERoute::kOutput, 0, nOuts, mAudioIO64.Get(), nFrames);
350 for (uint32_t i = 0, k = 0; i < pProcess->audio_outputs_count; i++)
352 auto bus = pProcess->audio_outputs[i];
353 for (uint32_t j = 0; j < bus.channel_count; j++, k++)
354 mAudioIO32.Get()[k] = bus.data32[j];
357 AttachBuffers(ERoute::kOutput, 0, nOuts, mAudioIO32.Get(), nFrames);
362 ProcessBuffers(0.0, nFrames);
364 ProcessBuffers(0.f, nFrames);
367 ProcessOutputEvents(pProcess->out_events, nFrames);
372 GetClapHost().tailChanged();
378 return CLAP_PROCESS_TAIL;
383 return CLAP_PROCESS_CONTINUE_IF_NOT_QUIET;
386 if (GetTailIsInfinite())
387 return CLAP_PROCESS_CONTINUE;
390 mTailCount = insQuiet ? std::min(mTailCount + nFrames, GetTailSize()) : 0;
392 return mTailCount < GetTailSize() ? CLAP_PROCESS_CONTINUE : CLAP_PROCESS_SLEEP;
395 return CLAP_PROCESS_CONTINUE;
400bool IPlugCLAP::renderSetMode(clap_plugin_render_mode mode)
noexcept
402 SetRenderingOffline(mode == CLAP_RENDER_OFFLINE);
407bool IPlugCLAP::stateSave(
const clap_ostream* pStream)
noexcept
411 if (!SerializeState(chunk))
418 const uint8_t* pData = chunk.
GetData();
419 int64_t remaining = chunk.
Size();
421 while (remaining > 0)
423 const int64_t written = pStream->write(pStream, pData,
static_cast<uint64_t
>(remaining));
429 remaining -= written;
435bool IPlugCLAP::stateLoad(
const clap_istream* pStream)
noexcept
437 constexpr int bytesPerBlock = 256;
438 char buffer[bytesPerBlock];
439 int64_t bytesRead = 0;
443 while ((bytesRead = pStream->read(pStream, buffer, bytesPerBlock)) > 0)
444 chunk.
PutBytes(buffer,
static_cast<int>(bytesRead));
449 bool restoredOK = UnserializeState(chunk, 0) >= 0;
455 if (GetClapHost().canUseParams())
456 GetClapHost().paramsRescan(CLAP_PARAM_RESCAN_VALUES);
463bool IPlugCLAP::paramsInfo(uint32_t paramIdx, clap_param_info* pInfo)
const noexcept
465 assert(MAX_PARAM_NAME_LEN <= CLAP_NAME_SIZE &&
"iPlug parameter name size exceeds CLAP maximum");
466 assert(MAX_PARAM_GROUP_LEN <= CLAP_PATH_SIZE &&
"iPlug group name size exceeds CLAP maximum");
468 const IParam* pParam = GetParam(paramIdx);
469 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
471 clap_param_info_flags flags = CLAP_PARAM_REQUIRES_PROCESS;
474 flags |= CLAP_PARAM_IS_STEPPED;
476 flags |= CLAP_PARAM_IS_AUTOMATABLE;
478 pInfo->id = paramIdx;
479 pInfo->flags = flags;
480 pInfo->cookie =
nullptr;
482 strcpy(pInfo->name, pParam->
GetName());
483 strcpy(pInfo->module, pParam->
GetGroup());
486 pInfo->min_value = isDoubleType ? 0.0 : pParam->
GetMin();
487 pInfo->max_value = isDoubleType ? 1.0 : pParam->
GetMax();
488 pInfo->default_value = pParam->
GetDefault(isDoubleType);
493bool IPlugCLAP::paramsValue(clap_id paramIdx,
double* pValue)
noexcept
495 const IParam* pParam = GetParam(paramIdx);
496 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
501bool IPlugCLAP::paramsValueToText(clap_id paramIdx,
double value,
char* display, uint32_t size)
noexcept
503 const IParam* pParam = GetParam(paramIdx);
504 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
521 if (size <=
static_cast<uint32_t
>(str.GetLength()))
524 strcpy(display, str.Get());
528bool IPlugCLAP::paramsTextToValue(clap_id paramIdx,
const char* display,
double* pValue)
noexcept
530 const IParam* pParam = GetParam(paramIdx);
531 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
534 *pValue = isDoubleType ? pParam->
ToNormalized(paramValue) : paramValue;
538void IPlugCLAP::paramsFlush(
const clap_input_events* pInputParamChanges,
const clap_output_events* pOutputParamChanges)
noexcept
540 ProcessInputEvents(pInputParamChanges);
541 ProcessOutputParams(pOutputParamChanges);
544void IPlugCLAP::ProcessInputEvents(
const clap_input_events* pInputEvents)
noexcept
550 for (
int i = 0; i < pInputEvents->size(pInputEvents); i++)
552 auto pEvent = pInputEvents->get(pInputEvents, i);
554 if (pEvent->space_id != CLAP_CORE_EVENT_SPACE_ID)
557 switch (pEvent->type)
559 case CLAP_EVENT_NOTE_ON:
562 auto pNote = ClapEventCast<clap_event_note>(pEvent);
563 auto velocity =
static_cast<int>(std::round(pNote->velocity * 127.0));
564 msg.
MakeNoteOnMsg(pNote->key, velocity, pEvent->time, pNote->channel);
566 mMidiMsgsFromProcessor.Push(msg);
570 case CLAP_EVENT_NOTE_OFF:
572 auto pNote = ClapEventCast<clap_event_note>(pEvent);
575 mMidiMsgsFromProcessor.Push(msg);
579 case CLAP_EVENT_MIDI:
581 auto pMidiEvent = ClapEventCast<clap_event_midi>(pEvent);
582 msg =
IMidiMsg(pEvent->time, pMidiEvent->data[0], pMidiEvent->data[1], pMidiEvent->data[2]);
584 mMidiMsgsFromProcessor.Push(msg);
588 case CLAP_EVENT_MIDI_SYSEX:
590 auto pSysexEvent = ClapEventCast<clap_event_midi_sysex>(pEvent);
591 ISysEx sysEx(pEvent->time, pSysexEvent->buffer, pSysexEvent->size);
593 mSysExDataFromProcessor.PushFromArgs(sysEx.mOffset, sysEx.mSize, sysEx.mData);
597 case CLAP_EVENT_PARAM_VALUE:
599 auto pParamValue = ClapEventCast<clap_event_param_value>(pEvent);
601 int paramIdx = pParamValue->param_id;
602 double value = pParamValue->value;
604 IParam* pParam = GetParam(paramIdx);
605 const bool isDoubleType = pParam->
Type() == IParam::kTypeDouble;
612 SendParameterValueFromAPI(paramIdx, value, isDoubleType);
613 OnParamChange(paramIdx, EParamSource::kHost, pEvent->time);
624void IPlugCLAP::ProcessOutputParams(
const clap_output_events* pOutputParamChanges)
noexcept
628 while (mParamValuesToHost.Pop(change))
631 bool isValue = change.type() == CLAP_EVENT_PARAM_VALUE;
633 clap_event_header_t header;
638 header.size = isValue ?
sizeof(clap_event_param_value) :
sizeof(clap_event_param_gesture);
640 header.space_id = CLAP_CORE_EVENT_SPACE_ID;
641 header.type = change.type();
646 clap_event_param_value
event { header, change.idx(),
nullptr, -1, -1, -1, -1, change.value() };
647 pOutputParamChanges->try_push(pOutputParamChanges, &event.header);
651 clap_event_param_gesture
event { header, change.idx() };
652 pOutputParamChanges->try_push(pOutputParamChanges, &event.header);
657void IPlugCLAP::ProcessOutputEvents(
const clap_output_events* pOutputEvents,
int nFrames)
noexcept
663 ProcessOutputParams(pOutputEvents);
667 clap_event_header_t header;
669 while (mMidiToHost.ToDo() || mSysExToHost.ToDo())
671 int midiMsgOffset = nFrames;
672 int sysExOffset = nFrames;
675 if (mMidiToHost.ToDo())
676 midiMsgOffset = mMidiToHost.Peek().mOffset;
678 if (mSysExToHost.ToDo())
679 sysExOffset = mSysExToHost.Peek().mOffset;
682 if (std::min(midiMsgOffset, sysExOffset) >= nFrames)
685 if (sysExOffset <= midiMsgOffset)
687 auto data = mSysExToHost.Peek();
689 uint32_t dataSize =
static_cast<uint32_t
>(data.mSize);
691 header.size =
sizeof(clap_event_midi_sysex);
692 header.time = data.mOffset;
693 header.space_id = CLAP_CORE_EVENT_SPACE_ID;
694 header.type = CLAP_EVENT_MIDI_SYSEX;
697 clap_event_midi_sysex sysex_event { header, 0, data.mData, dataSize };
699 pOutputEvents->try_push(pOutputEvents, &sysex_event.header);
701 mSysExToHost.Remove();
705 auto msg = mMidiToHost.Peek();
706 auto status = msg.mStatus;
709 header.size =
sizeof(clap_event_param_value);
710 header.time = msg.mOffset;
711 header.space_id = CLAP_CORE_EVENT_SPACE_ID;
712 header.type = CLAP_EVENT_MIDI;
715 if (msg.
StatusMsg() == IMidiMsg::kNoteOn)
716 header.type = CLAP_EVENT_NOTE_ON;
718 if (msg.
StatusMsg() == IMidiMsg::kNoteOff)
719 header.type = CLAP_EVENT_NOTE_OFF;
721 if (header.type == CLAP_EVENT_NOTE_ON || header.type == CLAP_EVENT_NOTE_OFF)
723 int16_t channel =
static_cast<int16_t
>(msg.
Channel());
724 clap_event_note note_event { header, -1, 0, channel, msg.mData1,
static_cast<double>(msg.mData2) / 127.0};
725 pOutputEvents->try_push(pOutputEvents, ¬e_event.header);
729 clap_event_midi midi_event { header, 0, { status, msg.mData1, msg.mData2 } };
730 pOutputEvents->try_push(pOutputEvents, &midi_event.header);
733 mMidiToHost.Remove();
737 mMidiToHost.Flush(nFrames);
738 mSysExToHost.Flush(nFrames);
742const char* ClapPortType(uint32_t nChans)
745 return nChans == 2 ? CLAP_PORT_STEREO : (nChans == 1 ? CLAP_PORT_MONO :
nullptr);
748bool IPlugCLAP::implementsAudioPorts() const noexcept
753uint32_t IPlugCLAP::audioPortsCount(
bool isInput)
const noexcept
755 return NBuses(isInput ? ERoute::kInput : ERoute::kOutput);
758bool IPlugCLAP::audioPortsInfo(uint32_t index,
bool isInput, clap_audio_port_info* pInfo)
const noexcept
763 const auto direction = isInput ? ERoute::kInput : ERoute::kOutput;
764 const auto nBuses = NBuses(direction);
765 const auto nChans = NChannels(direction, index);
767 GetBusName(direction, index, nBuses, busName);
769 constexpr uint32_t bitFlags = CLAP_AUDIO_PORT_SUPPORTS_64BITS
770 | CLAP_AUDIO_PORT_PREFERS_64BITS
771 | CLAP_AUDIO_PORT_REQUIRES_COMMON_SAMPLE_SIZE;
774 ClapNameCopy(pInfo->name, busName.Get());
775 pInfo->flags = !index ? bitFlags | CLAP_AUDIO_PORT_IS_MAIN : bitFlags;
776 pInfo->channel_count = nChans;
777 pInfo->port_type = ClapPortType(pInfo->channel_count);
778 pInfo->in_place_pair = CLAP_INVALID_ID;
782bool IPlugCLAP::implementsAudioPortsConfig() const noexcept
784 return audioPortsConfigCount();
787uint32_t IPlugCLAP::audioPortsConfigCount() const noexcept
792bool IPlugCLAP::audioPortsGetConfig(uint32_t index, clap_audio_ports_config* pConfig)
const noexcept
794 if (index >= audioPortsConfigCount())
797 WDL_String configName;
800 auto getNChans = [&](
ERoute direction,
int bus)
802 return static_cast<uint32_t
>(NChannels(direction,
static_cast<uint32_t
>(bus), index));
805 auto getDirectionName = [&](
ERoute direction)
808 configName.AppendFormatted(CLAP_NAME_SIZE,
"%d", getNChans(direction, 0));
810 for (
int i = 1; i < NBuses(direction, index); i++)
811 configName.AppendFormatted(CLAP_NAME_SIZE,
".%d", getNChans(direction, i));
814 getDirectionName(kInput);
815 configName.Append(
"-");
816 getDirectionName(kOutput);
819 ClapNameCopy(pConfig->name, configName.Get());
821 pConfig->input_port_count =
static_cast<uint32_t
>(NBuses(kInput, index));
822 pConfig->output_port_count =
static_cast<uint32_t
>(NBuses(kOutput, index));
825 pConfig->has_main_input = pConfig->input_port_count > 0;
826 pConfig->main_input_channel_count = pConfig->has_main_input ? getNChans(kInput, 0) : 0;
827 pConfig->main_input_port_type = ClapPortType(pConfig->main_input_channel_count);
829 pConfig->has_main_output = pConfig->output_port_count > 0;
830 pConfig->main_output_channel_count = pConfig->has_main_output ? getNChans(kOutput, 0) : 0;
831 pConfig->main_output_port_type = ClapPortType(pConfig->main_output_channel_count);
836bool IPlugCLAP::audioPortsSetConfig(clap_id configIdx)
noexcept
838 if (configIdx >= audioPortsConfigCount())
841 mConfigIdx =
static_cast<int>(configIdx);
846uint32_t IPlugCLAP::notePortsCount(
bool isInput)
const noexcept
849 return PLUG_DOES_MIDI_IN ? 1 : 0;
851 return PLUG_DOES_MIDI_OUT ? 1 : 0;
854bool IPlugCLAP::notePortsInfo(uint32_t index,
bool isInput, clap_note_port_info* pInfo)
const noexcept
859 pInfo->supported_dialects = CLAP_NOTE_DIALECT_MIDI;
860 pInfo->preferred_dialect = CLAP_NOTE_DIALECT_MIDI;
861 ClapNameCopy(pInfo->name,
"MIDI Input");
866 pInfo->supported_dialects = CLAP_NOTE_DIALECT_MIDI;
867 pInfo->preferred_dialect = CLAP_NOTE_DIALECT_MIDI;
868 ClapNameCopy(pInfo->name,
"MIDI Output");
874bool IPlugCLAP::guiIsApiSupported(
const char* api,
bool isFloating)
noexcept
877 return !isFloating && !strcmp(api, CLAP_WINDOW_API_COCOA);
879 return !isFloating && !strcmp(api, CLAP_WINDOW_API_WIN32);
881#error Not Implemented!
885bool IPlugCLAP::guiSetParent(
const clap_window* pWindow)
noexcept
888 return GUIWindowAttach(pWindow->cocoa);
890 return GUIWindowAttach(pWindow->win32);
892#error Not Implemented!
896bool IPlugCLAP::implementsGui() const noexcept
901bool IPlugCLAP::guiCreate(
const char* api,
bool isFloating)
noexcept
906void IPlugCLAP::guiDestroy() noexcept
913bool IPlugCLAP::guiShow() noexcept
915 if (
HasUI() && !mGUIOpen)
926bool IPlugCLAP::guiHide() noexcept
940bool IPlugCLAP::guiCanResize() const noexcept
945bool IPlugCLAP::guiSetScale(
double scale)
noexcept
949 SetScreenScale(
static_cast<float>(scale));
958bool IPlugCLAP::guiGetSize(uint32_t* pWidth, uint32_t* pHeight)
noexcept
964 *pWidth = GetEditorWidth();
965 *pHeight = GetEditorHeight();
975bool IPlugCLAP::GUIWindowAttach(
void* pWindow)
noexcept
990bool IPlugCLAP::guiAdjustSize(uint32_t* pWidth, uint32_t* pHeight)
noexcept
992 Trace(TRACELOC,
"width:%i height:%i\n", *pWidth, *pHeight);
998 ConstrainEditorResize(w, h);
1010bool IPlugCLAP::guiSetSize(uint32_t width, uint32_t height)
noexcept
1012 Trace(TRACELOC,
"width:%i height:%i\n", width, height);
1016 OnParentWindowResize(width, height);
1026void IPlugCLAP::SetDefaultConfig()
1028 auto isMatch = [&](
int idx,
int chans)
1030 if (NBuses(ERoute::kOutput, idx) >= 1 && NChannels(ERoute::kOutput, 0, idx) == chans)
1032 int numBuses = NBuses(ERoute::kInput, idx);
1035 if (
IsInstrument() && (numBuses == 0 || NChannels(ERoute::kInput, 0, idx) == 0))
1039 return numBuses >= 1 && NChannels(ERoute::kInput, 0, idx) == chans;
1045 auto testMatches = [&](
int chans)
1047 bool matched =
false;
1048 int configNBusesI = 0;
1049 int configNBusesO = 0;
1051 for (
int i = 0; i < static_cast<int>(audioPortsConfigCount()); i++)
1053 if (isMatch(i, chans))
1055 const int nBusesI = NBuses(ERoute::kInput, i);
1056 const int nBusesO = NBuses(ERoute::kOutput, i);
1058 const bool preferInput = nBusesO < configNBusesI;
1059 const bool preferOutput = nBusesI < configNBusesO;
1061 if (!matched || preferOutput || (nBusesO == configNBusesO && preferInput))
1065 configNBusesI = NBuses(ERoute::kInput, i);
1066 configNBusesO = NBuses(ERoute::kOutput, i);
1077 if (GetClapHost().canUseTrackInfo())
1079 clap_track_info info;
1080 GetClapHost().trackInfoGet(&info);
1082 if (testMatches(info.audio_channel_count) || info.audio_channel_count == 2)
1090int IPlugCLAP::RequiredChannels()
const
1095uint32_t IPlugCLAP::NBuses(
ERoute direction,
int configIdx)
const
1100uint32_t IPlugCLAP::NChannels(
ERoute direction, uint32_t bus,
int configIdx)
const
1105uint32_t IPlugCLAP::NBuses(
ERoute direction)
const
1107 return NBuses(direction, mConfigIdx);
1110uint32_t IPlugCLAP::NChannels(
ERoute direction, uint32_t bus)
const
1112 return NChannels(direction, bus, mConfigIdx);
Manages a block of memory, for plug-in settings store/recall.
int PutBytes(const void *pSrc, int nBytesToCopy)
Copies data into the chunk, placing it at the end, resizing if necessary.
uint8_t * GetData()
Gets a ptr to the chunk data.
int Size() const
Returns the current size of the chunk.
double GetDefault(bool normalized=false) const
Returns the parameter's default value.
EParamType Type() const
Get the parameter's type.
double ToNormalized(double nonNormalizedValue) const
Convert a real value to normalized value for this parameter.
bool GetCanAutomate() const
void GetDisplay(WDL_String &display, bool withDisplayText=true) const
Get the current textual display for the current parameter value.
double GetMin() const
Returns the parameter's minimum value.
void Set(double value)
Sets the parameter value.
const char * GetLabel() const
Returns the parameter's label.
double StringToValue(const char *str) const
Convert a textual representation of the parameter value to a double (real value)
void SetNormalized(double normalizedValue)
Sets the parameter value from a normalized range (usually coming from the linked IControl)
const char * GetName() const
Returns the parameter's name.
double FromNormalized(double normalizedValue) const
Convert a normalized value to real value for this parameter.
double GetNormalized() const
Returns the parameter's normalized value.
double Constrain(double value) const
Constrains the input value between mMin and mMax and apply stepping if relevant.
const char * GetDisplayText(double value) const
Get the display text for a particular value.
const char * GetGroup() const
Returns the parameter's group.
double Value() const
Gets a readable value of the parameter.
double GetMax() const
Returns the parameter's maximum value.
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
bool SendSysEx(const ISysEx &msg) override
Send a single MIDI System Exclusive (SysEx) message // TODO: info about what thread should this be ca...
void InformHostOfParamChange(int idx, double normalizedValue) override
Implemented by the API class, called by the UI via SetParameterValue() with the value of a parameter ...
void SetTailSize(int tailSize) override
Call this method if you need to update the tail size at runtime, for example if the decay time of you...
void SetLatency(int samples) override
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
bool EditorResize(int viewWidth, int viewHeight) override
Implementations call into the APIs resize hooks returns a bool to indicate whether the DAW or plugin ...
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...
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!
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...
The base class for IPlug Audio Processing.
bool GetTailIsInfinite() const
const IOConfig * GetIOConfig(int idx) const
virtual void SetTailSize(int tailSize)
Call this method if you need to update the tail size at runtime, for example if the decay time of you...
virtual void SetLatency(int latency)
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
bool IsInstrument() const
int MaxNBuses(ERoute direction, int *pConfigIdxWithTheMostBuses=nullptr) const
Used to determine the maximum number of input or output buses based on what was specified in the chan...
int MaxNChannels(ERoute direction) const
virtual void OnActivate(bool active)
Override OnActivate() which should be called by the API class when a plug-in is "switched on" by the ...
bool PushFromArgs(Args ...args)
Constructs and adds an item to the queue in-place from arguments.
bool GetHostResizeEnabled() const
ERoute
Used to identify whether a bus/channel connection is an input or an output.
Encapsulates information about the host transport state.
Encapsulates a MIDI message and provides helper functions.
void MakeNoteOnMsg(int noteNumber, int velocity, int offset, int channel=0)
Make a Note On message.
int Channel() const
Gets the channel of a MIDI message.
void MakeNoteOffMsg(int noteNumber, int offset, int channel=0)
Make a Note Off message.
EStatusMsg StatusMsg() const
Gets the MIDI Status message.
int NChansOnBusSAFE(ERoute direction, int index) const
Gets the number of channels on a bus with bounds checking.
int NBuses(ERoute direction) const
Gets the number of buses for a given direction.
A struct for dealing with SysEx messages.
This structure is used when queueing Sysex messages.