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.

CarlaEngineNative.cpp 25KB

11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. * Carla Plugin Engine (Native)
  3. * Copyright (C) 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. #ifdef BUILD_BRIDGE
  18. # error This file should not be compiled if building bridge
  19. #endif
  20. #include "CarlaEngineInternal.hpp"
  21. #include "CarlaStateUtils.hpp"
  22. #include "CarlaNative.hpp"
  23. CARLA_BACKEND_START_NAMESPACE
  24. #if 0
  25. // -----------------------------------------------------------------------
  26. class CarlaEngineNativeThread : public QThread
  27. {
  28. public:
  29. enum UiState {
  30. UiNone = 0,
  31. UiHide,
  32. UiShow,
  33. UiCrashed
  34. };
  35. CarlaEngineNativeThread(CarlaEngine* const engine)
  36. : kEngine(engine),
  37. fBinary("carla-control"),
  38. fProcess(nullptr),
  39. fUiState(UiNone)
  40. {
  41. carla_debug("CarlaEngineNativeThread::CarlaEngineNativeThread(engine:\"%s\")", engine->getName());
  42. }
  43. ~CarlaEngineNativeThread()
  44. {
  45. CARLA_ASSERT_INT(fUiState == UiNone, fUiState);
  46. carla_debug("CarlaEngineNativeThread::~CarlaEngineNativeThread()");
  47. if (fProcess != nullptr)
  48. {
  49. delete fProcess;
  50. fProcess = nullptr;
  51. }
  52. }
  53. void setOscData(const char* const binary)
  54. {
  55. fBinary = binary;
  56. }
  57. UiState getUiState()
  58. {
  59. const UiState state(fUiState);
  60. fUiState = UiNone;
  61. return state;
  62. }
  63. void stop()
  64. {
  65. if (fProcess == nullptr)
  66. return;
  67. fUiState = UiNone;
  68. fProcess->kill();
  69. //fProcess->close();
  70. }
  71. protected:
  72. void run()
  73. {
  74. carla_debug("CarlaEngineNativeThread::run() - binary:\"%s\"", (const char*)fBinary);
  75. if (fProcess == nullptr)
  76. {
  77. fProcess = new QProcess(nullptr);
  78. fProcess->setProcessChannelMode(QProcess::ForwardedChannels);
  79. }
  80. else if (fProcess->state() == QProcess::Running)
  81. {
  82. carla_stderr("CarlaEngineNativeThread::run() - already running, giving up...");
  83. fUiState = UiCrashed;
  84. fProcess->terminate();
  85. //kEngine->callback(CarlaBackend::CALLBACK_SHOW_GUI, kPlugin->id(), -1, 0, 0.0f, nullptr);
  86. // TODO: tell master to hide UI
  87. return;
  88. }
  89. QStringList arguments;
  90. arguments << kEngine->getOscServerPathTCP();
  91. fProcess->start((const char*)fBinary, arguments);
  92. fProcess->waitForStarted();
  93. fUiState = UiShow;
  94. fProcess->waitForFinished(-1);
  95. if (fProcess->exitCode() == 0)
  96. {
  97. // Hide
  98. fUiState = UiHide;
  99. carla_stdout("CarlaEngineNativeThread::run() - GUI closed");
  100. }
  101. else
  102. {
  103. // Kill
  104. fUiState = UiCrashed;
  105. carla_stderr("CarlaEngineNativeThread::run() - GUI crashed while running");
  106. }
  107. }
  108. private:
  109. CarlaEngine* const kEngine;
  110. CarlaString fBinary;
  111. QProcess* fProcess;
  112. UiState fUiState;
  113. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNativeThread)
  114. };
  115. // -----------------------------------------------------------------------
  116. #endif
  117. class CarlaEngineNative : public NativePluginClass,
  118. public CarlaEngine
  119. {
  120. public:
  121. CarlaEngineNative(const NativeHostDescriptor* const host, const bool isPatchbay)
  122. : NativePluginClass(host),
  123. CarlaEngine(),
  124. fIsPatchbay(isPatchbay)
  125. /*fIsRunning(true),
  126. fThread(this)*/
  127. {
  128. carla_debug("CarlaEngineNative::CarlaEngineNative()");
  129. // set-up engine
  130. if (fIsPatchbay)
  131. {
  132. pData->options.processMode = ENGINE_PROCESS_MODE_PATCHBAY;
  133. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  134. pData->options.forceStereo = false;
  135. pData->options.preferPluginBridges = false;
  136. pData->options.preferUiBridges = false;
  137. init("Carla-Patchbay");
  138. }
  139. else
  140. {
  141. pData->options.processMode = ENGINE_PROCESS_MODE_CONTINUOUS_RACK;
  142. pData->options.transportMode = ENGINE_TRANSPORT_MODE_PLUGIN;
  143. pData->options.forceStereo = true;
  144. pData->options.preferPluginBridges = false;
  145. pData->options.preferUiBridges = false;
  146. init("Carla-Rack");
  147. }
  148. #if 0
  149. // set control thread binary
  150. CarlaString threadBinary(getResourceDir());
  151. threadBinary += "/../";
  152. threadBinary += "carla_control.py";
  153. fThread.setOscData(threadBinary);
  154. // TESTING
  155. // if (! addPlugin(PLUGIN_INTERNAL, nullptr, "MIDI Transpose", "midiTranspose"))
  156. // carla_stdout("TESTING PLUG1 ERROR:\n%s", getLastError());
  157. // if (! addPlugin(PLUGIN_INTERNAL, nullptr, "ZynAddSubFX", "zynaddsubfx"))
  158. // carla_stdout("TESTING PLUG2 ERROR:\n%s", getLastError());
  159. // if (! addPlugin(PLUGIN_INTERNAL, nullptr, "Ping Pong Pan", "PingPongPan"))
  160. // carla_stdout("TESTING PLUG3 ERROR:\n%s", getLastError());
  161. #endif
  162. }
  163. ~CarlaEngineNative() override
  164. {
  165. carla_debug("CarlaEngineNative::~CarlaEngineNative()");
  166. //fIsRunning = false;
  167. setAboutToClose();
  168. removeAllPlugins();
  169. close();
  170. }
  171. protected:
  172. // -------------------------------------
  173. // CarlaEngine virtual calls
  174. bool init(const char* const clientName) override
  175. {
  176. carla_debug("CarlaEngineNative::init(\"%s\")", clientName);
  177. pData->bufferSize = NativePluginClass::getBufferSize();
  178. pData->sampleRate = NativePluginClass::getSampleRate();
  179. CarlaEngine::init(clientName);
  180. return true;
  181. }
  182. bool close() override
  183. {
  184. carla_debug("CarlaEngineNative::close()");
  185. runPendingRtEvents();
  186. return CarlaEngine::close();
  187. }
  188. bool isRunning() const noexcept override
  189. {
  190. return false; //fIsRunning;
  191. }
  192. bool isOffline() const noexcept override
  193. {
  194. return false;
  195. }
  196. EngineType getType() const noexcept override
  197. {
  198. return kEngineTypePlugin;
  199. }
  200. const char* getCurrentDriverName() const noexcept override
  201. {
  202. return "Plugin";
  203. }
  204. // -------------------------------------------------------------------
  205. // Plugin parameter calls
  206. uint32_t getParameterCount() const override
  207. {
  208. if (CarlaPlugin* const plugin = _getFirstPlugin())
  209. return plugin->getParameterCount();
  210. return 0;
  211. }
  212. const NativeParameter* getParameterInfo(const uint32_t index) const override
  213. {
  214. if (CarlaPlugin* const plugin = _getFirstPlugin())
  215. {
  216. if (plugin->getParameterCount() < index)
  217. {
  218. static NativeParameter param;
  219. static char strBufName[STR_MAX+1];
  220. static char strBufUnit[STR_MAX+1];
  221. const ParameterData& paramData(plugin->getParameterData(index));
  222. const ParameterRanges& paramRanges(plugin->getParameterRanges(index));
  223. plugin->getParameterName(index, strBufName);
  224. plugin->getParameterUnit(index, strBufUnit);
  225. unsigned int hints = 0x0;
  226. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  227. hints |= ::PARAMETER_IS_BOOLEAN;
  228. if (paramData.hints & PARAMETER_IS_INTEGER)
  229. hints |= ::PARAMETER_IS_INTEGER;
  230. if (paramData.hints & PARAMETER_IS_LOGARITHMIC)
  231. hints |= ::PARAMETER_IS_LOGARITHMIC;
  232. if (paramData.hints & PARAMETER_IS_AUTOMABLE)
  233. hints |= ::PARAMETER_IS_AUTOMABLE;
  234. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  235. hints |= ::PARAMETER_USES_SAMPLE_RATE;
  236. if (paramData.hints & PARAMETER_USES_SCALEPOINTS)
  237. hints |= ::PARAMETER_USES_SCALEPOINTS;
  238. if (paramData.hints & PARAMETER_USES_CUSTOM_TEXT)
  239. hints |= ::PARAMETER_USES_CUSTOM_TEXT;
  240. if (paramData.type == PARAMETER_INPUT || paramData.type == PARAMETER_OUTPUT)
  241. {
  242. if (paramData.hints & PARAMETER_IS_ENABLED)
  243. hints |= ::PARAMETER_IS_ENABLED;
  244. if (paramData.type == PARAMETER_OUTPUT)
  245. hints |= ::PARAMETER_IS_OUTPUT;
  246. }
  247. param.hints = static_cast<NativeParameterHints>(hints);
  248. param.name = strBufName;
  249. param.unit = strBufUnit;
  250. param.ranges.def = paramRanges.def;
  251. param.ranges.min = paramRanges.min;
  252. param.ranges.max = paramRanges.max;
  253. param.ranges.step = paramRanges.step;
  254. param.ranges.stepSmall = paramRanges.stepSmall;
  255. param.ranges.stepLarge = paramRanges.stepLarge;
  256. param.scalePointCount = 0; // TODO
  257. param.scalePoints = nullptr;
  258. return &param;
  259. }
  260. }
  261. return nullptr;
  262. }
  263. float getParameterValue(const uint32_t index) const override
  264. {
  265. if (CarlaPlugin* const plugin = _getFirstPlugin())
  266. {
  267. if (plugin->getParameterCount() < index)
  268. return plugin->getParameterValue(index);
  269. }
  270. return 0.0f;
  271. }
  272. const char* getParameterText(const uint32_t index, const float value) const override
  273. {
  274. if (CarlaPlugin* const plugin = _getFirstPlugin())
  275. {
  276. if (plugin->getParameterCount() < index)
  277. {
  278. static char strBuf[STR_MAX+1];
  279. carla_zeroChar(strBuf, STR_MAX+1);
  280. plugin->getParameterText(index, value, strBuf);
  281. return strBuf;
  282. }
  283. }
  284. return nullptr;
  285. }
  286. // -------------------------------------------------------------------
  287. // Plugin midi-program calls
  288. uint32_t getMidiProgramCount() const override
  289. {
  290. if (CarlaPlugin* const plugin = _getFirstPlugin())
  291. return plugin->getMidiProgramCount();
  292. return 0;
  293. }
  294. const NativeMidiProgram* getMidiProgramInfo(const uint32_t index) const override
  295. {
  296. if (CarlaPlugin* const plugin = _getFirstPlugin())
  297. {
  298. if (plugin->getMidiProgramCount() < index)
  299. {
  300. static NativeMidiProgram midiProg;
  301. {
  302. const MidiProgramData& midiProgData(plugin->getMidiProgramData(index));
  303. midiProg.bank = midiProgData.bank;
  304. midiProg.program = midiProgData.program;
  305. midiProg.name = midiProgData.name;
  306. }
  307. return &midiProg;
  308. }
  309. }
  310. return nullptr;
  311. }
  312. // -------------------------------------------------------------------
  313. // Plugin state calls
  314. void setParameterValue(const uint32_t index, const float value) override
  315. {
  316. if (CarlaPlugin* const plugin = _getFirstPlugin())
  317. {
  318. if (plugin->getParameterCount() < index)
  319. plugin->setParameterValue(index, value, false, false, false);
  320. }
  321. }
  322. void setMidiProgram(const uint8_t, const uint32_t bank, const uint32_t program) override
  323. {
  324. if (CarlaPlugin* const plugin = _getFirstPlugin())
  325. plugin->setMidiProgramById(bank, program, false, false, false);
  326. }
  327. void setCustomData(const char* const key, const char* const value) override
  328. {
  329. CARLA_SAFE_ASSERT_RETURN(key != nullptr,);
  330. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  331. // TODO
  332. }
  333. // -------------------------------------------------------------------
  334. // Plugin process calls
  335. void activate() override
  336. {
  337. #if 0
  338. for (uint32_t i=0; i < pData->curPluginCount; ++i)
  339. {
  340. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  341. if (plugin == nullptr || ! plugin->isEnabled())
  342. continue;
  343. plugin->setActive(true, true, false);
  344. }
  345. #endif
  346. }
  347. void deactivate() override
  348. {
  349. #if 0
  350. for (uint32_t i=0; i < pData->curPluginCount; ++i)
  351. {
  352. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  353. if (plugin == nullptr || ! plugin->isEnabled())
  354. continue;
  355. plugin->setActive(false, true, false);
  356. }
  357. #endif
  358. // just in case
  359. runPendingRtEvents();
  360. }
  361. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const midiEvents, const uint32_t midiEventCount) override
  362. {
  363. if (pData->curPluginCount == 0 && ! fIsPatchbay)
  364. {
  365. FLOAT_COPY(outBuffer[0], inBuffer[0], frames);
  366. FLOAT_COPY(outBuffer[1], inBuffer[1], frames);
  367. return runPendingRtEvents();;
  368. }
  369. // ---------------------------------------------------------------
  370. // Time Info
  371. const NativeTimeInfo* timeInfo(NativePluginClass::getTimeInfo());
  372. pData->timeInfo.playing = timeInfo->playing;
  373. pData->timeInfo.frame = timeInfo->frame;
  374. pData->timeInfo.usecs = timeInfo->usecs;
  375. pData->timeInfo.valid = 0x0;
  376. if (timeInfo->bbt.valid)
  377. {
  378. pData->timeInfo.valid |= EngineTimeInfo::kValidBBT;
  379. pData->timeInfo.bbt.bar = timeInfo->bbt.bar;
  380. pData->timeInfo.bbt.beat = timeInfo->bbt.beat;
  381. pData->timeInfo.bbt.tick = timeInfo->bbt.tick;
  382. pData->timeInfo.bbt.barStartTick = timeInfo->bbt.barStartTick;
  383. pData->timeInfo.bbt.beatsPerBar = timeInfo->bbt.beatsPerBar;
  384. pData->timeInfo.bbt.beatType = timeInfo->bbt.beatType;
  385. pData->timeInfo.bbt.ticksPerBeat = timeInfo->bbt.ticksPerBeat;
  386. pData->timeInfo.bbt.beatsPerMinute = timeInfo->bbt.beatsPerMinute;
  387. }
  388. #if 0
  389. // ---------------------------------------------------------------
  390. // initialize input events
  391. carla_zeroStruct<EngineEvent>(pData->bufEvents.in, INTERNAL_EVENT_COUNT);
  392. {
  393. uint32_t engineEventIndex = 0;
  394. for (uint32_t i=0; i < midiEventCount && engineEventIndex < INTERNAL_EVENT_COUNT; ++i)
  395. {
  396. const ::MidiEvent& midiEvent(midiEvents[i]);
  397. if (midiEvent.size > 4)
  398. continue;
  399. const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent.data);
  400. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent.data);
  401. // we don't want some events
  402. if (status == MIDI_STATUS_PROGRAM_CHANGE)
  403. continue;
  404. // handle note/sound off properly
  405. if (status == MIDI_STATUS_CONTROL_CHANGE)
  406. {
  407. const uint8_t control = midiEvent.data[1];
  408. if (MIDI_IS_CONTROL_BANK_SELECT(control))
  409. continue;
  410. if (control == MIDI_CONTROL_ALL_SOUND_OFF || control == MIDI_CONTROL_ALL_NOTES_OFF)
  411. {
  412. EngineEvent& engineEvent(pData->bufEvents.in[engineEventIndex++]);
  413. engineEvent.clear();
  414. engineEvent.type = kEngineEventTypeControl;
  415. engineEvent.time = midiEvent.time;
  416. engineEvent.channel = channel;
  417. engineEvent.ctrl.type = (control == MIDI_CONTROL_ALL_SOUND_OFF) ? kEngineControlEventTypeAllSoundOff : kEngineControlEventTypeAllNotesOff;
  418. engineEvent.ctrl.param = 0;
  419. engineEvent.ctrl.value = 0.0f;
  420. continue;
  421. }
  422. }
  423. EngineEvent& engineEvent(pData->bufEvents.in[engineEventIndex++]);
  424. engineEvent.clear();
  425. engineEvent.type = kEngineEventTypeMidi;
  426. engineEvent.time = midiEvent.time;
  427. engineEvent.channel = channel;
  428. engineEvent.midi.data[0] = MIDI_GET_STATUS_FROM_DATA(midiEvent.data);
  429. engineEvent.midi.data[1] = midiEvent.data[1];
  430. engineEvent.midi.data[2] = midiEvent.data[2];
  431. engineEvent.midi.data[3] = midiEvent.data[3];
  432. engineEvent.midi.size = midiEvent.size;
  433. }
  434. }
  435. // ---------------------------------------------------------------
  436. // create audio buffers
  437. float* inBuf[2] = { inBuffer[0], inBuffer[1] };
  438. float* outBuf[2] = { outBuffer[0], outBuffer[1] };
  439. // ---------------------------------------------------------------
  440. // process
  441. processRack(inBuf, outBuf, frames);
  442. #endif
  443. runPendingRtEvents();
  444. return;
  445. // TODO
  446. (void)midiEvents;
  447. (void)midiEventCount;
  448. }
  449. #if 0
  450. // -------------------------------------------------------------------
  451. // Plugin UI calls
  452. void uiShow(const bool show) override
  453. {
  454. if (show)
  455. {
  456. fThread.start();
  457. }
  458. else
  459. {
  460. #if 0
  461. for (uint32_t i=0; i < pData->curPluginCount; ++i)
  462. {
  463. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  464. if (plugin == nullptr || ! plugin->enabled())
  465. continue;
  466. plugin->showGui(false);
  467. }
  468. #endif
  469. fThread.stop();
  470. }
  471. }
  472. void uiIdle() override
  473. {
  474. CarlaEngine::idle();
  475. switch(fThread.getUiState())
  476. {
  477. case CarlaEngineNativeThread::UiNone:
  478. case CarlaEngineNativeThread::UiShow:
  479. break;
  480. case CarlaEngineNativeThread::UiCrashed:
  481. hostUiUnavailable();
  482. break;
  483. case CarlaEngineNativeThread::UiHide:
  484. uiClosed();
  485. break;
  486. }
  487. }
  488. #endif
  489. #if 0
  490. void uiSetParameterValue(const uint32_t index, const float value) override
  491. {
  492. if (index >= getParameterCount())
  493. return;
  494. CarlaPlugin* const plugin(pData->plugins[0].plugin);
  495. if (plugin == nullptr || ! plugin->isEnabled())
  496. return;
  497. plugin->uiParameterChange(index, value);
  498. }
  499. void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override
  500. {
  501. return;
  502. // TODO
  503. // unused
  504. (void)channel;
  505. (void)bank;
  506. (void)program;
  507. }
  508. void uiSetCustomData(const char* const key, const char* const value) override
  509. {
  510. CARLA_ASSERT(key != nullptr);
  511. CARLA_ASSERT(value != nullptr);
  512. return;
  513. // TODO
  514. // unused
  515. (void)key;
  516. (void)value;
  517. }
  518. #endif
  519. #if 0
  520. // -------------------------------------------------------------------
  521. // Plugin state calls
  522. char* getState() const override
  523. {
  524. QString string;
  525. QTextStream out(&string);
  526. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  527. out << "<!DOCTYPE CARLA-PROJECT>\n";
  528. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  529. bool firstPlugin = true;
  530. char strBuf[STR_MAX+1];
  531. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  532. {
  533. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  534. if (plugin != nullptr && plugin->isEnabled())
  535. {
  536. if (! firstPlugin)
  537. out << "\n";
  538. plugin->getRealName(strBuf);
  539. if (*strBuf != 0)
  540. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  541. QString content;
  542. fillXmlStringFromSaveState(content, plugin->getSaveState());
  543. out << " <Plugin>\n";
  544. out << content;
  545. out << " </Plugin>\n";
  546. firstPlugin = false;
  547. }
  548. }
  549. out << "</CARLA-PROJECT>\n";
  550. return strdup(string.toUtf8().constData());
  551. }
  552. void setState(const char* const data) override
  553. {
  554. QDomDocument xml;
  555. xml.setContent(QString(data));
  556. QDomNode xmlNode(xml.documentElement());
  557. if (xmlNode.toElement().tagName() != "CARLA-PROJECT")
  558. {
  559. carla_stderr2("Not a valid Carla project");
  560. return;
  561. }
  562. QDomNode node(xmlNode.firstChild());
  563. while (! node.isNull())
  564. {
  565. if (node.toElement().tagName() == "Plugin")
  566. {
  567. SaveState saveState;
  568. fillSaveStateFromXmlNode(saveState, node);
  569. CARLA_SAFE_ASSERT_CONTINUE(saveState.type != nullptr)
  570. const void* extraStuff = nullptr;
  571. // FIXME
  572. //if (std::strcmp(saveState.type, "DSSI") == 0)
  573. // extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  574. // TODO - proper find&load plugins
  575. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  576. {
  577. if (CarlaPlugin* plugin = getPlugin(pData->curPluginCount-1))
  578. plugin->loadSaveState(saveState);
  579. }
  580. }
  581. node = node.nextSibling();
  582. }
  583. }
  584. #endif
  585. // -------------------------------------------------------------------
  586. public:
  587. static NativePluginHandle _instantiateRack(const NativeHostDescriptor* host)
  588. {
  589. return new CarlaEngineNative(host, false);
  590. }
  591. #ifdef HAVE_JUCE
  592. static NativePluginHandle _instantiatePatchbay(const NativeHostDescriptor* host)
  593. {
  594. return new CarlaEngineNative(host, true);
  595. }
  596. #endif
  597. static void _cleanup(NativePluginHandle handle)
  598. {
  599. delete (CarlaEngineNative*)handle;
  600. }
  601. private:
  602. const bool fIsPatchbay; // rack if false
  603. #if 0
  604. bool fIsRunning;
  605. CarlaEngineNativeThread fThread;
  606. #endif
  607. CarlaPlugin* _getFirstPlugin() const noexcept
  608. {
  609. if (pData->curPluginCount == 0 || pData->plugins == nullptr)
  610. return nullptr;
  611. CarlaPlugin* const plugin(pData->plugins[0].plugin);
  612. if (plugin == nullptr || ! plugin->isEnabled())
  613. return nullptr;
  614. return pData->plugins[0].plugin;
  615. }
  616. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNative)
  617. };
  618. // -----------------------------------------------------------------------
  619. static const NativePluginDescriptor carlaRackDesc = {
  620. /* category */ ::PLUGIN_CATEGORY_OTHER,
  621. /* hints */ static_cast<NativePluginHints>(::PLUGIN_IS_SYNTH|::PLUGIN_HAS_UI|::PLUGIN_NEEDS_FIXED_BUFFERS|::PLUGIN_NEEDS_SINGLE_THREAD|::PLUGIN_USES_STATE|::PLUGIN_USES_TIME),
  622. /* supports */ static_cast<NativePluginSupports>(::PLUGIN_SUPPORTS_EVERYTHING),
  623. /* audioIns */ 2,
  624. /* audioOuts */ 2,
  625. /* midiIns */ 1,
  626. /* midiOuts */ 1,
  627. /* paramIns */ 0,
  628. /* paramOuts */ 0,
  629. /* name */ "Carla-Rack",
  630. /* label */ "carla",
  631. /* maker */ "falkTX",
  632. /* copyright */ "GNU GPL v2+",
  633. CarlaEngineNative::_instantiateRack,
  634. CarlaEngineNative::_cleanup,
  635. PluginDescriptorFILL2(CarlaEngineNative)
  636. };
  637. #ifdef HAVE_JUCE
  638. static const NativePluginDescriptor carlaPatchbayDesc = {
  639. /* category */ ::PLUGIN_CATEGORY_OTHER,
  640. /* hints */ static_cast<NativePluginHints>(::PLUGIN_IS_SYNTH|::PLUGIN_HAS_UI|::PLUGIN_NEEDS_FIXED_BUFFERS|::PLUGIN_NEEDS_SINGLE_THREAD|::PLUGIN_USES_STATE|::PLUGIN_USES_TIME),
  641. /* supports */ static_cast<NativePluginSupports>(::PLUGIN_SUPPORTS_EVERYTHING),
  642. /* audioIns */ 2,
  643. /* audioOuts */ 2,
  644. /* midiIns */ 1,
  645. /* midiOuts */ 1,
  646. /* paramIns */ 0,
  647. /* paramOuts */ 0,
  648. /* name */ "Carla-Patchbay",
  649. /* label */ "carla",
  650. /* maker */ "falkTX",
  651. /* copyright */ "GNU GPL v2+",
  652. CarlaEngineNative::_instantiatePatchbay,
  653. CarlaEngineNative::_cleanup,
  654. PluginDescriptorFILL2(CarlaEngineNative)
  655. };
  656. #endif
  657. // -----------------------------------------------------------------------
  658. CARLA_BACKEND_END_NAMESPACE
  659. // -----------------------------------------------------------------------
  660. CARLA_EXPORT
  661. void carla_register_native_plugin_carla()
  662. {
  663. CARLA_BACKEND_USE_NAMESPACE
  664. carla_register_native_plugin(&carlaRackDesc);
  665. #ifdef HAVE_JUCE
  666. carla_register_native_plugin(&carlaPatchbayDesc);
  667. #endif
  668. }
  669. // -----------------------------------------------------------------------