Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

799 lines
27KB

  1. // SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "CarlaPluginInternal.hpp"
  4. #include "CarlaEngine.hpp"
  5. #ifndef STATIC_PLUGIN_TARGET
  6. # define HAVE_SFZ
  7. #endif
  8. #ifdef HAVE_SFZ
  9. #include "CarlaBackendUtils.hpp"
  10. #include "sfzero/SFZero.h"
  11. #include "water/buffers/AudioSampleBuffer.h"
  12. #include "water/files/File.h"
  13. #include "water/midi/MidiMessage.h"
  14. using water::AudioSampleBuffer;
  15. using water::File;
  16. using water::MidiMessage;
  17. // -----------------------------------------------------------------------
  18. CARLA_BACKEND_START_NAMESPACE
  19. // -------------------------------------------------------------------------------------------------------------------
  20. // Fallback data
  21. static const ExternalMidiNote kExternalMidiNoteFallback = { -1, 0, 0 };
  22. static void loadingIdleCallbackFunction(void* ptr)
  23. {
  24. ((CarlaEngine*)ptr)->callback(true, false, ENGINE_CALLBACK_IDLE, 0, 0, 0, 0, 0.0f, nullptr);
  25. }
  26. // -------------------------------------------------------------------------------------------------------------------
  27. class CarlaPluginSFZero : public CarlaPlugin
  28. {
  29. public:
  30. CarlaPluginSFZero(CarlaEngine* const engine, const uint id)
  31. : CarlaPlugin(engine, id),
  32. fSynth(),
  33. fNumVoices(0.0f),
  34. fLabel(nullptr),
  35. fRealName(nullptr)
  36. {
  37. carla_debug("CarlaPluginSFZero::CarlaPluginSFZero(%p, %i)", engine, id);
  38. }
  39. ~CarlaPluginSFZero() override
  40. {
  41. carla_debug("CarlaPluginSFZero::~CarlaPluginSFZero()");
  42. pData->singleMutex.lock();
  43. pData->masterMutex.lock();
  44. if (pData->client != nullptr && pData->client->isActive())
  45. pData->client->deactivate(true);
  46. if (pData->active)
  47. {
  48. deactivate();
  49. pData->active = false;
  50. }
  51. if (fLabel != nullptr)
  52. {
  53. delete[] fLabel;
  54. fLabel = nullptr;
  55. }
  56. if (fRealName != nullptr)
  57. {
  58. delete[] fRealName;
  59. fRealName = nullptr;
  60. }
  61. clearBuffers();
  62. }
  63. // -------------------------------------------------------------------
  64. // Information (base)
  65. PluginType getType() const noexcept override
  66. {
  67. return PLUGIN_SFZ;
  68. }
  69. PluginCategory getCategory() const noexcept override
  70. {
  71. return PLUGIN_CATEGORY_SYNTH;
  72. }
  73. // -------------------------------------------------------------------
  74. // Information (count)
  75. // nothing
  76. // -------------------------------------------------------------------
  77. // Information (current data)
  78. // nothing
  79. // -------------------------------------------------------------------
  80. // Information (per-plugin data)
  81. uint getOptionsAvailable() const noexcept override
  82. {
  83. uint options = 0x0;
  84. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  85. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  86. options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  87. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  88. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  89. options |= PLUGIN_OPTION_SKIP_SENDING_NOTES;
  90. return options;
  91. }
  92. float getParameterValue(const uint32_t parameterId) const noexcept override
  93. {
  94. CARLA_SAFE_ASSERT_RETURN(parameterId == 0, 0.0f);
  95. return fNumVoices;
  96. }
  97. bool getLabel(char* const strBuf) const noexcept override
  98. {
  99. if (fLabel != nullptr)
  100. {
  101. std::strncpy(strBuf, fLabel, STR_MAX);
  102. return true;
  103. }
  104. return CarlaPlugin::getLabel(strBuf);
  105. }
  106. bool getMaker(char* const strBuf) const noexcept override
  107. {
  108. std::strncpy(strBuf, "SFZero engine", STR_MAX);
  109. return true;
  110. }
  111. bool getCopyright(char* const strBuf) const noexcept override
  112. {
  113. std::strncpy(strBuf, "ISC", STR_MAX);
  114. return true;
  115. }
  116. bool getRealName(char* const strBuf) const noexcept override
  117. {
  118. if (fRealName != nullptr)
  119. {
  120. std::strncpy(strBuf, fRealName, STR_MAX);
  121. return true;
  122. }
  123. return CarlaPlugin::getRealName(strBuf);
  124. }
  125. bool getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override
  126. {
  127. CARLA_SAFE_ASSERT_RETURN(parameterId == 0, false);
  128. std::strncpy(strBuf, "Voice Count", STR_MAX);
  129. return true;
  130. }
  131. // -------------------------------------------------------------------
  132. // Set data (state)
  133. // nothing
  134. // -------------------------------------------------------------------
  135. // Set data (internal stuff)
  136. // nothing
  137. // -------------------------------------------------------------------
  138. // Set data (plugin-specific stuff)
  139. // nothing
  140. // -------------------------------------------------------------------
  141. // Set ui stuff
  142. // nothing
  143. // -------------------------------------------------------------------
  144. // Plugin state
  145. void reload() override
  146. {
  147. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  148. carla_debug("CarlaPluginSFZero::reload() - start");
  149. const EngineProcessMode processMode(pData->engine->getProccessMode());
  150. // Safely disable plugin for reload
  151. const ScopedDisabler sd(this);
  152. if (pData->active)
  153. deactivate();
  154. clearBuffers();
  155. pData->audioOut.createNew(2);
  156. pData->param.createNew(1, false);
  157. const uint portNameSize(pData->engine->getMaxPortNameSize());
  158. String portName;
  159. // ---------------------------------------
  160. // Audio Outputs
  161. // out-left
  162. portName.clear();
  163. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  164. {
  165. portName = pData->name;
  166. portName += ":";
  167. }
  168. portName += "out-left";
  169. portName.truncate(portNameSize);
  170. pData->audioOut.ports[0].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, 0);
  171. pData->audioOut.ports[0].rindex = 0;
  172. // out-right
  173. portName.clear();
  174. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  175. {
  176. portName = pData->name;
  177. portName += ":";
  178. }
  179. portName += "out-right";
  180. portName.truncate(portNameSize);
  181. pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false, 1);
  182. pData->audioOut.ports[1].rindex = 1;
  183. // ---------------------------------------
  184. // Event Input
  185. portName.clear();
  186. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  187. {
  188. portName = pData->name;
  189. portName += ":";
  190. }
  191. portName += "events-in";
  192. portName.truncate(portNameSize);
  193. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, 0);
  194. // ---------------------------------------
  195. // Parameters
  196. pData->param.data[0].type = PARAMETER_OUTPUT;
  197. pData->param.data[0].hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMATABLE | PARAMETER_IS_INTEGER;
  198. pData->param.data[0].index = 0;
  199. pData->param.data[0].rindex = 0;
  200. pData->param.ranges[0].min = 0.0f;
  201. pData->param.ranges[0].max = 128;
  202. pData->param.ranges[0].def = 0.0f;
  203. pData->param.ranges[0].step = 1.0f;
  204. pData->param.ranges[0].stepSmall = 1.0f;
  205. pData->param.ranges[0].stepLarge = 1.0f;
  206. // ---------------------------------------
  207. // plugin hints
  208. pData->hints = 0x0;
  209. pData->hints |= PLUGIN_IS_SYNTH;
  210. pData->hints |= PLUGIN_CAN_VOLUME;
  211. pData->hints |= PLUGIN_CAN_BALANCE;
  212. // extra plugin hints
  213. pData->extraHints = 0x0;
  214. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  215. bufferSizeChanged(pData->engine->getBufferSize());
  216. reloadPrograms(true);
  217. if (pData->active)
  218. activate();
  219. carla_debug("CarlaPluginSFZero::reload() - end");
  220. }
  221. // -------------------------------------------------------------------
  222. // Plugin processing
  223. void process(const float* const* const, float** const audioOut, const float* const*, float**, const uint32_t frames) override
  224. {
  225. // --------------------------------------------------------------------------------------------------------
  226. // Check if active
  227. if (! pData->active)
  228. {
  229. // disable any output sound
  230. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  231. carla_zeroFloats(audioOut[i], frames);
  232. fNumVoices = 0.0f;
  233. return;
  234. }
  235. // --------------------------------------------------------------------------------------------------------
  236. // Check if needs reset
  237. if (pData->needsReset)
  238. {
  239. fSynth.allNotesOff(0, false);
  240. pData->needsReset = false;
  241. }
  242. // --------------------------------------------------------------------------------------------------------
  243. // Event Input and Processing
  244. {
  245. // ----------------------------------------------------------------------------------------------------
  246. // Setup audio buffer
  247. AudioSampleBuffer audioOutBuffer(audioOut, 2, frames);
  248. // ----------------------------------------------------------------------------------------------------
  249. // MIDI Input (External)
  250. if (pData->extNotes.mutex.tryLock())
  251. {
  252. for (RtLinkedList<ExternalMidiNote>::Itenerator it = pData->extNotes.data.begin2(); it.valid(); it.next())
  253. {
  254. const ExternalMidiNote& note(it.getValue(kExternalMidiNoteFallback));
  255. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  256. if (note.velo > 0)
  257. fSynth.noteOn(note.channel+1, note.note, static_cast<float>(note.velo)/127.0f);
  258. else
  259. fSynth.noteOff(note.channel+1, note.note, static_cast<float>(note.velo)/127.0f, true);
  260. }
  261. pData->extNotes.data.clear();
  262. pData->extNotes.mutex.unlock();
  263. } // End of MIDI Input (External)
  264. // ----------------------------------------------------------------------------------------------------
  265. // Event Input (System)
  266. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  267. bool allNotesOffSent = false;
  268. #endif
  269. uint32_t timeOffset = 0;
  270. for (uint32_t i=0, numEvents=pData->event.portIn->getEventCount(); i < numEvents; ++i)
  271. {
  272. const EngineEvent& event(pData->event.portIn->getEvent(i));
  273. uint32_t eventTime = event.time;
  274. CARLA_SAFE_ASSERT_UINT2_CONTINUE(eventTime < frames, eventTime, frames);
  275. if (eventTime < timeOffset)
  276. {
  277. carla_stderr2("Timing error, eventTime:%u < timeOffset:%u for '%s'",
  278. eventTime, timeOffset, pData->name);
  279. eventTime = timeOffset;
  280. }
  281. else if (eventTime > timeOffset)
  282. {
  283. if (processSingle(audioOutBuffer, eventTime - timeOffset, timeOffset))
  284. timeOffset = eventTime;
  285. }
  286. // Control change
  287. switch (event.type)
  288. {
  289. case kEngineEventTypeNull:
  290. break;
  291. case kEngineEventTypeControl:
  292. {
  293. const EngineControlEvent& ctrlEvent = event.ctrl;
  294. switch (ctrlEvent.type)
  295. {
  296. case kEngineControlEventTypeNull:
  297. break;
  298. case kEngineControlEventTypeParameter:
  299. {
  300. float value;
  301. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  302. // Control backend stuff
  303. if (event.channel == pData->ctrlChannel)
  304. {
  305. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  306. {
  307. value = ctrlEvent.normalizedValue;
  308. setDryWetRT(value, true);
  309. }
  310. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  311. {
  312. value = ctrlEvent.normalizedValue*127.0f/100.0f;
  313. setVolumeRT(value, true);
  314. }
  315. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  316. {
  317. float left, right;
  318. value = ctrlEvent.normalizedValue/0.5f - 1.0f;
  319. if (value < 0.0f)
  320. {
  321. left = -1.0f;
  322. right = (value*2.0f)+1.0f;
  323. }
  324. else if (value > 0.0f)
  325. {
  326. left = (value*2.0f)-1.0f;
  327. right = 1.0f;
  328. }
  329. else
  330. {
  331. left = -1.0f;
  332. right = 1.0f;
  333. }
  334. setBalanceLeftRT(left, true);
  335. setBalanceRightRT(right, true);
  336. }
  337. }
  338. #endif
  339. // Control plugin parameters
  340. for (uint32_t k=0; k < pData->param.count; ++k)
  341. {
  342. if (pData->param.data[k].midiChannel != event.channel)
  343. continue;
  344. if (pData->param.data[k].mappedControlIndex != ctrlEvent.param)
  345. continue;
  346. if (pData->param.data[k].hints != PARAMETER_INPUT)
  347. continue;
  348. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMATABLE) == 0)
  349. continue;
  350. value = pData->param.getFinalUnnormalizedValue(k, ctrlEvent.normalizedValue);
  351. setParameterValueRT(k, value, eventTime, true);
  352. }
  353. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param < MAX_MIDI_VALUE)
  354. {
  355. fSynth.handleController(event.channel+1, ctrlEvent.param, int(ctrlEvent.normalizedValue*127.0f + 0.5f));
  356. }
  357. break;
  358. }
  359. case kEngineControlEventTypeMidiBank:
  360. case kEngineControlEventTypeMidiProgram:
  361. case kEngineControlEventTypeAllSoundOff:
  362. break;
  363. case kEngineControlEventTypeAllNotesOff:
  364. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  365. {
  366. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  367. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  368. {
  369. allNotesOffSent = true;
  370. postponeRtAllNotesOff();
  371. }
  372. #endif
  373. fSynth.allNotesOff(event.channel+1, true);
  374. }
  375. break;
  376. }
  377. break;
  378. }
  379. case kEngineEventTypeMidi: {
  380. const EngineMidiEvent& midiEvent(event.midi);
  381. if (midiEvent.size > EngineMidiEvent::kDataSize)
  382. continue;
  383. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  384. if ((status == MIDI_STATUS_NOTE_OFF || status == MIDI_STATUS_NOTE_ON) && (pData->options & PLUGIN_OPTION_SKIP_SENDING_NOTES))
  385. continue;
  386. if (status == MIDI_STATUS_CHANNEL_PRESSURE && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  387. continue;
  388. if (status == MIDI_STATUS_CONTROL_CHANGE && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  389. continue;
  390. if (status == MIDI_STATUS_POLYPHONIC_AFTERTOUCH && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  391. continue;
  392. if (status == MIDI_STATUS_PITCH_WHEEL_CONTROL && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  393. continue;
  394. // Fix bad note-off
  395. if (status == MIDI_STATUS_NOTE_ON && midiEvent.data[2] == 0)
  396. status = MIDI_STATUS_NOTE_OFF;
  397. // put back channel in data
  398. uint8_t midiData2[EngineMidiEvent::kDataSize];
  399. midiData2[0] = uint8_t(status | (event.channel & MIDI_CHANNEL_BIT));
  400. std::memcpy(midiData2 + 1, midiEvent.data + 1, static_cast<std::size_t>(midiEvent.size - 1));
  401. const MidiMessage midiMessage(midiData2, static_cast<int>(midiEvent.size), 0.0);
  402. fSynth.handleMidiEvent(midiMessage);
  403. if (status == MIDI_STATUS_NOTE_ON)
  404. {
  405. pData->postponeNoteOnRtEvent(true, event.channel, midiEvent.data[1], midiEvent.data[2]);
  406. }
  407. else if (status == MIDI_STATUS_NOTE_OFF)
  408. {
  409. pData->postponeNoteOffRtEvent(true, event.channel, midiEvent.data[1]);
  410. }
  411. } break;
  412. }
  413. }
  414. pData->postRtEvents.trySplice();
  415. if (frames > timeOffset)
  416. processSingle(audioOutBuffer, frames - timeOffset, timeOffset);
  417. } // End of Event Input and Processing
  418. // --------------------------------------------------------------------------------------------------------
  419. // Parameter outputs
  420. fNumVoices = static_cast<float>(fSynth.numVoicesUsed());
  421. }
  422. bool processSingle(AudioSampleBuffer& audioOutBuffer, const uint32_t frames, const uint32_t timeOffset)
  423. {
  424. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  425. // --------------------------------------------------------------------------------------------------------
  426. // Try lock, silence otherwise
  427. #ifndef STOAT_TEST_BUILD
  428. if (pData->engine->isOffline())
  429. {
  430. pData->singleMutex.lock();
  431. }
  432. else
  433. #endif
  434. if (! pData->singleMutex.tryLock())
  435. {
  436. audioOutBuffer.clear(timeOffset, frames);
  437. return false;
  438. }
  439. // --------------------------------------------------------------------------------------------------------
  440. // Run plugin
  441. fSynth.renderVoices(audioOutBuffer, static_cast<int>(timeOffset), static_cast<int>(frames));
  442. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  443. // --------------------------------------------------------------------------------------------------------
  444. // Post-processing (dry/wet, volume and balance)
  445. {
  446. const bool doVolume = carla_isNotEqual(pData->postProc.volume, 1.0f);
  447. //const bool doBalance = carla_isNotEqual(pData->postProc.balanceLeft, -1.0f) || carla_isNotEqual(pData->postProc.balanceRight, 1.0f);
  448. float* outBufferL = audioOutBuffer.getWritePointer(0, timeOffset);
  449. float* outBufferR = audioOutBuffer.getWritePointer(1, timeOffset);
  450. #if 0
  451. if (doBalance)
  452. {
  453. float* const oldBufLeft = pData->postProc.extraBuffer;
  454. // there was a loop here
  455. {
  456. if (i % 2 == 0)
  457. carla_copyFloats(oldBufLeft, outBuffer[i], frames);
  458. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  459. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  460. for (uint32_t k=0; k < frames; ++k)
  461. {
  462. if (i % 2 == 0)
  463. {
  464. // left
  465. outBuffer[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  466. outBuffer[i][k] += outBuffer[i+1][k] * (1.0f - balRangeR);
  467. }
  468. else
  469. {
  470. // right
  471. outBuffer[i][k] = outBuffer[i][k] * balRangeR;
  472. outBuffer[i][k] += oldBufLeft[k] * balRangeL;
  473. }
  474. }
  475. }
  476. }
  477. #endif
  478. if (doVolume)
  479. {
  480. const float volume = pData->postProc.volume;
  481. for (uint32_t k=0; k < frames; ++k)
  482. {
  483. *outBufferL++ *= volume;
  484. *outBufferR++ *= volume;
  485. }
  486. }
  487. } // End of Post-processing
  488. #endif
  489. // --------------------------------------------------------------------------------------------------------
  490. pData->singleMutex.unlock();
  491. return true;
  492. }
  493. void sampleRateChanged(const double newSampleRate) override
  494. {
  495. fSynth.setCurrentPlaybackSampleRate(newSampleRate);
  496. }
  497. // -------------------------------------------------------------------
  498. // Plugin buffers
  499. // nothing
  500. // -------------------------------------------------------------------
  501. bool init(const CarlaPluginPtr plugin,
  502. const char* const filename, const char* const name, const char* const label, const uint options)
  503. {
  504. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  505. // ---------------------------------------------------------------
  506. // first checks
  507. if (pData->client != nullptr)
  508. {
  509. pData->engine->setLastError("Plugin client is already registered");
  510. return false;
  511. }
  512. if (filename == nullptr || filename[0] == '\0')
  513. {
  514. pData->engine->setLastError("null filename");
  515. return false;
  516. }
  517. for (int i = 128; --i >=0;)
  518. fSynth.addVoice(new sfzero::Voice());
  519. // ---------------------------------------------------------------
  520. // Init SFZero stuff
  521. fSynth.setCurrentPlaybackSampleRate(pData->engine->getSampleRate());
  522. File file(filename);
  523. sfzero::Sound* const sound = new sfzero::Sound(file);
  524. sfzero::Sound::LoadingIdleCallback cb = {
  525. loadingIdleCallbackFunction,
  526. pData->engine,
  527. };
  528. sound->loadRegions();
  529. sound->loadSamples(cb);
  530. if (fSynth.addSound(sound) == nullptr)
  531. {
  532. pData->engine->setLastError("Failed to allocate SFZ sounds in memory");
  533. return false;
  534. }
  535. sound->dumpToConsole();
  536. // ---------------------------------------------------------------
  537. const water::String basename(File(filename).getFileNameWithoutExtension());
  538. String label2(label != nullptr ? label : basename.toRawUTF8());
  539. fLabel = carla_strdup(label2);
  540. fRealName = carla_strdup(basename.toRawUTF8());
  541. pData->filename = carla_strdup(filename);
  542. if (name != nullptr && name[0] != '\0')
  543. pData->name = pData->engine->getUniquePluginName(name);
  544. else if (fRealName[0] != '\0')
  545. pData->name = pData->engine->getUniquePluginName(fRealName);
  546. else
  547. pData->name = pData->engine->getUniquePluginName(fLabel);
  548. // ---------------------------------------------------------------
  549. // register client
  550. pData->client = pData->engine->addClient(plugin);
  551. if (pData->client == nullptr || ! pData->client->isOk())
  552. {
  553. pData->engine->setLastError("Failed to register plugin client");
  554. return false;
  555. }
  556. // ---------------------------------------------------------------
  557. // set options
  558. pData->options = 0x0;
  559. if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_CONTROL_CHANGES))
  560. pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  561. if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_CHANNEL_PRESSURE))
  562. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  563. if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH))
  564. pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH;
  565. if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_PITCHBEND))
  566. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  567. if (isPluginOptionEnabled(options, PLUGIN_OPTION_SEND_ALL_SOUND_OFF))
  568. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  569. if (isPluginOptionInverseEnabled(options, PLUGIN_OPTION_SKIP_SENDING_NOTES))
  570. pData->options |= PLUGIN_OPTION_SKIP_SENDING_NOTES;
  571. return true;
  572. }
  573. // -------------------------------------------------------------------
  574. private:
  575. sfzero::Synth fSynth;
  576. float fNumVoices;
  577. const char* fLabel;
  578. const char* fRealName;
  579. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginSFZero)
  580. };
  581. CARLA_BACKEND_END_NAMESPACE
  582. #endif // HAVE_SFZ
  583. CARLA_BACKEND_START_NAMESPACE
  584. // -------------------------------------------------------------------------------------------------------------------
  585. CarlaPluginPtr CarlaPlugin::newSFZero(const Initializer& init)
  586. {
  587. carla_debug("CarlaPluginSFZero::newSFZero({%p, \"%s\", \"%s\", \"%s\", " P_INT64 "})",
  588. init.engine, init.filename, init.name, init.label, init.uniqueId);
  589. #ifdef HAVE_SFZ
  590. // -------------------------------------------------------------------
  591. // Check if file exists
  592. if (! water::File(init.filename).existsAsFile())
  593. {
  594. init.engine->setLastError("Requested file is not valid or does not exist");
  595. return nullptr;
  596. }
  597. std::shared_ptr<CarlaPluginSFZero> plugin(new CarlaPluginSFZero(init.engine, init.id));
  598. if (! plugin->init(plugin, init.filename, init.name, init.label, init.options))
  599. return nullptr;
  600. return plugin;
  601. #else
  602. init.engine->setLastError("SFZ support not available");
  603. return nullptr;
  604. #endif
  605. }
  606. // -------------------------------------------------------------------------------------------------------------------
  607. CARLA_BACKEND_END_NAMESPACE