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.

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