Fix carla.lv2 ttl validation
[carla.git] / source / plugin / carla-lv2-export.cpp
blobf2bed64d719bba101b9cd0df5b4c0636dd3dabac
1 /*
2 * Carla Native Plugins
3 * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #define CARLA_NATIVE_PLUGIN_LV2
19 #include "carla-base.cpp"
21 #include "lv2/atom.h"
22 #include "lv2/buf-size.h"
23 #include "lv2/instance-access.h"
24 #include "lv2/midi.h"
25 #include "lv2/options.h"
26 #include "lv2/parameters.h"
27 #include "lv2/patch.h"
28 #include "lv2/port-props.h"
29 #include "lv2/state.h"
30 #include "lv2/time.h"
31 #include "lv2/ui.h"
32 #include "lv2/units.h"
33 #include "lv2/urid.h"
34 #include "lv2/worker.h"
35 #include "lv2/inline-display.h"
36 #include "lv2/lv2_external_ui.h"
37 #include "lv2/lv2_programs.h"
39 #include "CarlaString.hpp"
41 #include "water/files/File.h"
42 #include "water/text/StringArray.h"
44 #include <fstream>
46 #if defined(CARLA_OS_WIN)
47 # define PLUGIN_EXT ".dll"
48 #elif defined(CARLA_OS_MAC)
49 # define PLUGIN_EXT ".dylib"
50 #else
51 # define PLUGIN_EXT ".so"
52 #endif
54 using water::String;
55 using water::StringArray;
56 using water::water_uchar;
58 // -----------------------------------------------------------------------
59 // Converts a parameter name to an LV2 compatible symbol
61 static StringArray gUsedSymbols;
63 static const String nameToSymbol(const String& name, const uint32_t portIndex)
65 String symbol, trimmedName = name.trim().toLowerCase();
67 if (trimmedName.isEmpty())
69 symbol += "lv2_port_";
70 symbol += String(portIndex+1);
72 else
74 if (std::isdigit(static_cast<int>(trimmedName[0])))
75 symbol += "_";
77 for (int i=0; i < trimmedName.length(); ++i)
79 const water_uchar c = trimmedName[i];
81 if (std::isalpha(static_cast<int>(c)) || std::isdigit(static_cast<int>(c)))
82 symbol += c;
83 else
84 symbol += "_";
88 // Do not allow identical symbols
89 if (gUsedSymbols.contains(symbol))
91 int offset = 2;
92 String offsetStr = "_2";
93 symbol += offsetStr;
95 while (gUsedSymbols.contains(symbol))
97 offset += 1;
98 String newOffsetStr = "_" + String(offset);
99 symbol = symbol.replace(offsetStr, newOffsetStr);
100 offsetStr = newOffsetStr;
104 gUsedSymbols.add(symbol);
106 return symbol;
109 // -----------------------------------------------------------------------
111 static void writeManifestFile(PluginListManager& plm, const uint32_t microVersion, const uint32_t minorVersion)
113 String text;
115 // -------------------------------------------------------------------
116 // Header
118 text += "@prefix atom: <" LV2_ATOM_PREFIX "> .\n";
119 text += "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
120 text += "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
121 text += "@prefix idpy: <http://harrisonconsoles.com/lv2/inlinedisplay#> .\n";
122 text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
123 text += "@prefix mod: <http://moddevices.com/ns/mod#> .\n";
124 text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
125 text += "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n";
126 text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
127 text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
128 text += "\n";
130 // -------------------------------------------------------------------
131 // Project
133 text += "<https://kx.studio/carla>\n";
134 text += " a owl:Ontology, doap:Project ;\n";
135 text += " doap:homepage <https://kx.studio/carla> ;\n";
136 text += " doap:maintainer [\n";
137 text += " foaf:homepage <https://falktx.com/> ;\n";
138 text += " foaf:mbox <mailto:falktx@falktx.com> ;\n";
139 text += " foaf:name \"Filipe Coelho\" ;\n";
140 text += " ] ;\n";
141 text += " doap:name \"Carla\" ;\n";
142 text += " doap:shortdesc \"fully-featured audio plugin host.\" ;\n";
143 text += " lv2:microVersion " + String(microVersion) + " ;\n";
144 text += " lv2:minorVersion " + String(minorVersion) + " ;\n";
145 text += " lv2:symbol \"carla\" .\n";
146 text += "\n";
148 // -------------------------------------------------------------------
149 // Extensions
151 text += "idpy:interface\n";
152 text += " a lv2:ExtensionData .\n";
153 text += "\n";
155 text += "idpy:queue_draw\n";
156 text += " a lv2:Feature .\n";
157 text += "\n";
159 // -------------------------------------------------------------------
160 // Plugins
162 for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
164 const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
165 CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
167 const String label(pluginDesc->label);
169 text += "<http://kxstudio.sf.net/carla/plugins/" + label + ">\n";
170 text += " a lv2:Plugin ;\n";
171 text += " lv2:binary <carla" PLUGIN_EXT "> ;\n";
172 text += " lv2:project <https://kx.studio/carla> ;\n";
173 text += " rdfs:seeAlso <" + label + ".ttl> .\n";
174 text += "\n";
177 // -------------------------------------------------------------------
178 // UI
180 #ifdef HAVE_PYQT
181 text += "<http://kxstudio.sf.net/carla/ui-ext>\n";
182 text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
183 text += " ui:binary <carla" PLUGIN_EXT "> ;\n";
184 text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
185 text += " <" LV2_UI__showInterface "> ,\n";
186 text += " <" LV2_PROGRAMS__UIInterface "> ;\n";
187 text += " lv2:optionalFeature <" LV2_UI__idleInterface "> ;\n";
188 text += " lv2:requiredFeature <" LV2_INSTANCE_ACCESS_URI "> ;\n";
189 text += " opts:supportedOption <" LV2_PARAMETERS__sampleRate "> .\n";
190 text += "\n";
192 # if 0
193 text += "<http://kxstudio.sf.net/carla/ui-bridge-ext>\n";
194 text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
195 text += " ui:binary <carla-ui" PLUGIN_EXT "> ;\n";
196 text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
197 text += " <" LV2_UI__showInterface "> ,\n";
198 text += " <" LV2_PROGRAMS__UIInterface "> .\n";
199 # endif
200 #endif
202 // -------------------------------------------------------------------
203 // File handling
205 text += "<http://kxstudio.sf.net/carla/file>\n";
206 text += " a lv2:Parameter ;\n";
207 text += " rdfs:label \"file\" ;\n";
208 text += " rdfs:range atom:Path .\n";
209 text += "\n";
211 text += "<http://kxstudio.sf.net/carla/file/audio>\n";
212 text += " a lv2:Parameter ;\n";
213 text += " mod:fileTypes \"audioloop,audiorecording,audiotrack\" ;\n";
214 text += " rdfs:label \"audio file\" ;\n";
215 text += " rdfs:range atom:Path .\n";
216 text += "\n";
218 text += "<http://kxstudio.sf.net/carla/file/midi>\n";
219 text += " a lv2:Parameter ;\n";
220 text += " mod:fileTypes \"midisong\" ;\n";
221 text += " rdfs:label \"midi file\" ;\n";
222 text += " rdfs:range atom:Path .\n";
223 text += "\n";
225 // -------------------------------------------------------------------
226 // Write file now
228 std::fstream manifest("carla.lv2/manifest.ttl", std::ios::out);
229 manifest << text.toRawUTF8();
230 manifest.close();
233 // -----------------------------------------------------------------------
235 static uint32_t host_getBufferSize(NativeHostHandle) { return 512; }
236 static double host_getSampleRate(NativeHostHandle) { return 44100.0; }
237 static bool host_isOffline(NativeHostHandle) { return true; }
238 static intptr_t host_dispatcher(NativeHostHandle, NativeHostDispatcherOpcode, int32_t, intptr_t, void*, float) { return 0; }
240 static void writePluginFile(const NativePluginDescriptor* const pluginDesc,
241 const uint32_t microVersion, const uint32_t minorVersion)
243 const String pluginLabel(pluginDesc->label);
244 const String pluginFile("carla.lv2/" + pluginLabel + ".ttl");
246 uint32_t portIndex = 0;
247 String text;
249 gUsedSymbols.clear();
251 carla_stdout("Generating data for %s...", pluginDesc->name);
253 // -------------------------------------------------------------------
254 // Init plugin
256 NativeHostDescriptor hostDesc;
257 hostDesc.handle = nullptr;
258 hostDesc.resourceDir = "";
259 hostDesc.uiName = "";
260 hostDesc.get_buffer_size = host_getBufferSize;
261 hostDesc.get_sample_rate = host_getSampleRate;
262 hostDesc.is_offline = host_isOffline;
263 hostDesc.get_time_info = nullptr;
264 hostDesc.write_midi_event = nullptr;
265 hostDesc.ui_parameter_changed = nullptr;
266 hostDesc.ui_midi_program_changed = nullptr;
267 hostDesc.ui_custom_data_changed = nullptr;
268 hostDesc.ui_closed = nullptr;
269 hostDesc.ui_open_file = nullptr;
270 hostDesc.ui_save_file = nullptr;
271 hostDesc.dispatcher = host_dispatcher;
273 NativePluginHandle pluginHandle = nullptr;
275 if (! pluginLabel.startsWithIgnoreCase("carla"))
277 pluginHandle = pluginDesc->instantiate(&hostDesc);
278 CARLA_SAFE_ASSERT_RETURN(pluginHandle != nullptr,)
281 // -------------------------------------------------------------------
282 // Header
284 text += "@prefix atom: <" LV2_ATOM_PREFIX "> .\n";
285 text += "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
286 text += "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
287 text += "@prefix idpy: <http://harrisonconsoles.com/lv2/inlinedisplay#> .\n";
288 text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
289 text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
290 text += "@prefix patch: <" LV2_PATCH_PREFIX "> .\n";
291 text += "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n";
292 text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
293 text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
294 text += "@prefix unit: <" LV2_UNITS_PREFIX "> .\n";
295 text += "\n";
297 // -------------------------------------------------------------------
298 // Plugin URI
300 text += "<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + ">\n";
302 // -------------------------------------------------------------------
303 // Category
305 switch (pluginDesc->category)
307 case NATIVE_PLUGIN_CATEGORY_SYNTH:
308 text += " a lv2:InstrumentPlugin, lv2:Plugin, doap:Project ;\n";
309 break;
310 case NATIVE_PLUGIN_CATEGORY_DELAY:
311 text += " a lv2:DelayPlugin, lv2:Plugin, doap:Project ;\n";
312 break;
313 case NATIVE_PLUGIN_CATEGORY_EQ:
314 text += " a lv2:EQPlugin, lv2:Plugin, doap:Project ;\n";
315 break;
316 case NATIVE_PLUGIN_CATEGORY_FILTER:
317 text += " a lv2:FilterPlugin, lv2:Plugin, doap:Project ;\n";
318 break;
319 case NATIVE_PLUGIN_CATEGORY_DYNAMICS:
320 text += " a lv2:DynamicsPlugin, lv2:Plugin, doap:Project ;\n";
321 break;
322 case NATIVE_PLUGIN_CATEGORY_MODULATOR:
323 text += " a lv2:ModulatorPlugin, lv2:Plugin, doap:Project ;\n";
324 break;
325 case NATIVE_PLUGIN_CATEGORY_UTILITY:
326 text += " a lv2:UtilityPlugin, lv2:Plugin, doap:Project ;\n";
327 break;
328 default:
329 if (pluginDesc->midiIns >= 1 && pluginDesc->midiOuts >= 1 && pluginDesc->audioIns + pluginDesc->audioOuts == 0)
330 text += " a lv2:MIDIPlugin, lv2:Plugin, doap:Project ;\n";
331 else
332 text += " a lv2:Plugin, doap:Project ;\n";
333 break;
336 text += "\n";
338 // -------------------------------------------------------------------
339 // Features
341 // optional
342 if (pluginDesc->hints & NATIVE_PLUGIN_IS_RTSAFE)
343 text += " lv2:optionalFeature <" LV2_CORE__hardRTCapable "> ;\n";
344 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
345 text += " lv2:optionalFeature idpy:queue_draw ;\n";
346 if ((pluginDesc->hints & NATIVE_PLUGIN_USES_STATE) || (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE))
347 text += " lv2:optionalFeature <" LV2_STATE__threadSafeRestore "> ;\n";
348 text += "\n";
350 // required
351 text += " lv2:requiredFeature <" LV2_BUF_SIZE__boundedBlockLength "> ,\n";
353 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
354 text += " <" LV2_BUF_SIZE__fixedBlockLength "> ,\n";
356 if (pluginDesc->hints & NATIVE_PLUGIN_REQUESTS_IDLE)
357 text += " <" LV2_WORKER__schedule "> ,\n";
359 text += " <" LV2_OPTIONS__options "> ,\n";
360 text += " <" LV2_URID__map "> ;\n";
361 text += "\n";
363 // -------------------------------------------------------------------
364 // Extensions
366 text += " lv2:extensionData <" LV2_OPTIONS__interface "> ;\n";
368 if ((pluginDesc->hints & NATIVE_PLUGIN_USES_STATE) || (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE))
369 text += " lv2:extensionData <" LV2_STATE__interface "> ;\n";
371 if (pluginDesc->category != NATIVE_PLUGIN_CATEGORY_SYNTH)
372 text += " lv2:extensionData <" LV2_PROGRAMS__Interface "> ;\n";
374 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
375 text += " lv2:extensionData <" LV2_WORKER__interface "> ;\n";
377 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
378 text += " lv2:extensionData idpy:interface ;\n";
380 text += "\n";
382 // -------------------------------------------------------------------
383 // Options
385 text += " opts:supportedOption <" LV2_BUF_SIZE__nominalBlockLength "> ,\n";
386 text += " <" LV2_BUF_SIZE__maxBlockLength "> ,\n";
387 text += " <" LV2_PARAMETERS__sampleRate "> ;\n";
388 text += "\n";
390 // -------------------------------------------------------------------
391 // UIs
393 #ifdef HAVE_PYQT
394 if ((pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0 && (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE) == 0)
396 text += " ui:ui <http://kxstudio.sf.net/carla/ui-ext> ;\n";
397 text += "\n";
399 #endif
401 // -------------------------------------------------------------------
402 // First input MIDI/Time/UI port
404 const bool hasEventInPort = (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME) != 0
405 || (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
407 if (pluginDesc->midiIns > 0 || hasEventInPort)
409 text += " lv2:port [\n";
410 text += " a lv2:InputPort, atom:AtomPort ;\n";
411 text += " atom:bufferType atom:Sequence ;\n";
413 if (pluginDesc->midiIns > 0 && hasEventInPort)
415 text += " atom:supports <" LV2_MIDI__MidiEvent "> ,\n";
416 text += " <" LV2_TIME__Position "> ;\n";
418 else if (pluginDesc->midiIns > 0)
420 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
422 else
424 text += " atom:supports <" LV2_TIME__Position "> ;\n";
426 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
427 text += " atom:supports <" LV2_PATCH__Message "> ;\n";
429 text += " lv2:designation lv2:control ;\n";
430 text += " lv2:index " + String(portIndex++) + " ;\n";
432 if (hasEventInPort)
434 if (pluginDesc->midiIns > 1)
436 text += " lv2:symbol \"lv2_events_in_1\" ;\n";
437 text += " lv2:name \"Events Input #1\" ;\n";
439 else
441 text += " lv2:symbol \"lv2_events_in\" ;\n";
442 text += " lv2:name \"Events Input\" ;\n";
445 else
447 if (pluginDesc->midiIns > 1)
449 text += " lv2:symbol \"lv2_midi_in_1\" ;\n";
450 text += " lv2:name \"MIDI Input #1\" ;\n";
452 else
454 text += " lv2:symbol \"lv2_midi_in\" ;\n";
455 text += " lv2:name \"MIDI Input\" ;\n";
459 text += " ] ;\n\n";
462 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
464 /**/ if (pluginLabel == "audiofile")
465 text += " patch:writable <http://kxstudio.sf.net/carla/file/audio> ;\n\n";
466 else if (pluginLabel == "midifile")
467 text += " patch:writable <http://kxstudio.sf.net/carla/file/midi> ;\n\n";
468 else
469 text += " patch:writable <http://kxstudio.sf.net/carla/file> ;\n\n";
472 // -------------------------------------------------------------------
473 // MIDI inputs
475 for (uint32_t i=1; i < pluginDesc->midiIns; ++i)
477 if (i == 1)
478 text += " lv2:port [\n";
480 text += " a lv2:InputPort, atom:AtomPort ;\n";
481 text += " atom:bufferType atom:Sequence ;\n";
482 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
483 text += " lv2:index " + String(portIndex++) + " ;\n";
484 text += " lv2:symbol \"lv2_midi_in_" + String(i+1) + "\" ;\n";
485 text += " lv2:name \"MIDI Input #" + String(i+1) + "\" ;\n";
487 if (i+1 == pluginDesc->midiIns)
488 text += " ] ;\n\n";
489 else
490 text += " ] , [\n";
493 // -------------------------------------------------------------------
494 // First output MIDI/UI port
496 const bool hasEventOutPort = (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
498 if (pluginDesc->midiIns > 0 || hasEventOutPort)
500 text += " lv2:port [\n";
501 text += " a lv2:OutputPort, atom:AtomPort ;\n";
502 text += " atom:bufferType atom:Sequence ;\n";
504 if (pluginDesc->midiOuts > 0)
505 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
506 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
507 text += " atom:supports <" LV2_PATCH__Message "> ;\n";
509 text += " lv2:index " + String(portIndex++) + " ;\n";
511 if (hasEventOutPort)
513 if (pluginDesc->midiOuts > 1)
515 text += " lv2:symbol \"lv2_events_out_1\" ;\n";
516 text += " lv2:name \"Events Input #1\" ;\n";
518 else
520 text += " lv2:symbol \"lv2_events_out\" ;\n";
521 text += " lv2:name \"Events Output\" ;\n";
524 else
526 if (pluginDesc->midiOuts > 1)
528 text += " lv2:symbol \"lv2_midi_out_1\" ;\n";
529 text += " lv2:name \"MIDI Output #1\" ;\n";
531 else
533 text += " lv2:symbol \"lv2_midi_out\" ;\n";
534 text += " lv2:name \"MIDI Output\" ;\n";
538 text += " ] ;\n\n";
541 // -------------------------------------------------------------------
542 // MIDI outputs
544 for (uint32_t i=1; i < pluginDesc->midiOuts; ++i)
546 if (i == 1)
547 text += " lv2:port [\n";
549 text += " a lv2:OutputPort, atom:AtomPort ;\n";
550 text += " atom:bufferType atom:Sequence ;\n";
551 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
552 text += " lv2:index " + String(portIndex++) + " ;\n";
554 if (pluginDesc->midiOuts > 1)
556 text += " lv2:symbol \"lv2_midi_out_" + String(i+1) + "\" ;\n";
557 text += " lv2:name \"MIDI Output #" + String(i+1) + "\" ;\n";
559 else
561 text += " lv2:symbol \"lv2_midi_out\" ;\n";
562 text += " lv2:name \"MIDI Output\" ;\n";
565 if (i+1 == pluginDesc->midiOuts)
566 text += " ] ;\n\n";
567 else
568 text += " ] , [\n";
571 // -------------------------------------------------------------------
572 // Freewheel port
574 text += " lv2:port [\n";
575 text += " a lv2:InputPort, lv2:ControlPort ;\n";
576 text += " lv2:index " + String(portIndex++) + " ;\n";
577 text += " lv2:symbol \"lv2_freewheel\" ;\n";
578 text += " lv2:name \"Freewheel\" ;\n";
579 text += " lv2:default 0.0 ;\n";
580 text += " lv2:minimum 0.0 ;\n";
581 text += " lv2:maximum 1.0 ;\n";
582 text += " lv2:designation <" LV2_CORE__freeWheeling "> ;\n";
583 text += " lv2:portProperty lv2:toggled, <" LV2_PORT_PROPS__notOnGUI "> ;\n";
584 text += " ] ;\n";
585 text += "\n";
587 // -------------------------------------------------------------------
588 // Audio inputs
590 for (uint32_t i=0; i < pluginDesc->audioIns; ++i)
592 if (i == 0)
593 text += " lv2:port [\n";
595 text += " a lv2:InputPort, lv2:AudioPort ;\n";
596 text += " lv2:index " + String(portIndex++) + " ;\n";
597 text += " lv2:symbol \"lv2_audio_in_" + String(i+1) + "\" ;\n";
598 text += " lv2:name \"Audio Input " + String(i+1) + "\" ;\n";
600 if (i+1 == pluginDesc->audioIns)
601 text += " ] ;\n\n";
602 else
603 text += " ] , [\n";
606 // -------------------------------------------------------------------
607 // Audio outputs
609 for (uint32_t i=0; i < pluginDesc->audioOuts; ++i)
611 if (i == 0)
612 text += " lv2:port [\n";
614 text += " a lv2:OutputPort, lv2:AudioPort ;\n";
615 text += " lv2:index " + String(portIndex++) + " ;\n";
616 text += " lv2:symbol \"lv2_audio_out_" + String(i+1) + "\" ;\n";
617 text += " lv2:name \"Audio Output " + String(i+1) + "\" ;\n";
619 if (i+1 == pluginDesc->audioOuts)
620 text += " ] ;\n\n";
621 else
622 text += " ] , [\n";
625 // -------------------------------------------------------------------
626 // CV inputs
628 for (uint32_t i=0; i < pluginDesc->cvIns; ++i)
630 if (i == 0)
631 text += " lv2:port [\n";
633 text += " a lv2:InputPort, lv2:CVPort ;\n";
634 text += " lv2:index " + String(portIndex++) + " ;\n";
635 text += " lv2:symbol \"lv2_cv_in_" + String(i+1) + "\" ;\n";
636 text += " lv2:name \"CV Input " + String(i+1) + "\" ;\n";
638 if (i+1 == pluginDesc->cvIns)
639 text += " ] ;\n\n";
640 else
641 text += " ] , [\n";
644 // -------------------------------------------------------------------
645 // CV outputs
647 for (uint32_t i=0; i < pluginDesc->cvOuts; ++i)
649 if (i == 0)
650 text += " lv2:port [\n";
652 text += " a lv2:OutputPort, lv2:CVPort ;\n";
653 text += " lv2:index " + String(portIndex++) + " ;\n";
654 text += " lv2:symbol \"lv2_cv_out_" + String(i+1) + "\" ;\n";
655 text += " lv2:name \"CV Output " + String(i+1) + "\" ;\n";
657 if (i+1 == pluginDesc->cvOuts)
658 text += " ] ;\n\n";
659 else
660 text += " ] , [\n";
663 // -------------------------------------------------------------------
664 // Parameters
666 const uint32_t paramCount = (pluginHandle != nullptr && pluginDesc->get_parameter_count != nullptr)
667 ? pluginDesc->get_parameter_count(pluginHandle)
668 : 0;
669 if (paramCount > 0)
671 CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_info != nullptr,)
672 CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_value != nullptr,)
675 for (uint32_t i=0; i < paramCount; ++i)
677 const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, i));
678 const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
679 const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
681 CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
683 if (i == 0)
684 text += " lv2:port [\n";
686 if (paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT)
687 text += " a lv2:OutputPort, lv2:ControlPort ;\n";
688 else
689 text += " a lv2:InputPort, lv2:ControlPort ;\n";
691 text += " lv2:index " + String(portIndex++) + " ;\n";
692 text += " lv2:symbol \"" + nameToSymbol(paramName, i) + "\" ;\n";
694 if (paramName.isNotEmpty())
695 text += " lv2:name \"" + paramName + "\" ;\n";
696 else
697 text += " lv2:name \"Port " + String(i+1) + "\" ;\n";
699 if ((paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT) == 0)
700 text += " lv2:default " + String::formatted("%f", static_cast<double>(paramInfo->ranges.def)) + " ;\n";
702 text += " lv2:minimum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.min)) + " ;\n";
703 text += " lv2:maximum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.max)) + " ;\n";
705 if ((paramInfo->hints & NATIVE_PARAMETER_IS_AUTOMATABLE) == 0)
706 text += " lv2:portProperty <" LV2_PORT_PROPS__expensive "> ;\n";
707 if (paramInfo->hints & NATIVE_PARAMETER_IS_BOOLEAN)
708 text += " lv2:portProperty lv2:toggled ;\n";
709 if (paramInfo->hints & NATIVE_PARAMETER_IS_INTEGER)
710 text += " lv2:portProperty lv2:integer ;\n";
711 if (paramInfo->hints & NATIVE_PARAMETER_IS_LOGARITHMIC)
712 text += " lv2:portProperty <" LV2_PORT_PROPS__logarithmic "> ;\n";
713 if (paramInfo->hints & NATIVE_PARAMETER_USES_SAMPLE_RATE)
714 text += " lv2:portProperty lv2:toggled ;\n";
715 if (paramInfo->hints & NATIVE_PARAMETER_USES_SCALEPOINTS)
716 text += " lv2:portProperty lv2:enumeration ;\n";
717 if ((paramInfo->hints & NATIVE_PARAMETER_IS_ENABLED) == 0)
718 text += " lv2:portProperty <" LV2_PORT_PROPS__notOnGUI "> ;\n";
720 for (uint32_t j=0; j < paramInfo->scalePointCount; ++j)
722 const NativeParameterScalePoint* const scalePoint(&paramInfo->scalePoints[j]);
724 if (j == 0)
725 text += " lv2:scalePoint [ ";
726 else
727 text += " [ ";
729 text += "rdfs:label \"" + String(scalePoint->label) + "\" ;\n";
730 text += " rdf:value " + String::formatted("%f", static_cast<double>(scalePoint->value)) + " ";
732 if (j+1 == paramInfo->scalePointCount)
733 text += "] ;\n";
734 else
735 text += "] ,\n";
738 if (paramUnit.isNotEmpty())
740 text += " unit:unit [\n";
741 text += " a unit:Unit ;\n";
742 text += " rdfs:label \"" + paramUnit + "\" ;\n";
743 text += " unit:symbol \"" + paramUnit + "\" ;\n";
744 text += " unit:render \"%f " + paramUnit + "\" ;\n";
745 text += " ] ;\n";
748 if (i+1 == paramCount)
749 text += " ] ;\n\n";
750 else
751 text += " ] , [\n";
754 text += " doap:developer [ foaf:name \"" + String(pluginDesc->maker) + "\" ] ;\n";
756 if (std::strcmp(pluginDesc->copyright, "GNU GPL v2+") == 0)
757 text += " doap:license <http://opensource.org/licenses/GPL-2.0> ;\n";
758 if (std::strcmp(pluginDesc->copyright, "LGPL") == 0)
759 text += " doap:license <http://opensource.org/licenses/LGPL-2.0> ;\n";
760 if (std::strcmp(pluginDesc->copyright, "ISC") == 0)
761 text += " doap:license <http://opensource.org/licenses/ISC> ;\n";
763 text += " doap:name \"" + String(pluginDesc->name) + "\" ;\n\n";
765 text += " lv2:microVersion " + String(microVersion) + " ;\n";
766 text += " lv2:minorVersion " + String(minorVersion) + " ;\n";
767 text += " lv2:symbol \"" + CarlaString(pluginDesc->label).toBasic() + "\" .\n";
769 #if 0
770 // -------------------------------------------------------------------
771 // Presets
773 if (pluginDesc->get_midi_program_count != nullptr && pluginDesc->get_midi_program_info != nullptr && pluginHandle != nullptr)
775 if (const uint32_t presetCount = pluginDesc->get_midi_program_count(pluginHandle))
777 const String presetsFile("carla.lv2/" + pluginLabel + "-presets.ttl");
778 std::fstream presetsStream(presetsFile.toRawUTF8(), std::ios::out);
780 String presetId, presetText;
782 presetText += "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
783 presetText += "@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n";
784 presetText += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
786 for (uint32_t i=0; i<presetCount; ++i)
788 const NativeMidiProgram* const midiProg(pluginDesc->get_midi_program_info(pluginHandle, i));
789 pluginDesc->set_midi_program(pluginHandle, 0, midiProg->bank, midiProg->program);
791 presetId = String::formatted("%03i", i+1);
793 text += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
794 text += " a pset:Preset ;\n";
795 text += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
796 text += " rdfs:seeAlso <" + pluginLabel + "-presets.ttl> .\n";
798 presetText += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
799 presetText += " a pset:Preset ;\n";
800 presetText += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
801 presetText += " rdfs:label \"" + String(midiProg->name) + "\" ;\n";
803 for (uint32_t j=0; j < paramCount; ++j)
805 const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, j));
806 const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
807 const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
809 CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
811 if (j == 0)
812 presetText += " lv2:port [\n";
814 presetText += " lv2:symbol \"" + nameToSymbol(paramName, j) + "\" ;\n";
815 presetText += " pset:value " + String::formatted("%f", static_cast<double>(pluginDesc->get_parameter_value(pluginHandle, j))) + " ;\n";
817 if (j+1 == paramCount)
818 presetText += " ] ;\n\n";
819 else
820 presetText += " ] , [\n";
823 presetsStream << presetText.toRawUTF8();
824 presetText.clear();
827 presetsStream.close();
830 #endif
832 // -------------------------------------------------------------------
833 // Write file now
835 std::fstream pluginStream(pluginFile.toRawUTF8(), std::ios::out);
836 pluginStream << text.toRawUTF8();
837 pluginStream.close();
839 // -------------------------------------------------------------------
840 // Cleanup plugin
842 if (pluginHandle != nullptr && pluginDesc->cleanup != nullptr)
843 pluginDesc->cleanup(pluginHandle);
846 // -----------------------------------------------------------------------
848 int main()
850 PluginListManager& plm(PluginListManager::getInstance());
852 const uint32_t majorVersion = (CARLA_VERSION_HEX & 0xFF0000) >> 16;
853 const uint32_t microVersion = (CARLA_VERSION_HEX & 0x00FF00) >> 8;
854 const uint32_t minorVersion = (CARLA_VERSION_HEX & 0x0000FF) >> 0;
856 const uint32_t lv2MicroVersion = majorVersion * 10 + microVersion;
858 writeManifestFile(plm, lv2MicroVersion, minorVersion);
860 for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
862 const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
863 CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
865 writePluginFile(pluginDesc, lv2MicroVersion, minorVersion);
868 carla_stdout("Done.");
870 return 0;
873 // -----------------------------------------------------------------------