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.

1399 lines
49KB

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