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.

802 lines
27KB

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