cannam@138
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@138
|
2
|
cannam@138
|
3 #include "vamp-sdk/PluginHostAdapter.h"
|
cannam@138
|
4 #include "vamp-sdk/hostext/PluginChannelAdapter.h"
|
cannam@138
|
5 #include "vamp-sdk/hostext/PluginInputDomainAdapter.h"
|
cannam@138
|
6 #include "vamp-sdk/hostext/PluginLoader.h"
|
cannam@138
|
7 #include "vamp/vamp.h"
|
cannam@138
|
8
|
cannam@138
|
9 #include <iostream>
|
cannam@138
|
10 #include <fstream>
|
cannam@138
|
11 #include <sstream>
|
cannam@138
|
12 #include <sndfile.h>
|
cannam@138
|
13
|
cannam@138
|
14 #include <cmath>
|
cannam@138
|
15
|
cannam@138
|
16 using std::cout;
|
cannam@138
|
17 using std::cin;
|
cannam@138
|
18 using std::cerr;
|
cannam@138
|
19 using std::getline;
|
cannam@138
|
20 using std::endl;
|
cannam@138
|
21 using std::string;
|
cannam@138
|
22 using std::vector;
|
cannam@138
|
23 using std::ofstream;
|
cannam@138
|
24 using std::ios;
|
cannam@138
|
25
|
cannam@138
|
26 using Vamp::HostExt::PluginLoader;
|
cannam@138
|
27 using Vamp::Plugin;
|
cannam@138
|
28
|
cannam@138
|
29 /*
|
cannam@138
|
30
|
cannam@138
|
31 usage:
|
cannam@138
|
32
|
cannam@138
|
33 template-generator vamp:aubioonset:onsets
|
cannam@138
|
34
|
cannam@138
|
35 */
|
cannam@138
|
36
|
cannam@138
|
37 string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator";
|
cannam@138
|
38
|
cannam@138
|
39 void usage()
|
cannam@138
|
40 {
|
cannam@138
|
41 cerr << "usage: template-generator [PLUGIN_BASE_URI YOUR_URI] vamp:soname:plugin[:output]" << endl;
|
cannam@138
|
42 exit(2);
|
cannam@138
|
43 }
|
cannam@138
|
44
|
cannam@138
|
45 template <class T>
|
cannam@138
|
46 inline string to_string (const T& t)
|
cannam@138
|
47 {
|
cannam@138
|
48 std::stringstream ss;
|
cannam@138
|
49 ss << t;
|
cannam@138
|
50 return ss.str();
|
cannam@138
|
51 }
|
cannam@138
|
52
|
cannam@138
|
53 string describe_namespaces(Plugin* plugin, string pluginBundleBaseURI)
|
cannam@138
|
54 {
|
cannam@138
|
55 string res=\
|
cannam@138
|
56 "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n\
|
cannam@138
|
57 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\
|
cannam@138
|
58 @prefix vamp: <http://www.vamp-plugins.org/ontology/> .\n\
|
cannam@138
|
59 @prefix vampex: <http://www.vamp-plugins.org/examples/> .\n\
|
cannam@138
|
60 @prefix plugbase: <"+pluginBundleBaseURI+"> .\n\
|
cannam@138
|
61 @prefix owl: <http://www.w3.org/2002/07/owl#> .\n\
|
cannam@138
|
62 @prefix dc: <http://purl.org/dc/elements/1.1/> .\n\
|
cannam@138
|
63 @prefix af: <http://purl.org/ontology/af/> .\n\
|
cannam@138
|
64 @prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\
|
cannam@138
|
65 @prefix cc: <http://web.resource.org/cc/> .\n\
|
cannam@138
|
66 @prefix thisplug: <"+pluginBundleBaseURI+plugin->getIdentifier()+"#> .\n\
|
cannam@138
|
67 @prefix : <> .\n\n";
|
cannam@138
|
68
|
cannam@138
|
69 return res;
|
cannam@138
|
70 }
|
cannam@138
|
71
|
cannam@138
|
72 string describe_doc(Plugin* plugin, string describerURI)
|
cannam@138
|
73 {
|
cannam@138
|
74 string res=\
|
cannam@138
|
75 "<> a vamp:PluginDescription ;\n\
|
cannam@138
|
76 foaf:maker <"+describerURI+"> ;\n\
|
cannam@138
|
77 foaf:maker <"+programURI+"> ;\n\
|
cannam@138
|
78 foaf:primaryTopic plugbase:"+plugin->getIdentifier()+" .\n\n";
|
cannam@138
|
79 return res;
|
cannam@138
|
80 }
|
cannam@138
|
81
|
cannam@138
|
82
|
cannam@138
|
83 string describe_plugin(Plugin* plugin)
|
cannam@138
|
84 {
|
cannam@138
|
85 string res=\
|
cannam@138
|
86 "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\
|
cannam@138
|
87 dc:title \""+plugin->getName()+"\" ;\n\
|
cannam@138
|
88 dc:description \""+plugin->getDescription()+"\" ;\n\
|
cannam@138
|
89 foaf:maker [ foaf:name \""+plugin->getMaker()+"\"] ; # FIXME could give plugin author's URI here\n\
|
cannam@138
|
90 cc:license <FIXME license for the plugin> ; \n\
|
cannam@138
|
91 vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\
|
cannam@138
|
92 vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\
|
cannam@138
|
93 owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n";
|
cannam@138
|
94 if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain)
|
cannam@138
|
95 res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n";
|
cannam@138
|
96 else
|
cannam@138
|
97 res+=" vamp:input_domain vamp:TimeDomain ;\n\n";
|
cannam@138
|
98
|
cannam@138
|
99
|
cannam@138
|
100 Plugin::ParameterList params = plugin->getParameterDescriptors();
|
cannam@138
|
101 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
|
cannam@138
|
102 res+=" vamp:parameter_descriptor thisplug:param_"+(*i).identifier+" ;\n";
|
cannam@138
|
103 res+="\n";
|
cannam@138
|
104
|
cannam@138
|
105 Plugin::OutputList outputs = plugin->getOutputDescriptors();
|
cannam@138
|
106 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++)
|
cannam@138
|
107 res+=" vamp:output_descriptor thisplug:output_"+(*i).identifier+" ;\n";
|
cannam@138
|
108 res+=" .\n";
|
cannam@138
|
109
|
cannam@138
|
110 return res;
|
cannam@138
|
111 }
|
cannam@138
|
112
|
cannam@138
|
113 string describe_param(Plugin::ParameterDescriptor p)
|
cannam@138
|
114 {
|
cannam@138
|
115 string res=\
|
cannam@138
|
116 "thisplug:param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\
|
cannam@138
|
117 vamp:identifier \""+p.identifier+"\" ;\n\
|
cannam@138
|
118 dc:title \""+p.name+"\" ;\n\
|
cannam@138
|
119 dc:format \""+p.unit+"\" ;\n\
|
cannam@138
|
120 vamp:minValue "+to_string(p.minValue)+" ;\n\
|
cannam@138
|
121 vamp:maxValue "+to_string(p.maxValue)+" ;\n\
|
cannam@138
|
122 vamp:defaultValue "+to_string(p.defaultValue)+" .\n\n";
|
cannam@138
|
123 return res;
|
cannam@138
|
124 }
|
cannam@138
|
125
|
cannam@138
|
126 string describe_output(Plugin::OutputDescriptor o)
|
cannam@138
|
127 {
|
cannam@138
|
128 string res=\
|
cannam@138
|
129 "thisplug:output_"+o.identifier+" a vamp:OutputDescriptor ;\n\
|
cannam@138
|
130 vamp:identifier \""+o.identifier+"\" ;\n\
|
cannam@138
|
131 dc:title \""+o.name+"\" ;\n\
|
cannam@138
|
132 vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n";
|
cannam@138
|
133
|
cannam@138
|
134 // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading...
|
cannam@138
|
135 if (o.hasFixedBinCount)
|
cannam@138
|
136 {
|
cannam@138
|
137 res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n";
|
cannam@138
|
138 res+=" vamp:bin_names (";
|
cannam@138
|
139
|
cannam@138
|
140 unsigned int i;
|
cannam@138
|
141 for (i=0; i+1 < o.binNames.size(); i++)
|
cannam@138
|
142 res+=" \""+o.binNames[i]+"\"";
|
cannam@138
|
143 if (i < o.binNames.size())
|
cannam@138
|
144 res+=" \""+o.binNames[i]+"\"";
|
cannam@138
|
145 res+=");\n";
|
cannam@138
|
146 }
|
cannam@138
|
147
|
cannam@138
|
148 if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate)
|
cannam@138
|
149 {
|
cannam@138
|
150 res+=" vamp:sample_type vamp:VariableSampleRate ;\n";
|
cannam@138
|
151 if (o.sampleRate > 0.0f)
|
cannam@138
|
152 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n";
|
cannam@138
|
153 }
|
cannam@138
|
154 else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate)
|
cannam@138
|
155 {
|
cannam@138
|
156 res+=" vamp:sample_type vamp:FixedSampleRate ;\n";
|
cannam@138
|
157 res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n";
|
cannam@138
|
158 }
|
cannam@138
|
159 else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep)
|
cannam@138
|
160 res+=" vamp:sample_type vamp:OneSamplePerStep ;\n";
|
cannam@138
|
161 else
|
cannam@138
|
162 {
|
cannam@138
|
163 cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<<endl;
|
cannam@138
|
164 exit(1);
|
cannam@138
|
165 }
|
cannam@138
|
166
|
cannam@138
|
167 res+=" vamp:computes_feature_type <FIXME feature type URI> ;\n";
|
cannam@138
|
168 res+=" vamp:computes_event_type <FIXME event type URI> ;\n";
|
cannam@138
|
169 res+=" .\n";
|
cannam@138
|
170
|
cannam@138
|
171 return res;
|
cannam@138
|
172 }
|
cannam@138
|
173 string describe(Plugin* plugin, string pluginBundleBaseURI, string describerURI)
|
cannam@138
|
174 {
|
cannam@138
|
175 string res = describe_namespaces(plugin, pluginBundleBaseURI);
|
cannam@138
|
176
|
cannam@138
|
177 res += describe_doc(plugin, describerURI);
|
cannam@138
|
178
|
cannam@138
|
179 res += describe_plugin(plugin);
|
cannam@138
|
180
|
cannam@138
|
181 Plugin::ParameterList params = plugin->getParameterDescriptors();
|
cannam@138
|
182 for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++)
|
cannam@138
|
183 res += describe_param(*i);
|
cannam@138
|
184
|
cannam@138
|
185 Plugin::OutputList outputs = plugin->getOutputDescriptors();
|
cannam@138
|
186 for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++)
|
cannam@138
|
187 res += describe_output(*i);
|
cannam@138
|
188
|
cannam@138
|
189 return res;
|
cannam@138
|
190 }
|
cannam@138
|
191
|
cannam@138
|
192 int main(int argc, char **argv)
|
cannam@138
|
193 {
|
cannam@138
|
194 if (argc != 2 && argc != 4) usage();
|
cannam@138
|
195
|
cannam@138
|
196 std::string pluginName = argv[argc-1];
|
cannam@138
|
197
|
cannam@138
|
198 if (pluginName.substr(0, 5) == "vamp:") {
|
cannam@138
|
199 pluginName = pluginName.substr(5);
|
cannam@138
|
200 }
|
cannam@138
|
201
|
cannam@138
|
202 Vamp::Plugin *plugin = PluginLoader::getInstance()->loadPlugin
|
cannam@138
|
203 (pluginName, size_t(44100), PluginLoader::ADAPT_ALL_SAFE);
|
cannam@138
|
204
|
cannam@138
|
205 if (!plugin) {
|
cannam@138
|
206 cerr << "ERROR: Plugin \"" << pluginName << "\" could not be loaded" << endl;
|
cannam@138
|
207 exit(1);
|
cannam@138
|
208 }
|
cannam@138
|
209
|
cannam@138
|
210 string pluginBundleBaseURI, describerURI;
|
cannam@138
|
211
|
cannam@138
|
212 if (argc == 4)
|
cannam@138
|
213 {
|
cannam@138
|
214 pluginBundleBaseURI = argv[1];
|
cannam@138
|
215 describerURI = argv[2];
|
cannam@138
|
216 }
|
cannam@138
|
217 else
|
cannam@138
|
218 {
|
cannam@138
|
219 cerr << "Please enter the base URI for the plugin bundle : ";
|
cannam@138
|
220 getline(cin, pluginBundleBaseURI);
|
cannam@138
|
221 cerr << "Please enter your URI : ";
|
cannam@138
|
222 getline(cin, describerURI);
|
cannam@138
|
223 }
|
cannam@138
|
224
|
cannam@138
|
225 cout << describe(plugin, pluginBundleBaseURI, describerURI) << endl;
|
cannam@138
|
226
|
cannam@138
|
227 return 0;
|
cannam@138
|
228 }
|
cannam@138
|
229
|
cannam@138
|
230
|