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.

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