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.

1392 lines
48KB

  1. /*
  2. * Carla LinuxSampler Plugin
  3. * Copyright (C) 2011-2014 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. /* TODO
  18. * - implement buffer size changes
  19. * - implement sample rate changes
  20. * - call outDev->ReconnectAll() after changing buffer size or sample rate
  21. * - use CARLA_SAFE_ASSERT_RETURN with err
  22. */
  23. #include "CarlaPluginInternal.hpp"
  24. #include "CarlaEngine.hpp"
  25. #ifdef HAVE_LINUXSAMPLER
  26. #include "CarlaBackendUtils.hpp"
  27. #include "CarlaMathUtils.hpp"
  28. #include "juce_core.h"
  29. #include "linuxsampler/EngineFactory.h"
  30. #include <linuxsampler/Sampler.h>
  31. // -----------------------------------------------------------------------
  32. namespace LinuxSampler {
  33. using CarlaBackend::CarlaEngine;
  34. using CarlaBackend::CarlaPlugin;
  35. // -----------------------------------------------------------------------
  36. // LinuxSampler static values
  37. static const float kVolumeMax = 3.16227766f; // +10 dB
  38. // -----------------------------------------------------------------------
  39. // LinuxSampler AudioOutputDevice Plugin
  40. class AudioOutputDevicePlugin : public AudioOutputDevice
  41. {
  42. public:
  43. AudioOutputDevicePlugin(const CarlaEngine* const engine, const CarlaPlugin* const plugin, const bool uses16Outs)
  44. : AudioOutputDevice(std::map<std::string, DeviceCreationParameter*>()),
  45. kEngine(engine),
  46. kPlugin(plugin)
  47. {
  48. CARLA_ASSERT(engine != nullptr);
  49. CARLA_ASSERT(plugin != nullptr);
  50. AcquireChannels(uses16Outs ? 32 : 2);
  51. }
  52. ~AudioOutputDevicePlugin() override {}
  53. // -------------------------------------------------------------------
  54. // LinuxSampler virtual methods
  55. void Play() override {}
  56. void Stop() override {}
  57. bool IsPlaying() override
  58. {
  59. return (kEngine->isRunning() && kPlugin->isEnabled());
  60. }
  61. uint MaxSamplesPerCycle() override
  62. {
  63. return kEngine->getBufferSize();
  64. }
  65. uint SampleRate() override
  66. {
  67. return uint(kEngine->getSampleRate());
  68. }
  69. std::string Driver() override
  70. {
  71. return "AudioOutputDevicePlugin";
  72. }
  73. AudioChannel* CreateChannel(uint channelNr) override
  74. {
  75. return new AudioChannel(channelNr, nullptr, 0);
  76. }
  77. // -------------------------------------------------------------------
  78. bool isAutonomousDevice() override { return false; }
  79. static bool isAutonomousDriver() { return false; }
  80. // -------------------------------------------------------------------
  81. // Give public access to the RenderAudio call
  82. int Render(const uint samples)
  83. {
  84. return RenderAudio(samples);
  85. }
  86. // -------------------------------------------------------------------
  87. private:
  88. const CarlaEngine* const kEngine;
  89. const CarlaPlugin* const kPlugin;
  90. };
  91. // -----------------------------------------------------------------------
  92. // LinuxSampler MidiInputPort Plugin
  93. class MidiInputPortPlugin : public MidiInputPort
  94. {
  95. public:
  96. MidiInputPortPlugin(MidiInputDevice* const device, const int portNum)
  97. : MidiInputPort(device, portNum) {}
  98. ~MidiInputPortPlugin() override {}
  99. };
  100. // -----------------------------------------------------------------------
  101. // LinuxSampler MidiInputDevice Plugin
  102. class MidiInputDevicePlugin : public MidiInputDevice
  103. {
  104. public:
  105. MidiInputDevicePlugin(Sampler* const sampler)
  106. : MidiInputDevice(std::map<std::string, DeviceCreationParameter*>(), sampler) {}
  107. // -------------------------------------------------------------------
  108. // LinuxSampler virtual methods
  109. void Listen() override {}
  110. void StopListen() override {}
  111. std::string Driver() override
  112. {
  113. return "MidiInputDevicePlugin";
  114. }
  115. MidiInputPort* CreateMidiPort() override
  116. {
  117. return new MidiInputPortPlugin(this, int(Ports.size()));
  118. }
  119. // -------------------------------------------------------------------
  120. bool isAutonomousDevice() override { return false; }
  121. static bool isAutonomousDriver() { return false; }
  122. // -------------------------------------------------------------------
  123. MidiInputPortPlugin* CreateMidiPortPlugin()
  124. {
  125. return new MidiInputPortPlugin(this, int(Ports.size()));
  126. }
  127. };
  128. // -----------------------------------------------------------------------
  129. // SamplerPlugin
  130. struct SamplerPlugin {
  131. Sampler sampler;
  132. MidiInputDevicePlugin midiIn;
  133. SamplerPlugin()
  134. : sampler(),
  135. midiIn(&sampler) {}
  136. };
  137. } // namespace LinuxSampler
  138. // -----------------------------------------------------------------------
  139. using juce::File;
  140. using juce::SharedResourcePointer;
  141. using juce::StringArray;
  142. CARLA_BACKEND_START_NAMESPACE
  143. // -----------------------------------------------------------------------
  144. class LinuxSamplerPlugin : public CarlaPlugin
  145. {
  146. public:
  147. LinuxSamplerPlugin(CarlaEngine* const engine, const uint id, const bool isGIG, const bool use16Outs)
  148. : CarlaPlugin(engine, id),
  149. kIsGIG(isGIG),
  150. kUses16Outs(use16Outs && isGIG),
  151. kMaxChannels(isGIG ? MAX_MIDI_CHANNELS : 1),
  152. fLabel(nullptr),
  153. fMaker(nullptr),
  154. fRealName(nullptr),
  155. fAudioOutputDevice(nullptr),
  156. fMidiInputPort(nullptr),
  157. fInstrument(nullptr)
  158. {
  159. carla_debug("LinuxSamplerPlugin::LinuxSamplerPlugin(%p, %i, %s, %s)", engine, id, bool2str(isGIG), bool2str(use16Outs));
  160. carla_zeroStruct(fCurProgs, MAX_MIDI_CHANNELS);
  161. carla_zeroStruct(fEngineChannels, MAX_MIDI_CHANNELS);
  162. carla_zeroStruct(fSamplerChannels, MAX_MIDI_CHANNELS);
  163. if (use16Outs && ! isGIG)
  164. carla_stderr("Tried to use SFZ with 16 stereo outs, this doesn't make much sense so single stereo mode will be used instead");
  165. }
  166. ~LinuxSamplerPlugin() override
  167. {
  168. carla_debug("LinuxSamplerPlugin::~LinuxSamplerPlugin()");
  169. pData->singleMutex.lock();
  170. pData->masterMutex.lock();
  171. if (pData->client != nullptr && pData->client->isActive())
  172. pData->client->deactivate();
  173. if (pData->active)
  174. {
  175. deactivate();
  176. pData->active = false;
  177. }
  178. if (fMidiInputPort != nullptr)
  179. {
  180. for (uint i=0; i<kMaxChannels; ++i)
  181. {
  182. if (fSamplerChannels[i] != nullptr)
  183. {
  184. if (fEngineChannels[i] != nullptr)
  185. {
  186. fMidiInputPort->Disconnect(fEngineChannels[i]);
  187. fEngineChannels[i]->DisconnectAudioOutputDevice();
  188. fEngineChannels[i] = nullptr;
  189. }
  190. sSampler->sampler.RemoveSamplerChannel(fSamplerChannels[i]);
  191. fSamplerChannels[i] = nullptr;
  192. }
  193. }
  194. delete fMidiInputPort;
  195. fMidiInputPort = nullptr;
  196. }
  197. if (fAudioOutputDevice != nullptr)
  198. {
  199. delete fAudioOutputDevice;
  200. fAudioOutputDevice = nullptr;
  201. }
  202. fInstrument = nullptr;
  203. fInstrumentIds.clear();
  204. if (fLabel != nullptr)
  205. {
  206. delete[] fLabel;
  207. fLabel = nullptr;
  208. }
  209. if (fMaker != nullptr)
  210. {
  211. delete[] fMaker;
  212. fMaker = nullptr;
  213. }
  214. if (fRealName != nullptr)
  215. {
  216. delete[] fRealName;
  217. fRealName = nullptr;
  218. }
  219. clearBuffers();
  220. }
  221. // -------------------------------------------------------------------
  222. // Information (base)
  223. PluginType getType() const noexcept override
  224. {
  225. return kIsGIG ? PLUGIN_GIG : PLUGIN_SFZ;
  226. }
  227. PluginCategory getCategory() const noexcept override
  228. {
  229. return PLUGIN_CATEGORY_SYNTH;
  230. }
  231. // -------------------------------------------------------------------
  232. // Information (count)
  233. // nothing
  234. // -------------------------------------------------------------------
  235. // Information (current data)
  236. // nothing
  237. // -------------------------------------------------------------------
  238. // Information (per-plugin data)
  239. uint getOptionsAvailable() const noexcept override
  240. {
  241. uint options = 0x0;
  242. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  243. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  244. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  245. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  246. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  247. return options;
  248. }
  249. void getLabel(char* const strBuf) const noexcept override
  250. {
  251. if (fLabel != nullptr)
  252. {
  253. std::strncpy(strBuf, fLabel, STR_MAX);
  254. return;
  255. }
  256. CarlaPlugin::getLabel(strBuf);
  257. }
  258. void getMaker(char* const strBuf) const noexcept override
  259. {
  260. if (fMaker != nullptr)
  261. {
  262. std::strncpy(strBuf, fMaker, STR_MAX);
  263. return;
  264. }
  265. CarlaPlugin::getMaker(strBuf);
  266. }
  267. void getCopyright(char* const strBuf) const noexcept override
  268. {
  269. getMaker(strBuf);
  270. }
  271. void getRealName(char* const strBuf) const noexcept override
  272. {
  273. if (fRealName != nullptr)
  274. {
  275. std::strncpy(strBuf, fRealName, STR_MAX);
  276. return;
  277. }
  278. CarlaPlugin::getRealName(strBuf);
  279. }
  280. // -------------------------------------------------------------------
  281. // Set data (state)
  282. void prepareForSave() override
  283. {
  284. if (kMaxChannels > 1 && fInstrumentIds.size() > 1)
  285. {
  286. char strBuf[STR_MAX+1];
  287. std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i:%i", fCurProgs[0], fCurProgs[1], fCurProgs[2], fCurProgs[3],
  288. fCurProgs[4], fCurProgs[5], fCurProgs[6], fCurProgs[7],
  289. fCurProgs[8], fCurProgs[9], fCurProgs[10], fCurProgs[11],
  290. fCurProgs[12], fCurProgs[13], fCurProgs[14], fCurProgs[15]);
  291. CarlaPlugin::setCustomData(CUSTOM_DATA_TYPE_STRING, "programs", strBuf, false);
  292. }
  293. }
  294. // -------------------------------------------------------------------
  295. // Set data (internal stuff)
  296. void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override
  297. {
  298. if (channel >= 0 && channel < MAX_MIDI_CHANNELS)
  299. pData->prog.current = fCurProgs[channel];
  300. CarlaPlugin::setCtrlChannel(channel, sendOsc, sendCallback);
  301. }
  302. // -------------------------------------------------------------------
  303. // Set data (plugin-specific stuff)
  304. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  305. {
  306. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  307. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  308. CARLA_SAFE_ASSERT_RETURN(value != nullptr && value[0] != '\0',);
  309. carla_debug("LinuxSamplerPlugin::setCustomData(%s, \"%s\", \"%s\", %s)", type, key, value, bool2str(sendGui));
  310. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) != 0)
  311. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  312. if (std::strcmp(key, "programs") != 0)
  313. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  314. if (kMaxChannels > 1 && fInstrumentIds.size() > 1)
  315. {
  316. StringArray programList(StringArray::fromTokens(value, ":", ""));
  317. if (programList.size() == MAX_MIDI_CHANNELS)
  318. {
  319. uint8_t channel = 0;
  320. for (juce::String *it=programList.begin(), *end=programList.end(); it != end; ++it)
  321. {
  322. const int index(it->getIntValue());
  323. if (index >= 0 && index < static_cast<int>(pData->prog.count))
  324. {
  325. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[channel]);
  326. CARLA_SAFE_ASSERT_CONTINUE(engineChannel != nullptr);
  327. if (pData->engine->isOffline())
  328. {
  329. try {
  330. engineChannel->PrepareLoadInstrument(pData->filename, index);
  331. engineChannel->LoadInstrument();
  332. } CARLA_SAFE_EXCEPTION("LoadInstrument");
  333. }
  334. else
  335. {
  336. try {
  337. fInstrument->LoadInstrumentInBackground(fInstrumentIds[index], engineChannel);
  338. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  339. }
  340. fCurProgs[channel] = index;
  341. if (pData->ctrlChannel == static_cast<int32_t>(channel))
  342. {
  343. pData->prog.current = index;
  344. pData->engine->callback(ENGINE_CALLBACK_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr);
  345. }
  346. }
  347. if (++channel >= MAX_MIDI_CHANNELS)
  348. break;
  349. }
  350. CARLA_SAFE_ASSERT(channel == MAX_MIDI_CHANNELS);
  351. }
  352. }
  353. CarlaPlugin::setCustomData(type, key, value, sendGui);
  354. }
  355. void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  356. {
  357. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->prog.count),);
  358. const int8_t channel(kIsGIG ? pData->ctrlChannel : 0);
  359. if (index >= 0 && channel >= 0 && channel < MAX_MIDI_CHANNELS)
  360. {
  361. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[channel]);
  362. CARLA_SAFE_ASSERT_RETURN(engineChannel != nullptr,);
  363. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  364. if (pData->engine->isOffline())
  365. {
  366. try {
  367. engineChannel->PrepareLoadInstrument(pData->filename, index);
  368. engineChannel->LoadInstrument();
  369. } CARLA_SAFE_EXCEPTION("LoadInstrument");
  370. }
  371. else
  372. {
  373. try {
  374. fInstrument->LoadInstrumentInBackground(fInstrumentIds[index], engineChannel);
  375. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  376. }
  377. fCurProgs[channel] = index;
  378. }
  379. CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback);
  380. }
  381. // -------------------------------------------------------------------
  382. // Set ui stuff
  383. // nothing
  384. // -------------------------------------------------------------------
  385. // Plugin state
  386. void reload() override
  387. {
  388. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,);
  389. CARLA_SAFE_ASSERT_RETURN(fInstrument != nullptr,);
  390. carla_debug("LinuxSamplerPlugin::reload() - start");
  391. const EngineProcessMode processMode(pData->engine->getProccessMode());
  392. // Safely disable plugin for reload
  393. const ScopedDisabler sd(this);
  394. if (pData->active)
  395. deactivate();
  396. clearBuffers();
  397. uint32_t aOuts;
  398. aOuts = kUses16Outs ? 32 : 2;
  399. pData->audioOut.createNew(aOuts);
  400. const uint portNameSize(pData->engine->getMaxPortNameSize());
  401. CarlaString portName;
  402. // ---------------------------------------
  403. // Audio Outputs
  404. if (kUses16Outs)
  405. {
  406. for (uint32_t i=0; i < 32; ++i)
  407. {
  408. portName.clear();
  409. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  410. {
  411. portName = pData->name;
  412. portName += ":";
  413. }
  414. portName += "out-";
  415. if ((i+2)/2 < 9)
  416. portName += "0";
  417. portName += CarlaString((i+2)/2);
  418. if (i % 2 == 0)
  419. portName += "L";
  420. else
  421. portName += "R";
  422. portName.truncate(portNameSize);
  423. pData->audioOut.ports[i].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  424. pData->audioOut.ports[i].rindex = i;
  425. }
  426. }
  427. else
  428. {
  429. // out-left
  430. portName.clear();
  431. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  432. {
  433. portName = pData->name;
  434. portName += ":";
  435. }
  436. portName += "out-left";
  437. portName.truncate(portNameSize);
  438. pData->audioOut.ports[0].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  439. pData->audioOut.ports[0].rindex = 0;
  440. // out-right
  441. portName.clear();
  442. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  443. {
  444. portName = pData->name;
  445. portName += ":";
  446. }
  447. portName += "out-right";
  448. portName.truncate(portNameSize);
  449. pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false);
  450. pData->audioOut.ports[1].rindex = 1;
  451. }
  452. // ---------------------------------------
  453. // Event Input
  454. {
  455. portName.clear();
  456. if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
  457. {
  458. portName = pData->name;
  459. portName += ":";
  460. }
  461. portName += "events-in";
  462. portName.truncate(portNameSize);
  463. pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true);
  464. }
  465. // ---------------------------------------
  466. // plugin hints
  467. pData->hints = 0x0;
  468. pData->hints |= PLUGIN_IS_SYNTH;
  469. pData->hints |= PLUGIN_CAN_VOLUME;
  470. if (! kUses16Outs)
  471. pData->hints |= PLUGIN_CAN_BALANCE;
  472. // extra plugin hints
  473. pData->extraHints = 0x0;
  474. pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN;
  475. if (! kUses16Outs)
  476. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  477. if (fInstrumentIds.size() > 1)
  478. pData->extraHints |= PLUGIN_EXTRA_HINT_USES_MULTI_PROGS;
  479. bufferSizeChanged(pData->engine->getBufferSize());
  480. reloadPrograms(true);
  481. if (pData->active)
  482. activate();
  483. carla_debug("LinuxSamplerPlugin::reload() - end");
  484. }
  485. void reloadPrograms(bool doInit) override
  486. {
  487. carla_debug("LinuxSamplerPlugin::reloadPrograms(%s)", bool2str(doInit));
  488. // Delete old programs
  489. pData->prog.clear();
  490. // Query new programs
  491. const uint32_t count(static_cast<uint32_t>(fInstrumentIds.size()));
  492. // sound kits must always have at least 1 midi-program
  493. CARLA_SAFE_ASSERT_RETURN(count > 0,);
  494. pData->prog.createNew(count);
  495. // Update data
  496. for (uint32_t i=0; i < pData->prog.count; ++i)
  497. {
  498. try {
  499. pData->prog.names[i] = carla_strdup(fInstrument->GetInstrumentName(fInstrumentIds[i]).c_str());
  500. } CARLA_SAFE_EXCEPTION_CONTINUE("GetInstrumentInfo");
  501. }
  502. #ifndef BUILD_BRIDGE
  503. // Update OSC Names
  504. if (pData->engine->isOscControlRegistered())
  505. {
  506. pData->engine->oscSend_control_set_program_count(pData->id, count);
  507. for (uint32_t i=0; i < count; ++i)
  508. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  509. }
  510. #endif
  511. if (doInit)
  512. {
  513. for (uint i=0; i<kMaxChannels; ++i)
  514. {
  515. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  516. try {
  517. fInstrument->LoadInstrumentInBackground(fInstrumentIds[0], fEngineChannels[i]);
  518. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  519. fCurProgs[i] = 0;
  520. }
  521. pData->prog.current = 0;
  522. }
  523. else
  524. {
  525. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  526. }
  527. }
  528. // -------------------------------------------------------------------
  529. // Plugin processing
  530. #if 0
  531. void activate() override
  532. {
  533. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  534. {
  535. if (fAudioOutputDevices[i] != nullptr)
  536. fAudioOutputDevices[i]->Play();
  537. }
  538. }
  539. void deactivate() override
  540. {
  541. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  542. {
  543. if (fAudioOutputDevices[i] != nullptr)
  544. fAudioOutputDevices[i]->Stop();
  545. }
  546. }
  547. #endif
  548. void process(float** const, float** const outBuffer, const uint32_t frames) override
  549. {
  550. // --------------------------------------------------------------------------------------------------------
  551. // Check if active
  552. if (! pData->active)
  553. {
  554. // disable any output sound
  555. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  556. FloatVectorOperations::clear(outBuffer[i], static_cast<int>(frames));
  557. return;
  558. }
  559. // --------------------------------------------------------------------------------------------------------
  560. // Check if needs reset
  561. if (pData->needsReset)
  562. {
  563. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  564. {
  565. for (uint i=0; i < MAX_MIDI_CHANNELS; ++i)
  566. {
  567. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, i);
  568. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, i);
  569. }
  570. }
  571. else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  572. {
  573. for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
  574. fMidiInputPort->DispatchNoteOff(i, 0, uint(pData->ctrlChannel));
  575. }
  576. pData->needsReset = false;
  577. }
  578. // --------------------------------------------------------------------------------------------------------
  579. // Event Input and Processing
  580. {
  581. // ----------------------------------------------------------------------------------------------------
  582. // MIDI Input (External)
  583. if (pData->extNotes.mutex.tryLock())
  584. {
  585. for (RtLinkedList<ExternalMidiNote>::Itenerator it = pData->extNotes.data.begin(); it.valid(); it.next())
  586. {
  587. const ExternalMidiNote& note(it.getValue());
  588. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  589. if (note.velo > 0)
  590. fMidiInputPort->DispatchNoteOn(note.note, note.velo, static_cast<uint>(note.channel));
  591. else
  592. fMidiInputPort->DispatchNoteOff(note.note, note.velo, static_cast<uint>(note.channel));
  593. }
  594. pData->extNotes.data.clear();
  595. pData->extNotes.mutex.unlock();
  596. } // End of MIDI Input (External)
  597. // ----------------------------------------------------------------------------------------------------
  598. // Event Input (System)
  599. #ifndef BUILD_BRIDGE
  600. bool allNotesOffSent = false;
  601. #endif
  602. bool sampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  603. uint32_t nEvents = pData->event.portIn->getEventCount();
  604. uint32_t startTime = 0;
  605. uint32_t timeOffset = 0;
  606. for (uint32_t i=0; i < nEvents; ++i)
  607. {
  608. const EngineEvent& event(pData->event.portIn->getEvent(i));
  609. CARLA_SAFE_ASSERT_CONTINUE(event.time < frames);
  610. CARLA_SAFE_ASSERT_BREAK(event.time >= timeOffset);
  611. if (event.time > timeOffset && sampleAccurate)
  612. {
  613. if (processSingle(outBuffer, event.time - timeOffset, timeOffset))
  614. {
  615. startTime = 0;
  616. timeOffset = event.time;
  617. }
  618. else
  619. startTime += timeOffset;
  620. }
  621. // Control change
  622. switch (event.type)
  623. {
  624. case kEngineEventTypeNull:
  625. break;
  626. case kEngineEventTypeControl:
  627. {
  628. const EngineControlEvent& ctrlEvent = event.ctrl;
  629. switch (ctrlEvent.type)
  630. {
  631. case kEngineControlEventTypeNull:
  632. break;
  633. case kEngineControlEventTypeParameter:
  634. {
  635. #ifndef BUILD_BRIDGE
  636. // Control backend stuff
  637. if (event.channel == pData->ctrlChannel)
  638. {
  639. float value;
  640. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  641. {
  642. value = ctrlEvent.value;
  643. setDryWet(value, false, false);
  644. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  645. }
  646. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  647. {
  648. value = ctrlEvent.value*127.0f/100.0f;
  649. setVolume(value, false, false);
  650. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  651. }
  652. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  653. {
  654. float left, right;
  655. value = ctrlEvent.value/0.5f - 1.0f;
  656. if (value < 0.0f)
  657. {
  658. left = -1.0f;
  659. right = (value*2.0f)+1.0f;
  660. }
  661. else if (value > 0.0f)
  662. {
  663. left = (value*2.0f)-1.0f;
  664. right = 1.0f;
  665. }
  666. else
  667. {
  668. left = -1.0f;
  669. right = 1.0f;
  670. }
  671. setBalanceLeft(left, false, false);
  672. setBalanceRight(right, false, false);
  673. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  674. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  675. }
  676. }
  677. #endif
  678. // Control plugin parameters
  679. for (uint32_t k=0; k < pData->param.count; ++k)
  680. {
  681. if (pData->param.data[k].midiChannel != event.channel)
  682. continue;
  683. if (pData->param.data[k].midiCC != ctrlEvent.param)
  684. continue;
  685. if (pData->param.data[k].hints != PARAMETER_INPUT)
  686. continue;
  687. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  688. continue;
  689. float value;
  690. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  691. {
  692. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  693. }
  694. else
  695. {
  696. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  697. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  698. value = std::rint(value);
  699. }
  700. setParameterValue(k, value, false, false, false);
  701. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  702. }
  703. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  704. {
  705. fMidiInputPort->DispatchControlChange(uint8_t(ctrlEvent.param), uint8_t(ctrlEvent.value*127.0f), event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  706. }
  707. break;
  708. }
  709. case kEngineControlEventTypeMidiBank:
  710. break;
  711. case kEngineControlEventTypeMidiProgram:
  712. if (event.channel < MAX_MIDI_CHANNELS && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  713. {
  714. const uint32_t programId(ctrlEvent.param);
  715. CARLA_SAFE_ASSERT_CONTINUE(programId < fInstrumentIds.size());
  716. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[kIsGIG ? event.channel : 0]);
  717. CARLA_SAFE_ASSERT_CONTINUE(engineChannel != nullptr);
  718. if (pData->engine->isOffline())
  719. {
  720. try {
  721. engineChannel->PrepareLoadInstrument(pData->filename, programId);
  722. engineChannel->LoadInstrument();
  723. } CARLA_SAFE_EXCEPTION("LoadInstrument");
  724. }
  725. else
  726. {
  727. try {
  728. fInstrument->LoadInstrumentInBackground(fInstrumentIds[programId], engineChannel);
  729. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  730. }
  731. fCurProgs[event.channel] = static_cast<int32_t>(programId);
  732. if (pData->ctrlChannel == event.channel)
  733. pData->postponeRtEvent(kPluginPostRtEventProgramChange, static_cast<int32_t>(programId), 0, 0.0f);
  734. }
  735. break;
  736. case kEngineControlEventTypeAllSoundOff:
  737. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  738. {
  739. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  740. }
  741. break;
  742. case kEngineControlEventTypeAllNotesOff:
  743. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  744. {
  745. #ifndef BUILD_BRIDGE
  746. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  747. {
  748. allNotesOffSent = true;
  749. sendMidiAllNotesOffToCallback();
  750. }
  751. #endif
  752. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  753. }
  754. break;
  755. }
  756. break;
  757. }
  758. case kEngineEventTypeMidi:
  759. {
  760. const EngineMidiEvent& midiEvent(event.midi);
  761. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  762. uint8_t channel = event.channel;
  763. // Fix bad note-off
  764. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  765. status = MIDI_STATUS_NOTE_OFF;
  766. if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  767. continue;
  768. if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  769. continue;
  770. if (MIDI_IS_STATUS_CHANNEL_PRESSURE(status) && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  771. continue;
  772. if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  773. continue;
  774. // put back channel in data
  775. uint8_t data[EngineMidiEvent::kDataSize];
  776. std::memcpy(data, event.midi.data, EngineMidiEvent::kDataSize);
  777. if (status < 0xF0 && channel < MAX_MIDI_CHANNELS)
  778. data[0] = uint8_t(data[0] + channel);
  779. fMidiInputPort->DispatchRaw(data, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  780. if (status == MIDI_STATUS_NOTE_ON)
  781. pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, data[1], data[2]);
  782. else if (status == MIDI_STATUS_NOTE_OFF)
  783. pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel,data[1], 0.0f);
  784. break;
  785. }
  786. }
  787. }
  788. pData->postRtEvents.trySplice();
  789. if (frames > timeOffset)
  790. processSingle(outBuffer, frames - timeOffset, timeOffset);
  791. } // End of Event Input and Processing
  792. }
  793. bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  794. {
  795. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  796. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  797. // --------------------------------------------------------------------------------------------------------
  798. // Try lock, silence otherwise
  799. if (pData->engine->isOffline())
  800. {
  801. pData->singleMutex.lock();
  802. }
  803. else if (! pData->singleMutex.tryLock())
  804. {
  805. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  806. {
  807. for (uint32_t k=0; k < frames; ++k)
  808. outBuffer[i][k+timeOffset] = 0.0f;
  809. }
  810. return false;
  811. }
  812. // --------------------------------------------------------------------------------------------------------
  813. // Run plugin
  814. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  815. {
  816. if (LinuxSampler::AudioChannel* const outDev = fAudioOutputDevice->Channel(i))
  817. outDev->SetBuffer(outBuffer[i] + timeOffset);
  818. }
  819. fAudioOutputDevice->Render(frames);
  820. #ifndef BUILD_BRIDGE
  821. // --------------------------------------------------------------------------------------------------------
  822. // Post-processing (dry/wet, volume and balance)
  823. {
  824. const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) > 0 && pData->postProc.volume != 1.0f;
  825. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) > 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
  826. float oldBufLeft[doBalance ? frames : 1];
  827. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  828. {
  829. // Balance
  830. if (doBalance)
  831. {
  832. if (i % 2 == 0)
  833. FloatVectorOperations::copy(oldBufLeft, outBuffer[i], static_cast<int>(frames));
  834. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  835. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  836. for (uint32_t k=0; k < frames; ++k)
  837. {
  838. if (i % 2 == 0)
  839. {
  840. // left
  841. outBuffer[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  842. outBuffer[i][k] += outBuffer[i+1][k] * (1.0f - balRangeR);
  843. }
  844. else
  845. {
  846. // right
  847. outBuffer[i][k] = outBuffer[i][k] * balRangeR;
  848. outBuffer[i][k] += oldBufLeft[k] * balRangeL;
  849. }
  850. }
  851. }
  852. // Volume
  853. if (doVolume)
  854. {
  855. for (uint32_t k=0; k < frames; ++k)
  856. outBuffer[i][k+timeOffset] *= pData->postProc.volume;
  857. }
  858. }
  859. } // End of Post-processing
  860. #endif
  861. // --------------------------------------------------------------------------------------------------------
  862. pData->singleMutex.unlock();
  863. return true;
  864. }
  865. #ifndef CARLA_OS_WIN // FIXME, need to update linuxsampler win32 build
  866. void bufferSizeChanged(const uint32_t) override
  867. {
  868. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  869. fAudioOutputDevice->ReconnectAll();
  870. }
  871. void sampleRateChanged(const double) override
  872. {
  873. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  874. fAudioOutputDevice->ReconnectAll();
  875. }
  876. #endif
  877. // -------------------------------------------------------------------
  878. // Plugin buffers
  879. // nothing
  880. // -------------------------------------------------------------------
  881. const void* getExtraStuff() const noexcept override
  882. {
  883. static const char xtrue[] = "true";
  884. static const char xfalse[] = "false";
  885. return kUses16Outs ? xtrue : xfalse;
  886. }
  887. bool init(const char* const filename, const char* const name, const char* const label)
  888. {
  889. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  890. // ---------------------------------------------------------------
  891. // first checks
  892. if (pData->client != nullptr)
  893. {
  894. pData->engine->setLastError("Plugin client is already registered");
  895. return false;
  896. }
  897. if (filename == nullptr || filename[0] == '\0')
  898. {
  899. pData->engine->setLastError("null filename");
  900. return false;
  901. }
  902. // ---------------------------------------------------------------
  903. // Init LinuxSampler stuff
  904. fAudioOutputDevice = new LinuxSampler::AudioOutputDevicePlugin(pData->engine, this, kUses16Outs);
  905. fMidiInputPort = sSampler->midiIn.CreateMidiPortPlugin();
  906. for (uint i=0; i<kMaxChannels; ++i)
  907. {
  908. fSamplerChannels[i] = sSampler->sampler.AddSamplerChannel();
  909. CARLA_SAFE_ASSERT_CONTINUE(fSamplerChannels[i] != nullptr);
  910. fSamplerChannels[i]->SetEngineType(kIsGIG ? "GIG" : "SFZ");
  911. fSamplerChannels[i]->SetAudioOutputDevice(fAudioOutputDevice);
  912. fEngineChannels[i] = fSamplerChannels[i]->GetEngineChannel();
  913. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  914. fEngineChannels[i]->Connect(fAudioOutputDevice); // FIXME
  915. fEngineChannels[i]->Pan(0.0f);
  916. fEngineChannels[i]->Volume(LinuxSampler::kVolumeMax);
  917. if (kUses16Outs)
  918. {
  919. fEngineChannels[i]->SetOutputChannel(0, i*2);
  920. fEngineChannels[i]->SetOutputChannel(1, i*2 +1);
  921. fMidiInputPort->Connect(fEngineChannels[i], static_cast<LinuxSampler::midi_chan_t>(i));
  922. }
  923. else
  924. {
  925. fEngineChannels[i]->SetOutputChannel(0, 0);
  926. fEngineChannels[i]->SetOutputChannel(1, 1);
  927. fMidiInputPort->Connect(fEngineChannels[i], LinuxSampler::midi_chan_all);
  928. }
  929. }
  930. // ---------------------------------------------------------------
  931. // Get Engine
  932. LinuxSampler::Engine* const engine(fEngineChannels[0]->GetEngine());
  933. if (engine == nullptr)
  934. {
  935. pData->engine->setLastError("Failed to get LinuxSampler instrument manager");
  936. return false;
  937. }
  938. // ---------------------------------------------------------------
  939. // Get the Engine's Instrument Manager
  940. fInstrument = engine->GetInstrumentManager();
  941. if (fInstrument == nullptr)
  942. {
  943. pData->engine->setLastError("Failed to get LinuxSampler instrument manager");
  944. return false;
  945. }
  946. // ---------------------------------------------------------------
  947. // Load the Instrument via filename
  948. try {
  949. fInstrumentIds = fInstrument->GetInstrumentFileContent(filename);
  950. }
  951. catch (const LinuxSampler::InstrumentManagerException& e)
  952. {
  953. pData->engine->setLastError(e.what());
  954. return false;
  955. }
  956. // ---------------------------------------------------------------
  957. // Get info
  958. if (fInstrumentIds.size() == 0)
  959. {
  960. pData->engine->setLastError("Failed to find any instruments");
  961. return false;
  962. }
  963. LinuxSampler::InstrumentManager::instrument_info_t info;
  964. try {
  965. info = fInstrument->GetInstrumentInfo(fInstrumentIds[0]);
  966. }
  967. catch (const LinuxSampler::InstrumentManagerException& e)
  968. {
  969. pData->engine->setLastError(e.what());
  970. return false;
  971. }
  972. CarlaString label2(label != nullptr ? label : File(filename).getFileNameWithoutExtension().toRawUTF8());
  973. if (kUses16Outs && ! label2.endsWith(" (16 outs)"))
  974. label2 += " (16 outs)";
  975. fLabel = label2.dup();
  976. fMaker = carla_strdup(info.Artists.c_str());
  977. fRealName = carla_strdup(info.InstrumentName.c_str());
  978. pData->filename = carla_strdup(filename);
  979. if (name != nullptr && name[0] != '\0')
  980. pData->name = pData->engine->getUniquePluginName(name);
  981. else if (fRealName[0] != '\0')
  982. pData->name = pData->engine->getUniquePluginName(fRealName);
  983. else
  984. pData->name = pData->engine->getUniquePluginName(fLabel);
  985. // ---------------------------------------------------------------
  986. // register client
  987. pData->client = pData->engine->addClient(this);
  988. if (pData->client == nullptr || ! pData->client->isOk())
  989. {
  990. pData->engine->setLastError("Failed to register plugin client");
  991. return false;
  992. }
  993. // ---------------------------------------------------------------
  994. // set default options
  995. pData->options = 0x0;
  996. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  997. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  998. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  999. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1000. return true;
  1001. }
  1002. // -------------------------------------------------------------------
  1003. private:
  1004. const bool kIsGIG; // SFZ if false
  1005. const bool kUses16Outs;
  1006. const uint kMaxChannels; // 1 or 16 depending on format
  1007. const char* fLabel;
  1008. const char* fMaker;
  1009. const char* fRealName;
  1010. int32_t fCurProgs[MAX_MIDI_CHANNELS];
  1011. LinuxSampler::SamplerChannel* fSamplerChannels[MAX_MIDI_CHANNELS];
  1012. LinuxSampler::EngineChannel* fEngineChannels[MAX_MIDI_CHANNELS];
  1013. LinuxSampler::AudioOutputDevicePlugin* fAudioOutputDevice;
  1014. LinuxSampler::MidiInputPortPlugin* fMidiInputPort;
  1015. LinuxSampler::InstrumentManager* fInstrument;
  1016. std::vector<LinuxSampler::InstrumentManager::instrument_id_t> fInstrumentIds;
  1017. SharedResourcePointer<LinuxSampler::SamplerPlugin> sSampler;
  1018. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinuxSamplerPlugin)
  1019. };
  1020. CARLA_BACKEND_END_NAMESPACE
  1021. #endif // HAVE_LINUXSAMPLER
  1022. CARLA_BACKEND_START_NAMESPACE
  1023. // -------------------------------------------------------------------------------------------------------------------
  1024. CarlaPlugin* CarlaPlugin::newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs)
  1025. {
  1026. carla_debug("LinuxSamplerPlugin::newLinuxSampler({%p, \"%s\", \"%s\", \"%s\", " P_INT64 "}, %s, %s)", init.engine, init.filename, init.name, init.label, init.uniqueId, format, bool2str(use16Outs));
  1027. #ifdef HAVE_LINUXSAMPLER
  1028. CarlaString sformat(format);
  1029. sformat.toLower();
  1030. if (sformat != "gig" && sformat != "sfz")
  1031. {
  1032. init.engine->setLastError("Unsupported format requested for LinuxSampler");
  1033. return nullptr;
  1034. }
  1035. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && use16Outs)
  1036. {
  1037. init.engine->setLastError("Carla's rack mode can only work with Stereo modules, please choose the 2-channel only sample-library version");
  1038. return nullptr;
  1039. }
  1040. // -------------------------------------------------------------------
  1041. // Check if file exists
  1042. if (! File(init.filename).existsAsFile())
  1043. {
  1044. init.engine->setLastError("Requested file is not valid or does not exist");
  1045. return nullptr;
  1046. }
  1047. LinuxSamplerPlugin* const plugin(new LinuxSamplerPlugin(init.engine, init.id, (sformat == "gig"), use16Outs));
  1048. if (! plugin->init(init.filename, init.name, init.label))
  1049. {
  1050. delete plugin;
  1051. return nullptr;
  1052. }
  1053. plugin->reload();
  1054. return plugin;
  1055. #else
  1056. init.engine->setLastError("linuxsampler support not available");
  1057. return nullptr;
  1058. // unused
  1059. (void)format;
  1060. (void)use16Outs;
  1061. #endif
  1062. }
  1063. CarlaPlugin* CarlaPlugin::newFileGIG(const Initializer& init, const bool use16Outs)
  1064. {
  1065. carla_debug("CarlaPlugin::newFileGIG({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  1066. #ifdef HAVE_LINUXSAMPLER
  1067. return newLinuxSampler(init, "GIG", use16Outs);
  1068. #else
  1069. init.engine->setLastError("GIG support not available");
  1070. return nullptr;
  1071. // unused
  1072. (void)use16Outs;
  1073. #endif
  1074. }
  1075. CarlaPlugin* CarlaPlugin::newFileSFZ(const Initializer& init)
  1076. {
  1077. carla_debug("CarlaPlugin::newFileSFZ({%p, \"%s\", \"%s\", \"%s\"})", init.engine, init.filename, init.name, init.label);
  1078. #ifdef HAVE_LINUXSAMPLER
  1079. return newLinuxSampler(init, "SFZ", false);
  1080. #else
  1081. init.engine->setLastError("SFZ support not available");
  1082. return nullptr;
  1083. #endif
  1084. }
  1085. // -------------------------------------------------------------------------------------------------------------------
  1086. CARLA_BACKEND_END_NAMESPACE