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.

1415 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. // -----------------------------------------------------------------------
  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<String, DeviceCreationParameter*>()),
  45. fEngine(engine),
  46. fPlugin(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. {
  57. }
  58. bool IsPlaying() override
  59. {
  60. return (fEngine->isRunning() && fPlugin->isEnabled());
  61. }
  62. void Stop() override
  63. {
  64. }
  65. uint MaxSamplesPerCycle() override
  66. {
  67. return fEngine->getBufferSize();
  68. }
  69. uint SampleRate() override
  70. {
  71. return uint(fEngine->getSampleRate());
  72. }
  73. String Driver() override
  74. {
  75. return "AudioOutputDevicePlugin";
  76. }
  77. AudioChannel* CreateChannel(uint channelNr) override
  78. {
  79. return new AudioChannel(channelNr, nullptr, 0);
  80. }
  81. // -------------------------------------------------------------------
  82. // Give public access to the RenderAudio call
  83. int Render(const uint samples)
  84. {
  85. return RenderAudio(samples);
  86. }
  87. // -------------------------------------------------------------------
  88. private:
  89. const CarlaEngine* const fEngine;
  90. const CarlaPlugin* const fPlugin;
  91. };
  92. // -----------------------------------------------------------------------
  93. // LinuxSampler MidiInputPort Plugin
  94. class MidiInputPortPlugin : public MidiInputPort
  95. {
  96. public:
  97. MidiInputPortPlugin(MidiInputDevice* const device, const int portNum)
  98. : MidiInputPort(device, portNum)
  99. {
  100. }
  101. ~MidiInputPortPlugin() override {}
  102. };
  103. // -----------------------------------------------------------------------
  104. // LinuxSampler MidiInputDevice Plugin
  105. class MidiInputDevicePlugin : public MidiInputDevice
  106. {
  107. public:
  108. MidiInputDevicePlugin(Sampler* const sampler)
  109. : MidiInputDevice(std::map<String, DeviceCreationParameter*>(), sampler)
  110. {
  111. }
  112. // -------------------------------------------------------------------
  113. // LinuxSampler virtual methods
  114. void Listen() override
  115. {
  116. }
  117. void StopListen() override
  118. {
  119. }
  120. String Driver() override
  121. {
  122. return "MidiInputDevicePlugin";
  123. }
  124. MidiInputPort* CreateMidiPort() override
  125. {
  126. return new MidiInputPortPlugin(this, int(Ports.size()));
  127. }
  128. MidiInputPortPlugin* CreateMidiPortPlugin()
  129. {
  130. return new MidiInputPortPlugin(this, int(Ports.size()));
  131. }
  132. };
  133. } // namespace LinuxSampler
  134. // -----------------------------------------------------------------------
  135. CARLA_BACKEND_START_NAMESPACE
  136. #if 0
  137. }
  138. #endif
  139. class LinuxSamplerPlugin : public CarlaPlugin
  140. {
  141. public:
  142. LinuxSamplerPlugin(CarlaEngine* const engine, const unsigned int id, const char* const format, const bool use16Outs)
  143. : CarlaPlugin(engine, id),
  144. fUses16Outs(use16Outs),
  145. fFormat(carla_strdup(format)),
  146. fLabel(nullptr),
  147. fMaker(nullptr),
  148. fRealName(nullptr),
  149. fEngine(nullptr),
  150. fAudioOutputDevice(nullptr),
  151. fMidiInputDevice(nullptr),
  152. fMidiInputPort(nullptr),
  153. fInstrument(nullptr)
  154. {
  155. carla_debug("LinuxSamplerPlugin::LinuxSamplerPlugin(%p, %i, %s, %s)", engine, id, format, bool2str(use16Outs));
  156. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  157. {
  158. fCurMidiProgs[0] = 0;
  159. fSamplerChannels[i] = nullptr;
  160. fEngineChannels[i] = nullptr;
  161. }
  162. }
  163. ~LinuxSamplerPlugin() override
  164. {
  165. carla_debug("LinuxSamplerPlugin::~LinuxSamplerPlugin()");
  166. pData->singleMutex.lock();
  167. pData->masterMutex.lock();
  168. if (pData->client != nullptr && pData->client->isActive())
  169. pData->client->deactivate();
  170. if (pData->active)
  171. {
  172. deactivate();
  173. pData->active = false;
  174. }
  175. if (fEngine != nullptr)
  176. {
  177. if (fMidiInputDevice != nullptr)
  178. {
  179. if (fMidiInputPort != nullptr)
  180. {
  181. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  182. {
  183. if (fSamplerChannels[i] != nullptr)
  184. {
  185. if (fEngineChannels[i] != nullptr)
  186. {
  187. fMidiInputPort->Disconnect(fEngineChannels[i]);
  188. fEngineChannels[i]->DisconnectAudioOutputDevice();
  189. fEngineChannels[i] = nullptr;
  190. }
  191. fSampler.RemoveSamplerChannel(fSamplerChannels[i]);
  192. fSamplerChannels[i] = nullptr;
  193. }
  194. }
  195. delete fMidiInputPort;
  196. fMidiInputPort = nullptr;
  197. }
  198. delete fMidiInputDevice;
  199. fMidiInputDevice = nullptr;
  200. }
  201. if (fAudioOutputDevice != nullptr)
  202. {
  203. delete fAudioOutputDevice;
  204. fAudioOutputDevice = nullptr;
  205. }
  206. fInstrument = nullptr;
  207. LinuxSampler::EngineFactory::Destroy(fEngine);
  208. fEngine = nullptr;
  209. }
  210. fInstrumentIds.clear();
  211. if (fFormat != nullptr)
  212. {
  213. delete[] fFormat;
  214. fFormat = nullptr;
  215. }
  216. if (fLabel != nullptr)
  217. {
  218. delete[] fLabel;
  219. fLabel = nullptr;
  220. }
  221. if (fMaker != nullptr)
  222. {
  223. delete[] fMaker;
  224. fMaker = nullptr;
  225. }
  226. if (fRealName != nullptr)
  227. {
  228. delete[] fRealName;
  229. fRealName = nullptr;
  230. }
  231. clearBuffers();
  232. }
  233. // -------------------------------------------------------------------
  234. // Information (base)
  235. PluginType getType() const noexcept override
  236. {
  237. return getPluginTypeFromString(fFormat);
  238. }
  239. PluginCategory getCategory() const noexcept override
  240. {
  241. return PLUGIN_CATEGORY_SYNTH;
  242. }
  243. // -------------------------------------------------------------------
  244. // Information (count)
  245. // nothing
  246. // -------------------------------------------------------------------
  247. // Information (current data)
  248. // nothing
  249. // -------------------------------------------------------------------
  250. // Information (per-plugin data)
  251. unsigned int getOptionsAvailable() const noexcept override
  252. {
  253. unsigned int options = 0x0;
  254. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  255. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  256. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  257. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  258. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  259. return options;
  260. }
  261. void getLabel(char* const strBuf) const noexcept override
  262. {
  263. if (fLabel != nullptr)
  264. std::strncpy(strBuf, fLabel, STR_MAX);
  265. else
  266. CarlaPlugin::getLabel(strBuf);
  267. }
  268. void getMaker(char* const strBuf) const noexcept override
  269. {
  270. if (fMaker != nullptr)
  271. std::strncpy(strBuf, fMaker, STR_MAX);
  272. else
  273. CarlaPlugin::getMaker(strBuf);
  274. }
  275. void getCopyright(char* const strBuf) const noexcept override
  276. {
  277. getMaker(strBuf);
  278. }
  279. void getRealName(char* const strBuf) const noexcept override
  280. {
  281. if (fRealName != nullptr)
  282. std::strncpy(strBuf, fRealName, STR_MAX);
  283. else
  284. CarlaPlugin::getRealName(strBuf);
  285. }
  286. // -------------------------------------------------------------------
  287. // Set data (state)
  288. void prepareForSave() override
  289. {
  290. char strBuf[STR_MAX+1];
  291. 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],
  292. fCurMidiProgs[4], fCurMidiProgs[5], fCurMidiProgs[6], fCurMidiProgs[7],
  293. fCurMidiProgs[8], fCurMidiProgs[9], fCurMidiProgs[10], fCurMidiProgs[11],
  294. fCurMidiProgs[12], fCurMidiProgs[13], fCurMidiProgs[14], fCurMidiProgs[15]);
  295. CarlaPlugin::setCustomData(CUSTOM_DATA_TYPE_STRING, "midiPrograms", strBuf, false);
  296. }
  297. // -------------------------------------------------------------------
  298. // Set data (internal stuff)
  299. void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override
  300. {
  301. if (channel < MAX_MIDI_CHANNELS)
  302. pData->midiprog.current = fCurMidiProgs[channel];
  303. CarlaPlugin::setCtrlChannel(channel, sendOsc, sendCallback);
  304. }
  305. // -------------------------------------------------------------------
  306. // Set data (plugin-specific stuff)
  307. void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override
  308. {
  309. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  310. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  311. CARLA_SAFE_ASSERT_RETURN(value != nullptr && value[0] != '\0',);
  312. carla_debug("LinuxSamplerPlugin::setCustomData(%s, \"%s\", \"%s\", %s)", type, key, value, bool2str(sendGui));
  313. if (std::strcmp(type, CUSTOM_DATA_TYPE_STRING) != 0)
  314. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  315. if (std::strcmp(key, "midiPrograms") != 0)
  316. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  317. if (fUses16Outs)
  318. {
  319. QStringList midiProgramList(QString(value).split(":", QString::SkipEmptyParts));
  320. if (midiProgramList.count() == MAX_MIDI_CHANNELS)
  321. {
  322. uint i = 0;
  323. foreach (const QString& midiProg, midiProgramList)
  324. {
  325. CARLA_SAFE_ASSERT_BREAK(i < MAX_MIDI_CHANNELS);
  326. bool ok;
  327. int index = midiProg.toInt(&ok);
  328. if (ok && index >= 0 && index < static_cast<int>(pData->midiprog.count))
  329. {
  330. const uint32_t bank = pData->midiprog.data[index].bank;
  331. const uint32_t program = pData->midiprog.data[index].program;
  332. const uint32_t rIndex = bank*128 + program;
  333. /*if (pData->engine->isOffline())
  334. {
  335. fEngineChannels[i]->PrepareLoadInstrument(pData->filename, rIndex);
  336. fEngineChannels[i]->LoadInstrument();
  337. }
  338. else*/
  339. {
  340. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], fEngineChannels[i]);
  341. }
  342. fCurMidiProgs[i] = index;
  343. if (pData->ctrlChannel == static_cast<int32_t>(i))
  344. {
  345. pData->midiprog.current = index;
  346. pData->engine->callback(ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED, pData->id, index, 0, 0.0f, nullptr);
  347. }
  348. }
  349. ++i;
  350. }
  351. CARLA_SAFE_ASSERT(i == MAX_MIDI_CHANNELS);
  352. }
  353. }
  354. CarlaPlugin::setCustomData(type, key, value, sendGui);
  355. }
  356. void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override
  357. {
  358. CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast<int32_t>(pData->midiprog.count),);
  359. if (index >= 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  360. {
  361. const uint32_t bank = pData->midiprog.data[index].bank;
  362. const uint32_t program = pData->midiprog.data[index].program;
  363. const uint32_t rIndex = bank*128 + program;
  364. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[pData->ctrlChannel]);
  365. const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  366. /*if (pData->engine->isOffline())
  367. {
  368. engineChannel->PrepareLoadInstrument(pData->filename, rIndex);
  369. engineChannel->LoadInstrument();
  370. }
  371. else*/
  372. {
  373. try {
  374. fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel);
  375. } catch(...) {}
  376. }
  377. fCurMidiProgs[pData->ctrlChannel] = index;
  378. }
  379. CarlaPlugin::setMidiProgram(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 = fUses16Outs ? 32 : 2;
  399. pData->audioOut.createNew(aOuts);
  400. const uint portNameSize(pData->engine->getMaxPortNameSize());
  401. CarlaString portName;
  402. // ---------------------------------------
  403. // Audio Outputs
  404. if (fUses16Outs)
  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 (! fUses16Outs)
  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 (fUses16Outs)
  476. pData->extraHints |= PLUGIN_EXTRA_HINT_USES_MULTI_PROGS;
  477. else
  478. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  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->midiprog.clear();
  490. // Query new programs
  491. uint32_t count = uint32_t(fInstrumentIds.size());
  492. // sound kits must always have at least 1 midi-program
  493. CARLA_SAFE_ASSERT_RETURN(count > 0,);
  494. pData->midiprog.createNew(count);
  495. // Update data
  496. LinuxSampler::InstrumentManager::instrument_info_t info;
  497. for (uint32_t i=0; i < pData->midiprog.count; ++i)
  498. {
  499. pData->midiprog.data[i].bank = i / 128;
  500. pData->midiprog.data[i].program = i % 128;
  501. try {
  502. info = fInstrument->GetInstrumentInfo(fInstrumentIds[i]);
  503. }
  504. catch (const LinuxSampler::InstrumentManagerException&)
  505. {
  506. continue;
  507. }
  508. pData->midiprog.data[i].name = carla_strdup(info.InstrumentName.c_str());
  509. }
  510. #ifndef BUILD_BRIDGE
  511. // Update OSC Names
  512. if (pData->engine->isOscControlRegistered())
  513. {
  514. pData->engine->oscSend_control_set_midi_program_count(pData->id, count);
  515. for (uint32_t i=0; i < count; ++i)
  516. 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);
  517. }
  518. #endif
  519. if (doInit)
  520. {
  521. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  522. {
  523. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  524. /*fEngineChannels[i]->PrepareLoadInstrument(pData->filename, 0);
  525. fEngineChannels[i]->LoadInstrument();*/
  526. fInstrument->LoadInstrumentInBackground(fInstrumentIds[0], fEngineChannels[i]);
  527. fCurMidiProgs[i] = 0;
  528. }
  529. pData->midiprog.current = 0;
  530. }
  531. else
  532. {
  533. pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr);
  534. }
  535. }
  536. // -------------------------------------------------------------------
  537. // Plugin processing
  538. #if 0
  539. void activate() override
  540. {
  541. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  542. {
  543. if (fAudioOutputDevices[i] != nullptr)
  544. fAudioOutputDevices[i]->Play();
  545. }
  546. }
  547. void deactivate() override
  548. {
  549. for (int i=0; i < MAX_MIDI_CHANNELS; ++i)
  550. {
  551. if (fAudioOutputDevices[i] != nullptr)
  552. fAudioOutputDevices[i]->Stop();
  553. }
  554. }
  555. #endif
  556. void process(float** const, float** const outBuffer, const uint32_t frames) override
  557. {
  558. // --------------------------------------------------------------------------------------------------------
  559. // Check if active
  560. if (! pData->active)
  561. {
  562. // disable any output sound
  563. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  564. FLOAT_CLEAR(outBuffer[i], frames);
  565. return;
  566. }
  567. // --------------------------------------------------------------------------------------------------------
  568. // Check if needs reset
  569. if (pData->needsReset)
  570. {
  571. if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF)
  572. {
  573. for (uint i=0; i < MAX_MIDI_CHANNELS; ++i)
  574. {
  575. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_NOTES_OFF, 0, i);
  576. fMidiInputPort->DispatchControlChange(MIDI_CONTROL_ALL_SOUND_OFF, 0, i);
  577. }
  578. }
  579. else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  580. {
  581. for (uint8_t i=0; i < MAX_MIDI_NOTE; ++i)
  582. fMidiInputPort->DispatchNoteOff(i, 0, uint(pData->ctrlChannel));
  583. }
  584. pData->needsReset = false;
  585. }
  586. // --------------------------------------------------------------------------------------------------------
  587. // Event Input and Processing
  588. {
  589. // ----------------------------------------------------------------------------------------------------
  590. // MIDI Input (External)
  591. if (pData->extNotes.mutex.tryLock())
  592. {
  593. while (! pData->extNotes.data.isEmpty())
  594. {
  595. const ExternalMidiNote& note(pData->extNotes.data.getFirst(true));
  596. CARLA_SAFE_ASSERT_CONTINUE(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS);
  597. if (note.velo > 0)
  598. fMidiInputPort->DispatchNoteOn(note.note, note.velo, static_cast<uint>(note.channel));
  599. else
  600. fMidiInputPort->DispatchNoteOff(note.note, note.velo, static_cast<uint>(note.channel));
  601. }
  602. pData->extNotes.mutex.unlock();
  603. } // End of MIDI Input (External)
  604. // ----------------------------------------------------------------------------------------------------
  605. // Event Input (System)
  606. bool allNotesOffSent = false;
  607. bool sampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  608. uint32_t nEvents = pData->event.portIn->getEventCount();
  609. uint32_t startTime = 0;
  610. uint32_t timeOffset = 0;
  611. uint32_t nextBankIds[MAX_MIDI_CHANNELS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0 };
  612. if (pData->midiprog.current >= 0 && pData->midiprog.count > 0 && pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS)
  613. nextBankIds[pData->ctrlChannel] = pData->midiprog.data[pData->midiprog.current].bank;
  614. for (uint32_t i=0; i < nEvents; ++i)
  615. {
  616. const EngineEvent& event(pData->event.portIn->getEvent(i));
  617. CARLA_SAFE_ASSERT_CONTINUE(event.time < frames);
  618. CARLA_SAFE_ASSERT_BREAK(event.time >= timeOffset);
  619. if (event.time > timeOffset && sampleAccurate)
  620. {
  621. if (processSingle(outBuffer, event.time - timeOffset, timeOffset))
  622. {
  623. startTime = 0;
  624. timeOffset = event.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, static_cast<int32_t>(sampleAccurate ? startTime : event.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] = static_cast<int32_t>(k);
  744. if (event.channel == pData->ctrlChannel)
  745. pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, static_cast<int32_t>(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, static_cast<int32_t>(sampleAccurate ? startTime : event.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, static_cast<int32_t>(sampleAccurate ? startTime : event.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, static_cast<int32_t>(sampleAccurate ? startTime : event.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.buffer());
  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 (uint 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\", " P_INT64 "}, %s, %s)", init.engine, init.filename, init.name, init.label, init.uniqueId, 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