From e3b77b0417fb599c12b1b470a09f4a4baab3fa5c Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 1 Mar 2021 06:17:58 +0100 Subject: [PATCH] vst: eliminate some string comparisons --- plugins/vst/SfizzVstProcessor.cpp | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index 609de2f8..d2d308f3 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -33,6 +33,14 @@ enum { static const char* kRingIdMidi = "Mid"; static const char* kRingIdOsc = "Osc"; +static const char* kMsgIdSetNumVoices = "SetNumVoices"; +static const char* kMsgIdSetOversampling = "SetOversampling"; +static const char* kMsgIdSetPreloadSize = "SetPreloadSize"; +static const char* kMsgIdCheckShouldReload = "CheckShouldReload"; +static const char* kMsgIdNotifyPlayState = "NotifyPlayState"; +static const char* kMsgIdReceiveMessage = "ReceiveMessage"; +static const char* kMsgIdNoteEvents = "NoteEvents"; + SfizzVstProcessor::SfizzVstProcessor() : _fifoToWorker(64 * 1024), _fifoMessageFromUi(64 * 1024), _oscTemp(new uint8_t[kOscTempSize]) @@ -265,7 +273,7 @@ tresult PLUGIN_API SfizzVstProcessor::process(Vst::ProcessData& data) _fileChangeCounter += numFrames; if (_fileChangeCounter > _fileChangePeriod) { _fileChangeCounter %= _fileChangePeriod; - if (writeWorkerMessage("CheckShouldReload", nullptr, 0)) + if (writeWorkerMessage(kMsgIdCheckShouldReload, nullptr, 0)) _semaToWorker.post(); } @@ -279,7 +287,7 @@ tresult PLUGIN_API SfizzVstProcessor::process(Vst::ProcessData& data) playState.regions = synth.getNumRegions(); playState.preloadedSamples = synth.getNumPreloadedSamples(); playState.activeVoices = synth.getNumActiveVoices(); - if (writeWorkerMessage("NotifyPlayState", &playState, sizeof(playState))) + if (writeWorkerMessage(kMsgIdNotifyPlayState, &playState, sizeof(playState))) _semaToWorker.post(); } @@ -294,7 +302,7 @@ tresult PLUGIN_API SfizzVstProcessor::process(Vst::ProcessData& data) _noteEventsCurrentCycle[key] = -1.0f; } if (numNoteEvents > 0) { - if (writeWorkerMessage("NoteEvents", noteEvents, numNoteEvents * sizeof(noteEvents[0]))) + if (writeWorkerMessage(kMsgIdNoteEvents, noteEvents, numNoteEvents * sizeof(noteEvents[0]))) _semaToWorker.post(); } @@ -349,7 +357,7 @@ void SfizzVstProcessor::processParameterChanges(Vst::IParameterChanges& pc) if (pointCount > 0 && vq->getPoint(pointCount - 1, sampleOffset, value) == kResultTrue) { int32 data = static_cast(range.denormalize(value)); _state.numVoices = data; - if (writeWorkerMessage("SetNumVoices", &data, sizeof(data))) + if (writeWorkerMessage(kMsgIdSetNumVoices, &data, sizeof(data))) _semaToWorker.post(); } break; @@ -357,7 +365,7 @@ void SfizzVstProcessor::processParameterChanges(Vst::IParameterChanges& pc) if (pointCount > 0 && vq->getPoint(pointCount - 1, sampleOffset, value) == kResultTrue) { int32 data = static_cast(range.denormalize(value)); _state.oversamplingLog2 = data; - if (writeWorkerMessage("SetOversampling", &data, sizeof(data))) + if (writeWorkerMessage(kMsgIdSetOversampling, &data, sizeof(data))) _semaToWorker.post(); } break; @@ -365,7 +373,7 @@ void SfizzVstProcessor::processParameterChanges(Vst::IParameterChanges& pc) if (pointCount > 0 && vq->getPoint(pointCount - 1, sampleOffset, value) == kResultTrue) { int32 data = static_cast(range.denormalize(value)); _state.preloadSize = data; - if (writeWorkerMessage("SetPreloadSize", &data, sizeof(data))) + if (writeWorkerMessage(kMsgIdSetPreloadSize, &data, sizeof(data))) _semaToWorker.post(); } break; @@ -606,7 +614,7 @@ void SfizzVstProcessor::receiveMessage(int delay, const char* path, const char* uint8_t* oscTemp = _oscTemp.get(); uint32 oscSize = sfizz_prepare_message(oscTemp, kOscTempSize, path, sig, args); if (oscSize <= kOscTempSize) { - if (writeWorkerMessage("ReceiveMessage", oscTemp, oscSize)) + if (writeWorkerMessage(kMsgIdReceiveMessage, oscTemp, oscSize)) _semaToWorker.post(); } } @@ -635,22 +643,22 @@ void SfizzVstProcessor::doBackgroundWork() const char* id = msg->type; - if (!std::strcmp(id, "SetNumVoices")) { + if (id == kMsgIdSetNumVoices) { int32 value = *msg->payload(); std::lock_guard lock(_processMutex); _synth->setNumVoices(value); } - else if (!std::strcmp(id, "SetOversampling")) { + else if (id == kMsgIdSetOversampling) { int32 value = *msg->payload(); std::lock_guard lock(_processMutex); _synth->setOversamplingFactor(1 << value); } - else if (!std::strcmp(id, "SetPreloadSize")) { + else if (id == kMsgIdSetPreloadSize) { int32 value = *msg->payload(); std::lock_guard lock(_processMutex); _synth->setPreloadSize(value); } - else if (!std::strcmp(id, "CheckShouldReload")) { + else if (id == kMsgIdCheckShouldReload) { if (_synth->shouldReloadFile()) { fprintf(stderr, "[Sfizz] sfz file has changed, reloading\n"); std::lock_guard lock(_processMutex); @@ -667,20 +675,20 @@ void SfizzVstProcessor::doBackgroundWork() _synth->loadScalaFile(_state.scalaFile); } } - else if (!std::strcmp(id, "NotifyPlayState")) { + else if (id == kMsgIdNotifyPlayState) { SfizzPlayState playState = *msg->payload(); Steinberg::OPtr notification { allocateMessage() }; notification->setMessageID("NotifiedPlayState"); notification->getAttributes()->setBinary("PlayState", &playState, sizeof(playState)); sendMessage(notification); } - else if (!std::strcmp(id, "ReceiveMessage")) { + else if (id == kMsgIdReceiveMessage) { Steinberg::OPtr notification { allocateMessage() }; notification->setMessageID("ReceivedMessage"); notification->getAttributes()->setBinary("Message", msg->payload(), msg->size); sendMessage(notification); } - else if (!std::strcmp(id, "NoteEvents")) { + else if (id == kMsgIdNoteEvents) { Steinberg::OPtr notification { allocateMessage() }; notification->setMessageID("NoteEvents"); notification->getAttributes()->setBinary("Events", msg->payload(), msg->size);