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.

857 lines
31KB

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