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.

801 lines
27KB

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