comparison rdf/generator/template-generator.cpp @ 142:8e3a5f779d89

* Reindent and remove inaccurate comment about usage
author cannam
date Fri, 20 Jun 2008 11:31:26 +0000
parents bb46b8bd213a
children a4aad47aaf96
comparison
equal deleted inserted replaced
141:cabf8e65c10f 142:8e3a5f779d89
24 using std::ios; 24 using std::ios;
25 25
26 using Vamp::HostExt::PluginLoader; 26 using Vamp::HostExt::PluginLoader;
27 using Vamp::Plugin; 27 using Vamp::Plugin;
28 28
29 /*
30
31 usage:
32
33 template-generator vamp:aubioonset:onsets
34
35 */
36
37 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator"; 29 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator";
38 30
39 void usage() 31 void usage()
40 { 32 {
41 cerr << "usage: template-generator [PLUGIN_BASE_URI YOUR_URI] vamp:soname:plugin[:output]" << endl; 33 cerr << "usage: template-generator [PLUGIN_BASE_URI YOUR_URI] vamp:soname:plugin[:output]" << endl;
50 return ss.str(); 42 return ss.str();
51 } 43 }
52 44
53 string describe_namespaces(Plugin* plugin, string pluginBundleBaseURI) 45 string describe_namespaces(Plugin* plugin, string pluginBundleBaseURI)
54 { 46 {
55 string res=\ 47 string res=\
56 "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n\ 48 "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n\
57 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\ 49 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\
58 @prefix vamp: <http://www.purl.org/ontology/vamp/> .\n\ 50 @prefix vamp: <http://www.purl.org/ontology/vamp/> .\n\
59 @prefix vampex: <http://www.purl.org/ontology/vamp/examples/> .\n\ 51 @prefix vampex: <http://www.purl.org/ontology/vamp/examples/> .\n\
60 @prefix plugbase: <"+pluginBundleBaseURI+"> .\n\ 52 @prefix plugbase: <"+pluginBundleBaseURI+"> .\n\
61 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\ 53 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\
64 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\ 56 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\
65 @prefix cc: <http://web.resource.org/cc/> .\n\ 57 @prefix cc: <http://web.resource.org/cc/> .\n\
66 @prefix thisplug: <"+pluginBundleBaseURI+plugin->getIdentifier()+"#> .\n\ 58 @prefix thisplug: <"+pluginBundleBaseURI+plugin->getIdentifier()+"#> .\n\
67 @prefix : <> .\n\n"; 59 @prefix : <> .\n\n";
68 60
69 return res; 61 return res;
70 } 62 }
71 63
72 string describe_doc(Plugin* plugin, string describerURI) 64 string describe_doc(Plugin* plugin, string describerURI)
73 { 65 {
74 string res=\ 66 string res=\
75 "<> a vamp:PluginDescription ;\n\ 67 "<> a vamp:PluginDescription ;\n\
76 foaf:maker <"+describerURI+"> ;\n\ 68 foaf:maker <"+describerURI+"> ;\n\
77 foaf:maker <"+programURI+"> ;\n\ 69 foaf:maker <"+programURI+"> ;\n\
78 foaf:primaryTopic plugbase:"+plugin->getIdentifier()+" .\n\n"; 70 foaf:primaryTopic plugbase:"+plugin->getIdentifier()+" .\n\n";
79 return res; 71 return res;
80 } 72 }
81 73
82 74
83 string describe_plugin(Plugin* plugin) 75 string describe_plugin(Plugin* plugin)
84 { 76 {
85 string res=\ 77 string res=\
86 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\ 78 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\
87 dc:title \""+plugin->getName()+"\" ;\n\ 79 dc:title \""+plugin->getName()+"\" ;\n\
88 vamp:name \""+plugin->getName()+"\" ;\n\ 80 vamp:name \""+plugin->getName()+"\" ;\n\
89 dc:description \""+plugin->getDescription()+"\" ;\n\ 81 dc:description \""+plugin->getDescription()+"\" ;\n\
90 foaf:maker [ foaf:name \""+plugin->getMaker()+"\"] ; # FIXME could give plugin author's URI here\n\ 82 foaf:maker [ foaf:name \""+plugin->getMaker()+"\"] ; # FIXME could give plugin author's URI here\n\
91 cc:license <FIXME license for the plugin> ; \n\ 83 cc:license <FIXME license for the plugin> ; \n\
92 vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\ 84 vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\
93 vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\ 85 vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\
94 owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n"; 86 owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n";
95 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) 87 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain)
96 res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n"; 88 res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n";
97 else 89 else
98 res+=" vamp:input_domain vamp:TimeDomain ;\n\n"; 90 res+=" vamp:input_domain vamp:TimeDomain ;\n\n";
99 91
100 92
101 Plugin::ParameterList params = plugin->getParameterDescriptors(); 93 Plugin::ParameterList params = plugin->getParameterDescriptors();
102 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) 94 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
103 res+=" vamp:parameter_descriptor thisplug:param_"+(*i).identifier+" ;\n"; 95 res+=" vamp:parameter_descriptor thisplug:param_"+(*i).identifier+" ;\n";
104 res+="\n"; 96 res+="\n";
105 97
106 Plugin::OutputList outputs = plugin->getOutputDescriptors(); 98 Plugin::OutputList outputs = plugin->getOutputDescriptors();
107 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) 99 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++)
108 res+=" vamp:output_descriptor thisplug:output_"+(*i).identifier+" ;\n"; 100 res+=" vamp:output_descriptor thisplug:output_"+(*i).identifier+" ;\n";
109 res+=" .\n"; 101 res+=" .\n";
110 102
111 return res; 103 return res;
112 } 104 }
113 105
114 string describe_param(Plugin::ParameterDescriptor p) 106 string describe_param(Plugin::ParameterDescriptor p)
115 { 107 {
116 string res=\ 108 string res=\
117 "thisplug:param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\ 109 "thisplug:param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\
118 vamp:identifier \""+p.identifier+"\" ;\n\ 110 vamp:identifier \""+p.identifier+"\" ;\n\
119 dc:title \""+p.name+"\" ;\n\ 111 dc:title \""+p.name+"\" ;\n\
120 dc:format \""+p.unit+"\" ;\n\ 112 dc:format \""+p.unit+"\" ;\n\
121 vamp:min_value "+to_string(p.minValue)+" ;\n\ 113 vamp:min_value "+to_string(p.minValue)+" ;\n\
122 vamp:max_value "+to_string(p.maxValue)+" ;\n\ 114 vamp:max_value "+to_string(p.maxValue)+" ;\n\
123 vamp:default_value "+to_string(p.defaultValue)+" .\n\n"; 115 vamp:default_value "+to_string(p.defaultValue)+" .\n\n";
124 return res; 116 return res;
125 } 117 }
126 118
127 string describe_output(Plugin::OutputDescriptor o) 119 string describe_output(Plugin::OutputDescriptor o)
128 { 120 {
129 121
130 //we need to distinguish here between different output types: 122 //we need to distinguish here between different output types:
131 //DenseOutput 123 //DenseOutput
132 //SparseOutput 124 //SparseOutput
133 //TrackLevelOutput 125 //TrackLevelOutput
134 126
135 127
136 //SparseOutput: variable sample rate. Events are not evenly spaced so we need to record the time associated with the event as it its not ensured that we have an event after the next one (but there is not time to set the duration, it has to be calculated as the different between 2 different events). The timestamp must be read. 128 //SparseOutput: variable sample rate. Events are not evenly spaced so we need to record the time associated with the event as it its not ensured that we have an event after the next one (but there is not time to set the duration, it has to be calculated as the different between 2 different events). The timestamp must be read.
137 129
138 string res; 130 string res;
139 131
140 if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate) 132 if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate)
141 { 133 {
142 134
143 res=\ 135 res=\
144 "thisplug:output_"+o.identifier+" a vamp:SparseOutput ;\n\ 136 "thisplug:output_"+o.identifier+" a vamp:SparseOutput ;\n\
145 vamp:identifier \""+o.identifier+"\" ;\n\ 137 vamp:identifier \""+o.identifier+"\" ;\n\
146 dc:title \""+o.name+"\" ;\n\ 138 dc:title \""+o.name+"\" ;\n\
147 dc:description \""+o.description+"\" ;\n\ 139 dc:description \""+o.description+"\" ;\n\
148 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ 140 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\
149 vamp:is_quantized \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ 141 vamp:is_quantized \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\
150 vamp:unit \""+(o.unit)+"\" ;\n"; 142 vamp:unit \""+(o.unit)+"\" ;\n";
151 143
152 144
153 145
154 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... 146 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading...
155 if (o.hasFixedBinCount) 147 if (o.hasFixedBinCount)
156 { 148 {
157 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; 149 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n";
158 res+=" vamp:bin_names ("; 150 res+=" vamp:bin_names (";
159 151
160 unsigned int i; 152 unsigned int i;
161 for (i=0; i+1 < o.binNames.size(); i++) 153 for (i=0; i+1 < o.binNames.size(); i++)
162 res+=" \""+o.binNames[i]+"\""; 154 res+=" \""+o.binNames[i]+"\"";
163 if (i < o.binNames.size()) 155 if (i < o.binNames.size())
164 res+=" \""+o.binNames[i]+"\""; 156 res+=" \""+o.binNames[i]+"\"";
165 res+=");\n"; 157 res+=");\n";
166 } 158 }
167 159
168 if (o.isQuantized) 160 if (o.isQuantized)
169 { 161 {
170 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; 162 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n";
171 } 163 }
172 164
173 res+=" vamp:sample_type vamp:VariableSampleRate ;\n"; 165 res+=" vamp:sample_type vamp:VariableSampleRate ;\n";
174 if (o.sampleRate > 0.0f) 166 if (o.sampleRate > 0.0f)
175 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; 167 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n";
176 168
177 } 169 }
178 170
179 //If we do not have SparseOutput, then we have DenseOutput. TrackLevelOutput can not be inferred from the plugin directly without actually 171 //If we do not have SparseOutput, then we have DenseOutput. TrackLevelOutput can not be inferred from the plugin directly without actually
180 //running the plugin. 172 //running the plugin.
181 else{ 173 else{
182 174
183 res=\ 175 res=\
184 "thisplug:output_"+o.identifier+" a vamp:DenseOutput ;\n\ 176 "thisplug:output_"+o.identifier+" a vamp:DenseOutput ;\n\
185 vamp:identifier \""+o.identifier+"\" ;\n\ 177 vamp:identifier \""+o.identifier+"\" ;\n\
186 dc:title \""+o.name+"\" ;\n\ 178 dc:title \""+o.name+"\" ;\n\
187 dc:description \""+o.description+"\" ;\n\ 179 dc:description \""+o.description+"\" ;\n\
188 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ 180 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\
189 vamp:is_quantised \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ 181 vamp:is_quantised \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\
190 vamp:unit \""+(o.unit)+"\" ;\n"; 182 vamp:unit \""+(o.unit)+"\" ;\n";
191 183
192 184
193 185
194 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... 186 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading...
195 if (o.hasFixedBinCount) 187 if (o.hasFixedBinCount)
196 { 188 {
197 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; 189 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n";
198 res+=" vamp:bin_names ("; 190 res+=" vamp:bin_names (";
199 191
200 unsigned int i; 192 unsigned int i;
201 for (i=0; i+1 < o.binNames.size(); i++) 193 for (i=0; i+1 < o.binNames.size(); i++)
202 res+=" \""+o.binNames[i]+"\""; 194 res+=" \""+o.binNames[i]+"\"";
203 if (i < o.binNames.size()) 195 if (i < o.binNames.size())
204 res+=" \""+o.binNames[i]+"\""; 196 res+=" \""+o.binNames[i]+"\"";
205 res+=");\n"; 197 res+=");\n";
206 } 198 }
207 199
208 if (o.isQuantized) 200 if (o.isQuantized)
209 { 201 {
210 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; 202 res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n";
211 } 203 }
212 204
213 205
214 else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate) 206 else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate)
215 { 207 {
216 res+=" vamp:sample_type vamp:FixedSampleRate ;\n"; 208 res+=" vamp:sample_type vamp:FixedSampleRate ;\n";
217 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; 209 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n";
218 } 210 }
219 else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep) 211 else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep)
220 res+=" vamp:sample_type vamp:OneSamplePerStep ;\n"; 212 res+=" vamp:sample_type vamp:OneSamplePerStep ;\n";
221 else 213 else
222 { 214 {
223 cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<<endl; 215 cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<<endl;
224 exit(1); 216 exit(1);
225 } 217 }
226 } 218 }
227 219
228 //There is no way to know this in advance, but we can use the km a bit for this. 220 //There is no way to know this in advance, but we can use the km a bit for this.
229 res+=" vamp:computes_feature_type <FIXME feature type URI> ;\n"; 221 res+=" vamp:computes_feature_type <FIXME feature type URI> ;\n";
230 res+=" vamp:computes_event_type <FIXME event type URI> ;\n"; 222 res+=" vamp:computes_event_type <FIXME event type URI> ;\n";
231 res+=" .\n"; 223 res+=" .\n";
232 224
233 return res; 225 return res;
234 } 226 }
235 227
236 string describe(Plugin* plugin, string pluginBundleBaseURI, string describerURI) 228 string describe(Plugin* plugin, string pluginBundleBaseURI, string describerURI)
237 { 229 {
238 string res = describe_namespaces(plugin, pluginBundleBaseURI); 230 string res = describe_namespaces(plugin, pluginBundleBaseURI);
239 231
240 res += describe_doc(plugin, describerURI); 232 res += describe_doc(plugin, describerURI);
241 233
242 res += describe_plugin(plugin); 234 res += describe_plugin(plugin);
243 235
244 Plugin::ParameterList params = plugin->getParameterDescriptors(); 236 Plugin::ParameterList params = plugin->getParameterDescriptors();
245 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) 237 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
246 res += describe_param(*i); 238 res += describe_param(*i);
247 239
248 Plugin::OutputList outputs = plugin->getOutputDescriptors(); 240 Plugin::OutputList outputs = plugin->getOutputDescriptors();
249 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) 241 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++)
250 res += describe_output(*i); 242 res += describe_output(*i);
251 243
252 return res; 244 return res;
253 } 245 }
254 246
255 int main(int argc, char **argv) 247 int main(int argc, char **argv)
256 { 248 {
257 if (argc != 2 && argc != 4) usage(); 249 if (argc != 2 && argc != 4) usage();