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.

874 lines
32KB

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