naspro
view naspro-core/src/manifest.c @ 169:54b611b34083
Removed useless NDF bridge + a little fix in NASPRO core
| author | Stefano D'Angelo <zanga.mail@gmail.com> |
|---|---|
| date | Thu Mar 11 05:47:49 2010 +0200 (2010-03-11) |
| parents | d7568c8379c1 |
| children | d1f0d4a83318 |
line source
1 /*
2 * NASPRO - NASPRO Architecture for Sound Processing
3 * Core library
4 *
5 * Copyright (C) 2007-2009 Stefano D'Angelo <zanga.mail@gmail.com>
6 *
7 * See the COPYING file for license conditions.
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
14 #include <locale.h>
16 #include <NASPRO/core/lib.h>
18 /* TODO: setlocale + multi-threading = ouch! */
20 void
21 nacore_manifest_print_subject_prefixes(FILE *fp)
22 {
23 fprintf(fp, "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n");
24 }
26 void
27 nacore_manifest_print_subject_triple(struct nacore_descriptor *desc, FILE *fp)
28 {
29 fprintf(fp, "<%s> a lv2:Plugin .\n", desc->uri);
30 }
32 static void
33 print_escaped_string(FILE *fp, const char *string)
34 {
35 size_t i, len;
37 len = strlen(string);
38 for (i = 0; i < len; i++)
39 {
40 switch (string[i])
41 {
42 case '\t':
43 fputs("\\t", fp);
44 break;
45 case '\r':
46 fputs("\\r", fp);
47 break;
48 case '\n':
49 fputs("\\n", fp);
50 break;
51 case '"':
52 fputs("\\\"", fp);
53 break;
54 case '\\':
55 fputs("\\\\", fp);
56 break;
57 /* TODO: unicode escapes, see
58 * http://www.dajobe.org/2004/01/turtle/#sec-strings */
59 default:
60 fputc(string[i], fp);
61 break;
62 }
63 }
64 }
66 #define PRINT_C1(na_class, string) \
67 if (desc->classes_1 & na_class) \
68 fprintf(fp, "\ta " string " ;\n");
70 #define PRINT_C2(na_class, string) \
71 if (desc->classes_2 & na_class) \
72 fprintf(fp, "\ta " string " ;\n");
74 static void
75 print_classes(FILE *fp, struct nacore_descriptor *desc)
76 {
77 PRINT_C1(NACORE_DESCRIPTOR_CLASS_GENERATOR, "lv2:GeneratorPlugin");
78 PRINT_C1(NACORE_DESCRIPTOR_CLASS_INSTRUMENT, "lv2:InstrumentPlugin");
79 PRINT_C1(NACORE_DESCRIPTOR_CLASS_OSCILLATOR, "lv2:OscillatorPlugin");
80 PRINT_C1(NACORE_DESCRIPTOR_CLASS_UTILITY, "lv2:UtilityPlugin");
81 PRINT_C1(NACORE_DESCRIPTOR_CLASS_CONVERTER, "lv2:ConverterPlugin");
82 PRINT_C1(NACORE_DESCRIPTOR_CLASS_ANALYSER, "lv2:AnalyserPlugin");
83 PRINT_C1(NACORE_DESCRIPTOR_CLASS_MIXER, "lv2:MixerPlugin");
84 PRINT_C1(NACORE_DESCRIPTOR_CLASS_SIMULATOR, "lv2:SimulatorPlugin");
85 PRINT_C1(NACORE_DESCRIPTOR_CLASS_DELAY, "lv2:DelayPlugin");
86 PRINT_C1(NACORE_DESCRIPTOR_CLASS_MODULATOR, "lv2:ModulatorPlugin");
87 PRINT_C1(NACORE_DESCRIPTOR_CLASS_REVERB, "lv2:ReverbPlugin");
88 PRINT_C1(NACORE_DESCRIPTOR_CLASS_PHASER, "lv2:PhaserPlugin");
89 PRINT_C1(NACORE_DESCRIPTOR_CLASS_FLANGER, "lv2:FlangerPlugin");
90 PRINT_C1(NACORE_DESCRIPTOR_CLASS_CHORUS, "lv2:ChorusPlugin");
91 PRINT_C1(NACORE_DESCRIPTOR_CLASS_FILTER, "lv2:FilterPlugin");
92 PRINT_C1(NACORE_DESCRIPTOR_CLASS_LOWPASS, "lv2:LowpassPlugin");
93 PRINT_C1(NACORE_DESCRIPTOR_CLASS_BANDPASS, "lv2:BandpassPlugin");
94 PRINT_C1(NACORE_DESCRIPTOR_CLASS_HIGHPASS, "lv2:HighpassPlugin");
95 PRINT_C1(NACORE_DESCRIPTOR_CLASS_COMB, "lv2:CombPlugin");
96 PRINT_C1(NACORE_DESCRIPTOR_CLASS_ALLPASS, "lv2:AllpassPlugin");
97 PRINT_C1(NACORE_DESCRIPTOR_CLASS_EQ, "lv2:EQPlugin");
98 PRINT_C1(NACORE_DESCRIPTOR_CLASS_PARAEQ, "lv2:ParaEQPlugin");
99 PRINT_C1(NACORE_DESCRIPTOR_CLASS_MULTIEQ, "lv2:MultiEQPlugin");
100 PRINT_C1(NACORE_DESCRIPTOR_CLASS_SPECTRAL, "lv2:SpectralPlugin");
101 PRINT_C1(NACORE_DESCRIPTOR_CLASS_PITCH, "lv2:PitchPlugin");
102 PRINT_C1(NACORE_DESCRIPTOR_CLASS_AMPLIFIER, "lv2:AmplifierPlugin");
103 PRINT_C1(NACORE_DESCRIPTOR_CLASS_DISTORTION, "lv2:DistortionPlugin");
104 PRINT_C1(NACORE_DESCRIPTOR_CLASS_WAVESHAPER, "lv2:WaveshaperPlugin");
105 PRINT_C2(NACORE_DESCRIPTOR_CLASS_DYNAMICS, "lv2:DynamicsPlugin");
106 PRINT_C2(NACORE_DESCRIPTOR_CLASS_COMPRESSOR, "lv2:CompressorPlugin");
107 PRINT_C2(NACORE_DESCRIPTOR_CLASS_EXPANDER, "lv2:ExpanderPlugin");
108 PRINT_C2(NACORE_DESCRIPTOR_CLASS_LIMITER, "lv2:LimiterPlugin");
109 PRINT_C2(NACORE_DESCRIPTOR_CLASS_GATE, "lv2:GatePlugin");
110 }
112 #define PRINT_UNIT(na_unit, lv2_unit) \
113 case na_unit: \
114 fprintf(fp, "\t\tlv2units:unit " lv2_unit " ;\n"); \
115 break;
117 static void
118 print_scale_units(FILE *fp, struct nacore_descriptor *desc, size_t index)
119 {
120 switch (desc->port_descs[index].scale.unit)
121 {
122 PRINT_UNIT(nacore_scale_unit_bar, "lv2units:bar");
123 PRINT_UNIT(nacore_scale_unit_beat, "lv2units:beat");
124 PRINT_UNIT(nacore_scale_unit_bpm, "lv2units:bpm");
125 PRINT_UNIT(nacore_scale_unit_cent, "lv2units:cent");
126 PRINT_UNIT(nacore_scale_unit_cm, "lv2units:cm");
127 PRINT_UNIT(nacore_scale_unit_coeff, "lv2units:coef");
128 PRINT_UNIT(nacore_scale_unit_db, "lv2units:db");
129 PRINT_UNIT(nacore_scale_unit_deg, "lv2units:degree");
130 PRINT_UNIT(nacore_scale_unit_hz, "lv2units:hz");
131 PRINT_UNIT(nacore_scale_unit_inch, "lv2units:inch");
132 PRINT_UNIT(nacore_scale_unit_khz, "lv2units:khz");
133 PRINT_UNIT(nacore_scale_unit_km, "lv2units:km");
134 PRINT_UNIT(nacore_scale_unit_m, "lv2units:m");
135 PRINT_UNIT(nacore_scale_unit_mhz, "lv2units:mhz");
136 PRINT_UNIT(nacore_scale_unit_midi_note, "lv2units:midiNote");
137 PRINT_UNIT(nacore_scale_unit_mi, "lv2units:mile");
138 PRINT_UNIT(nacore_scale_unit_min, "lv2units:min");
139 PRINT_UNIT(nacore_scale_unit_mm, "lv2units:mm");
140 PRINT_UNIT(nacore_scale_unit_ms, "lv2units:ms");
141 PRINT_UNIT(nacore_scale_unit_oct, "lv2units:oct");
142 PRINT_UNIT(nacore_scale_unit_pc, "lv2units:pc");
143 PRINT_UNIT(nacore_scale_unit_s, "lv2units:s");
144 PRINT_UNIT(nacore_scale_unit_semitone,
145 "lv2units:semitone12TET");
146 default:
147 break;
148 }
149 }
151 static void
152 print_scale_points(FILE *fp, struct nacore_descriptor *desc, size_t index)
153 {
154 size_t i;
156 if (desc->port_descs[index].scale.points_count == 0)
157 return;
159 for (i = 0; i < desc->port_descs[index].scale.points_count; i++)
160 {
161 fprintf(fp, "\t\tlv2:scalePoint [ rdfs:label \"");
162 print_escaped_string(fp,
163 desc->port_descs[index].scale.points[i].label);
164 fprintf(fp, "\"; rdf:value %f ] ;\n",
165 desc->port_descs[index].scale.points[i].value);
166 }
167 }
169 void
170 nacore_manifest_print_data(struct nacore_descriptor *desc, FILE *fp,
171 const char *binary)
172 {
173 struct nacore_port_descriptor *port_desc;
174 char *prev_locale;
175 size_t i;
177 prev_locale = setlocale(LC_NUMERIC, NULL);
178 setlocale(LC_NUMERIC, "C");
180 fprintf(fp, "@prefix rdf: <http://www.w3.org/1999/02/"
181 "22-rdf-syntax-ns#> .\n");
182 fprintf(fp, "@prefix rdfs: <http://www.w3.org/2000/01/"
183 "rdf-schema#> .\n");
184 fprintf(fp, "@prefix lv2: <http://lv2plug.in/ns/lv2core#> .\n");
185 fprintf(fp, "@prefix doap: <http://usefulinc.com/ns/doap#> .\n");
186 fprintf(fp, "@prefix dc: <http://purl.org/dc/elements/1.1/> .\n");
187 fprintf(fp, "@prefix epp: <http://lv2plug.in/ns/dev/extportinfo#> .\n");
188 fprintf(fp, "@prefix lv2units: <http://lv2plug.in/ns/extensions/"
189 "units#> .\n");
190 fprintf(fp, "@prefix lv2ev: <http://lv2plug.in/ns/ext/event#> .\n");
191 fprintf(fp, "@prefix lv2midi: <http://lv2plug.in/ns/ext/midi#> .\n");
193 fprintf(fp, "<%s>\n", desc->uri);
194 fprintf(fp, "\ta lv2:Plugin ;\n");
195 fprintf(fp, "\tlv2:binary <");
196 print_escaped_string(fp, binary);
197 fprintf(fp, SO_FILE_EXT "> ;\n");
198 fprintf(fp, "\tdoap:name \"");
199 print_escaped_string(fp, desc->name);
200 fprintf(fp, "\" ;\n");
201 fprintf(fp, "\tdoap:license "
202 "<http://usefulinc.com/doap/licenses/unknown> ;\n");
203 if (desc->creator != NULL)
204 {
205 fprintf(fp, "\tdc:creator \"");
206 print_escaped_string(fp, desc->creator);
207 fprintf(fp, "\" ;\n");
208 }
209 if (desc->rights != NULL)
210 {
211 fprintf(fp, "\tdc:rights \"");
212 print_escaped_string(fp, desc->rights);
213 fprintf(fp, "\" ;\n");
214 }
216 if (desc->properties & NACORE_DESCRIPTOR_HAS_LIVE_DEP)
217 fprintf(fp, "\tlv2:requiredFeature lv2:isLive ;\n");
218 if (desc->properties & NACORE_DESCRIPTOR_INPLACE_BROKEN)
219 fprintf(fp, "\tlv2:requiredFeature lv2:inPlaceBroken ;\n");
220 if (desc->properties & NACORE_DESCRIPTOR_HARD_RT_CAPABLE)
221 fprintf(fp, "\tlv2:optionalFeature lv2:hardRtCapable ;\n");
223 print_classes(fp, desc);
225 #if 0
226 for (i = 0; i < desc->port_descs_count; i++)
227 {
228 if (desc->port_descs[i].properties & NACORE_PORT_IS_MIDI)
229 {
230 fprintf(fp, "\tlv2:requiredFeature "
231 "<http://lv2plug.in/ns/ext/event> ;\n");
232 fprintf(fp, "\tlv2:requiredFeature "
233 "<http://lv2plug.in/ns/ext/uri-map> ;\n");
234 break;
235 }
236 }
237 #endif
239 for (i = 0; i < desc->port_descs_count; i++)
240 {
241 port_desc = desc->port_descs + i;
243 if (i)
244 fprintf(fp, " ,\n\t");
245 else
246 fprintf(fp, "\tlv2:port ");
248 fprintf(fp, "[\n");
249 fprintf(fp, "\t\ta %s, lv2:%s ;\n",
250 (port_desc->properties & NACORE_PORT_IS_AUDIO)
251 ? "lv2:AudioPort" :
252 ((port_desc->properties & NACORE_PORT_IS_MIDI)
253 ? "lv2ev:EventPort" : "lv2:ControlPort"),
254 (port_desc->properties & NACORE_PORT_IS_OUTPUT)
255 ? "OutputPort" : "InputPort");
257 fprintf(fp, "\t\tlv2:index %lu ;\n", (unsigned long)i);
258 fprintf(fp, "\t\tlv2:symbol \"port%lu\" ;\n", (unsigned long)i);
259 fprintf(fp, "\t\tlv2:name \"");
260 print_escaped_string(fp, port_desc->name);
261 fprintf(fp, "\" ;\n");
263 if (port_desc->properties & NACORE_PORT_CONNECTION_OPTIONAL)
264 fprintf(fp, "\t\tlv2:portProperty "
265 "lv2:connectionOptional ;\n");
267 if (!(port_desc->properties & NACORE_PORT_IS_AUDIO)
268 && !(port_desc->properties & NACORE_PORT_IS_MIDI))
269 {
270 if (port_desc->properties & NACORE_PORT_REPORTS_LATENCY)
271 fprintf(fp, "\t\tlv2:portProperty "
272 "lv2:reportsLatency ;\n");
273 if (port_desc->properties & NACORE_PORT_TOGGLED)
274 fprintf(fp, "\t\tlv2:portProperty "
275 "lv2:toggled ;\n");
276 if (port_desc->properties & NACORE_PORT_SAMPLE_RATE)
277 fprintf(fp, "\t\tlv2:portProperty "
278 "lv2:sampleRate ;\n");
279 if (port_desc->properties & NACORE_PORT_INTEGER)
280 fprintf(fp, "\t\tlv2:portProperty "
281 "lv2:integer ;\n");
282 if (port_desc->properties & NACORE_PORT_LOGARITHMIC)
283 fprintf(fp, "\t\tlv2:portProperty "
284 "epp:logarithmic ;\n");
285 if (port_desc->scale.properties & NACORE_SCALE_HAS_MIN)
286 fprintf(fp, "\t\tlv2:minimum %f ;\n",
287 port_desc->scale.min);
288 if (port_desc->scale.properties & NACORE_SCALE_HAS_MAX)
289 fprintf(fp, "\t\tlv2:maximum %f ;\n",
290 port_desc->scale.max);
291 if (port_desc->scale.properties
292 & NACORE_SCALE_HAS_DEFAULT)
293 fprintf(fp, "\t\tlv2:default %f ;\n",
294 port_desc->scale.defaultv);
296 print_scale_units(fp, desc, i);
297 print_scale_points(fp, desc, i);
298 }
299 else if (port_desc->properties & NACORE_PORT_IS_MIDI)
300 {
301 fprintf(fp, "\t\tlv2ev:supportsEvent "
302 "lv2midi:MidiEvent ;\n");
303 }
305 fprintf(fp, "\t]");
306 }
308 fprintf(fp, " .\n");
310 setlocale(LC_NUMERIC, prev_locale);
311 }
