cmake: Install host-plugin/native-plugin/standalone pkgconfig files
[carla.git] / source / plugin / carla-lv2-export.cpp
blobb64df5482926fa71c6d87e806a7f0be8d0d51dec
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 lv2: <" LV2_CORE_PREFIX "> .\n";
122 text += "@prefix mod: <http://moddevices.com/ns/mod#> .\n";
123 text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
124 text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
125 text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
126 text += "\n";
128 // -------------------------------------------------------------------
129 // Project
131 text += "<https://kx.studio/carla>\n";
132 text += " a lv2:Project ;\n";
133 text += " doap:homepage <https://kx.studio/carla> ;\n";
134 text += " doap:maintainer [\n";
135 text += " foaf:homepage <https://falktx.com/> ;\n";
136 text += " foaf:mbox <mailto:falktx@falktx.com> ;\n";
137 text += " foaf:name \"Filipe Coelho\" ;\n";
138 text += " ] ;\n";
139 text += " doap:name \"Carla\" ;\n";
140 text += " doap:shortdesc \"fully-featured audio plugin host.\" ;\n";
141 text += " lv2:microVersion " + String(microVersion) + " ;\n";
142 text += " lv2:minorVersion " + String(minorVersion) + " ;\n";
143 text += " lv2:symbol \"carla\" .\n";
144 text += "\n";
146 // -------------------------------------------------------------------
147 // Plugins
149 for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
151 const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
152 CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
154 const String label(pluginDesc->label);
156 text += "<http://kxstudio.sf.net/carla/plugins/" + label + ">\n";
157 text += " a lv2:Plugin ;\n";
158 text += " lv2:binary <carla" PLUGIN_EXT "> ;\n";
159 text += " lv2:project <https://kx.studio/carla> ;\n";
160 text += " rdfs:seeAlso <" + label + ".ttl> .\n";
161 text += "\n";
164 // -------------------------------------------------------------------
165 // UI
167 #ifdef HAVE_PYQT
168 text += "<http://kxstudio.sf.net/carla/ui-ext>\n";
169 text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
170 text += " ui:binary <carla" PLUGIN_EXT "> ;\n";
171 text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
172 text += " <" LV2_UI__showInterface "> ,\n";
173 text += " <" LV2_PROGRAMS__UIInterface "> ;\n";
174 text += " lv2:optionalFeature <" LV2_UI__idleInterface "> ;\n";
175 text += " lv2:requiredFeature <" LV2_INSTANCE_ACCESS_URI "> ;\n";
176 text += " opts:supportedOption <" LV2_PARAMETERS__sampleRate "> .\n";
177 text += "\n";
179 # if 0
180 text += "<http://kxstudio.sf.net/carla/ui-bridge-ext>\n";
181 text += " a <" LV2_EXTERNAL_UI__Widget "> ;\n";
182 text += " ui:binary <carla-ui" PLUGIN_EXT "> ;\n";
183 text += " lv2:extensionData <" LV2_UI__idleInterface "> ,\n";
184 text += " <" LV2_UI__showInterface "> ,\n";
185 text += " <" LV2_PROGRAMS__UIInterface "> .\n";
186 # endif
187 #endif
189 // -------------------------------------------------------------------
190 // File handling
192 text += "<http://kxstudio.sf.net/carla/file>\n";
193 text += " a lv2:Parameter ;\n";
194 text += " rdfs:label \"file\" ;\n";
195 text += " rdfs:range atom:Path .\n";
196 text += "\n";
198 text += "<http://kxstudio.sf.net/carla/file/audio>\n";
199 text += " a lv2:Parameter ;\n";
200 text += " mod:fileTypes \"audioloop,audiorecording,audiotrack\" ;\n";
201 text += " rdfs:label \"audio file\" ;\n";
202 text += " rdfs:range atom:Path .\n";
203 text += "\n";
205 text += "<http://kxstudio.sf.net/carla/file/midi>\n";
206 text += " a lv2:Parameter ;\n";
207 text += " mod:fileTypes \"midisong\" ;\n";
208 text += " rdfs:label \"midi file\" ;\n";
209 text += " rdfs:range atom:Path .\n";
210 text += "\n";
212 // -------------------------------------------------------------------
213 // Write file now
215 std::fstream manifest("carla.lv2/manifest.ttl", std::ios::out);
216 manifest << text.toRawUTF8();
217 manifest.close();
220 // -----------------------------------------------------------------------
222 static uint32_t host_getBufferSize(NativeHostHandle) { return 512; }
223 static double host_getSampleRate(NativeHostHandle) { return 44100.0; }
224 static bool host_isOffline(NativeHostHandle) { return true; }
225 static intptr_t host_dispatcher(NativeHostHandle, NativeHostDispatcherOpcode, int32_t, intptr_t, void*, float) { return 0; }
227 static void writePluginFile(const NativePluginDescriptor* const pluginDesc,
228 const uint32_t microVersion, const uint32_t minorVersion)
230 const String pluginLabel(pluginDesc->label);
231 const String pluginFile("carla.lv2/" + pluginLabel + ".ttl");
233 uint32_t portIndex = 0;
234 String text;
236 gUsedSymbols.clear();
238 carla_stdout("Generating data for %s...", pluginDesc->name);
240 // -------------------------------------------------------------------
241 // Init plugin
243 NativeHostDescriptor hostDesc;
244 hostDesc.handle = nullptr;
245 hostDesc.resourceDir = "";
246 hostDesc.uiName = "";
247 hostDesc.get_buffer_size = host_getBufferSize;
248 hostDesc.get_sample_rate = host_getSampleRate;
249 hostDesc.is_offline = host_isOffline;
250 hostDesc.get_time_info = nullptr;
251 hostDesc.write_midi_event = nullptr;
252 hostDesc.ui_parameter_changed = nullptr;
253 hostDesc.ui_midi_program_changed = nullptr;
254 hostDesc.ui_custom_data_changed = nullptr;
255 hostDesc.ui_closed = nullptr;
256 hostDesc.ui_open_file = nullptr;
257 hostDesc.ui_save_file = nullptr;
258 hostDesc.dispatcher = host_dispatcher;
260 NativePluginHandle pluginHandle = nullptr;
262 if (! pluginLabel.startsWithIgnoreCase("carla"))
264 pluginHandle = pluginDesc->instantiate(&hostDesc);
265 CARLA_SAFE_ASSERT_RETURN(pluginHandle != nullptr,)
268 // -------------------------------------------------------------------
269 // Header
271 text += "@prefix atom: <" LV2_ATOM_PREFIX "> .\n";
272 text += "@prefix doap: <http://usefulinc.com/ns/doap#> .\n";
273 text += "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n";
274 text += "@prefix lv2: <" LV2_CORE_PREFIX "> .\n";
275 text += "@prefix opts: <" LV2_OPTIONS_PREFIX "> .\n";
276 text += "@prefix patch: <" LV2_PATCH_PREFIX "> .\n";
277 text += "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n";
278 text += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
279 text += "@prefix ui: <" LV2_UI_PREFIX "> .\n";
280 text += "@prefix unit: <" LV2_UNITS_PREFIX "> .\n";
281 text += "\n";
283 // -------------------------------------------------------------------
284 // Plugin URI
286 text += "<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + ">\n";
288 // -------------------------------------------------------------------
289 // Category
291 switch (pluginDesc->category)
293 case NATIVE_PLUGIN_CATEGORY_SYNTH:
294 text += " a lv2:InstrumentPlugin, lv2:Plugin ;\n";
295 break;
296 case NATIVE_PLUGIN_CATEGORY_DELAY:
297 text += " a lv2:DelayPlugin, lv2:Plugin ;\n";
298 break;
299 case NATIVE_PLUGIN_CATEGORY_EQ:
300 text += " a lv2:EQPlugin, lv2:Plugin ;\n";
301 break;
302 case NATIVE_PLUGIN_CATEGORY_FILTER:
303 text += " a lv2:FilterPlugin, lv2:Plugin ;\n";
304 break;
305 case NATIVE_PLUGIN_CATEGORY_DYNAMICS:
306 text += " a lv2:DynamicsPlugin, lv2:Plugin ;\n";
307 break;
308 case NATIVE_PLUGIN_CATEGORY_MODULATOR:
309 text += " a lv2:ModulatorPlugin, lv2:Plugin ;\n";
310 break;
311 case NATIVE_PLUGIN_CATEGORY_UTILITY:
312 text += " a lv2:UtilityPlugin, lv2:Plugin ;\n";
313 break;
314 default:
315 text += " a lv2:Plugin ;\n";
316 break;
319 text += "\n";
321 // -------------------------------------------------------------------
322 // Features
324 // optional
325 if (pluginDesc->hints & NATIVE_PLUGIN_IS_RTSAFE)
326 text += " lv2:optionalFeature <" LV2_CORE__hardRTCapable "> ;\n";
327 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
328 text += " lv2:optionalFeature <" LV2_INLINEDISPLAY__queue_draw "> ;\n";
329 if ((pluginDesc->hints & NATIVE_PLUGIN_USES_STATE) || (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE))
330 text += " lv2:optionalFeature <" LV2_STATE__threadSafeRestore "> ;\n";
331 text += "\n";
333 // required
334 text += " lv2:requiredFeature <" LV2_BUF_SIZE__boundedBlockLength "> ,\n";
336 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
337 text += " <" LV2_BUF_SIZE__fixedBlockLength "> ,\n";
339 if (pluginDesc->hints & NATIVE_PLUGIN_REQUESTS_IDLE)
340 text += " <" LV2_WORKER__schedule "> ,\n";
342 text += " <" LV2_OPTIONS__options "> ,\n";
343 text += " <" LV2_URID__map "> ;\n";
344 text += "\n";
346 // -------------------------------------------------------------------
347 // Extensions
349 text += " lv2:extensionData <" LV2_OPTIONS__interface "> ;\n";
351 if ((pluginDesc->hints & NATIVE_PLUGIN_USES_STATE) || (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE))
352 text += " lv2:extensionData <" LV2_STATE__interface "> ;\n";
354 if (pluginDesc->category != NATIVE_PLUGIN_CATEGORY_SYNTH)
355 text += " lv2:extensionData <" LV2_PROGRAMS__Interface "> ;\n";
357 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
358 text += " lv2:extensionData <" LV2_WORKER__interface "> ;\n";
360 if (pluginDesc->hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
361 text += " lv2:extensionData <" LV2_INLINEDISPLAY__interface "> ;\n";
363 text += "\n";
365 // -------------------------------------------------------------------
366 // Options
368 text += " opts:supportedOption <" LV2_BUF_SIZE__nominalBlockLength "> ,\n";
369 text += " <" LV2_BUF_SIZE__maxBlockLength "> ,\n";
370 text += " <" LV2_PARAMETERS__sampleRate "> ;\n";
371 text += "\n";
373 // -------------------------------------------------------------------
374 // UIs
376 #ifdef HAVE_PYQT
377 if ((pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0 && (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE) == 0)
379 text += " ui:ui <http://kxstudio.sf.net/carla/ui-ext> ;\n";
380 text += "\n";
382 #endif
384 // -------------------------------------------------------------------
385 // First input MIDI/Time/UI port
387 const bool hasEventInPort = (pluginDesc->hints & NATIVE_PLUGIN_USES_TIME) != 0
388 || (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
390 if (pluginDesc->midiIns > 0 || hasEventInPort)
392 text += " lv2:port [\n";
393 text += " a lv2:InputPort, atom:AtomPort ;\n";
394 text += " atom:bufferType atom:Sequence ;\n";
396 if (pluginDesc->midiIns > 0 && hasEventInPort)
398 text += " atom:supports <" LV2_MIDI__MidiEvent "> ,\n";
399 text += " <" LV2_TIME__Position "> ;\n";
401 else if (pluginDesc->midiIns > 0)
403 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
405 else
407 text += " atom:supports <" LV2_TIME__Position "> ;\n";
409 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
410 text += " atom:supports <" LV2_PATCH__Message "> ;\n";
412 text += " lv2:designation lv2:control ;\n";
413 text += " lv2:index " + String(portIndex++) + " ;\n";
415 if (hasEventInPort)
417 if (pluginDesc->midiIns > 1)
419 text += " lv2:symbol \"lv2_events_in_1\" ;\n";
420 text += " lv2:name \"Events Input #1\" ;\n";
422 else
424 text += " lv2:symbol \"lv2_events_in\" ;\n";
425 text += " lv2:name \"Events Input\" ;\n";
428 else
430 if (pluginDesc->midiIns > 1)
432 text += " lv2:symbol \"lv2_midi_in_1\" ;\n";
433 text += " lv2:name \"MIDI Input #1\" ;\n";
435 else
437 text += " lv2:symbol \"lv2_midi_in\" ;\n";
438 text += " lv2:name \"MIDI Input\" ;\n";
442 text += " ] ;\n\n";
445 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
447 /**/ if (pluginLabel == "audiofile")
448 text += " patch:writable <http://kxstudio.sf.net/carla/file/audio> ;\n\n";
449 else if (pluginLabel == "midifile")
450 text += " patch:writable <http://kxstudio.sf.net/carla/file/midi> ;\n\n";
451 else
452 text += " patch:writable <http://kxstudio.sf.net/carla/file> ;\n\n";
455 // -------------------------------------------------------------------
456 // MIDI inputs
458 for (uint32_t i=1; i < pluginDesc->midiIns; ++i)
460 if (i == 1)
461 text += " lv2:port [\n";
463 text += " a lv2:InputPort, atom:AtomPort ;\n";
464 text += " atom:bufferType atom:Sequence ;\n";
465 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
466 text += " lv2:index " + String(portIndex++) + " ;\n";
467 text += " lv2:symbol \"lv2_midi_in_" + String(i+1) + "\" ;\n";
468 text += " lv2:name \"MIDI Input #" + String(i+1) + "\" ;\n";
470 if (i+1 == pluginDesc->midiIns)
471 text += " ] ;\n\n";
472 else
473 text += " ] , [\n";
476 // -------------------------------------------------------------------
477 // First output MIDI/UI port
479 const bool hasEventOutPort = (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI) != 0;
481 if (pluginDesc->midiIns > 0 || hasEventOutPort)
483 text += " lv2:port [\n";
484 text += " a lv2:OutputPort, atom:AtomPort ;\n";
485 text += " atom:bufferType atom:Sequence ;\n";
487 if (pluginDesc->midiOuts > 0)
488 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
489 if (pluginDesc->hints & NATIVE_PLUGIN_NEEDS_UI_OPEN_SAVE)
490 text += " atom:supports <" LV2_PATCH__Message "> ;\n";
492 text += " lv2:index " + String(portIndex++) + " ;\n";
494 if (hasEventOutPort)
496 if (pluginDesc->midiOuts > 1)
498 text += " lv2:symbol \"lv2_events_out_1\" ;\n";
499 text += " lv2:name \"Events Input #1\" ;\n";
501 else
503 text += " lv2:symbol \"lv2_events_out\" ;\n";
504 text += " lv2:name \"Events Output\" ;\n";
507 else
509 if (pluginDesc->midiOuts > 1)
511 text += " lv2:symbol \"lv2_midi_out_1\" ;\n";
512 text += " lv2:name \"MIDI Output #1\" ;\n";
514 else
516 text += " lv2:symbol \"lv2_midi_out\" ;\n";
517 text += " lv2:name \"MIDI Output\" ;\n";
521 text += " ] ;\n\n";
524 // -------------------------------------------------------------------
525 // MIDI outputs
527 for (uint32_t i=1; i < pluginDesc->midiOuts; ++i)
529 if (i == 1)
530 text += " lv2:port [\n";
532 text += " a lv2:OutputPort, atom:AtomPort ;\n";
533 text += " atom:bufferType atom:Sequence ;\n";
534 text += " atom:supports <" LV2_MIDI__MidiEvent "> ;\n";
535 text += " lv2:index " + String(portIndex++) + " ;\n";
537 if (pluginDesc->midiOuts > 1)
539 text += " lv2:symbol \"lv2_midi_out_" + String(i+1) + "\" ;\n";
540 text += " lv2:name \"MIDI Output #" + String(i+1) + "\" ;\n";
542 else
544 text += " lv2:symbol \"lv2_midi_out\" ;\n";
545 text += " lv2:name \"MIDI Output\" ;\n";
548 if (i+1 == pluginDesc->midiOuts)
549 text += " ] ;\n\n";
550 else
551 text += " ] , [\n";
554 // -------------------------------------------------------------------
555 // Freewheel port
557 text += " lv2:port [\n";
558 text += " a lv2:InputPort, lv2:ControlPort ;\n";
559 text += " lv2:index " + String(portIndex++) + " ;\n";
560 text += " lv2:symbol \"lv2_freewheel\" ;\n";
561 text += " lv2:name \"Freewheel\" ;\n";
562 text += " lv2:default 0.0 ;\n";
563 text += " lv2:minimum 0.0 ;\n";
564 text += " lv2:maximum 1.0 ;\n";
565 text += " lv2:designation <" LV2_CORE__freeWheeling "> ;\n";
566 text += " lv2:portProperty lv2:toggled, <" LV2_PORT_PROPS__notOnGUI "> ;\n";
567 text += " ] ;\n";
568 text += "\n";
570 // -------------------------------------------------------------------
571 // Audio inputs
573 for (uint32_t i=0; i < pluginDesc->audioIns; ++i)
575 if (i == 0)
576 text += " lv2:port [\n";
578 text += " a lv2:InputPort, lv2:AudioPort ;\n";
579 text += " lv2:index " + String(portIndex++) + " ;\n";
580 text += " lv2:symbol \"lv2_audio_in_" + String(i+1) + "\" ;\n";
581 text += " lv2:name \"Audio Input " + String(i+1) + "\" ;\n";
583 if (i+1 == pluginDesc->audioIns)
584 text += " ] ;\n\n";
585 else
586 text += " ] , [\n";
589 // -------------------------------------------------------------------
590 // Audio outputs
592 for (uint32_t i=0; i < pluginDesc->audioOuts; ++i)
594 if (i == 0)
595 text += " lv2:port [\n";
597 text += " a lv2:OutputPort, lv2:AudioPort ;\n";
598 text += " lv2:index " + String(portIndex++) + " ;\n";
599 text += " lv2:symbol \"lv2_audio_out_" + String(i+1) + "\" ;\n";
600 text += " lv2:name \"Audio Output " + String(i+1) + "\" ;\n";
602 if (i+1 == pluginDesc->audioOuts)
603 text += " ] ;\n\n";
604 else
605 text += " ] , [\n";
608 // -------------------------------------------------------------------
609 // CV inputs
611 for (uint32_t i=0; i < pluginDesc->cvIns; ++i)
613 if (i == 0)
614 text += " lv2:port [\n";
616 text += " a lv2:InputPort, lv2:CVPort ;\n";
617 text += " lv2:index " + String(portIndex++) + " ;\n";
618 text += " lv2:symbol \"lv2_cv_in_" + String(i+1) + "\" ;\n";
619 text += " lv2:name \"CV Input " + String(i+1) + "\" ;\n";
621 if (i+1 == pluginDesc->cvIns)
622 text += " ] ;\n\n";
623 else
624 text += " ] , [\n";
627 // -------------------------------------------------------------------
628 // CV outputs
630 for (uint32_t i=0; i < pluginDesc->cvOuts; ++i)
632 if (i == 0)
633 text += " lv2:port [\n";
635 text += " a lv2:OutputPort, lv2:CVPort ;\n";
636 text += " lv2:index " + String(portIndex++) + " ;\n";
637 text += " lv2:symbol \"lv2_cv_out_" + String(i+1) + "\" ;\n";
638 text += " lv2:name \"CV Output " + String(i+1) + "\" ;\n";
640 if (i+1 == pluginDesc->cvOuts)
641 text += " ] ;\n\n";
642 else
643 text += " ] , [\n";
646 // -------------------------------------------------------------------
647 // Parameters
649 const uint32_t paramCount = (pluginHandle != nullptr && pluginDesc->get_parameter_count != nullptr)
650 ? pluginDesc->get_parameter_count(pluginHandle)
651 : 0;
652 if (paramCount > 0)
654 CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_info != nullptr,)
655 CARLA_SAFE_ASSERT_RETURN(pluginDesc->get_parameter_value != nullptr,)
658 for (uint32_t i=0; i < paramCount; ++i)
660 const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, i));
661 const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
662 const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
664 CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
666 if (i == 0)
667 text += " lv2:port [\n";
669 if (paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT)
670 text += " a lv2:OutputPort, lv2:ControlPort ;\n";
671 else
672 text += " a lv2:InputPort, lv2:ControlPort ;\n";
674 text += " lv2:index " + String(portIndex++) + " ;\n";
675 text += " lv2:symbol \"" + nameToSymbol(paramName, i) + "\" ;\n";
677 if (paramName.isNotEmpty())
678 text += " lv2:name \"" + paramName + "\" ;\n";
679 else
680 text += " lv2:name \"Port " + String(i+1) + "\" ;\n";
682 if ((paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT) == 0)
683 text += " lv2:default " + String::formatted("%f", static_cast<double>(paramInfo->ranges.def)) + " ;\n";
685 text += " lv2:minimum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.min)) + " ;\n";
686 text += " lv2:maximum " + String::formatted("%f", static_cast<double>(paramInfo->ranges.max)) + " ;\n";
688 if ((paramInfo->hints & NATIVE_PARAMETER_IS_AUTOMATABLE) == 0)
689 text += " lv2:portProperty <" LV2_PORT_PROPS__expensive "> ;\n";
690 if (paramInfo->hints & NATIVE_PARAMETER_IS_BOOLEAN)
691 text += " lv2:portProperty lv2:toggled ;\n";
692 if (paramInfo->hints & NATIVE_PARAMETER_IS_INTEGER)
693 text += " lv2:portProperty lv2:integer ;\n";
694 if (paramInfo->hints & NATIVE_PARAMETER_IS_LOGARITHMIC)
695 text += " lv2:portProperty <" LV2_PORT_PROPS__logarithmic "> ;\n";
696 if (paramInfo->hints & NATIVE_PARAMETER_USES_SAMPLE_RATE)
697 text += " lv2:portProperty lv2:toggled ;\n";
698 if (paramInfo->hints & NATIVE_PARAMETER_USES_SCALEPOINTS)
699 text += " lv2:portProperty lv2:enumeration ;\n";
700 if ((paramInfo->hints & NATIVE_PARAMETER_IS_ENABLED) == 0)
701 text += " lv2:portProperty <" LV2_PORT_PROPS__notOnGUI "> ;\n";
703 for (uint32_t j=0; j < paramInfo->scalePointCount; ++j)
705 const NativeParameterScalePoint* const scalePoint(&paramInfo->scalePoints[j]);
707 if (j == 0)
708 text += " lv2:scalePoint [ ";
709 else
710 text += " [ ";
712 text += "rdfs:label \"" + String(scalePoint->label) + "\" ;\n";
713 text += " rdf:value " + String::formatted("%f", static_cast<double>(scalePoint->value)) + " ";
715 if (j+1 == paramInfo->scalePointCount)
716 text += "] ;\n";
717 else
718 text += "] ,\n";
721 if (paramUnit.isNotEmpty())
723 text += " unit:unit [\n";
724 text += " a unit:Unit ;\n";
725 text += " rdfs:label \"" + paramUnit + "\" ;\n";
726 text += " unit:symbol \"" + paramUnit + "\" ;\n";
727 text += " unit:render \"%f " + paramUnit + "\" ;\n";
728 text += " ] ;\n";
731 if (i+1 == paramCount)
732 text += " ] ;\n\n";
733 else
734 text += " ] , [\n";
737 text += " doap:developer [ foaf:name \"" + String(pluginDesc->maker) + "\" ] ;\n";
739 if (std::strcmp(pluginDesc->copyright, "GNU GPL v2+") == 0)
740 text += " doap:license <http://opensource.org/licenses/GPL-2.0> ;\n";
741 if (std::strcmp(pluginDesc->copyright, "LGPL") == 0)
742 text += " doap:license <http://opensource.org/licenses/LGPL-2.0> ;\n";
743 if (std::strcmp(pluginDesc->copyright, "ISC") == 0)
744 text += " doap:license <http://opensource.org/licenses/ISC> ;\n";
746 text += " doap:name \"" + String(pluginDesc->name) + "\" ;\n\n";
748 text += " lv2:microVersion " + String(microVersion) + " ;\n";
749 text += " lv2:minorVersion " + String(minorVersion) + " ;\n";
750 text += " lv2:symbol \"" + CarlaString(pluginDesc->label).toBasic() + "\" .\n";
752 #if 0
753 // -------------------------------------------------------------------
754 // Presets
756 if (pluginDesc->get_midi_program_count != nullptr && pluginDesc->get_midi_program_info != nullptr && pluginHandle != nullptr)
758 if (const uint32_t presetCount = pluginDesc->get_midi_program_count(pluginHandle))
760 const String presetsFile("carla.lv2/" + pluginLabel + "-presets.ttl");
761 std::fstream presetsStream(presetsFile.toRawUTF8(), std::ios::out);
763 String presetId, presetText;
765 presetText += "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n";
766 presetText += "@prefix pset: <http://lv2plug.in/ns/ext/presets#> .\n";
767 presetText += "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n";
769 for (uint32_t i=0; i<presetCount; ++i)
771 const NativeMidiProgram* const midiProg(pluginDesc->get_midi_program_info(pluginHandle, i));
772 pluginDesc->set_midi_program(pluginHandle, 0, midiProg->bank, midiProg->program);
774 presetId = String::formatted("%03i", i+1);
776 text += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
777 text += " a pset:Preset ;\n";
778 text += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
779 text += " rdfs:seeAlso <" + pluginLabel + "-presets.ttl> .\n";
781 presetText += "\n<http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "#preset" + presetId + ">\n";
782 presetText += " a pset:Preset ;\n";
783 presetText += " lv2:appliesTo <http://kxstudio.sf.net/carla/plugins/" + pluginLabel + "> ;\n";
784 presetText += " rdfs:label \"" + String(midiProg->name) + "\" ;\n";
786 for (uint32_t j=0; j < paramCount; ++j)
788 const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, j));
789 const String paramName(paramInfo->name != nullptr ? paramInfo->name : "");
790 const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : "");
792 CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,)
794 if (j == 0)
795 presetText += " lv2:port [\n";
797 presetText += " lv2:symbol \"" + nameToSymbol(paramName, j) + "\" ;\n";
798 presetText += " pset:value " + String::formatted("%f", static_cast<double>(pluginDesc->get_parameter_value(pluginHandle, j))) + " ;\n";
800 if (j+1 == paramCount)
801 presetText += " ] ;\n\n";
802 else
803 presetText += " ] , [\n";
806 presetsStream << presetText.toRawUTF8();
807 presetText.clear();
810 presetsStream.close();
813 #endif
815 // -------------------------------------------------------------------
816 // Write file now
818 std::fstream pluginStream(pluginFile.toRawUTF8(), std::ios::out);
819 pluginStream << text.toRawUTF8();
820 pluginStream.close();
822 // -------------------------------------------------------------------
823 // Cleanup plugin
825 if (pluginHandle != nullptr && pluginDesc->cleanup != nullptr)
826 pluginDesc->cleanup(pluginHandle);
829 // -----------------------------------------------------------------------
831 int main()
833 PluginListManager& plm(PluginListManager::getInstance());
835 const uint32_t majorVersion = (CARLA_VERSION_HEX & 0xFF0000) >> 16;
836 const uint32_t microVersion = (CARLA_VERSION_HEX & 0x00FF00) >> 8;
837 const uint32_t minorVersion = (CARLA_VERSION_HEX & 0x0000FF) >> 0;
839 const uint32_t lv2MicroVersion = majorVersion * 10 + microVersion;
841 writeManifestFile(plm, lv2MicroVersion, minorVersion);
843 for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
845 const NativePluginDescriptor* const& pluginDesc(it.getValue(nullptr));
846 CARLA_SAFE_ASSERT_CONTINUE(pluginDesc != nullptr);
848 writePluginFile(pluginDesc, lv2MicroVersion, minorVersion);
851 carla_stdout("Done.");
853 return 0;
856 // -----------------------------------------------------------------------