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.

1414 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 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 portNum)
  99. : MidiInputPort(device, portNum)
  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. int index = midiProg.toInt(&ok);
  329. if (ok && index >= 0 && index < static_cast<int>(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 uint portNameSize(pData->engine->getMaxPortNameSize());
  402. CarlaString portName;
  403. // ---------------------------------------
  404. // Audio Outputs
  405. if (fUses16Outs)
  406. {
  407. for (uint32_t 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 doInit) override
  485. {
  486. carla_debug("LinuxSamplerPlugin::reloadPrograms(%s)", bool2str(doInit));
  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 (doInit)
  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, static_cast<uint>(note.channel));
  598. else
  599. fMidiInputPort->DispatchNoteOff(note.note, note.velo, static_cast<uint>(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 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. CARLA_SAFE_ASSERT_CONTINUE(event.time < frames);
  617. CARLA_SAFE_ASSERT_BREAK(event.time >= timeOffset);
  618. if (event.time > timeOffset && sampleAccurate)
  619. {
  620. if (processSingle(outBuffer, event.time - timeOffset, timeOffset))
  621. {
  622. startTime = 0;
  623. timeOffset = event.time;
  624. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  625. nextBankIds[pData->ctrlChannel] = pData->midiprog.data[pData->midiprog.current].bank;
  626. }
  627. else
  628. startTime += timeOffset;
  629. }
  630. // Control change
  631. switch (event.type)
  632. {
  633. case kEngineEventTypeNull:
  634. break;
  635. case kEngineEventTypeControl:
  636. {
  637. const EngineControlEvent& ctrlEvent = event.ctrl;
  638. switch (ctrlEvent.type)
  639. {
  640. case kEngineControlEventTypeNull:
  641. break;
  642. case kEngineControlEventTypeParameter:
  643. {
  644. #ifndef BUILD_BRIDGE
  645. // Control backend stuff
  646. if (event.channel == pData->ctrlChannel)
  647. {
  648. float value;
  649. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) != 0)
  650. {
  651. value = ctrlEvent.value;
  652. setDryWet(value, false, false);
  653. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  654. }
  655. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) != 0)
  656. {
  657. value = ctrlEvent.value*127.0f/100.0f;
  658. setVolume(value, false, false);
  659. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  660. }
  661. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) != 0)
  662. {
  663. float left, right;
  664. value = ctrlEvent.value/0.5f - 1.0f;
  665. if (value < 0.0f)
  666. {
  667. left = -1.0f;
  668. right = (value*2.0f)+1.0f;
  669. }
  670. else if (value > 0.0f)
  671. {
  672. left = (value*2.0f)-1.0f;
  673. right = 1.0f;
  674. }
  675. else
  676. {
  677. left = -1.0f;
  678. right = 1.0f;
  679. }
  680. setBalanceLeft(left, false, false);
  681. setBalanceRight(right, false, false);
  682. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  683. pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  684. }
  685. }
  686. #endif
  687. // Control plugin parameters
  688. for (uint32_t k=0; k < pData->param.count; ++k)
  689. {
  690. if (pData->param.data[k].midiChannel != event.channel)
  691. continue;
  692. if (pData->param.data[k].midiCC != ctrlEvent.param)
  693. continue;
  694. if (pData->param.data[k].hints != PARAMETER_INPUT)
  695. continue;
  696. if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  697. continue;
  698. float value;
  699. if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  700. {
  701. value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max;
  702. }
  703. else
  704. {
  705. value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value);
  706. if (pData->param.data[k].hints & PARAMETER_IS_INTEGER)
  707. value = std::rint(value);
  708. }
  709. setParameterValue(k, value, false, false, false);
  710. pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  711. }
  712. if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F)
  713. {
  714. fMidiInputPort->DispatchControlChange(uint8_t(ctrlEvent.param), uint8_t(ctrlEvent.value*127.0f), event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  715. }
  716. break;
  717. }
  718. case kEngineControlEventTypeMidiBank:
  719. if (event.channel < MAX_MIDI_CHANNELS && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  720. nextBankIds[event.channel] = ctrlEvent.param;
  721. break;
  722. case kEngineControlEventTypeMidiProgram:
  723. if (event.channel < MAX_MIDI_CHANNELS && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0)
  724. {
  725. const uint32_t bankId(nextBankIds[event.channel]);
  726. const uint32_t progId(ctrlEvent.param);
  727. const uint32_t rIndex = bankId*128 + progId;
  728. for (uint32_t k=0; k < pData->midiprog.count; ++k)
  729. {
  730. if (pData->midiprog.data[k].bank == bankId && pData->midiprog.data[k].program == progId)
  731. {
  732. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[pData->ctrlChannel]);
  733. /*if (pData->engine->isOffline())
  734. {
  735. engineChannel->PrepareLoadInstrument(pData->filename, rIndex);
  736. engineChannel->LoadInstrument();
  737. }
  738. else*/
  739. {
  740. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel);
  741. }
  742. fCurMidiProgs[event.channel] = static_cast<int32_t>(k);
  743. if (event.channel == pData->ctrlChannel)
  744. pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, static_cast<int32_t>(k), 0, 0.0f);
  745. break;
  746. }
  747. }
  748. }
  749. break;
  750. case kEngineControlEventTypeAllSoundOff:
  751. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  752. {
  753. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  754. }
  755. break;
  756. case kEngineControlEventTypeAllNotesOff:
  757. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  758. {
  759. if (event.channel == pData->ctrlChannel && ! allNotesOffSent)
  760. {
  761. allNotesOffSent = true;
  762. sendMidiAllNotesOffToCallback();
  763. }
  764. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, event.channel, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  765. }
  766. break;
  767. }
  768. break;
  769. }
  770. case kEngineEventTypeMidi:
  771. {
  772. const EngineMidiEvent& midiEvent(event.midi);
  773. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  774. uint8_t channel = event.channel;
  775. // Fix bad note-off
  776. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  777. status = MIDI_STATUS_NOTE_OFF;
  778. if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  779. continue;
  780. if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  781. continue;
  782. if (MIDI_IS_STATUS_CHANNEL_PRESSURE(status) && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  783. continue;
  784. if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  785. continue;
  786. // put back channel in data
  787. uint8_t data[EngineMidiEvent::kDataSize];
  788. std::memcpy(data, event.midi.data, EngineMidiEvent::kDataSize);
  789. if (status < 0xF0 && channel < MAX_MIDI_CHANNELS)
  790. data[0] = uint8_t(data[0] + channel);
  791. fMidiInputPort->DispatchRaw(data, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  792. if (status == MIDI_STATUS_NOTE_ON)
  793. pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, data[1], data[2]);
  794. else if (status == MIDI_STATUS_NOTE_OFF)
  795. pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel,data[1], 0.0f);
  796. break;
  797. }
  798. }
  799. }
  800. pData->postRtEvents.trySplice();
  801. if (frames > timeOffset)
  802. processSingle(outBuffer, frames - timeOffset, timeOffset);
  803. } // End of Event Input and Processing
  804. }
  805. bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  806. {
  807. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  808. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  809. // --------------------------------------------------------------------------------------------------------
  810. // Try lock, silence otherwise
  811. if (pData->engine->isOffline())
  812. {
  813. pData->singleMutex.lock();
  814. }
  815. else if (! pData->singleMutex.tryLock())
  816. {
  817. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  818. {
  819. for (uint32_t k=0; k < frames; ++k)
  820. outBuffer[i][k+timeOffset] = 0.0f;
  821. }
  822. return false;
  823. }
  824. // --------------------------------------------------------------------------------------------------------
  825. // Run plugin
  826. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  827. {
  828. if (LinuxSampler::AudioChannel* const outDev = fAudioOutputDevice->Channel(i))
  829. outDev->SetBuffer(outBuffer[i] + timeOffset);
  830. }
  831. fAudioOutputDevice->Render(frames);
  832. #ifndef BUILD_BRIDGE
  833. // --------------------------------------------------------------------------------------------------------
  834. // Post-processing (dry/wet, volume and balance)
  835. {
  836. const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) > 0 && pData->postProc.volume != 1.0f;
  837. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) > 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
  838. float oldBufLeft[doBalance ? frames : 1];
  839. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  840. {
  841. // Balance
  842. if (doBalance)
  843. {
  844. if (i % 2 == 0)
  845. FLOAT_COPY(oldBufLeft, outBuffer[i], frames);
  846. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  847. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  848. for (uint32_t k=0; k < frames; ++k)
  849. {
  850. if (i % 2 == 0)
  851. {
  852. // left
  853. outBuffer[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  854. outBuffer[i][k] += outBuffer[i+1][k] * (1.0f - balRangeR);
  855. }
  856. else
  857. {
  858. // right
  859. outBuffer[i][k] = outBuffer[i][k] * balRangeR;
  860. outBuffer[i][k] += oldBufLeft[k] * balRangeL;
  861. }
  862. }
  863. }
  864. // Volume
  865. if (doVolume)
  866. {
  867. for (uint32_t k=0; k < frames; ++k)
  868. outBuffer[i][k+timeOffset] *= pData->postProc.volume;
  869. }
  870. }
  871. } // End of Post-processing
  872. #endif
  873. // --------------------------------------------------------------------------------------------------------
  874. pData->singleMutex.unlock();
  875. return true;
  876. }
  877. #ifndef CARLA_OS_WIN // FIXME, need to update linuxsampler win32 build
  878. void bufferSizeChanged(const uint32_t) override
  879. {
  880. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  881. fAudioOutputDevice->ReconnectAll();
  882. }
  883. void sampleRateChanged(const double) override
  884. {
  885. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  886. fAudioOutputDevice->ReconnectAll();
  887. }
  888. #endif
  889. // -------------------------------------------------------------------
  890. // Plugin buffers
  891. // nothing
  892. // -------------------------------------------------------------------
  893. const void* getExtraStuff() const noexcept override
  894. {
  895. static const char xtrue[] = "true";
  896. static const char xfalse[] = "false";
  897. return fUses16Outs ? xtrue : xfalse;
  898. }
  899. bool init(const char* const filename, const char* const name, const char* const label)
  900. {
  901. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  902. // ---------------------------------------------------------------
  903. // first checks
  904. if (pData->client != nullptr)
  905. {
  906. pData->engine->setLastError("Plugin client is already registered");
  907. return false;
  908. }
  909. if (filename == nullptr || filename[0] == '\0')
  910. {
  911. pData->engine->setLastError("null filename");
  912. return false;
  913. }
  914. if (label == nullptr || label[0] == '\0')
  915. {
  916. pData->engine->setLastError("null label");
  917. return false;
  918. }
  919. // ---------------------------------------------------------------
  920. // Store format
  921. CarlaString cstype(fFormat);
  922. cstype.toLower();
  923. const char* const ctype(cstype.getBuffer());
  924. // ---------------------------------------------------------------
  925. // Create the LinuxSampler Engine
  926. try {
  927. fEngine = LinuxSampler::EngineFactory::Create(ctype);
  928. }
  929. catch (LinuxSampler::Exception& e)
  930. {
  931. pData->engine->setLastError(e.what());
  932. return false;
  933. }
  934. // ---------------------------------------------------------------
  935. // Init LinuxSampler stuff
  936. fAudioOutputDevice = new LinuxSampler::AudioOutputDevicePlugin(pData->engine, this, fUses16Outs);
  937. fMidiInputDevice = new LinuxSampler::MidiInputDevicePlugin(&fSampler);
  938. fMidiInputPort = fMidiInputDevice->CreateMidiPortPlugin();
  939. for (uint i=0; i < MAX_MIDI_CHANNELS; ++i)
  940. {
  941. fSamplerChannels[i] = fSampler.AddSamplerChannel();
  942. CARLA_SAFE_ASSERT_CONTINUE(fSamplerChannels[i] != nullptr);
  943. fSamplerChannels[i]->SetEngineType(ctype);
  944. fSamplerChannels[i]->SetAudioOutputDevice(fAudioOutputDevice);
  945. fEngineChannels[i] = fSamplerChannels[i]->GetEngineChannel();
  946. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  947. fEngineChannels[i]->Connect(fAudioOutputDevice);
  948. fEngineChannels[i]->Volume(LinuxSampler::kVolumeMax);
  949. if (fUses16Outs)
  950. {
  951. fEngineChannels[i]->SetOutputChannel(0, i*2);
  952. fEngineChannels[i]->SetOutputChannel(1, i*2 +1);
  953. }
  954. else
  955. {
  956. fEngineChannels[i]->SetOutputChannel(0, 0);
  957. fEngineChannels[i]->SetOutputChannel(1, 1);
  958. }
  959. fMidiInputPort->Connect(fEngineChannels[i], static_cast<LinuxSampler::midi_chan_t>(i));
  960. }
  961. // ---------------------------------------------------------------
  962. // Get the Engine's Instrument Manager
  963. fInstrument = fEngine->GetInstrumentManager();
  964. if (fInstrument == nullptr)
  965. {
  966. pData->engine->setLastError("Failed to get LinuxSampler instrument manager");
  967. return false;
  968. }
  969. // ---------------------------------------------------------------
  970. // Load the Instrument via filename
  971. try {
  972. fInstrumentIds = fInstrument->GetInstrumentFileContent(filename);
  973. }
  974. catch (const LinuxSampler::InstrumentManagerException& e)
  975. {
  976. pData->engine->setLastError(e.what());
  977. return false;
  978. }
  979. // ---------------------------------------------------------------
  980. // Get info
  981. if (fInstrumentIds.size() == 0)
  982. {
  983. pData->engine->setLastError("Failed to find any instruments");
  984. return false;
  985. }
  986. LinuxSampler::InstrumentManager::instrument_info_t info;
  987. try {
  988. info = fInstrument->GetInstrumentInfo(fInstrumentIds[0]);
  989. }
  990. catch (const LinuxSampler::InstrumentManagerException& e)
  991. {
  992. pData->engine->setLastError(e.what());
  993. return false;
  994. }
  995. CarlaString label2(label);
  996. if (fUses16Outs && ! label2.endsWith(" (16 outs)"))
  997. label2 += " (16 outs)";
  998. fLabel = label2.dup();
  999. fMaker = carla_strdup(info.Artists.c_str());
  1000. fRealName = carla_strdup(info.InstrumentName.c_str());
  1001. pData->filename = carla_strdup(filename);
  1002. if (name != nullptr && name[0] != '\0')
  1003. pData->name = pData->engine->getUniquePluginName(name);
  1004. else if (fRealName[0] != '\0')
  1005. pData->name = pData->engine->getUniquePluginName(fRealName);
  1006. else
  1007. pData->name = pData->engine->getUniquePluginName(label);
  1008. // ---------------------------------------------------------------
  1009. // register client
  1010. pData->client = pData->engine->addClient(this);
  1011. if (pData->client == nullptr || ! pData->client->isOk())
  1012. {
  1013. pData->engine->setLastError("Failed to register plugin client");
  1014. return false;
  1015. }
  1016. // ---------------------------------------------------------------
  1017. // load plugin settings
  1018. {
  1019. // set default options
  1020. pData->options = 0x0;
  1021. pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  1022. pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  1023. pData->options |= PLUGIN_OPTION_SEND_PITCHBEND;
  1024. pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  1025. // set identifier string
  1026. CarlaString identifier(fFormat);
  1027. identifier += "/";
  1028. if (const char* const shortname = std::strrchr(filename, OS_SEP))
  1029. identifier += shortname+1;
  1030. else
  1031. identifier += label;
  1032. pData->identifier = identifier.dup();
  1033. // load settings
  1034. pData->options = pData->loadSettings(pData->options, getOptionsAvailable());
  1035. }
  1036. return true;
  1037. }
  1038. // -------------------------------------------------------------------
  1039. private:
  1040. const bool fUses16Outs;
  1041. const char* fFormat;
  1042. const char* fLabel;
  1043. const char* fMaker;
  1044. const char* fRealName;
  1045. int32_t fCurMidiProgs[MAX_MIDI_CHANNELS];
  1046. LinuxSampler::Sampler fSampler;
  1047. LinuxSampler::Engine* fEngine;
  1048. LinuxSampler::SamplerChannel* fSamplerChannels[MAX_MIDI_CHANNELS];
  1049. LinuxSampler::EngineChannel* fEngineChannels[MAX_MIDI_CHANNELS];
  1050. LinuxSampler::AudioOutputDevicePlugin* fAudioOutputDevice;
  1051. LinuxSampler::MidiInputDevicePlugin* fMidiInputDevice;
  1052. LinuxSampler::MidiInputPortPlugin* fMidiInputPort;
  1053. LinuxSampler::InstrumentManager* fInstrument;
  1054. std::vector<LinuxSampler::InstrumentManager::instrument_id_t> fInstrumentIds;
  1055. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinuxSamplerPlugin)
  1056. };
  1057. CARLA_BACKEND_END_NAMESPACE
  1058. #endif // WANT_LINUXSAMPLER
  1059. CARLA_BACKEND_START_NAMESPACE
  1060. CarlaPlugin* CarlaPlugin::newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs)
  1061. {
  1062. carla_debug("LinuxSamplerPlugin::newLinuxSampler({%p, \"%s\", \"%s\", \"%s\"}, %s, %s)", init.engine, init.filename, init.name, init.label, format, bool2str(use16Outs));
  1063. #ifdef WANT_LINUXSAMPLER
  1064. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && use16Outs)
  1065. {
  1066. init.engine->setLastError("Carla's rack mode can only work with Stereo modules, please choose the 2-channel only sample-library version");
  1067. return nullptr;
  1068. }
  1069. // -------------------------------------------------------------------
  1070. // Check if file exists
  1071. {
  1072. QFileInfo file(init.filename);
  1073. if (! file.exists())
  1074. {
  1075. init.engine->setLastError("Requested file does not exist");
  1076. return nullptr;
  1077. }
  1078. if (! file.isFile())
  1079. {
  1080. init.engine->setLastError("Requested file is not valid");
  1081. return nullptr;
  1082. }
  1083. if (! file.isReadable())
  1084. {
  1085. init.engine->setLastError("Requested file is not readable");
  1086. return nullptr;
  1087. }
  1088. }
  1089. LinuxSamplerPlugin* const plugin(new LinuxSamplerPlugin(init.engine, init.id, format, use16Outs));
  1090. if (! plugin->init(init.filename, init.name, init.label))
  1091. {
  1092. delete plugin;
  1093. return nullptr;
  1094. }
  1095. plugin->reload();
  1096. return plugin;
  1097. #else
  1098. init.engine->setLastError("linuxsampler support not available");
  1099. return nullptr;
  1100. // unused
  1101. (void)format;
  1102. (void)use16Outs;
  1103. #endif
  1104. }
  1105. CARLA_BACKEND_END_NAMESPACE