Mercurial > hg > vamp-plugin-sdk
comparison rdf/generator/template-generator.cpp @ 144:a4aad47aaf96
* Restructure output so that each file describes a plugin library rather
than a single plugin (or at least, so that the base uri is for a library --
the file can still contain one or more plugins so long as they all come
from the same library).
* Make it possible to give the library name instead of individual plugin
names on the command line to generate templates for entire library
* Make program accept more than one plugin name, too
author | cannam |
---|---|
date | Fri, 20 Jun 2008 13:44:34 +0000 |
parents | 8e3a5f779d89 |
children | 521ff35b8b4c |
comparison
equal
deleted
inserted
replaced
143:fcf07a78871d | 144:a4aad47aaf96 |
---|---|
28 | 28 |
29 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator"; | 29 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator"; |
30 | 30 |
31 void usage() | 31 void usage() |
32 { | 32 { |
33 cerr << "usage: template-generator [PLUGIN_BASE_URI YOUR_URI] vamp:soname:plugin[:output]" << endl; | 33 cerr << "usage: template-generator -i vamp:soname[:plugin] [vamp:soname[:plugin] ...]" << endl; |
34 cerr << "usage: template-generator PLUGIN_BASE_URI YOUR_URI vamp:soname[:plugin] [vamp:soname[:plugin] ...]" << endl; | |
34 exit(2); | 35 exit(2); |
35 } | 36 } |
36 | 37 |
37 template <class T> | 38 template <class T> |
38 inline string to_string (const T& t) | 39 inline string to_string (const T& t) |
40 std::stringstream ss; | 41 std::stringstream ss; |
41 ss << t; | 42 ss << t; |
42 return ss.str(); | 43 return ss.str(); |
43 } | 44 } |
44 | 45 |
45 string describe_namespaces(Plugin* plugin, string pluginBundleBaseURI) | 46 string describe_namespaces(string pluginBundleBaseURI, string libname) |
46 { | 47 { |
47 string res=\ | 48 string res=\ |
48 "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n\ | 49 "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n\ |
49 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\ | 50 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\ |
50 @prefix vamp: <http://www.purl.org/ontology/vamp/> .\n\ | 51 @prefix vamp: <http://www.purl.org/ontology/vamp/> .\n\ |
51 @prefix vampex: <http://www.purl.org/ontology/vamp/examples/> .\n\ | 52 @prefix plugbase: <"+pluginBundleBaseURI+libname+"#> .\n\ |
52 @prefix plugbase: <"+pluginBundleBaseURI+"> .\n\ | |
53 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\ | 53 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\ |
54 @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\ | 54 @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\ |
55 @prefix af: <http://purl.org/ontology/af/> .\n\ | 55 @prefix af: <http://purl.org/ontology/af/> .\n\ |
56 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\ | 56 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\ |
57 @prefix cc: <http://web.resource.org/cc/> .\n\ | 57 @prefix cc: <http://web.resource.org/cc/> .\n\ |
58 @prefix thisplug: <"+pluginBundleBaseURI+plugin->getIdentifier()+"#> .\n\ | |
59 @prefix : <> .\n\n"; | 58 @prefix : <> .\n\n"; |
60 | 59 |
61 return res; | 60 return res; |
62 } | 61 } |
63 | 62 |
64 string describe_doc(Plugin* plugin, string describerURI) | 63 string describe_doc(string describerURI, string pluginBundleBaseURI, |
64 string libname) | |
65 { | 65 { |
66 string res=\ | 66 string res=\ |
67 "<> a vamp:PluginDescription ;\n\ | 67 "<> a vamp:PluginDescription ;\n\ |
68 foaf:maker <"+describerURI+"> ;\n\ | 68 foaf:maker <"+describerURI+"> ;\n\ |
69 foaf:maker <"+programURI+"> ;\n\ | 69 foaf:maker <"+programURI+"> ;\n\ |
70 foaf:primaryTopic plugbase:"+plugin->getIdentifier()+" .\n\n"; | 70 foaf:primaryTopic <"+pluginBundleBaseURI+libname+"> .\n\n"; |
71 return res; | 71 return res; |
72 } | 72 } |
73 | 73 |
74 | |
75 string describe_library(string libname, vector<Plugin *> plugins) | |
76 { | |
77 string res=\ | |
78 ":"+libname+" a vamp:PluginLibrary ;\n\ | |
79 vamp:identifier \""+libname+"\" "; | |
80 | |
81 for (size_t i = 0; i < plugins.size(); ++i) { | |
82 res += "; \n\ | |
83 vamp:available_plugin \"plugbase:"+plugins[i]->getIdentifier()+"\""; | |
84 } | |
85 | |
86 res += " .\n\n"; | |
87 return res; | |
88 } | |
74 | 89 |
75 string describe_plugin(Plugin* plugin) | 90 string describe_plugin(Plugin* plugin) |
76 { | 91 { |
77 string res=\ | 92 string res=\ |
78 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\ | 93 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\ |
90 res+=" vamp:input_domain vamp:TimeDomain ;\n\n"; | 105 res+=" vamp:input_domain vamp:TimeDomain ;\n\n"; |
91 | 106 |
92 | 107 |
93 Plugin::ParameterList params = plugin->getParameterDescriptors(); | 108 Plugin::ParameterList params = plugin->getParameterDescriptors(); |
94 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) | 109 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) |
95 res+=" vamp:parameter_descriptor thisplug:param_"+(*i).identifier+" ;\n"; | 110 res+=" vamp:parameter_descriptor plugbase:"+plugin->getIdentifier()+"_param_"+(*i).identifier+" ;\n"; |
96 res+="\n"; | 111 res+="\n"; |
97 | 112 |
98 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 113 Plugin::OutputList outputs = plugin->getOutputDescriptors(); |
99 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) | 114 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) |
100 res+=" vamp:output_descriptor thisplug:output_"+(*i).identifier+" ;\n"; | 115 res+=" vamp:output_descriptor plugbase:"+plugin->getIdentifier()+"_output_"+(*i).identifier+" ;\n"; |
101 res+=" .\n"; | 116 res+=" .\n"; |
102 | 117 |
103 return res; | 118 return res; |
104 } | 119 } |
105 | 120 |
106 string describe_param(Plugin::ParameterDescriptor p) | 121 string describe_param(Plugin *plugin, Plugin::ParameterDescriptor p) |
107 { | 122 { |
108 string res=\ | 123 string res=\ |
109 "thisplug:param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\ | 124 "plugbase:"+plugin->getIdentifier()+"_param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\ |
110 vamp:identifier \""+p.identifier+"\" ;\n\ | 125 vamp:identifier \""+p.identifier+"\" ;\n\ |
111 dc:title \""+p.name+"\" ;\n\ | 126 dc:title \""+p.name+"\" ;\n\ |
112 dc:format \""+p.unit+"\" ;\n\ | 127 dc:format \""+p.unit+"\" ;\n\ |
113 vamp:min_value "+to_string(p.minValue)+" ;\n\ | 128 vamp:min_value "+to_string(p.minValue)+" ;\n\ |
114 vamp:max_value "+to_string(p.maxValue)+" ;\n\ | 129 vamp:max_value "+to_string(p.maxValue)+" ;\n\ |
115 vamp:default_value "+to_string(p.defaultValue)+" .\n\n"; | 130 vamp:default_value "+to_string(p.defaultValue)+" .\n\n"; |
116 return res; | 131 return res; |
117 } | 132 } |
118 | 133 |
119 string describe_output(Plugin::OutputDescriptor o) | 134 string describe_output(Plugin *plugin, Plugin::OutputDescriptor o) |
120 { | 135 { |
121 | 136 |
122 //we need to distinguish here between different output types: | 137 //we need to distinguish here between different output types: |
123 //DenseOutput | 138 //DenseOutput |
124 //SparseOutput | 139 //SparseOutput |
131 | 146 |
132 if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate) | 147 if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate) |
133 { | 148 { |
134 | 149 |
135 res=\ | 150 res=\ |
136 "thisplug:output_"+o.identifier+" a vamp:SparseOutput ;\n\ | 151 "plugbase:"+plugin->getIdentifier()+"_output_"+o.identifier+" a vamp:SparseOutput ;\n\ |
137 vamp:identifier \""+o.identifier+"\" ;\n\ | 152 vamp:identifier \""+o.identifier+"\" ;\n\ |
138 dc:title \""+o.name+"\" ;\n\ | 153 dc:title \""+o.name+"\" ;\n\ |
139 dc:description \""+o.description+"\" ;\n\ | 154 dc:description \""+o.description+"\" ;\n\ |
140 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ | 155 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ |
141 vamp:is_quantized \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ | 156 vamp:is_quantized \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ |
144 | 159 |
145 | 160 |
146 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... | 161 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... |
147 if (o.hasFixedBinCount) | 162 if (o.hasFixedBinCount) |
148 { | 163 { |
149 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; | 164 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; |
150 res+=" vamp:bin_names ("; | 165 res+=" vamp:bin_names ("; |
151 | 166 |
152 unsigned int i; | 167 unsigned int i; |
153 for (i=0; i+1 < o.binNames.size(); i++) | 168 for (i=0; i+1 < o.binNames.size(); i++) |
154 res+=" \""+o.binNames[i]+"\""; | 169 res+=" \""+o.binNames[i]+"\""; |
155 if (i < o.binNames.size()) | 170 if (i < o.binNames.size()) |
157 res+=");\n"; | 172 res+=");\n"; |
158 } | 173 } |
159 | 174 |
160 if (o.isQuantized) | 175 if (o.isQuantized) |
161 { | 176 { |
162 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; | 177 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; |
163 } | 178 } |
164 | 179 |
165 res+=" vamp:sample_type vamp:VariableSampleRate ;\n"; | 180 res+=" vamp:sample_type vamp:VariableSampleRate ;\n"; |
166 if (o.sampleRate > 0.0f) | 181 if (o.sampleRate > 0.0f) |
167 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; | 182 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; |
168 | 183 |
169 } | 184 } |
170 | 185 |
171 //If we do not have SparseOutput, then we have DenseOutput. TrackLevelOutput can not be inferred from the plugin directly without actually | 186 //If we do not have SparseOutput, then we have DenseOutput. TrackLevelOutput can not be inferred from the plugin directly without actually |
172 //running the plugin. | 187 //running the plugin. |
173 else{ | 188 else{ |
174 | 189 |
175 res=\ | 190 res=\ |
176 "thisplug:output_"+o.identifier+" a vamp:DenseOutput ;\n\ | 191 "plugbase:"+plugin->getIdentifier()+"_output_"+o.identifier+" a vamp:DenseOutput ;\n\ |
177 vamp:identifier \""+o.identifier+"\" ;\n\ | 192 vamp:identifier \""+o.identifier+"\" ;\n\ |
178 dc:title \""+o.name+"\" ;\n\ | 193 dc:title \""+o.name+"\" ;\n\ |
179 dc:description \""+o.description+"\" ;\n\ | 194 dc:description \""+o.description+"\" ;\n\ |
180 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ | 195 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ |
181 vamp:is_quantised \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ | 196 vamp:is_quantised \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ |
184 | 199 |
185 | 200 |
186 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... | 201 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... |
187 if (o.hasFixedBinCount) | 202 if (o.hasFixedBinCount) |
188 { | 203 { |
189 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; | 204 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; |
190 res+=" vamp:bin_names ("; | 205 res+=" vamp:bin_names ("; |
191 | 206 |
192 unsigned int i; | 207 unsigned int i; |
193 for (i=0; i+1 < o.binNames.size(); i++) | 208 for (i=0; i+1 < o.binNames.size(); i++) |
194 res+=" \""+o.binNames[i]+"\""; | 209 res+=" \""+o.binNames[i]+"\""; |
195 if (i < o.binNames.size()) | 210 if (i < o.binNames.size()) |
197 res+=");\n"; | 212 res+=");\n"; |
198 } | 213 } |
199 | 214 |
200 if (o.isQuantized) | 215 if (o.isQuantized) |
201 { | 216 { |
202 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; | 217 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; |
203 } | 218 } |
204 | 219 |
205 | 220 |
206 else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate) | 221 else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate) |
207 { | 222 { |
208 res+=" vamp:sample_type vamp:FixedSampleRate ;\n"; | 223 res+=" vamp:sample_type vamp:FixedSampleRate ;\n"; |
209 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; | 224 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; |
210 } | 225 } |
211 else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep) | 226 else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep) |
212 res+=" vamp:sample_type vamp:OneSamplePerStep ;\n"; | 227 res+=" vamp:sample_type vamp:OneSamplePerStep ;\n"; |
213 else | 228 else |
214 { | 229 { |
215 cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<<endl; | 230 cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<<endl; |
216 exit(1); | 231 exit(1); |
217 } | 232 } |
223 res+=" .\n"; | 238 res+=" .\n"; |
224 | 239 |
225 return res; | 240 return res; |
226 } | 241 } |
227 | 242 |
228 string describe(Plugin* plugin, string pluginBundleBaseURI, string describerURI) | 243 string describe(vector<Plugin *> plugins, string pluginBundleBaseURI, |
229 { | 244 string describerURI, string libname) |
230 string res = describe_namespaces(plugin, pluginBundleBaseURI); | 245 { |
231 | 246 string res = describe_namespaces(pluginBundleBaseURI, libname); |
232 res += describe_doc(plugin, describerURI); | 247 |
233 | 248 res += describe_doc(describerURI, pluginBundleBaseURI, libname); |
234 res += describe_plugin(plugin); | 249 |
235 | 250 res += describe_library(libname, plugins); |
236 Plugin::ParameterList params = plugin->getParameterDescriptors(); | 251 |
237 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) | 252 for (size_t i = 0; i < plugins.size(); ++i) { |
238 res += describe_param(*i); | 253 |
239 | 254 Plugin *plugin = plugins[i]; |
240 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 255 |
241 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) | 256 res += describe_plugin(plugin); |
242 res += describe_output(*i); | 257 |
258 Plugin::ParameterList params = plugin->getParameterDescriptors(); | |
259 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) | |
260 res += describe_param(plugin, *i); | |
261 | |
262 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | |
263 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) | |
264 res += describe_output(plugin, *i); | |
265 } | |
243 | 266 |
244 return res; | 267 return res; |
245 } | 268 } |
246 | 269 |
247 int main(int argc, char **argv) | 270 int main(int argc, char **argv) |
248 { | 271 { |
249 if (argc != 2 && argc != 4) usage(); | 272 if (argc < 3) usage(); |
250 | 273 |
251 std::string pluginName = argv[argc-1]; | 274 bool interactive = false; |
252 | 275 if (!strcmp(argv[1], "-i")) interactive = true; |
253 if (pluginName.substr(0, 5) == "vamp:") { | 276 |
254 pluginName = pluginName.substr(5); | 277 if (!interactive && argc < 4) usage(); |
255 } | |
256 | |
257 Vamp::Plugin *plugin = PluginLoader::getInstance()->loadPlugin | |
258 (pluginName, size_t(44100), PluginLoader::ADAPT_ALL_SAFE); | |
259 | |
260 if (!plugin) { | |
261 cerr << "ERROR: Plugin \"" << pluginName << "\" could not be loaded" << endl; | |
262 exit(1); | |
263 } | |
264 | 278 |
265 string pluginBundleBaseURI, describerURI; | 279 string pluginBundleBaseURI, describerURI; |
266 | 280 |
267 if (argc == 4) | 281 int argidx = 2; |
268 { | 282 |
283 if (!interactive) { | |
269 pluginBundleBaseURI = argv[1]; | 284 pluginBundleBaseURI = argv[1]; |
270 describerURI = argv[2]; | 285 describerURI = argv[2]; |
271 } | 286 argidx = 3; |
272 else | 287 } else { |
273 { | |
274 cerr << "Please enter the base URI for the plugin bundle : "; | 288 cerr << "Please enter the base URI for the plugin bundle : "; |
275 getline(cin, pluginBundleBaseURI); | 289 getline(cin, pluginBundleBaseURI); |
276 cerr << "Please enter your URI : "; | 290 cerr << "Please enter your URI : "; |
277 getline(cin, describerURI); | 291 getline(cin, describerURI); |
278 } | 292 } |
279 | 293 |
280 cout << describe(plugin, pluginBundleBaseURI, describerURI) << endl; | 294 vector<Plugin *> plugins; |
295 string libname; | |
296 | |
297 PluginLoader *loader = PluginLoader::getInstance(); | |
298 | |
299 while (argidx < argc) { | |
300 | |
301 string pluginName = argv[argidx]; | |
302 | |
303 if (pluginName.substr(0, 5) == "vamp:") { | |
304 pluginName = pluginName.substr(5); | |
305 } | |
306 | |
307 string mylibname = pluginName.substr(0, pluginName.find(':')); | |
308 | |
309 if (libname == "") libname = mylibname; | |
310 else if (libname != mylibname) { | |
311 cerr << "ERROR: All plugins specified on command line must originate in the same library" << endl; | |
312 exit(1); | |
313 } | |
314 | |
315 if (mylibname == pluginName) { // pluginName is a library, not a plugin | |
316 | |
317 PluginLoader::PluginKeyList list = loader->listPlugins(); | |
318 for (size_t i = 0; i < list.size(); ++i) { | |
319 string thislibname = list[i].substr(0, list[i].find(':')); | |
320 if (thislibname != mylibname) continue; | |
321 Plugin *plugin = loader->loadPlugin(list[i], 44100); | |
322 if (!plugin) { | |
323 cerr << "ERROR: Plugin \"" << list[i] << "\" could not be loaded" << endl; | |
324 exit(1); | |
325 } | |
326 plugins.push_back(plugin); | |
327 } | |
328 } else { // pluginName is a plugin | |
329 | |
330 Plugin *plugin = loader->loadPlugin(pluginName, size_t(44100)); | |
331 if (!plugin) { | |
332 cerr << "ERROR: Plugin \"" << pluginName << "\" could not be loaded" << endl; | |
333 exit(1); | |
334 } | |
335 plugins.push_back(plugin); | |
336 } | |
337 | |
338 ++argidx; | |
339 } | |
340 | |
341 cout << describe(plugins, pluginBundleBaseURI, describerURI, libname) << endl; | |
281 | 342 |
282 return 0; | 343 return 0; |
283 } | 344 } |
284 | 345 |
285 | 346 |