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.

738 lines
26KB

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