summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xvamphost/config.make2
-rw-r--r--vamphost/src/ofxVamphost.cpp318
-rw-r--r--vamphost/src/ofxVamphost.h10
-rw-r--r--vamphost/src/testApp.cpp34
-rw-r--r--vamphost/src/testApp.h4
5 files changed, 67 insertions, 301 deletions
diff --git a/vamphost/config.make b/vamphost/config.make
index da65b3e..aff87ad 100755
--- a/vamphost/config.make
+++ b/vamphost/config.make
@@ -11,7 +11,7 @@ OF_ROOT = /home/tim/workspace/openFrameworks
# for example search paths like:
# USER_CFLAGS = -I src/objects
-USER_CFLAGS = -fpermissive
+USER_CFLAGS = -fpermissive -std=c++11
# USER_LDFLAGS allows to pass custom flags to the linker
diff --git a/vamphost/src/ofxVamphost.cpp b/vamphost/src/ofxVamphost.cpp
index 6d2cefc..4a8ade6 100644
--- a/vamphost/src/ofxVamphost.cpp
+++ b/vamphost/src/ofxVamphost.cpp
@@ -1,317 +1,53 @@
#include "ofxVamphost.h"
using namespace std;
+using namespace Vamp;
int Vamphost::getRT(){
return rt.msec();
}
-enum Verbosity {
- PluginIds,
- PluginOutputIds,
- PluginInformation,
- PluginInformationDetailed
-};
-
-static string header(string text, int level)
-{
- string out = '\n' + text + '\n';
- for (size_t i = 0; i < text.length(); ++i) {
- out += (level == 1 ? '=' : level == 2 ? '-' : '~');
- }
- out += '\n';
- return out;
-}
-void printPluginPath(bool verbose)
-{
- if (verbose) {
- cout << "\nVamp plugin search path: ";
- }
-
- vector<string> path = PluginHostAdapter::getPluginPath();
- for (size_t i = 0; i < path.size(); ++i) {
- if (verbose) {
- cout << "[" << path[i] << "]";
- } else {
- cout << path[i] << endl;
- }
- }
-
- if (verbose) cout << endl;
+Vamphost::Vamphost(){
+ loader = PluginLoader::getInstance();
+ list=loader->listPlugins();
+ for (auto p: list) {
+ cerr<<p<<endl;
+ }
}
-void enumeratePlugins(Verbosity verbosity)
-{
- PluginLoader *loader = PluginLoader::getInstance();
-
- if (verbosity == PluginInformation) {
- cout << "\nVamp plugin libraries found in search path:" << endl;
- }
-
- vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
- typedef multimap<string, PluginLoader::PluginKey>
- LibraryMap;
- LibraryMap libraryMap;
-
- for (size_t i = 0; i < plugins.size(); ++i) {
- string path = loader->getLibraryPathForPlugin(plugins[i]);
- libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
- }
-
- string prevPath = "";
- int index = 0;
-
- for (LibraryMap::iterator i = libraryMap.begin();
- i != libraryMap.end(); ++i) {
-
- string path = i->first;
- PluginLoader::PluginKey key = i->second;
-
- if (path != prevPath) {
- prevPath = path;
- index = 0;
- if (verbosity == PluginInformation) {
- cout << "\n " << path << ":" << endl;
- } else if (verbosity == PluginInformationDetailed) {
- string::size_type ki = i->second.find(':');
- string text = "Library \"" + i->second.substr(0, ki) + "\"";
- cout << "\n" << header(text, 1);
- }
- }
-
- Plugin *plugin = loader->loadPlugin(key, 48000);
- if (plugin) {
-
- char c = char('A' + index);
- if (c > 'Z') c = char('a' + (index - 26));
-
- PluginLoader::PluginCategoryHierarchy category =
- loader->getPluginCategory(key);
- string catstr;
- if (!category.empty()) {
- for (size_t ci = 0; ci < category.size(); ++ci) {
- if (ci > 0) catstr += " > ";
- catstr += category[ci];
- }
- }
-
- if (verbosity == PluginInformation) {
-
- cout << " [" << c << "] [v"
- << plugin->getVampApiVersion() << "] "
- << plugin->getName() << ", \""
- << plugin->getIdentifier() << "\"" << " ["
- << plugin->getMaker() << "]" << endl;
-
- if (catstr != "") {
- cout << " > " << catstr << endl;
- }
-
- if (plugin->getDescription() != "") {
- cout << " - " << plugin->getDescription() << endl;
- }
-
- } else if (verbosity == PluginInformationDetailed) {
-
- cout << header(plugin->getName(), 2);
- cout << " - Identifier: "
- << key << endl;
- cout << " - Plugin Version: "
- << plugin->getPluginVersion() << endl;
- cout << " - Vamp API Version: "
- << plugin->getVampApiVersion() << endl;
- cout << " - Maker: \""
- << plugin->getMaker() << "\"" << endl;
- cout << " - Copyright: \""
- << plugin->getCopyright() << "\"" << endl;
- cout << " - Description: \""
- << plugin->getDescription() << "\"" << endl;
- cout << " - Input Domain: "
- << (plugin->getInputDomain() == Vamp::Plugin::TimeDomain ?
- "Time Domain" : "Frequency Domain") << endl;
- cout << " - Default Step Size: "
- << plugin->getPreferredStepSize() << endl;
- cout << " - Default Block Size: "
- << plugin->getPreferredBlockSize() << endl;
- cout << " - Minimum Channels: "
- << plugin->getMinChannelCount() << endl;
- cout << " - Maximum Channels: "
- << plugin->getMaxChannelCount() << endl;
-
- } else if (verbosity == PluginIds) {
- cout << "vamp:" << key << endl;
- }
-
- Plugin::OutputList outputs =
- plugin->getOutputDescriptors();
-
- if (verbosity == PluginInformationDetailed) {
-
- Plugin::ParameterList params = plugin->getParameterDescriptors();
- for (size_t j = 0; j < params.size(); ++j) {
- Plugin::ParameterDescriptor &pd(params[j]);
- cout << "\nParameter " << j+1 << ": \"" << pd.name << "\"" << endl;
- cout << " - Identifier: " << pd.identifier << endl;
- cout << " - Description: \"" << pd.description << "\"" << endl;
- if (pd.unit != "") {
- cout << " - Unit: " << pd.unit << endl;
- }
- cout << " - Range: ";
- cout << pd.minValue << " -> " << pd.maxValue << endl;
- cout << " - Default: ";
- cout << pd.defaultValue << endl;
- if (pd.isQuantized) {
- cout << " - Quantize Step: "
- << pd.quantizeStep << endl;
- }
- if (!pd.valueNames.empty()) {
- cout << " - Value Names: ";
- for (size_t k = 0; k < pd.valueNames.size(); ++k) {
- if (k > 0) cout << ", ";
- cout << "\"" << pd.valueNames[k] << "\"";
- }
- cout << endl;
- }
- }
-
- if (outputs.empty()) {
- cout << "\n** Note: This plugin reports no outputs!" << endl;
- }
- for (size_t j = 0; j < outputs.size(); ++j) {
- Plugin::OutputDescriptor &od(outputs[j]);
- cout << "\nOutput " << j+1 << ": \"" << od.name << "\"" << endl;
- cout << " - Identifier: " << od.identifier << endl;
- cout << " - Description: \"" << od.description << "\"" << endl;
- if (od.unit != "") {
- cout << " - Unit: " << od.unit << endl;
- }
- if (od.hasFixedBinCount) {
- cout << " - Default Bin Count: " << od.binCount << endl;
- }
- if (!od.binNames.empty()) {
- bool have = false;
- for (size_t k = 0; k < od.binNames.size(); ++k) {
- if (od.binNames[k] != "") {
- have = true; break;
- }
- }
- if (have) {
- cout << " - Bin Names: ";
- for (size_t k = 0; k < od.binNames.size(); ++k) {
- if (k > 0) cout << ", ";
- cout << "\"" << od.binNames[k] << "\"";
- }
- cout << endl;
- }
- }
- if (od.hasKnownExtents) {
- cout << " - Default Extents: ";
- cout << od.minValue << " -> " << od.maxValue << endl;
- }
- if (od.isQuantized) {
- cout << " - Quantize Step: "
- << od.quantizeStep << endl;
- }
- cout << " - Sample Type: "
- << (od.sampleType ==
- Plugin::OutputDescriptor::OneSamplePerStep ?
- "One Sample Per Step" :
- od.sampleType ==
- Plugin::OutputDescriptor::FixedSampleRate ?
- "Fixed Sample Rate" :
- "Variable Sample Rate") << endl;
- if (od.sampleType !=
- Plugin::OutputDescriptor::OneSamplePerStep) {
- cout << " - Default Rate: "
- << od.sampleRate << endl;
- }
- cout << " - Has Duration: "
- << (od.hasDuration ? "Yes" : "No") << endl;
- }
- }
-
- if (outputs.size() > 1 || verbosity == PluginOutputIds) {
- for (size_t j = 0; j < outputs.size(); ++j) {
- if (verbosity == PluginInformation) {
- cout << " (" << j << ") "
- << outputs[j].name << ", \""
- << outputs[j].identifier << "\"" << endl;
- if (outputs[j].description != "") {
- cout << " - "
- << outputs[j].description << endl;
- }
- } else if (verbosity == PluginOutputIds) {
- cout << "vamp:" << key << ":" << outputs[j].identifier << endl;
- }
- }
- }
-
- ++index;
-
- delete plugin;
- }
- }
-
- if (verbosity == PluginInformation ||
- verbosity == PluginInformationDetailed) {
- cout << endl;
- }
+int Vamphost::init(int whichplugin,const int &_channels,const int &_rate,const int &_outputNo,const string &_output){
+ key = list[whichplugin];
+ init(_channels,_rate,_outputNo,_output);
}
-void printPluginCategoryList()
-{
- PluginLoader *loader = PluginLoader::getInstance();
-
- vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
-
- set<string> printedcats;
-
- for (size_t i = 0; i < plugins.size(); ++i) {
-
- PluginLoader::PluginKey key = plugins[i];
-
- PluginLoader::PluginCategoryHierarchy category =
- loader->getPluginCategory(key);
-
- Plugin *plugin = loader->loadPlugin(key, 48000);
- if (!plugin) continue;
-
- string catstr = "";
-
- if (category.empty()) catstr = '|';
- else {
- for (size_t j = 0; j < category.size(); ++j) {
- catstr += category[j];
- catstr += '|';
- if (printedcats.find(catstr) == printedcats.end()) {
- std::cout << catstr << std::endl;
- printedcats.insert(catstr);
- }
- }
- }
-
- std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
- }
-}
int Vamphost::init(const string &soname,const string &id,const int &_channels,const int &_rate,const int &_outputNo,const string &_output){
-
- //stuff that only happens once
+ key = loader->composePluginKey(soname, id);
+ init(_channels,_rate,_outputNo,_output);
+}
+int Vamphost::init(const int &_channels,const int &_rate,const int &_outputNo,const string &_output){
channels =_channels;
rate=_rate;
outputNo=_outputNo;
output=_output;
+}
+int Vamphost::init(int whichplugin){
+ key = list[whichplugin];
+ init();
+}
+int Vamphost::init(){
+ //stuff that only happens once
+
features[0.0f]=0;
- loader = PluginLoader::getInstance();
- key = loader->composePluginKey(soname, id);
- plugin = loader->loadPlugin(key, _rate, PluginLoader::ADAPT_ALL_SAFE);
+
+
+ plugin = loader->loadPlugin(key, rate, PluginLoader::ADAPT_ALL_SAFE);
if (!plugin) {
- cerr << ": ERROR: Failed to load plugin \"" << id
- << "\" from library \"" << soname << "\"" << endl;
+ cerr << ": ERROR: Failed to load plugin \"" << key<< "\"" << endl;
return -1;
}
@@ -455,6 +191,8 @@ void Vamphost::process_frame(float *data,int samples_in_frame){
Plugin::FeatureSet feat=plugin->process(plugbuf, rt);
+ //if (feat[outputNo].size()>0) cerr<<"BEAT"<<endl;
+
for (unsigned int i = 0; i < feat[outputNo].size(); ++i) {
features[((float)feat[outputNo][i].timestamp.sec)+(((float)feat[outputNo][i].timestamp.nsec)*.000000001)]=featureNo;
featureNo++;
diff --git a/vamphost/src/ofxVamphost.h b/vamphost/src/ofxVamphost.h
index 2c618eb..245b7ff 100644
--- a/vamphost/src/ofxVamphost.h
+++ b/vamphost/src/ofxVamphost.h
@@ -21,7 +21,12 @@ using Vamp::HostExt::PluginInputDomainAdapter;
class Vamphost{
//can load any vamp analysis plugin and present its data with a unified interface
public:
+ Vamphost();
int init(const std::string &soname,const std::string &id,const int &_channels,const int &_rate,const int &_outputNo=0,const std::string &_output="");
+ int init(int whichplugin,const int &_channels,const int &_rate,const int &_outputNo=0,const std::string &_output="");
+ int init(const int &_channels,const int &_rate,const int &_outputNo=0,const std::string &_output="");
+ int init(int whichplugin);
+ int init();
void process_frame(float *data,int samples_in_frame);
void cleanup();
@@ -33,10 +38,13 @@ class Vamphost{
float avg;
int num;
int numFeat;
+
+ PluginLoader::PluginKey key;
+ PluginLoader::PluginKeyList list;
private:
+
PluginLoader *loader;
- PluginLoader::PluginKey key;
Plugin *plugin;
RealTime rt;
int channels,bits,samples,rate;
diff --git a/vamphost/src/testApp.cpp b/vamphost/src/testApp.cpp
index d9cbfe7..fabf712 100644
--- a/vamphost/src/testApp.cpp
+++ b/vamphost/src/testApp.cpp
@@ -35,7 +35,9 @@ void testApp::setup() {
string soname="vamp-example-plugins.so";
string id="percussiononsets";
- int bufferSize = vamphost.init(soname,id,channels,rate,outputNo);
+ whichplugin=0;
+
+ int bufferSize = vamphost.init(whichplugin,channels,rate,outputNo);
left.assign(bufferSize, 0.0);
@@ -54,6 +56,10 @@ void testApp::setup() {
ofSetFrameRate(25);
+
+
+
+
}
@@ -160,6 +166,7 @@ ofSetColor(225);
ofSetColor(225);
string reportString = "buffers received: "+ofToString(bufferCounter)+"\ndraw routines called: "+ofToString(drawCounter)+"\nticks: " + ofToString(soundStream.getTickCount());
reportString +="\nfeatures found: "+ofToString(vamphost.numFeat)+" average signal: "+ofToString(vamphost.avg)+" samples: "+ofToString(vamphost.num);
+ reportString +=vamphost.key;
ofDrawBitmapString(reportString, 32, 589);
}
@@ -206,12 +213,27 @@ void testApp::exit(){
//--------------------------------------------------------------
void testApp::keyPressed(int key){
- if( key == 's' ){
- soundStream.start();
- }
- if( key == 'e' ){
- soundStream.stop();
+ switch (key) {
+ case 's':
+ case 'S':
+ soundStream.start();
+ break;
+ case 'e':
+ case 'E':
+ soundStream.stop();
+ break;
+ case OF_KEY_UP:
+ whichplugin=((whichplugin+1)%vamphost.list.size());
+ vamphost.cleanup();
+ vamphost.init(whichplugin);
+ break;
+ case OF_KEY_DOWN:
+ whichplugin=whichplugin>0?whichplugin-1:vamphost.list.size()-1;
+ vamphost.cleanup();
+ vamphost.init(whichplugin);
+ break;
+
}
}
diff --git a/vamphost/src/testApp.h b/vamphost/src/testApp.h
index 390071a..112f697 100644
--- a/vamphost/src/testApp.h
+++ b/vamphost/src/testApp.h
@@ -3,7 +3,6 @@
#include "ofMain.h"
#include "ofxVamphost.h"
-#include "ofxXmlSettings.h"
class testApp : public ofBaseApp{
@@ -37,8 +36,7 @@ public:
ofSoundStream soundStream;
Vamphost vamphost;
- vector<map<string,vector<string> > > pluginList;
-
+ int whichplugin;
};