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.

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