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.

855 lines
32KB

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