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.

654 lines
23KB

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