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.

1397 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 HAVE_LINUXSAMPLER
  26. #include "CarlaBackendUtils.hpp"
  27. #include "CarlaMathUtils.hpp"
  28. #include "juce_core.h"
  29. #include "linuxsampler/EngineFactory.h"
  30. #include <linuxsampler/Sampler.h>
  31. // -----------------------------------------------------------------------
  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<std::string, DeviceCreationParameter*>()),
  45. kEngine(engine),
  46. kPlugin(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. void Stop() override {}
  57. bool IsPlaying() override
  58. {
  59. return (kEngine->isRunning() && kPlugin->isEnabled());
  60. }
  61. uint MaxSamplesPerCycle() override
  62. {
  63. return kEngine->getBufferSize();
  64. }
  65. uint SampleRate() override
  66. {
  67. return uint(kEngine->getSampleRate());
  68. }
  69. std::string Driver() override
  70. {
  71. return "AudioOutputDevicePlugin";
  72. }
  73. AudioChannel* CreateChannel(uint channelNr) override
  74. {
  75. return new AudioChannel(channelNr, nullptr, 0);
  76. }
  77. // -------------------------------------------------------------------
  78. bool isAutonomousDevice() override { return false; }
  79. static bool isAutonomousDriver() { return false; }
  80. // -------------------------------------------------------------------
  81. // Give public access to the RenderAudio call
  82. int Render(const uint samples)
  83. {
  84. return RenderAudio(samples);
  85. }
  86. // -------------------------------------------------------------------
  87. private:
  88. const CarlaEngine* const kEngine;
  89. const CarlaPlugin* const kPlugin;
  90. };
  91. // -----------------------------------------------------------------------
  92. // LinuxSampler MidiInputPort Plugin
  93. class MidiInputPortPlugin : public MidiInputPort
  94. {
  95. public:
  96. MidiInputPortPlugin(MidiInputDevice* const device, const int portNum)
  97. : MidiInputPort(device, portNum) {}
  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<std::string, DeviceCreationParameter*>(), sampler) {}
  107. // -------------------------------------------------------------------
  108. // LinuxSampler virtual methods
  109. void Listen() override {}
  110. void StopListen() override {}
  111. std::string Driver() override
  112. {
  113. return "MidiInputDevicePlugin";
  114. }
  115. MidiInputPort* CreateMidiPort() override
  116. {
  117. return new MidiInputPortPlugin(this, int(Ports.size()));
  118. }
  119. // -------------------------------------------------------------------
  120. bool isAutonomousDevice() override { return false; }
  121. static bool isAutonomousDriver() { return false; }
  122. // -------------------------------------------------------------------
  123. MidiInputPortPlugin* CreateMidiPortPlugin()
  124. {
  125. return new MidiInputPortPlugin(this, int(Ports.size()));
  126. }
  127. };
  128. // -----------------------------------------------------------------------
  129. // SamplerPlugin
  130. struct SamplerPlugin {
  131. Sampler sampler;
  132. MidiInputDevicePlugin midiIn;
  133. SamplerPlugin()
  134. : sampler(),
  135. midiIn(&sampler) {}
  136. };
  137. } // namespace LinuxSampler
  138. // -----------------------------------------------------------------------
  139. using juce::File;
  140. using juce::SharedResourcePointer;
  141. using juce::StringArray;
  142. CARLA_BACKEND_START_NAMESPACE
  143. // -----------------------------------------------------------------------
  144. class LinuxSamplerPlugin : public CarlaPlugin
  145. {
  146. public:
  147. LinuxSamplerPlugin(CarlaEngine* const engine, const uint id, const bool isGIG, const bool use16Outs)
  148. : CarlaPlugin(engine, id),
  149. kIsGIG(isGIG),
  150. kUses16Outs(use16Outs && isGIG),
  151. kMaxChannels(isGIG ? MAX_MIDI_CHANNELS : 1),
  152. fLabel(nullptr),
  153. fMaker(nullptr),
  154. fRealName(nullptr),
  155. fAudioOutputDevice(nullptr),
  156. fMidiInputPort(nullptr),
  157. fInstrument(nullptr)
  158. {
  159. carla_debug("LinuxSamplerPlugin::LinuxSamplerPlugin(%p, %i, %s, %s)", engine, id, bool2str(isGIG), bool2str(use16Outs));
  160. carla_zeroStruct(fCurProgs, MAX_MIDI_CHANNELS);
  161. carla_zeroStruct(fEngineChannels, MAX_MIDI_CHANNELS);
  162. carla_zeroStruct(fSamplerChannels, MAX_MIDI_CHANNELS);
  163. if (use16Outs && ! isGIG)
  164. carla_stderr("Tried to use SFZ with 16 stereo outs, this doesn't make much sense so single stereo mode will be used instead");
  165. }
  166. ~LinuxSamplerPlugin() override
  167. {
  168. carla_debug("LinuxSamplerPlugin::~LinuxSamplerPlugin()");
  169. pData->singleMutex.lock();
  170. pData->masterMutex.lock();
  171. if (pData->client != nullptr && pData->client->isActive())
  172. pData->client->deactivate();
  173. if (pData->active)
  174. {
  175. deactivate();
  176. pData->active = false;
  177. }
  178. if (fMidiInputPort != nullptr)
  179. {
  180. for (uint i=0; i<kMaxChannels; ++i)
  181. {
  182. if (fSamplerChannels[i] != nullptr)
  183. {
  184. if (fEngineChannels[i] != nullptr)
  185. {
  186. fMidiInputPort->Disconnect(fEngineChannels[i]);
  187. fEngineChannels[i]->DisconnectAudioOutputDevice();
  188. fEngineChannels[i] = nullptr;
  189. }
  190. sSampler->sampler.RemoveSamplerChannel(fSamplerChannels[i]);
  191. fSamplerChannels[i] = nullptr;
  192. }
  193. }
  194. delete fMidiInputPort;
  195. fMidiInputPort = nullptr;
  196. }
  197. if (fAudioOutputDevice != nullptr)
  198. {
  199. delete fAudioOutputDevice;
  200. fAudioOutputDevice = nullptr;
  201. }
  202. fInstrument = nullptr;
  203. fInstrumentIds.clear();
  204. if (fLabel != nullptr)
  205. {
  206. delete[] fLabel;
  207. fLabel = nullptr;
  208. }
  209. if (fMaker != nullptr)
  210. {
  211. delete[] fMaker;
  212. fMaker = nullptr;
  213. }
  214. if (fRealName != nullptr)
  215. {
  216. delete[] fRealName;
  217. fRealName = nullptr;
  218. }
  219. clearBuffers();
  220. }
  221. // -------------------------------------------------------------------
  222. // Information (base)
  223. PluginType getType() const noexcept override
  224. {
  225. return kIsGIG ? PLUGIN_GIG : PLUGIN_SFZ;
  226. }
  227. PluginCategory getCategory() const noexcept override
  228. {
  229. return PLUGIN_CATEGORY_SYNTH;
  230. }
  231. // -------------------------------------------------------------------
  232. // Information (count)
  233. // nothing
  234. // -------------------------------------------------------------------
  235. // Information (current data)
  236. // nothing
  237. // -------------------------------------------------------------------
  238. // Information (per-plugin data)
  239. uint getOptionsAvailable() const noexcept override
  240. {
  241. uint options = 0x0;
  242. options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES;
  243. options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES;
  244. options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE;
  245. options |= PLUGIN_OPTION_SEND_PITCHBEND;
  246. options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF;
  247. return options;
  248. }
  249. void getLabel(char* const strBuf) const noexcept override
  250. {
  251. if (fLabel != nullptr)
  252. {
  253. std::strncpy(strBuf, fLabel, STR_MAX);
  254. return;
  255. }
  256. CarlaPlugin::getLabel(strBuf);
  257. }
  258. void getMaker(char* const strBuf) const noexcept override
  259. {
  260. if (fMaker != nullptr)
  261. {
  262. std::strncpy(strBuf, fMaker, STR_MAX);
  263. return;
  264. }
  265. CarlaPlugin::getMaker(strBuf);
  266. }
  267. void getCopyright(char* const strBuf) const noexcept override
  268. {
  269. getMaker(strBuf);
  270. }
  271. void getRealName(char* const strBuf) const noexcept override
  272. {
  273. if (fRealName != nullptr)
  274. {
  275. std::strncpy(strBuf, fRealName, STR_MAX);
  276. return;
  277. }
  278. CarlaPlugin::getRealName(strBuf);
  279. }
  280. // -------------------------------------------------------------------
  281. // Set data (state)
  282. void prepareForSave() override
  283. {
  284. if (kMaxChannels > 1 && fInstrumentIds.size() > 1)
  285. {
  286. char strBuf[STR_MAX+1];
  287. 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],
  288. fCurProgs[4], fCurProgs[5], fCurProgs[6], fCurProgs[7],
  289. fCurProgs[8], fCurProgs[9], fCurProgs[10], fCurProgs[11],
  290. fCurProgs[12], fCurProgs[13], fCurProgs[14], fCurProgs[15]);
  291. CarlaPlugin::setCustomData(CUSTOM_DATA_TYPE_STRING, "programs", strBuf, false);
  292. }
  293. }
  294. // -------------------------------------------------------------------
  295. // Set data (internal stuff)
  296. void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override
  297. {
  298. if (channel >= 0 && channel < MAX_MIDI_CHANNELS)
  299. pData->prog.current = fCurProgs[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, "programs") != 0)
  313. return carla_stderr2("LinuxSamplerPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is not string", type, key, value, bool2str(sendGui));
  314. if (kMaxChannels > 1 && fInstrumentIds.size() > 1)
  315. {
  316. StringArray programList(StringArray::fromTokens(value, ":", ""));
  317. if (programList.size() == MAX_MIDI_CHANNELS)
  318. {
  319. uint8_t channel = 0;
  320. for (juce::String *it=programList.begin(), *end=programList.end(); it != end; ++it)
  321. {
  322. const int index(it->getIntValue());
  323. if (index >= 0 && index < static_cast<int>(pData->prog.count))
  324. {
  325. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[channel]);
  326. CARLA_SAFE_ASSERT_CONTINUE(engineChannel != nullptr);
  327. if (pData->engine->isOffline())
  328. {
  329. try {
  330. engineChannel->PrepareLoadInstrument(pData->filename, index);
  331. engineChannel->LoadInstrument();
  332. } CARLA_SAFE_EXCEPTION("LoadInstrument");
  333. }
  334. else
  335. {
  336. try {
  337. fInstrument->LoadInstrumentInBackground(fInstrumentIds[index], 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 : 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 ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback));
  364. if (pData->engine->isOffline())
  365. {
  366. try {
  367. engineChannel->PrepareLoadInstrument(pData->filename, index);
  368. engineChannel->LoadInstrument();
  369. } CARLA_SAFE_EXCEPTION("LoadInstrument");
  370. }
  371. else
  372. {
  373. try {
  374. fInstrument->LoadInstrumentInBackground(fInstrumentIds[index], engineChannel);
  375. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  376. }
  377. fCurProgs[channel] = index;
  378. }
  379. CarlaPlugin::setProgram(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 = kUses16Outs ? 32 : 2;
  399. pData->audioOut.createNew(aOuts);
  400. const uint portNameSize(pData->engine->getMaxPortNameSize());
  401. CarlaString portName;
  402. // ---------------------------------------
  403. // Audio Outputs
  404. if (kUses16Outs)
  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 (! kUses16Outs)
  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 (! kUses16Outs)
  476. pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK;
  477. if (fInstrumentIds.size() > 1)
  478. pData->extraHints |= PLUGIN_EXTRA_HINT_USES_MULTI_PROGS;
  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->prog.clear();
  490. // Query new programs
  491. const uint32_t count(static_cast<uint32_t>(fInstrumentIds.size()));
  492. // sound kits must always have at least 1 midi-program
  493. CARLA_SAFE_ASSERT_RETURN(count > 0,);
  494. pData->prog.createNew(count);
  495. // Update data
  496. LinuxSampler::InstrumentManager::instrument_info_t info;
  497. for (uint32_t i=0; i < pData->prog.count; ++i)
  498. {
  499. try {
  500. info = fInstrument->GetInstrumentInfo(fInstrumentIds[i]);
  501. } CARLA_SAFE_EXCEPTION_CONTINUE("GetInstrumentInfo");
  502. pData->prog.names[i] = carla_strdup_safe(info.InstrumentName.c_str());
  503. }
  504. #ifndef BUILD_BRIDGE
  505. // Update OSC Names
  506. if (pData->engine->isOscControlRegistered())
  507. {
  508. pData->engine->oscSend_control_set_program_count(pData->id, count);
  509. for (uint32_t i=0; i < count; ++i)
  510. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  511. }
  512. #endif
  513. if (doInit)
  514. {
  515. for (uint i=0; i<kMaxChannels; ++i)
  516. {
  517. LinuxSampler::EngineChannel* const engineChannel(fEngineChannels[i]);
  518. CARLA_SAFE_ASSERT_CONTINUE(engineChannel != nullptr);
  519. try {
  520. fInstrument->LoadInstrumentInBackground(fInstrumentIds[0], engineChannel);
  521. } CARLA_SAFE_EXCEPTION("LoadInstrumentInBackground");
  522. fCurProgs[i] = 0;
  523. }
  524. pData->prog.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 < MAX_MIDI_CHANNELS; ++i)
  537. {
  538. if (fAudioOutputDevices[i] != nullptr)
  539. fAudioOutputDevices[i]->Play();
  540. }
  541. }
  542. void deactivate() override
  543. {
  544. for (int i=0; i < MAX_MIDI_CHANNELS; ++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. FloatVectorOperations::clear(outBuffer[i], static_cast<int>(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. for (RtLinkedList<ExternalMidiNote>::Itenerator it = pData->extNotes.data.begin(); it.valid(); it.next())
  589. {
  590. const ExternalMidiNote& note(it.getValue());
  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, static_cast<uint>(note.channel));
  594. else
  595. fMidiInputPort->DispatchNoteOff(note.note, note.velo, static_cast<uint>(note.channel));
  596. }
  597. pData->extNotes.data.clear();
  598. pData->extNotes.mutex.unlock();
  599. } // End of MIDI Input (External)
  600. // ----------------------------------------------------------------------------------------------------
  601. // Event Input (System)
  602. #ifndef BUILD_BRIDGE
  603. bool allNotesOffSent = false;
  604. #endif
  605. bool sampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0;
  606. uint32_t nEvents = pData->event.portIn->getEventCount();
  607. uint32_t startTime = 0;
  608. uint32_t timeOffset = 0;
  609. for (uint32_t i=0; i < nEvents; ++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(outBuffer, 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 <= 0x5F)
  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. {
  763. const EngineMidiEvent& midiEvent(event.midi);
  764. uint8_t status = uint8_t(MIDI_GET_STATUS_FROM_DATA(midiEvent.data));
  765. uint8_t channel = event.channel;
  766. // Fix bad note-off
  767. if (MIDI_IS_STATUS_NOTE_ON(status) && midiEvent.data[2] == 0)
  768. status = MIDI_STATUS_NOTE_OFF;
  769. if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0)
  770. continue;
  771. if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0)
  772. continue;
  773. if (MIDI_IS_STATUS_CHANNEL_PRESSURE(status) && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0)
  774. continue;
  775. if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0)
  776. continue;
  777. // put back channel in data
  778. uint8_t data[EngineMidiEvent::kDataSize];
  779. std::memcpy(data, event.midi.data, EngineMidiEvent::kDataSize);
  780. if (status < 0xF0 && channel < MAX_MIDI_CHANNELS)
  781. data[0] = uint8_t(data[0] + channel);
  782. fMidiInputPort->DispatchRaw(data, static_cast<int32_t>(sampleAccurate ? startTime : event.time));
  783. if (status == MIDI_STATUS_NOTE_ON)
  784. pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, data[1], data[2]);
  785. else if (status == MIDI_STATUS_NOTE_OFF)
  786. pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel,data[1], 0.0f);
  787. break;
  788. }
  789. }
  790. }
  791. pData->postRtEvents.trySplice();
  792. if (frames > timeOffset)
  793. processSingle(outBuffer, frames - timeOffset, timeOffset);
  794. } // End of Event Input and Processing
  795. }
  796. bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  797. {
  798. CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false);
  799. CARLA_SAFE_ASSERT_RETURN(frames > 0, false);
  800. // --------------------------------------------------------------------------------------------------------
  801. // Try lock, silence otherwise
  802. if (pData->engine->isOffline())
  803. {
  804. pData->singleMutex.lock();
  805. }
  806. else if (! pData->singleMutex.tryLock())
  807. {
  808. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  809. {
  810. for (uint32_t k=0; k < frames; ++k)
  811. outBuffer[i][k+timeOffset] = 0.0f;
  812. }
  813. return false;
  814. }
  815. // --------------------------------------------------------------------------------------------------------
  816. // Run plugin
  817. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  818. {
  819. if (LinuxSampler::AudioChannel* const outDev = fAudioOutputDevice->Channel(i))
  820. outDev->SetBuffer(outBuffer[i] + timeOffset);
  821. }
  822. fAudioOutputDevice->Render(frames);
  823. #ifndef BUILD_BRIDGE
  824. // --------------------------------------------------------------------------------------------------------
  825. // Post-processing (dry/wet, volume and balance)
  826. {
  827. const bool doVolume = (pData->hints & PLUGIN_CAN_VOLUME) > 0 && pData->postProc.volume != 1.0f;
  828. const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) > 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f);
  829. float oldBufLeft[doBalance ? frames : 1];
  830. for (uint32_t i=0; i < pData->audioOut.count; ++i)
  831. {
  832. // Balance
  833. if (doBalance)
  834. {
  835. if (i % 2 == 0)
  836. FloatVectorOperations::copy(oldBufLeft, outBuffer[i], static_cast<int>(frames));
  837. float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f;
  838. float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f;
  839. for (uint32_t k=0; k < frames; ++k)
  840. {
  841. if (i % 2 == 0)
  842. {
  843. // left
  844. outBuffer[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  845. outBuffer[i][k] += outBuffer[i+1][k] * (1.0f - balRangeR);
  846. }
  847. else
  848. {
  849. // right
  850. outBuffer[i][k] = outBuffer[i][k] * balRangeR;
  851. outBuffer[i][k] += oldBufLeft[k] * balRangeL;
  852. }
  853. }
  854. }
  855. // Volume
  856. if (doVolume)
  857. {
  858. for (uint32_t k=0; k < frames; ++k)
  859. outBuffer[i][k+timeOffset] *= pData->postProc.volume;
  860. }
  861. }
  862. } // End of Post-processing
  863. #endif
  864. // --------------------------------------------------------------------------------------------------------
  865. pData->singleMutex.unlock();
  866. return true;
  867. }
  868. #ifndef CARLA_OS_WIN // FIXME, need to update linuxsampler win32 build
  869. void bufferSizeChanged(const uint32_t) override
  870. {
  871. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  872. fAudioOutputDevice->ReconnectAll();
  873. }
  874. void sampleRateChanged(const double) override
  875. {
  876. CARLA_SAFE_ASSERT_RETURN(fAudioOutputDevice != nullptr,);
  877. fAudioOutputDevice->ReconnectAll();
  878. }
  879. #endif
  880. // -------------------------------------------------------------------
  881. // Plugin buffers
  882. // nothing
  883. // -------------------------------------------------------------------
  884. const void* getExtraStuff() const noexcept override
  885. {
  886. static const char xtrue[] = "true";
  887. static const char xfalse[] = "false";
  888. return kUses16Outs ? xtrue : xfalse;
  889. }
  890. bool init(const char* const filename, const char* const name, const char* const label)
  891. {
  892. CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false);
  893. // ---------------------------------------------------------------
  894. // first checks
  895. if (pData->client != nullptr)
  896. {
  897. pData->engine->setLastError("Plugin client is already registered");
  898. return false;
  899. }
  900. if (filename == nullptr || filename[0] == '\0')
  901. {
  902. pData->engine->setLastError("null filename");
  903. return false;
  904. }
  905. // ---------------------------------------------------------------
  906. // Init LinuxSampler stuff
  907. fAudioOutputDevice = new LinuxSampler::AudioOutputDevicePlugin(pData->engine, this, kUses16Outs);
  908. fMidiInputPort = sSampler->midiIn.CreateMidiPortPlugin();
  909. for (uint i=0; i<kMaxChannels; ++i)
  910. {
  911. fSamplerChannels[i] = sSampler->sampler.AddSamplerChannel();
  912. CARLA_SAFE_ASSERT_CONTINUE(fSamplerChannels[i] != nullptr);
  913. fSamplerChannels[i]->SetEngineType(kIsGIG ? "GIG" : "SFZ");
  914. fSamplerChannels[i]->SetAudioOutputDevice(fAudioOutputDevice);
  915. fEngineChannels[i] = fSamplerChannels[i]->GetEngineChannel();
  916. CARLA_SAFE_ASSERT_CONTINUE(fEngineChannels[i] != nullptr);
  917. fEngineChannels[i]->Pan(0.0f);
  918. fEngineChannels[i]->Volume(kIsGIG ? LinuxSampler::kVolumeMax/10.0f : LinuxSampler::kVolumeMax); // FIXME
  919. fEngineChannels[i]->Connect(fAudioOutputDevice);
  920. if (kUses16Outs)
  921. {
  922. fEngineChannels[i]->SetOutputChannel(0, i*2);
  923. fEngineChannels[i]->SetOutputChannel(1, i*2 +1);
  924. fMidiInputPort->Connect(fEngineChannels[i], static_cast<LinuxSampler::midi_chan_t>(i));
  925. }
  926. else
  927. {
  928. fEngineChannels[i]->SetOutputChannel(0, 0);
  929. fEngineChannels[i]->SetOutputChannel(1, 1);
  930. fMidiInputPort->Connect(fEngineChannels[i], 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. LinuxSampler::SamplerChannel* fSamplerChannels[MAX_MIDI_CHANNELS];
  1015. LinuxSampler::EngineChannel* fEngineChannels[MAX_MIDI_CHANNELS];
  1016. LinuxSampler::AudioOutputDevicePlugin* fAudioOutputDevice;
  1017. LinuxSampler::MidiInputPortPlugin* fMidiInputPort;
  1018. LinuxSampler::InstrumentManager* fInstrument;
  1019. std::vector<LinuxSampler::InstrumentManager::instrument_id_t> fInstrumentIds;
  1020. SharedResourcePointer<LinuxSampler::SamplerPlugin> sSampler;
  1021. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinuxSamplerPlugin)
  1022. };
  1023. CARLA_BACKEND_END_NAMESPACE
  1024. #endif // HAVE_LINUXSAMPLER
  1025. CARLA_BACKEND_START_NAMESPACE
  1026. // -------------------------------------------------------------------------------------------------------------------
  1027. CarlaPlugin* CarlaPlugin::newLinuxSampler(const Initializer& init, const char* const format, const bool use16Outs)
  1028. {
  1029. 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));
  1030. #ifdef HAVE_LINUXSAMPLER
  1031. CarlaString sformat(format);
  1032. sformat.toLower();
  1033. if (sformat != "gig" && sformat != "sfz")
  1034. {
  1035. init.engine->setLastError("Unsupported format requested for LinuxSampler");
  1036. return nullptr;
  1037. }
  1038. if (init.engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && use16Outs)
  1039. {
  1040. init.engine->setLastError("Carla's rack mode can only work with Stereo modules, please choose the 2-channel only sample-library version");
  1041. return nullptr;
  1042. }
  1043. // -------------------------------------------------------------------
  1044. // Check if file exists
  1045. if (! File(init.filename).existsAsFile())
  1046. {
  1047. init.engine->setLastError("Requested file is not valid or does not exist");
  1048. return nullptr;
  1049. }
  1050. LinuxSamplerPlugin* const plugin(new LinuxSamplerPlugin(init.engine, init.id, (sformat == "gig"), use16Outs));
  1051. if (! plugin->init(init.filename, init.name, init.label))
  1052. {
  1053. delete plugin;
  1054. return nullptr;
  1055. }
  1056. plugin->reload();
  1057. return plugin;
  1058. #else
  1059. init.engine->setLastError("linuxsampler support not available");
  1060. return nullptr;
  1061. // unused
  1062. (void)format;
  1063. (void)use16Outs;
  1064. #endif
  1065. }
  1066. CarlaPlugin* CarlaPlugin::newFileGIG(const Initializer& init, const bool use16Outs)
  1067. {
  1068. carla_debug("CarlaPlugin::newFileGIG({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  1069. #ifdef HAVE_LINUXSAMPLER
  1070. return newLinuxSampler(init, "GIG", use16Outs);
  1071. #else
  1072. init.engine->setLastError("GIG support not available");
  1073. return nullptr;
  1074. // unused
  1075. (void)use16Outs;
  1076. #endif
  1077. }
  1078. CarlaPlugin* CarlaPlugin::newFileSFZ(const Initializer& init)
  1079. {
  1080. carla_debug("CarlaPlugin::newFileSFZ({%p, \"%s\", \"%s\", \"%s\"})", init.engine, init.filename, init.name, init.label);
  1081. #ifdef HAVE_LINUXSAMPLER
  1082. return newLinuxSampler(init, "SFZ", false);
  1083. #else
  1084. init.engine->setLastError("SFZ support not available");
  1085. return nullptr;
  1086. #endif
  1087. }
  1088. // -------------------------------------------------------------------------------------------------------------------
  1089. CARLA_BACKEND_END_NAMESPACE