cannam@138: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@138: cannam@138: #include "vamp-sdk/PluginHostAdapter.h" cannam@138: #include "vamp-sdk/hostext/PluginChannelAdapter.h" cannam@138: #include "vamp-sdk/hostext/PluginInputDomainAdapter.h" cannam@138: #include "vamp-sdk/hostext/PluginLoader.h" cannam@138: #include "vamp/vamp.h" cannam@138: cannam@138: #include cannam@138: #include cannam@138: #include cannam@138: #include cannam@138: cannam@138: #include cannam@138: cannam@138: using std::cout; cannam@138: using std::cin; cannam@138: using std::cerr; cannam@138: using std::getline; cannam@138: using std::endl; cannam@138: using std::string; cannam@138: using std::vector; cannam@138: using std::ofstream; cannam@138: using std::ios; cannam@138: cannam@138: using Vamp::HostExt::PluginLoader; cannam@138: using Vamp::Plugin; cannam@138: cannam@138: /* cannam@138: cannam@138: usage: cannam@138: cannam@138: template-generator vamp:aubioonset:onsets cannam@138: cannam@138: */ cannam@138: cannam@138: string programURI = "http://www.vamp-plugins.org/doap.rdf#template-generator"; cannam@138: cannam@138: void usage() cannam@138: { cannam@138: cerr << "usage: template-generator [PLUGIN_BASE_URI YOUR_URI] vamp:soname:plugin[:output]" << endl; cannam@138: exit(2); cannam@138: } cannam@138: cannam@138: template cannam@138: inline string to_string (const T& t) cannam@138: { cannam@138: std::stringstream ss; cannam@138: ss << t; cannam@138: return ss.str(); cannam@138: } cannam@138: cannam@138: string describe_namespaces(Plugin* plugin, string pluginBundleBaseURI) cannam@138: { cannam@138: string res=\ cannam@138: "@prefix rdfs: .\n\ cannam@138: @prefix xsd: .\n\ cannam@139: @prefix vamp: .\n\ cannam@139: @prefix vampex: .\n\ cannam@138: @prefix plugbase: <"+pluginBundleBaseURI+"> .\n\ cannam@138: @prefix owl: .\n\ cannam@138: @prefix dc: .\n\ cannam@138: @prefix af: .\n\ cannam@138: @prefix foaf: .\n\ cannam@138: @prefix cc: .\n\ cannam@138: @prefix thisplug: <"+pluginBundleBaseURI+plugin->getIdentifier()+"#> .\n\ cannam@138: @prefix : <> .\n\n"; cannam@138: cannam@138: return res; cannam@138: } cannam@138: cannam@138: string describe_doc(Plugin* plugin, string describerURI) cannam@138: { cannam@138: string res=\ cannam@138: "<> a vamp:PluginDescription ;\n\ cannam@138: foaf:maker <"+describerURI+"> ;\n\ cannam@138: foaf:maker <"+programURI+"> ;\n\ cannam@138: foaf:primaryTopic plugbase:"+plugin->getIdentifier()+" .\n\n"; cannam@138: return res; cannam@138: } cannam@138: cannam@138: cannam@138: string describe_plugin(Plugin* plugin) cannam@138: { cannam@138: string res=\ cannam@138: "plugbase:"+plugin->getIdentifier()+" a vamp:Plugin ;\n\ cannam@138: dc:title \""+plugin->getName()+"\" ;\n\ cannam@139: vamp:name \""+plugin->getName()+"\" ;\n\ cannam@138: dc:description \""+plugin->getDescription()+"\" ;\n\ cannam@138: foaf:maker [ foaf:name \""+plugin->getMaker()+"\"] ; # FIXME could give plugin author's URI here\n\ cannam@138: cc:license ; \n\ cannam@138: vamp:identifier \""+plugin->getIdentifier()+"\" ;\n\ cannam@138: vamp:vamp_API_version vamp:api_version_"+to_string(plugin->getVampApiVersion())+" ;\n\ cannam@138: owl:versionInfo \""+to_string(plugin->getPluginVersion())+"\" ;\n"; cannam@138: if (plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) cannam@138: res+=" vamp:input_domain vamp:FrequencyDomain ;\n\n"; cannam@138: else cannam@138: res+=" vamp:input_domain vamp:TimeDomain ;\n\n"; cannam@138: cannam@138: cannam@138: Plugin::ParameterList params = plugin->getParameterDescriptors(); cannam@138: for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) cannam@138: res+=" vamp:parameter_descriptor thisplug:param_"+(*i).identifier+" ;\n"; cannam@138: res+="\n"; cannam@138: cannam@138: Plugin::OutputList outputs = plugin->getOutputDescriptors(); cannam@138: for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) cannam@138: res+=" vamp:output_descriptor thisplug:output_"+(*i).identifier+" ;\n"; cannam@138: res+=" .\n"; cannam@138: cannam@138: return res; cannam@138: } cannam@138: cannam@138: string describe_param(Plugin::ParameterDescriptor p) cannam@138: { cannam@138: string res=\ cannam@138: "thisplug:param_"+p.identifier+" a vamp:ParameterDescriptor ;\n\ cannam@138: vamp:identifier \""+p.identifier+"\" ;\n\ cannam@138: dc:title \""+p.name+"\" ;\n\ cannam@138: dc:format \""+p.unit+"\" ;\n\ cannam@139: vamp:min_value "+to_string(p.minValue)+" ;\n\ cannam@139: vamp:max_value "+to_string(p.maxValue)+" ;\n\ cannam@139: vamp:default_value "+to_string(p.defaultValue)+" .\n\n"; cannam@138: return res; cannam@138: } cannam@138: cannam@138: string describe_output(Plugin::OutputDescriptor o) cannam@138: { cannam@138: cannam@139: //we need to distinguish here between different output types: cannam@139: //DenseOutput cannam@139: //SparseOutput cannam@139: //TrackLevelOutput cannam@139: cannam@139: cannam@139: //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. cannam@139: cannam@139: string res; cannam@139: cannam@139: if (o.sampleType == Plugin::OutputDescriptor::VariableSampleRate) cannam@138: { cannam@139: cannam@139: res=\ cannam@139: "thisplug:output_"+o.identifier+" a vamp:SparseOutput ;\n\ cannam@139: vamp:identifier \""+o.identifier+"\" ;\n\ cannam@139: dc:title \""+o.name+"\" ;\n\ cannam@139: dc:description \""+o.description+"\" ;\n\ cannam@139: vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ cannam@139: vamp:is_quantized \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ cannam@139: vamp:unit \""+(o.unit)+"\" ;\n"; cannam@139: cannam@139: cannam@139: cannam@139: // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... cannam@139: if (o.hasFixedBinCount) cannam@139: { cannam@139: res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; cannam@139: res+=" vamp:bin_names ("; cannam@138: cannam@138: unsigned int i; cannam@138: for (i=0; i+1 < o.binNames.size(); i++) cannam@138: res+=" \""+o.binNames[i]+"\""; cannam@138: if (i < o.binNames.size()) cannam@138: res+=" \""+o.binNames[i]+"\""; cannam@138: res+=");\n"; cannam@139: } cannam@139: cannam@139: if (o.isQuantized) cannam@139: { cannam@139: res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; cannam@139: } cannam@139: cannam@139: res+=" vamp:sample_type vamp:VariableSampleRate ;\n"; cannam@138: if (o.sampleRate > 0.0f) cannam@138: res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; cannam@139: cannam@139: } cannam@138: cannam@139: //If we do not have SparseOutput, then we have DenseOutput. TrackLevelOutput can not be inferred from the plugin directly without actually cannam@139: //running the plugin. cannam@139: else{ cannam@139: cannam@139: res=\ cannam@139: "thisplug:output_"+o.identifier+" a vamp:DenseOutput ;\n\ cannam@139: vamp:identifier \""+o.identifier+"\" ;\n\ cannam@139: dc:title \""+o.name+"\" ;\n\ cannam@139: dc:description \""+o.description+"\" ;\n\ cannam@139: vamp:fixed_bin_count \""+(o.hasFixedBinCount == 1 ? "true" : "false")+"\" ;\n\ cannam@139: vamp:is_quantised \""+(o.isQuantized == 1 ? "true" : "false")+"\" ;\n\ cannam@139: vamp:unit \""+(o.unit)+"\" ;\n"; cannam@139: cannam@139: cannam@139: cannam@139: // FIXME ? Bin names may vary based on plugin setup, so including them here might be misleading... cannam@139: if (o.hasFixedBinCount) cannam@139: { cannam@139: res+=" vamp:bin_count "+to_string(o.binCount)+" ;\n"; cannam@139: res+=" vamp:bin_names ("; cannam@139: cannam@139: unsigned int i; cannam@139: for (i=0; i+1 < o.binNames.size(); i++) cannam@139: res+=" \""+o.binNames[i]+"\""; cannam@139: if (i < o.binNames.size()) cannam@139: res+=" \""+o.binNames[i]+"\""; cannam@139: res+=");\n"; cannam@139: } cannam@139: cannam@139: if (o.isQuantized) cannam@139: { cannam@139: res+=" vamp:quantize_step "+to_string(o.quantizeStep)+" ;\n"; cannam@139: } cannam@139: cannam@139: cannam@139: else if (o.sampleType == Plugin::OutputDescriptor::FixedSampleRate) cannam@139: { cannam@139: res+=" vamp:sample_type vamp:FixedSampleRate ;\n"; cannam@139: res+=" vamp:sample_rate "+to_string(o.sampleRate)+" ;\n"; cannam@139: } cannam@139: else if (o.sampleType == Plugin::OutputDescriptor::OneSamplePerStep) cannam@139: res+=" vamp:sample_type vamp:OneSamplePerStep ;\n"; cannam@139: else cannam@139: { cannam@139: cerr<<"Incomprehensible sampleType for output descriptor "+o.identifier<<" !"<getParameterDescriptors(); cannam@138: for (Plugin::ParameterList::const_iterator i = params.begin(); i != params.end(); i++) cannam@138: res += describe_param(*i); cannam@138: cannam@138: Plugin::OutputList outputs = plugin->getOutputDescriptors(); cannam@138: for (Plugin::OutputList::const_iterator i = outputs.begin(); i!= outputs.end(); i++) cannam@138: res += describe_output(*i); cannam@138: cannam@138: return res; cannam@138: } cannam@138: cannam@138: int main(int argc, char **argv) cannam@138: { cannam@138: if (argc != 2 && argc != 4) usage(); cannam@138: cannam@138: std::string pluginName = argv[argc-1]; cannam@138: cannam@138: if (pluginName.substr(0, 5) == "vamp:") { cannam@138: pluginName = pluginName.substr(5); cannam@138: } cannam@138: cannam@138: Vamp::Plugin *plugin = PluginLoader::getInstance()->loadPlugin cannam@138: (pluginName, size_t(44100), PluginLoader::ADAPT_ALL_SAFE); cannam@138: cannam@138: if (!plugin) { cannam@138: cerr << "ERROR: Plugin \"" << pluginName << "\" could not be loaded" << endl; cannam@138: exit(1); cannam@138: } cannam@138: cannam@138: string pluginBundleBaseURI, describerURI; cannam@138: cannam@138: if (argc == 4) cannam@138: { cannam@138: pluginBundleBaseURI = argv[1]; cannam@138: describerURI = argv[2]; cannam@138: } cannam@138: else cannam@138: { cannam@138: cerr << "Please enter the base URI for the plugin bundle : "; cannam@138: getline(cin, pluginBundleBaseURI); cannam@138: cerr << "Please enter your URI : "; cannam@138: getline(cin, describerURI); cannam@138: } cannam@138: cannam@138: cout << describe(plugin, pluginBundleBaseURI, describerURI) << endl; cannam@138: cannam@138: return 0; cannam@138: } cannam@138: cannam@138: