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.

740 lines
26KB

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