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

10 years ago
7 years ago
10 years ago
10 years ago
10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-2017 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/lv2_external_ui.h"
  32. #include "lv2/lv2_programs.h"
  33. #include "water/files/File.h"
  34. #include "water/text/StringArray.h"
  35. #include <fstream>
  36. #if defined(CARLA_OS_WIN)
  37. # define PLUGIN_EXT ".dll"
  38. #elif defined(CARLA_OS_MAC)
  39. # define PLUGIN_EXT ".dylib"
  40. #else
  41. # define PLUGIN_EXT ".so"
  42. #endif
  43. using water::String;
  44. using water::StringArray;
  45. using water::water_uchar;
  46. // -----------------------------------------------------------------------
  47. // Converts a parameter name to an LV2 compatible symbol
  48. static StringArray gUsedSymbols;
  49. static const String nameToSymbol(const String& name, const uint32_t portIndex)
  50. {
  51. String symbol, trimmedName = name.trim().toLowerCase();
  52. if (trimmedName.isEmpty())
  53. {
  54. symbol += "lv2_port_";
  55. symbol += String(portIndex+1);
  56. }
  57. else
  58. {
  59. for (int i=0; i < trimmedName.length(); ++i)
  60. {
  61. const water_uchar c = trimmedName[i];
  62. if (i == 0 && std::isdigit(c))
  63. symbol += "_";
  64. else if (std::isalpha(c) || std::isdigit(c))
  65. symbol += c;
  66. else
  67. symbol += "_";
  68. }
  69. }
  70. // Do not allow identical symbols
  71. if (gUsedSymbols.contains(symbol))
  72. {
  73. int offset = 2;
  74. String offsetStr = "_2";
  75. symbol += offsetStr;
  76. while (gUsedSymbols.contains(symbol))
  77. {
  78. offset += 1;
  79. String newOffsetStr = "_" + String(offset);
  80. symbol = symbol.replace(offsetStr, newOffsetStr);
  81. offsetStr = newOffsetStr;
  82. }
  83. }
  84. gUsedSymbols.add(symbol);
  85. return symbol;
  86. }
  87. // -----------------------------------------------------------------------
  88. static void writeManifestFile(PluginListManager& plm)
  89. {
  90. String text;
  91. // -------------------------------------------------------------------
  92. // Header
  93. text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
  94. text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
  95. text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  96. text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
  97. text += "\n";
  98. // -------------------------------------------------------------------
  99. // Plugins
  100. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  101. {
  102. const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
  103. CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
  104. const String label(pluginDesc->label);
  105. text += "<http://kxstudio.sf.net/carla/plugins/" + label + ">\n";
  106. text += " a lv2:Plugin ;\n";
  107. text += " lv2:binary <carla" PLUGIN_EXT "> ;\n";
  108. text += " rdfs:seeAlso <" + label + ".ttl> .\n";
  109. text += "\n";
  110. }
  111. // -------------------------------------------------------------------
  112. // UI
  113. #ifdef CARLA_OS_LINUX
  114. text += "<http://kxstudio.sf.net/carla/ui-embed>\n";
  115. text += " a <" LV2_UI__X11UI "> ;\n";
  116. text += " ui:binary <carla" PLUGIN_EXT "> ;\n";
  117. text += " lv2:extensionData <" LV2_PROGRAMS__UIInterface "> ;\n";
  118. text += " lv2:optionalFeature <" LV2_UI__fixedSize "> ,\n";
  119. text += " <" LV2_UI__noUserResize "> ;\n";
  120. text += " lv2:requiredFeature <" LV2_INSTANCE_ACCESS_URI "> ,\n";
  121. text += " <" LV2_UI__resize "> ;\n";
  122. text += " opts:supportedOption <" LV2_PARAMETERS__sampleRate "> .\n";
  123. text += "\n";
  124. #endif
  125. text += "<http://kxstudio.sf.net/carla/ui-ext>\n";
  126. text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
  127. text += " ui:binary <carla" PLUGIN_EXT "> ;\n";
  128. text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
  129. text += " <" LV2_UI__showInterface "> ,\n";
  130. text += " <" LV2_PROGRAMS__UIInterface "> ;\n";
  131. text += " lv2:requiredFeature <" LV2_INSTANCE_ACCESS_URI "> ;\n";
  132. text += " opts:supportedOption <" LV2_PARAMETERS__sampleRate "> .\n";
  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. text += "\n";
  241. // -------------------------------------------------------------------
  242. // Options
  243. text += " opts:supportedOption <" LV2_BUF_SIZE__nominalBlockLength "> ,\n";
  244. text += " <" LV2_BUF_SIZE__maxBlockLength "> ,\n";
  245. text += " <" LV2_PARAMETERS__sampleRate "> ;\n";
  246. text += "\n";
  247. // -------------------------------------------------------------------
  248. // UIs
  249. if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
  250. {
  251. #ifdef CARLA_OS_LINUX
  252. if (std::strncmp(pluginDesc->label, "carla", 5) == 0)
  253. {
  254. text += " ui:ui <http://kxstudio.sf.net/carla/ui-embed> ,\n";
  255. text += " <http://kxstudio.sf.net/carla/ui-ext> ;\n";
  256. }
  257. else
  258. #endif
  259. {
  260. text += " ui:ui <http://kxstudio.sf.net/carla/ui-ext> ;\n";
  261. }
  262. text += "\n";
  263. }
  264. // -------------------------------------------------------------------
  265. // First MIDI/Time port
  266. if (pluginDesc->midiIns > 0 || (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME) != 0)
  267. {
  268. text += " lv2:port [\n";
  269. text += " a lv2:InputPort, atom:AtomPort ;\n";
  270. text += " atom:bufferType atom:Sequence ;\n";
  271. if (pluginDesc->midiIns > 0 && (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME) != 0)
  272. {
  273. text += " atom:supports <" LV2_MIDI__MidiEvent "> ,\n";
  274. text += " <" LV2_TIME__Position "> ;\n";
  275. }
  276. else if (pluginDesc->midiIns > 0)
  277. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  278. else
  279. text += " atom:supports <" LV2_TIME__Position "> ;\n";
  280. text += " lv2:designation lv2:control ;\n";
  281. text += " lv2:index " + String(portIndex++) + " ;\n";
  282. if (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME)
  283. {
  284. if (pluginDesc->midiIns > 1)
  285. {
  286. text += " lv2:symbol \"lv2_events_in_1\" ;\n";
  287. text += " lv2:name \"Events Input #1\" ;\n";
  288. }
  289. else
  290. {
  291. text += " lv2:symbol \"lv2_events_in\" ;\n";
  292. text += " lv2:name \"Events Input\" ;\n";
  293. }
  294. }
  295. else
  296. {
  297. if (pluginDesc->midiIns > 1)
  298. {
  299. text += " lv2:symbol \"lv2_midi_in_1\" ;\n";
  300. text += " lv2:name \"MIDI Input #1\" ;\n";
  301. }
  302. else
  303. {
  304. text += " lv2:symbol \"lv2_midi_in\" ;\n";
  305. text += " lv2:name \"MIDI Input\" ;\n";
  306. }
  307. }
  308. text += " ] ;\n\n";
  309. }
  310. // -------------------------------------------------------------------
  311. // MIDI inputs
  312. for (uint32_t i=1; i < pluginDesc->midiIns; ++i)
  313. {
  314. if (i == 1)
  315. text += " lv2:port [\n";
  316. text += " a lv2:InputPort, atom:AtomPort ;\n";
  317. text += " atom:bufferType atom:Sequence ;\n";
  318. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  319. text += " lv2:index " + String(portIndex++) + " ;\n";
  320. text += " lv2:symbol \"lv2_midi_in_" + String(i+1) + "\" ;\n";
  321. text += " lv2:name \"MIDI Input #" + String(i+1) + "\" ;\n";
  322. if (i+1 == pluginDesc->midiIns)
  323. text += " ] ;\n\n";
  324. else
  325. text += " ] , [\n";
  326. }
  327. // -------------------------------------------------------------------
  328. // MIDI outputs
  329. for (uint32_t i=0; i < pluginDesc->midiOuts; ++i)
  330. {
  331. if (i == 0)
  332. text += " lv2:port [\n";
  333. text += " a lv2:OutputPort, atom:AtomPort ;\n";
  334. text += " atom:bufferType atom:Sequence ;\n";
  335. text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
  336. text += " lv2:index " + String(portIndex++) + " ;\n";
  337. if (pluginDesc->midiOuts > 1)
  338. {
  339. text += " lv2:symbol \"lv2_midi_out_" + String(i+1) + "\" ;\n";
  340. text += " lv2:name \"MIDI Output #" + String(i+1) + "\" ;\n";
  341. }
  342. else
  343. {
  344. text += " lv2:symbol \"lv2_midi_out\" ;\n";
  345. text += " lv2:name \"MIDI Output\" ;\n";
  346. }
  347. if (i+1 == pluginDesc->midiOuts)
  348. text += " ] ;\n\n";
  349. else
  350. text += " ] , [\n";
  351. }
  352. // -------------------------------------------------------------------
  353. // Freewheel port
  354. text += " lv2:port [\n";
  355. text += " a lv2:InputPort, lv2:ControlPort ;\n";
  356. text += " lv2:index " + String(portIndex++) + " ;\n";
  357. text += " lv2:symbol \"lv2_freewheel\" ;\n";
  358. text += " lv2:name \"Freewheel\" ;\n";
  359. text += " lv2:default 0.0 ;\n";
  360. text += " lv2:minimum 0.0 ;\n";
  361. text += " lv2:maximum 1.0 ;\n";
  362. text += " lv2:designation <" LV2_CORE__freeWheeling "> ;\n";
  363. text += " lv2:portProperty lv2:toggled, <" LV2_PORT_PROPS__notOnGUI "> ;\n";
  364. text += " ] ;\n";
  365. text += "\n";
  366. // -------------------------------------------------------------------
  367. // Audio inputs
  368. for (uint32_t i=0; i < pluginDesc->audioIns; ++i)
  369. {
  370. if (i == 0)
  371. text += " lv2:port [\n";
  372. text += " a lv2:InputPort, lv2:AudioPort ;\n";
  373. text += " lv2:index " + String(portIndex++) + " ;\n";
  374. text += " lv2:symbol \"lv2_audio_in_" + String(i+1) + "\" ;\n";
  375. text += " lv2:name \"Audio Input " + String(i+1) + "\" ;\n";
  376. if (i+1 == pluginDesc->audioIns)
  377. text += " ] ;\n\n";
  378. else
  379. text += " ] , [\n";
  380. }
  381. // -------------------------------------------------------------------
  382. // Audio outputs
  383. for (uint32_t i=0; i < pluginDesc->audioOuts; ++i)
  384. {
  385. if (i == 0)
  386. text += " lv2:port [\n";
  387. text += " a lv2:OutputPort, lv2:AudioPort ;\n";
  388. text += " lv2:index " + String(portIndex++) + " ;\n";
  389. text += " lv2:symbol \"lv2_audio_out_" + String(i+1) + "\" ;\n";
  390. text += " lv2:name \"Audio Output " + String(i+1) + "\" ;\n";
  391. if (i+1 == pluginDesc->audioOuts)
  392. text += " ] ;\n\n";
  393. else
  394. text += " ] , [\n";
  395. }
  396. // -------------------------------------------------------------------
  397. // Parameters
  398. const uint32_t paramCount((pluginHandle != nullptr && pluginDesc->get_parameter_count != nullptr) ? pluginDesc->get_parameter_count(pluginHandle) : 0);
  399. if (paramCount > 0)
  400. {
  401. CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_info != nullptr,)
  402. CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_value != nullptr,)
  403. }
  404. for (uint32_t i=0; i < paramCount; ++i)
  405. {
  406. const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, i));
  407. const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
  408. const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
  409. CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
  410. if (i == 0)
  411. text += " lv2:port [\n";
  412. if (paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT)
  413. text += " a lv2:OutputPort, lv2:ControlPort ;\n";
  414. else
  415. text += " a lv2:InputPort, lv2:ControlPort ;\n";
  416. text += " lv2:index " + String(portIndex++) + " ;\n";
  417. text += " lv2:symbol \"" + nameToSymbol(paramName, i) + "\" ;\n";
  418. if (paramName.isNotEmpty())
  419. text += " lv2:name \"" + paramName + "\" ;\n";
  420. else
  421. text += " lv2:name \"Port " + String(i+1) + "\" ;\n";
  422. if ((paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT) == 0)
  423. text += " lv2:default " + String::formatted("%f", paramInfo->ranges.def) + " ;\n";
  424. text += " lv2:minimum " + String::formatted("%f", paramInfo->ranges.min) + " ;\n";
  425. text += " lv2:maximum " + String::formatted("%f", paramInfo->ranges.max) + " ;\n";
  426. if ((paramInfo->hints & NATIVE_PARAMETER_IS_AUTOMABLE) == 0)
  427. text += " lv2:portProperty <" LV2_PORT_PROPS__expensive "> ;\n";
  428. if (paramInfo->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  429. text += " lv2:portProperty lv2:toggled ;\n";
  430. if (paramInfo->hints & NATIVE_PARAMETER_IS_INTEGER)
  431. text += " lv2:portProperty lv2:integer ;\n";
  432. if (paramInfo->hints & NATIVE_PARAMETER_IS_LOGARITHMIC)
  433. text += " lv2:portProperty <" LV2_PORT_PROPS__logarithmic "> ;\n";
  434. if (paramInfo->hints & NATIVE_PARAMETER_USES_SAMPLE_RATE)
  435. text += " lv2:portProperty lv2:toggled ;\n";
  436. if (paramInfo->hints & NATIVE_PARAMETER_USES_SCALEPOINTS)
  437. text += " lv2:portProperty lv2:enumeration ;\n";
  438. if ((paramInfo->hints & NATIVE_PARAMETER_IS_ENABLED) == 0)
  439. text += " lv2:portProperty <" LV2_PORT_PROPS__notOnGUI "> ;\n";
  440. for (uint32_t j=0; j < paramInfo->scalePointCount; ++j)
  441. {
  442. const NativeParameterScalePoint* const scalePoint(&paramInfo->scalePoints[j]);
  443. if (j == 0)
  444. text += " lv2:scalePoint [ ";
  445. else
  446. text += " [ ";
  447. text += "rdfs:label \"" + String(scalePoint->label) + "\" ;\n";
  448. text += " rdf:value " + String::formatted("%f", scalePoint->value) + " ";
  449. if (j+1 == paramInfo->scalePointCount)
  450. text += "] ;\n";
  451. else
  452. text += "] ,\n";
  453. }
  454. if (paramUnit.isNotEmpty())
  455. {
  456. text += " unit:unit [\n";
  457. text += " a unit:Unit ;\n";
  458. text += " rdfs:label \"" + paramUnit + "\" ;\n";
  459. text += " unit:symbol \"" + paramUnit + "\" ;\n";
  460. text += " unit:render \"%f " + paramUnit + "\" ;\n";
  461. text += " ] ;\n";
  462. }
  463. if (i+1 == paramCount)
  464. text += " ] ;\n\n";
  465. else
  466. text += " ] , [\n";
  467. }
  468. text += " doap:name \"" + String(pluginDesc->name) + "\" ;\n";
  469. text += " doap:maintainer [ foaf:name \"" + String(pluginDesc->maker) + "\" ] .\n";
  470. #if 0
  471. // -------------------------------------------------------------------
  472. // Presets
  473. if (pluginDesc->get_midi_program_count != nullptr && pluginDesc->get_midi_program_info != nullptr && pluginHandle != nullptr)
  474. {
  475. if (const uint32_t presetCount = pluginDesc->get_midi_program_count(pluginHandle))
  476. {
  477. const String presetsFile("carla.lv2/" + pluginLabel + "-presets.ttl");
  478. std::fstream presetsStream(presetsFile.toRawUTF8(), std::ios::out);
  479. String presetId, presetText;
  480. presetText += "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
  481. presetText += "@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n";
  482. presetText += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
  483. for (uint32_t i=0; i<presetCount; ++i)
  484. {
  485. const NativeMidiProgram* const midiProg(pluginDesc->get_midi_program_info(pluginHandle, i));
  486. pluginDesc->set_midi_program(pluginHandle, 0, midiProg->bank, midiProg->program);
  487. presetId = String::formatted("%03i", i+1);
  488. text += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
  489. text += " a pset:Preset ;\n";
  490. text += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
  491. text += " rdfs:seeAlso <" + pluginLabel + "-presets.ttl> .\n";
  492. presetText += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
  493. presetText += " a pset:Preset ;\n";
  494. presetText += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
  495. presetText += " rdfs:label \"" + String(midiProg->name) + "\" ;\n";
  496. for (uint32_t j=0; j < paramCount; ++j)
  497. {
  498. const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, j));
  499. const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
  500. const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
  501. CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
  502. if (j == 0)
  503. presetText += " lv2:port [\n";
  504. presetText += " lv2:symbol \"" + nameToSymbol(paramName, j) + "\" ;\n";
  505. presetText += " pset:value " + String::formatted("%f", pluginDesc->get_parameter_value(pluginHandle, j)) + " ;\n";
  506. if (j+1 == paramCount)
  507. presetText += " ] ;\n\n";
  508. else
  509. presetText += " ] , [\n";
  510. }
  511. presetsStream << presetText.toRawUTF8();
  512. presetText.clear();
  513. }
  514. presetsStream.close();
  515. }
  516. }
  517. #endif
  518. // -------------------------------------------------------------------
  519. // Write file now
  520. std::fstream pluginStream(pluginFile.toRawUTF8(), std::ios::out);
  521. pluginStream << text.toRawUTF8();
  522. pluginStream.close();
  523. // -------------------------------------------------------------------
  524. // Cleanup plugin
  525. if (pluginHandle != nullptr && pluginDesc->cleanup != nullptr)
  526. pluginDesc->cleanup(pluginHandle);
  527. }
  528. // -----------------------------------------------------------------------
  529. int main()
  530. {
  531. PluginListManager& plm(PluginListManager::getInstance());
  532. writeManifestFile(plm);
  533. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  534. {
  535. const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
  536. CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
  537. writePluginFile(pluginDesc);
  538. }
  539. carla_stdout("Done.");
  540. return 0;
  541. }
  542. // -----------------------------------------------------------------------