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.

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