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.

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