Skip to content

Commit

Permalink
Vamp: Add list-plugins() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 26, 2024
1 parent a56f1ad commit 4bd8174
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
5 changes: 5 additions & 0 deletions auxiliary/scripts/auto-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def generate_class_bindings(cls: NodeClass):
else:
output += ', "{name}"_a'.format(name=parameter.name)
output += ')\n'

# TODO: This needs refactoring into something general-purpose!
if cls.name == "VampAnalysis":
output += '.def("list_plugins", &VampAnalysis::list_plugins, R"pbdoc(list[str]: List the available plugin names.)pbdoc")\n'

output = output[:-1] + ";\n"
return output

Expand Down
1 change: 1 addition & 0 deletions source/include/signalflow/node/analysis/vamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class VampAnalysis : public UnaryOpNode
~VampAnalysis();

virtual void process(Buffer &out, int num_frames);
std::vector<std::string> list_plugins();

protected:
int current_frame;
Expand Down
56 changes: 41 additions & 15 deletions source/src/node/analysis/vamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ using Vamp::HostExt::PluginLoader;
namespace signalflow
{

std::vector<std::string> VampAnalysis::list_plugins()
{
PluginLoader *loader = PluginLoader::getInstance();
std::vector<std::string> plugins = loader->listPlugins();
return plugins;
}

VampAnalysis::VampAnalysis(NodeRef input, std::string plugin_id)
: UnaryOpNode(input)
{
Expand Down Expand Up @@ -43,26 +50,36 @@ VampAnalysis::VampAnalysis(NodeRef input, std::string plugin_id)

this->plugin = loader->loadPlugin(key, this->graph->get_sample_rate(), PluginLoader::ADAPT_ALL);

if (!this->plugin)
throw std::runtime_error("Failed to load Vamp plugin: " + plugin_id);
if (this->plugin)
{
std::cerr << "WARNING: Couldn't find Vamp plugin: " << plugin_id << std::endl;
std::cerr << "Iinformation on finding and installing Vamp plugins: https://www.vamp-plugins.org/download.html" << std::endl;
}
else
{
/*------------------------------------------------------------------------
* Get required output index.
*-----------------------------------------------------------------------*/
Plugin::OutputList outputs = this->plugin->getOutputDescriptors();
this->output_index = -1;

/*------------------------------------------------------------------------
* Get required output index.
*-----------------------------------------------------------------------*/
Plugin::OutputList outputs = this->plugin->getOutputDescriptors();
this->output_index = -1;
for (unsigned int oi = 0; oi < outputs.size(); oi++)
{
if (outputs[oi].identifier == vamp_plugin_output)
{
this->output_index = oi;
break;
}
}

for (unsigned int oi = 0; oi < outputs.size(); oi++)
{
if (outputs[oi].identifier == vamp_plugin_output)
signalflow_debug("Loaded plugin (output index %d)", this->output_index);
bool rv = this->plugin->initialise(1, graph->get_output_buffer_size(), graph->get_output_buffer_size());
// bool rv = this->plugin->initialise(1, 1024, 1024);
if (!rv)
{
this->output_index = oi;
break;
printf("WARNING: Vamp initialisation reported failure\n");
}
}

signalflow_debug("Loaded plugin (output index %d)", this->output_index);
this->plugin->initialise(1, graph->get_output_buffer_size(), graph->get_output_buffer_size());
}

VampAnalysis::~VampAnalysis()
Expand All @@ -72,6 +89,11 @@ VampAnalysis::~VampAnalysis()

void VampAnalysis::process(Buffer &out, int num_frames)
{
if (!this->plugin)
{
return;
}

RealTime rt = RealTime::frame2RealTime(this->current_frame, this->graph->get_sample_rate());
Plugin::FeatureSet features = this->plugin->process(this->input->out.data, rt);
if (features[this->output_index].size())
Expand Down Expand Up @@ -100,6 +122,10 @@ void VampAnalysis::process(Buffer &out, int num_frames)
}
}
}
else
{
// no features extracted
}
}

VampEventExtractor::VampEventExtractor(NodeRef input, std::string plugin_id)
Expand Down
3 changes: 2 additions & 1 deletion source/src/python/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void init_python_nodes(py::module &m)
#ifdef HAVE_VAMP

py::class_<VampAnalysis, Node, NodeRefTemplate<VampAnalysis>>(m, "VampAnalysis", "Feature extraction using the Vamp plugin toolkit.")
.def(py::init<NodeRef, std::string>(), "input"_a = 0.0, "plugin_id"_a = "vamp-example-plugins:spectralcentroid:linearcentroid");
.def(py::init<NodeRef, std::string>(), "input"_a = 0.0, "plugin_id"_a = "vamp-example-plugins:spectralcentroid:linearcentroid")
.def("list_plugins", &VampAnalysis::list_plugins, R"pbdoc(list[str]: List the available plugin names.)pbdoc");

#endif

Expand Down

0 comments on commit 4bd8174

Please sign in to comment.