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.

798 lines
28KB

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