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.

795 lines
26KB

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