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.

823 lines
29KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-2019 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. #define CARLA_NATIVE_PLUGIN_LV2
  18. #include "carla-base.cpp"
  19. #include "lv2/atom.h"
  20. #include "lv2/buf-size.h"
  21. #include "lv2/instance-access.h"
  22. #include "lv2/midi.h"
  23. #include "lv2/options.h"
  24. #include "lv2/parameters.h"
  25. #include "lv2/patch.h"
  26. #include "lv2/port-props.h"
  27. #include "lv2/state.h"
  28. #include "lv2/time.h"
  29. #include "lv2/ui.h"
  30. #include "lv2/units.h"
  31. #include "lv2/urid.h"
  32. #include "lv2/worker.h"
  33. #include "lv2/lv2_external_ui.h"
  34. #include "lv2/lv2_programs.h"
  35. #include "water/files/File.h"
  36. #include "water/text/StringArray.h"
  37. #include <fstream>
  38. #if defined(CARLA_OS_WIN)
  39. # define PLUGIN_EXT ".dll"
  40. #elif defined(CARLA_OS_MAC)
  41. # define PLUGIN_EXT ".dylib"
  42. #else
  43. # define PLUGIN_EXT ".so"
  44. #endif
  45. using water::String;
  46. using water::StringArray;
  47. using water::water_uchar;
  48. // -----------------------------------------------------------------------
  49. // Converts a parameter name to an LV2 compatible symbol
  50. static StringArray gUsedSymbols;
  51. static const String nameToSymbol(const String& name, const uint32_t portIndex)
  52. {
  53. String symbol, trimmedName = name.trim().toLowerCase();
  54. if (trimmedName.isEmpty())
  55. {
  56. symbol += "lv2_port_";
  57. symbol += String(portIndex+1);
  58. }
  59. else
  60. {
  61. if (std::isdigit(static_cast<int>(trimmedName[0])))
  62. symbol += "_";
  63. for (int i=0; i < trimmedName.length(); ++i)
  64. {
  65. const water_uchar c = trimmedName[i];
  66. if (std::isalpha(static_cast<int>(c)) || std::isdigit(static_cast<int>(c)))
  67. symbol += c;
  68. else
  69. symbol += "_";
  70. }
  71. }
  72. // Do not allow identical symbols
  73. if (gUsedSymbols.contains(symbol))
  74. {
  75. int offset = 2;
  76. String offsetStr = "_2";
  77. symbol += offsetStr;
  78. while (gUsedSymbols.contains(symbol))
  79. {
  80. offset += 1;
  81. String newOffsetStr = "_" + String(offset);
  82. symbol = symbol.replace(offsetStr, newOffsetStr);
  83. offsetStr = newOffsetStr;
  84. }
  85. }
  86. gUsedSymbols.add(symbol);
  87. return symbol;
  88. }
  89. // -----------------------------------------------------------------------
  90. static void writeManifestFile(PluginListManager& plm)
  91. {
  92. String text;
  93. const uint32_t majorVersion = (CARLA_VERSION_HEX & 0xFF0000) >> 16;
  94. const uint32_t microVersion = (CARLA_VERSION_HEX & 0x00FF00) >> 8;
  95. const uint32_t minorVersion = (CARLA_VERSION_HEX & 0x0000FF) >> 0;
  96. const uint32_t lv2MicroVersion = majorVersion * 10 + microVersion;
  97. // -------------------------------------------------------------------
  98. // Header
  99. text += "@prefix atom: <" LV2_ATOM_PREFIX "> .\n";
  100. text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
  101. text += "@prefix mod: <http://moddevices.com/ns/mod#> .\n";
  102. text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
  103. text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  104. text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
  105. text += "\n";
  106. // -------------------------------------------------------------------
  107. // Plugins
  108. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  109. {
  110. const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
  111. CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
  112. const String label(pluginDesc->label);
  113. text += "<http://kxstudio.sf.net/carla/plugins/" + label + ">\n";
  114. text += " a lv2:Plugin ;\n";
  115. text += " lv2:binary <carla" PLUGIN_EXT "> ;\n";
  116. text += " lv2:microVersion " + String(lv2MicroVersion) + " ;\n";
  117. text += " lv2:minorVersion " + String(minorVersion) + " ;\n";
  118. text += " rdfs:seeAlso <" + label + ".ttl> .\n";
  119. text += "\n";
  120. }
  121. // -------------------------------------------------------------------
  122. // UI
  123. #ifdef HAVE_PYQT
  124. text += "<http://kxstudio.sf.net/carla/ui-ext>\n";
  125. text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
  126. text += " ui:binary <carla" PLUGIN_EXT "> ;\n";
  127. text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
  128. text += " <" LV2_UI__showInterface "> ,\n";
  129. text += " <" LV2_PROGRAMS__UIInterface "> ;\n";
  130. text += " lv2:optionalFeature <" LV2_UI__idleInterface "> ;\n";
  131. text += " lv2:requiredFeature <" LV2_INSTANCE_ACCESS_URI "> ;\n";
  132. text += " opts:supportedOption <" LV2_PARAMETERS__sampleRate "> .\n";
  133. text += "\n";
  134. # if 0
  135. text += "<http://kxstudio.sf.net/carla/ui-bridge-ext>\n";
  136. text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
  137. text += " ui:binary <carla-ui" PLUGIN_EXT "> ;\n";
  138. text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
  139. text += " <" LV2_UI__showInterface "> ,\n";
  140. text += " <" LV2_PROGRAMS__UIInterface "> .\n";
  141. # endif
  142. #endif
  143. // -------------------------------------------------------------------
  144. // File handling
  145. text += "<http://kxstudio.sf.net/carla/file>\n";
  146. text += " a lv2:Parameter ;\n";
  147. text += " rdfs:label \"file\" ;\n";
  148. text += " rdfs:range atom:Path .\n";
  149. text += "\n";
  150. text += "<http://kxstudio.sf.net/carla/file/audio>\n";
  151. text += " a lv2:Parameter ;\n";
  152. text += " mod:fileTypes \"audiofiles,audioloops\" ;\n";
  153. text += " rdfs:label \"audio file\" ;\n";
  154. text += " rdfs:range atom:Path .\n";
  155. text += "\n";
  156. text += "<http://kxstudio.sf.net/carla/file/midi>\n";
  157. text += " a lv2:Parameter ;\n";
  158. text += " mod:fileTypes \"midi\" ;\n";
  159. text += " rdfs:label \"midi file\" ;\n";
  160. text += " rdfs:range atom:Path .\n";
  161. text += "\n";
  162. // -------------------------------------------------------------------
  163. // Write file now
  164. std::fstream manifest("carla.lv2/manifest.ttl", std::ios::out);
  165. manifest << text.toRawUTF8();
  166. manifest.close();
  167. }
  168. // -----------------------------------------------------------------------
  169. static uint32_t host_getBufferSize(NativeHostHandle) { return 512; }
  170. static double host_getSampleRate(NativeHostHandle) { return 44100.0; }
  171. static bool host_isOffline(NativeHostHandle) { return true; }
  172. static intptr_t host_dispatcher(NativeHostHandle, NativeHostDispatcherOpcode, int32_t, intptr_t, void*, float) { return 0; }
  173. static void writePluginFile(const NativePluginDescriptor* const pluginDesc)
  174. {
  175. const String pluginLabel(pluginDesc->label);
  176. const String pluginFile("carla.lv2/" + pluginLabel + ".ttl");
  177. uint32_t portIndex = 0;
  178. String text;
  179. gUsedSymbols.clear();
  180. carla_stdout("Generating data for %s...", pluginDesc->name);
  181. // -------------------------------------------------------------------
  182. // Init plugin
  183. NativeHostDescriptor hostDesc;
  184. hostDesc.handle = nullptr;
  185. hostDesc.resourceDir = "";
  186. hostDesc.uiName = "";
  187. hostDesc.get_buffer_size = host_getBufferSize;
  188. hostDesc.get_sample_rate = host_getSampleRate;
  189. hostDesc.is_offline = host_isOffline;
  190. hostDesc.get_time_info = nullptr;
  191. hostDesc.write_midi_event = nullptr;
  192. hostDesc.ui_parameter_changed = nullptr;
  193. hostDesc.ui_midi_program_changed = nullptr;
  194. hostDesc.ui_custom_data_changed = nullptr;
  195. hostDesc.ui_closed = nullptr;
  196. hostDesc.ui_open_file = nullptr;
  197. hostDesc.ui_save_file = nullptr;
  198. hostDesc.dispatcher = host_dispatcher;
  199. NativePluginHandle pluginHandle = nullptr;
  200. if (! pluginLabel.startsWithIgnoreCase("carla"))
  201. {
  202. pluginHandle = pluginDesc->instantiate(&hostDesc);
  203. CARLA_SAFE_ASSERT_RETURN(pluginHandle != nullptr,)
  204. }
  205. // -------------------------------------------------------------------
  206. // Header
  207. text += "@prefix atom: <" LV2_ATOM_PREFIX "> .\n";
  208. text += "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
  209. text += "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
  210. text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
  211. text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
  212. text += "@prefix patch: <" LV2_PATCH_PREFIX "> .\n";
  213. text += "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n";
  214. text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  215. text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
  216. text += "@prefix unit: <" LV2_UNITS_PREFIX "> .\n";
  217. text += "\n";
  218. // -------------------------------------------------------------------
  219. // Plugin URI
  220. text += "<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + ">\n";
  221. // -------------------------------------------------------------------
  222. // Category
  223. switch (pluginDesc->category)
  224. {
  225. case NATIVE_PLUGIN_CATEGORY_SYNTH:
  226. text += " a lv2:InstrumentPlugin, lv2:Plugin ;\n";
  227. break;
  228. case NATIVE_PLUGIN_CATEGORY_DELAY:
  229. text += " a lv2:DelayPlugin, lv2:Plugin ;\n";
  230. break;
  231. case NATIVE_PLUGIN_CATEGORY_EQ:
  232. text += " a lv2:EQPlugin, lv2:Plugin ;\n";
  233. break;
  234. case NATIVE_PLUGIN_CATEGORY_FILTER:
  235. text += " a lv2:FilterPlugin, lv2:Plugin ;\n";
  236. break;
  237. case NATIVE_PLUGIN_CATEGORY_DYNAMICS:
  238. text += " a lv2:DynamicsPlugin, lv2:Plugin ;\n";
  239. break;
  240. case NATIVE_PLUGIN_CATEGORY_MODULATOR:
  241. text += " a lv2:ModulatorPlugin, lv2:Plugin ;\n";
  242. break;
  243. case NATIVE_PLUGIN_CATEGORY_UTILITY:
  244. text += " a lv2:UtilityPlugin, lv2:Plugin ;\n";
  245. break;
  246. default:
  247. text += " a lv2:Plugin ;\n";
  248. break;
  249. }
  250. text += "\n";
  251. // -------------------------------------------------------------------
  252. // Features
  253. // optional
  254. if (pluginDesc->hints & NATIVE_PLUGIN_IS_RTSAFE)
  255. text += " lv2:optionalFeature <" LV2_CORE__hardRTCapable "> ;\n\n";
  256. // required
  257. text += " lv2:requiredFeature <" LV2_BUF_SIZE__boundedBlockLength "> ,\n";
  258. if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  259. text += " <" LV2_BUF_SIZE__fixedBlockLength "> ,\n";
  260. text += " <" LV2_OPTIONS__options "> ,\n";
  261. text += " <" LV2_URID__map "> ;\n";
  262. text += "\n";
  263. // -------------------------------------------------------------------
  264. // Extensions
  265. text += " lv2:extensionData <" LV2_OPTIONS__interface "> ;\n";
  266. if ((pluginDesc->hints & NATIVE_PLUGIN_USES_STATE) || (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE))
  267. text += " lv2:extensionData <" LV2_STATE__interface "> ;\n";
  268. if (pluginDesc->category != NATIVE_PLUGIN_CATEGORY_SYNTH)
  269. text += " lv2:extensionData <" LV2_PROGRAMS__Interface "> ;\n";
  270. if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
  271. text += " lv2:extensionData <" LV2_WORKER__interface "> ;\n";
  272. text += "\n";
  273. // -------------------------------------------------------------------
  274. // Options
  275. text += " opts:supportedOption <" LV2_BUF_SIZE__nominalBlockLength "> ,\n";
  276. text += " <" LV2_BUF_SIZE__maxBlockLength "> ,\n";
  277. text += " <" LV2_PARAMETERS__sampleRate "> ;\n";
  278. text += "\n";
  279. // -------------------------------------------------------------------
  280. // UIs
  281. #ifdef HAVE_PYQT
  282. if ((pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0 && (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE) == 0)
  283. {
  284. text += " ui:ui <http://kxstudio.sf.net/carla/ui-ext> ;\n";
  285. text += "\n";
  286. }
  287. #endif
  288. // -------------------------------------------------------------------
  289. // First input MIDI/Time/UI port
  290. const bool hasEventInPort = (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME) != 0
  291. || (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
  292. if (pluginDesc->midiIns > 0 || hasEventInPort)
  293. {
  294. text += " lv2:port [\n";
  295. text += " a lv2:InputPort, atom:AtomPort ;\n";
  296. text += " atom:bufferType atom:Sequence ;\n";
  297. if (pluginDesc->midiIns > 0 && hasEventInPort)
  298. {
  299. text += " atom:supports <" LV2_MIDI__MidiEvent "> ,\n";
  300. text += " <" LV2_TIME__Position "> ;\n";
  301. }
  302. else if (pluginDesc->midiIns > 0)
  303. {
  304. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  305. }
  306. else
  307. {
  308. text += " atom:supports <" LV2_TIME__Position "> ;\n";
  309. }
  310. text += " lv2:designation lv2:control ;\n";
  311. text += " lv2:index " + String(portIndex++) + " ;\n";
  312. if (hasEventInPort)
  313. {
  314. if (pluginDesc->midiIns > 1)
  315. {
  316. text += " lv2:symbol \"lv2_events_in_1\" ;\n";
  317. text += " lv2:name \"Events Input #1\" ;\n";
  318. }
  319. else
  320. {
  321. text += " lv2:symbol \"lv2_events_in\" ;\n";
  322. text += " lv2:name \"Events Input\" ;\n";
  323. }
  324. }
  325. else
  326. {
  327. if (pluginDesc->midiIns > 1)
  328. {
  329. text += " lv2:symbol \"lv2_midi_in_1\" ;\n";
  330. text += " lv2:name \"MIDI Input #1\" ;\n";
  331. }
  332. else
  333. {
  334. text += " lv2:symbol \"lv2_midi_in\" ;\n";
  335. text += " lv2:name \"MIDI Input\" ;\n";
  336. }
  337. }
  338. text += " ] ;\n\n";
  339. }
  340. if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
  341. {
  342. /**/ if (pluginLabel == "audiofile")
  343. text += " patch:writable <http://kxstudio.sf.net/carla/file/audio> ;\n\n";
  344. else if (pluginLabel == "midifile")
  345. text += " patch:writable <http://kxstudio.sf.net/carla/file/midi> ;\n\n";
  346. else
  347. text += " patch:writable <http://kxstudio.sf.net/carla/file> ;\n\n";
  348. }
  349. // -------------------------------------------------------------------
  350. // MIDI inputs
  351. for (uint32_t i=1; i < pluginDesc->midiIns; ++i)
  352. {
  353. if (i == 1)
  354. text += " lv2:port [\n";
  355. text += " a lv2:InputPort, atom:AtomPort ;\n";
  356. text += " atom:bufferType atom:Sequence ;\n";
  357. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  358. text += " lv2:index " + String(portIndex++) + " ;\n";
  359. text += " lv2:symbol \"lv2_midi_in_" + String(i+1) + "\" ;\n";
  360. text += " lv2:name \"MIDI Input #" + String(i+1) + "\" ;\n";
  361. if (i+1 == pluginDesc->midiIns)
  362. text += " ] ;\n\n";
  363. else
  364. text += " ] , [\n";
  365. }
  366. // -------------------------------------------------------------------
  367. // First output MIDI/UI port
  368. const bool hasEventOutPort = (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
  369. if (pluginDesc->midiIns > 0 || hasEventOutPort)
  370. {
  371. text += " lv2:port [\n";
  372. text += " a lv2:OutputPort, atom:AtomPort ;\n";
  373. text += " atom:bufferType atom:Sequence ;\n";
  374. if (pluginDesc->midiOuts > 0)
  375. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  376. text += " lv2:index " + String(portIndex++) + " ;\n";
  377. if (hasEventOutPort)
  378. {
  379. if (pluginDesc->midiOuts > 1)
  380. {
  381. text += " lv2:symbol \"lv2_events_out_1\" ;\n";
  382. text += " lv2:name \"Events Input #1\" ;\n";
  383. }
  384. else
  385. {
  386. text += " lv2:symbol \"lv2_events_out\" ;\n";
  387. text += " lv2:name \"Events Output\" ;\n";
  388. }
  389. }
  390. else
  391. {
  392. if (pluginDesc->midiOuts > 1)
  393. {
  394. text += " lv2:symbol \"lv2_midi_out_1\" ;\n";
  395. text += " lv2:name \"MIDI Output #1\" ;\n";
  396. }
  397. else
  398. {
  399. text += " lv2:symbol \"lv2_midi_out\" ;\n";
  400. text += " lv2:name \"MIDI Output\" ;\n";
  401. }
  402. }
  403. text += " ] ;\n\n";
  404. }
  405. // -------------------------------------------------------------------
  406. // MIDI outputs
  407. for (uint32_t i=1; i < pluginDesc->midiOuts; ++i)
  408. {
  409. if (i == 1)
  410. text += " lv2:port [\n";
  411. text += " a lv2:OutputPort, atom:AtomPort ;\n";
  412. text += " atom:bufferType atom:Sequence ;\n";
  413. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  414. text += " lv2:index " + String(portIndex++) + " ;\n";
  415. if (pluginDesc->midiOuts > 1)
  416. {
  417. text += " lv2:symbol \"lv2_midi_out_" + String(i+1) + "\" ;\n";
  418. text += " lv2:name \"MIDI Output #" + String(i+1) + "\" ;\n";
  419. }
  420. else
  421. {
  422. text += " lv2:symbol \"lv2_midi_out\" ;\n";
  423. text += " lv2:name \"MIDI Output\" ;\n";
  424. }
  425. if (i+1 == pluginDesc->midiOuts)
  426. text += " ] ;\n\n";
  427. else
  428. text += " ] , [\n";
  429. }
  430. // -------------------------------------------------------------------
  431. // Freewheel port
  432. text += " lv2:port [\n";
  433. text += " a lv2:InputPort, lv2:ControlPort ;\n";
  434. text += " lv2:index " + String(portIndex++) + " ;\n";
  435. text += " lv2:symbol \"lv2_freewheel\" ;\n";
  436. text += " lv2:name \"Freewheel\" ;\n";
  437. text += " lv2:default 0.0 ;\n";
  438. text += " lv2:minimum 0.0 ;\n";
  439. text += " lv2:maximum 1.0 ;\n";
  440. text += " lv2:designation <" LV2_CORE__freeWheeling "> ;\n";
  441. text += " lv2:portProperty lv2:toggled, <" LV2_PORT_PROPS__notOnGUI "> ;\n";
  442. text += " ] ;\n";
  443. text += "\n";
  444. // -------------------------------------------------------------------
  445. // Audio inputs
  446. for (uint32_t i=0; i < pluginDesc->audioIns; ++i)
  447. {
  448. if (i == 0)
  449. text += " lv2:port [\n";
  450. text += " a lv2:InputPort, lv2:AudioPort ;\n";
  451. text += " lv2:index " + String(portIndex++) + " ;\n";
  452. text += " lv2:symbol \"lv2_audio_in_" + String(i+1) + "\" ;\n";
  453. text += " lv2:name \"Audio Input " + String(i+1) + "\" ;\n";
  454. if (i+1 == pluginDesc->audioIns)
  455. text += " ] ;\n\n";
  456. else
  457. text += " ] , [\n";
  458. }
  459. // -------------------------------------------------------------------
  460. // Audio outputs
  461. for (uint32_t i=0; i < pluginDesc->audioOuts; ++i)
  462. {
  463. if (i == 0)
  464. text += " lv2:port [\n";
  465. text += " a lv2:OutputPort, lv2:AudioPort ;\n";
  466. text += " lv2:index " + String(portIndex++) + " ;\n";
  467. text += " lv2:symbol \"lv2_audio_out_" + String(i+1) + "\" ;\n";
  468. text += " lv2:name \"Audio Output " + String(i+1) + "\" ;\n";
  469. if (i+1 == pluginDesc->audioOuts)
  470. text += " ] ;\n\n";
  471. else
  472. text += " ] , [\n";
  473. }
  474. // -------------------------------------------------------------------
  475. // CV inputs
  476. for (uint32_t i=0; i < pluginDesc->cvIns; ++i)
  477. {
  478. if (i == 0)
  479. text += " lv2:port [\n";
  480. text += " a lv2:InputPort, lv2:CVPort ;\n";
  481. text += " lv2:index " + String(portIndex++) + " ;\n";
  482. text += " lv2:symbol \"lv2_cv_in_" + String(i+1) + "\" ;\n";
  483. text += " lv2:name \"CV Input " + String(i+1) + "\" ;\n";
  484. if (i+1 == pluginDesc->cvIns)
  485. text += " ] ;\n\n";
  486. else
  487. text += " ] , [\n";
  488. }
  489. // -------------------------------------------------------------------
  490. // CV outputs
  491. for (uint32_t i=0; i < pluginDesc->cvOuts; ++i)
  492. {
  493. if (i == 0)
  494. text += " lv2:port [\n";
  495. text += " a lv2:OutputPort, lv2:CVPort ;\n";
  496. text += " lv2:index " + String(portIndex++) + " ;\n";
  497. text += " lv2:symbol \"lv2_cv_out_" + String(i+1) + "\" ;\n";
  498. text += " lv2:name \"CV Output " + String(i+1) + "\" ;\n";
  499. if (i+1 == pluginDesc->cvOuts)
  500. text += " ] ;\n\n";
  501. else
  502. text += " ] , [\n";
  503. }
  504. // -------------------------------------------------------------------
  505. // Parameters
  506. const uint32_t paramCount = (pluginHandle != nullptr && pluginDesc->get_parameter_count != nullptr)
  507. ? pluginDesc->get_parameter_count(pluginHandle)
  508. : 0;
  509. if (paramCount > 0)
  510. {
  511. CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_info != nullptr,)
  512. CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_value != nullptr,)
  513. }
  514. for (uint32_t i=0; i < paramCount; ++i)
  515. {
  516. const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, i));
  517. const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
  518. const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
  519. CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
  520. if (i == 0)
  521. text += " lv2:port [\n";
  522. if (paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT)
  523. text += " a lv2:OutputPort, lv2:ControlPort ;\n";
  524. else
  525. text += " a lv2:InputPort, lv2:ControlPort ;\n";
  526. text += " lv2:index " + String(portIndex++) + " ;\n";
  527. text += " lv2:symbol \"" + nameToSymbol(paramName, i) + "\" ;\n";
  528. if (paramName.isNotEmpty())
  529. text += " lv2:name \"" + paramName + "\" ;\n";
  530. else
  531. text += " lv2:name \"Port " + String(i+1) + "\" ;\n";
  532. if ((paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT) == 0)
  533. text += " lv2:default " + String::formatted("%f", static_cast<double>(paramInfo->ranges.def)) + " ;\n";
  534. text += " lv2:minimum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.min)) + " ;\n";
  535. text += " lv2:maximum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.max)) + " ;\n";
  536. if ((paramInfo->hints & NATIVE_PARAMETER_IS_AUTOMABLE) == 0)
  537. text += " lv2:portProperty <" LV2_PORT_PROPS__expensive "> ;\n";
  538. if (paramInfo->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  539. text += " lv2:portProperty lv2:toggled ;\n";
  540. if (paramInfo->hints & NATIVE_PARAMETER_IS_INTEGER)
  541. text += " lv2:portProperty lv2:integer ;\n";
  542. if (paramInfo->hints & NATIVE_PARAMETER_IS_LOGARITHMIC)
  543. text += " lv2:portProperty <" LV2_PORT_PROPS__logarithmic "> ;\n";
  544. if (paramInfo->hints & NATIVE_PARAMETER_USES_SAMPLE_RATE)
  545. text += " lv2:portProperty lv2:toggled ;\n";
  546. if (paramInfo->hints & NATIVE_PARAMETER_USES_SCALEPOINTS)
  547. text += " lv2:portProperty lv2:enumeration ;\n";
  548. if ((paramInfo->hints & NATIVE_PARAMETER_IS_ENABLED) == 0)
  549. text += " lv2:portProperty <" LV2_PORT_PROPS__notOnGUI "> ;\n";
  550. for (uint32_t j=0; j < paramInfo->scalePointCount; ++j)
  551. {
  552. const NativeParameterScalePoint* const scalePoint(&paramInfo->scalePoints[j]);
  553. if (j == 0)
  554. text += " lv2:scalePoint [ ";
  555. else
  556. text += " [ ";
  557. text += "rdfs:label \"" + String(scalePoint->label) + "\" ;\n";
  558. text += " rdf:value " + String::formatted("%f", static_cast<double>(scalePoint->value)) + " ";
  559. if (j+1 == paramInfo->scalePointCount)
  560. text += "] ;\n";
  561. else
  562. text += "] ,\n";
  563. }
  564. if (paramUnit.isNotEmpty())
  565. {
  566. text += " unit:unit [\n";
  567. text += " a unit:Unit ;\n";
  568. text += " rdfs:label \"" + paramUnit + "\" ;\n";
  569. text += " unit:symbol \"" + paramUnit + "\" ;\n";
  570. text += " unit:render \"%f " + paramUnit + "\" ;\n";
  571. text += " ] ;\n";
  572. }
  573. if (i+1 == paramCount)
  574. text += " ] ;\n\n";
  575. else
  576. text += " ] , [\n";
  577. }
  578. if (std::strcmp(pluginDesc->copyright, "GNU GPL v2+") == 0)
  579. text += " doap:license <http://opensource.org/licenses/GPL-2.0> ;\n\n";
  580. if (std::strcmp(pluginDesc->copyright, "LGPL") == 0)
  581. text += " doap:license <http://opensource.org/licenses/LGPL-2.0> ;\n\n";
  582. if (std::strcmp(pluginDesc->copyright, "ISC") == 0)
  583. text += " doap:license <http://opensource.org/licenses/ISC> ;\n\n";
  584. text += " doap:developer [\n";
  585. text += " foaf:name \"" + String(pluginDesc->maker) + "\" ;\n";
  586. text += " ] ;\n\n";
  587. text += " doap:maintainer [\n";
  588. text += " foaf:homepage <https://falktx.com/> ;\n";
  589. text += " foaf:mbox <mailto:falktx@falktx.com> ;\n";
  590. text += " foaf:name \"Filipe Coelho\" ;\n";
  591. text += " ] ;\n\n";
  592. text += " doap:name \"" + String(pluginDesc->name) + "\" .\n";
  593. #if 0
  594. // -------------------------------------------------------------------
  595. // Presets
  596. if (pluginDesc->get_midi_program_count != nullptr && pluginDesc->get_midi_program_info != nullptr && pluginHandle != nullptr)
  597. {
  598. if (const uint32_t presetCount = pluginDesc->get_midi_program_count(pluginHandle))
  599. {
  600. const String presetsFile("carla.lv2/" + pluginLabel + "-presets.ttl");
  601. std::fstream presetsStream(presetsFile.toRawUTF8(), std::ios::out);
  602. String presetId, presetText;
  603. presetText += "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  604. presetText += "@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n";
  605. presetText += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  606. for (uint32_t i=0; i<presetCount; ++i)
  607. {
  608. const NativeMidiProgram* const midiProg(pluginDesc->get_midi_program_info(pluginHandle, i));
  609. pluginDesc->set_midi_program(pluginHandle, 0, midiProg->bank, midiProg->program);
  610. presetId = String::formatted("%03i", i+1);
  611. text += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
  612. text += " a pset:Preset ;\n";
  613. text += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
  614. text += " rdfs:seeAlso <" + pluginLabel + "-presets.ttl> .\n";
  615. presetText += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
  616. presetText += " a pset:Preset ;\n";
  617. presetText += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
  618. presetText += " rdfs:label \"" + String(midiProg->name) + "\" ;\n";
  619. for (uint32_t j=0; j < paramCount; ++j)
  620. {
  621. const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, j));
  622. const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
  623. const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
  624. CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
  625. if (j == 0)
  626. presetText += " lv2:port [\n";
  627. presetText += " lv2:symbol \"" + nameToSymbol(paramName, j) + "\" ;\n";
  628. presetText += " pset:value " + String::formatted("%f", static_cast<double>(pluginDesc->get_parameter_value(pluginHandle, j))) + " ;\n";
  629. if (j+1 == paramCount)
  630. presetText += " ] ;\n\n";
  631. else
  632. presetText += " ] , [\n";
  633. }
  634. presetsStream << presetText.toRawUTF8();
  635. presetText.clear();
  636. }
  637. presetsStream.close();
  638. }
  639. }
  640. #endif
  641. // -------------------------------------------------------------------
  642. // Write file now
  643. std::fstream pluginStream(pluginFile.toRawUTF8(), std::ios::out);
  644. pluginStream << text.toRawUTF8();
  645. pluginStream.close();
  646. // -------------------------------------------------------------------
  647. // Cleanup plugin
  648. if (pluginHandle != nullptr && pluginDesc->cleanup != nullptr)
  649. pluginDesc->cleanup(pluginHandle);
  650. }
  651. // -----------------------------------------------------------------------
  652. int main()
  653. {
  654. PluginListManager& plm(PluginListManager::getInstance());
  655. writeManifestFile(plm);
  656. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  657. {
  658. const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
  659. CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
  660. writePluginFile(pluginDesc);
  661. }
  662. carla_stdout("Done.");
  663. return 0;
  664. }
  665. // -----------------------------------------------------------------------