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 25KB

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