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.

carla-lv2-export.cpp 26KB

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