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.

660 lines
23KB

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