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.

1416 lines
48KB

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