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.

841 lines
30KB

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