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.

722 lines
26KB

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