summaryrefslogtreecommitdiff
path: root/rotord/vampHost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/vampHost.cpp')
-rw-r--r--rotord/vampHost.cpp269
1 files changed, 190 insertions, 79 deletions
diff --git a/rotord/vampHost.cpp b/rotord/vampHost.cpp
index c7e5691..947e49a 100644
--- a/rotord/vampHost.cpp
+++ b/rotord/vampHost.cpp
@@ -2,7 +2,6 @@
int vampHost::runPlugin(string myname, string soname, string id, string output,
int outputNo, string inputFile, ostream& out, bool useFrames)
-
{
PluginLoader *loader = PluginLoader::getInstance();
@@ -210,69 +209,9 @@ done:
return returnValue;
}
-void vampHost::printFeatures(int frame, int sr, int output,
- Plugin::FeatureSet features, ostream& out, bool useFrames)
+int vampHost::rotorRunPlugin(string soname, string id, string output,
+ int outputNo, string inputFile, vector<float>& out, float& progress)
{
- for (unsigned int i = 0; i < features[output].size(); ++i) {
-
- if (useFrames) {
-
- int displayFrame = frame;
-
- if (features[output][i].hasTimestamp) {
- displayFrame = RealTime::realTime2Frame
- (features[output][i].timestamp, sr);
- }
-
- out << displayFrame;
-
- if (features[output][i].hasDuration) {
- displayFrame = RealTime::realTime2Frame
- (features[output][i].duration, sr);
- out << "," << displayFrame;
- }
-
- out << ":";
-
- } else {
-
- RealTime rt = RealTime::frame2RealTime(frame, sr);
-
- if (features[output][i].hasTimestamp) {
- rt = features[output][i].timestamp;
- }
-
- out << rt.toString();
-
- if (features[output][i].hasDuration) {
- rt = features[output][i].duration;
- out<< "," << rt.toString();
- }
-
- out << ":";
- }
-
- for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
- out<< " " << features[output][i].values[j];
- }
- out << " " << features[output][i].label;
-
- out << endl;
- }
-
-}
-
-int vampHost::QMBeats::process(const string inputFile){
- //vampHost::runPlugin("",settings.soname,settings.filtername, "",0, settings.inputFile, ostr,true);
- //would run the plugin, outputting progress to cerr and the data to ostr
- //
- //we want to run a specific plugin, outputting progress to a mutex-protected passed variable
- //and ultimately passing the data back as a string
- //get the progress as a float
- //how to handle errors?
- string soname="qm-vamp-plugins";
- string filtername="qm-tempotracker";
-
PluginLoader *loader = PluginLoader::getInstance();
PluginLoader::PluginKey key = loader->composePluginKey(soname, id);
@@ -283,15 +222,15 @@ int vampHost::QMBeats::process(const string inputFile){
sndfile = sf_open(inputFile.c_str(), SFM_READ, &sfinfo);
if (!sndfile) {
- cerr << myname << ": ERROR: Failed to open input file \""
+ cerr << ": ERROR: Failed to open input file \""
<< inputFile << "\": " << sf_strerror(sndfile) << endl;
return 1;
}
- Plugin *plugin = loader->loadPlugin(key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
-
+ Plugin *plugin = loader->loadPlugin
+ (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
if (!plugin) {
- cerr << myname << ": ERROR: Failed to load plugin \"" << id
+ cerr << ": ERROR: Failed to load plugin \"" << id
<< "\" from library \"" << soname << "\"" << endl;
sf_close(sndfile);
return 1;
@@ -341,7 +280,8 @@ int vampHost::QMBeats::process(const string inputFile){
float **plugbuf = new float*[channels];
for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2];
- cerr << "Using block size = " << blockSize << ", step size = " << stepSize << endl;
+ cerr << "Using block size = " << blockSize << ", step size = "
+ << stepSize << endl;
// The channel queries here are for informational purposes only --
// a PluginChannelAdapter is being used automatically behind the
@@ -356,7 +296,7 @@ int vampHost::QMBeats::process(const string inputFile){
Plugin::OutputDescriptor od;
int returnValue = 1;
- int _progress = 0;
+ int prog = 0;
RealTime rt;
PluginWrapper *wrapper = 0;
@@ -445,17 +385,14 @@ int vampHost::QMBeats::process(const string inputFile){
rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
- vampHost::printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo, plugin->process(plugbuf, rt),out, useFrames);
+ vampHost::rotorGetFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo,plugin->getRemainingFeatures(), out, progress);
if (sfinfo.frames > 0){
- int pp = _progress;
- _progress = lrintf((float(currentStep * stepSize) / sfinfo.frames) * 100.f);
- if (_progress != pp) {
- cerr << "\r" << _progress << "%";
+ int pp = prog;
+ prog = lrintf((float(currentStep * stepSize) / sfinfo.frames) * 100.f);
+ if (prog != pp ) {
+ cerr << "\r" << progress << "%";
}
- mutex.lock();
- progress = (float(currentStep * stepSize) / sfinfo.frames) * 100.f;
- mutex.unlock();
}
++currentStep;
@@ -466,7 +403,7 @@ int vampHost::QMBeats::process(const string inputFile){
rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate);
- vampHost::printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo,plugin->getRemainingFeatures(), out, useFrames);
+ vampHost::rotorGetFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),sfinfo.samplerate, outputNo,plugin->getRemainingFeatures(), out, progress);
returnValue = 0;
@@ -474,6 +411,180 @@ done:
delete plugin;
sf_close(sndfile);
return returnValue;
+}
+
+void vampHost::printFeatures(int frame, int sr, int output,
+ Plugin::FeatureSet features, ostream& out, bool useFrames)
+{
+ if (features[output].size()) {
+ cout << "." << features[output].size();
+ }
+ for (unsigned int i = 0; i < features[output].size(); ++i) {
+
+ if (useFrames) {
+
+ int displayFrame = frame;
+
+ if (features[output][i].hasTimestamp) {
+ displayFrame = RealTime::realTime2Frame
+ (features[output][i].timestamp, sr);
+ }
+
+ out << displayFrame;
+
+ if (features[output][i].hasDuration) {
+ displayFrame = RealTime::realTime2Frame
+ (features[output][i].duration, sr);
+ out << "," << displayFrame;
+ }
+
+ out << ":";
+
+ } else {
+
+ RealTime rt = RealTime::frame2RealTime(frame, sr);
+
+ if (features[output][i].hasTimestamp) {
+ rt = features[output][i].timestamp;
+ }
+
+ out << rt.toString();
+
+ if (features[output][i].hasDuration) {
+ rt = features[output][i].duration;
+ out<< "," << rt.toString();
+ }
+
+ out << ":";
+ }
+
+ for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
+ out<< " " << features[output][i].values[j];
+ }
+ out << " " << features[output][i].label;
+
+ out << endl;
+ }
+
+}
+
+
+
+void vampHost::rotorGetFeatures(int frame, int sr, int output,Plugin::FeatureSet features, vector<float>& out, float& progress)
+{
+ if (features[output].size()) {
+ cout << "." << features[output].size();
+ }
+ for (unsigned int i = 0; i < features[output].size(); ++i) {
+
+
+
+ int displayFrame = frame;
+
+ if (features[output][i].hasTimestamp) {
+ displayFrame = RealTime::realTime2Frame
+ (features[output][i].timestamp, sr);
+ }
+
+ cout << displayFrame;
+
+
+ cout << endl;
+ }
+
+}
+
+
+int vampHost::QMAnalyser::process(const string inputFile){
+ //vampHost::runPlugin("",settings.soname,settings.filtername, "",0, settings.inputFile, ostr,true);
+ //would run the plugin, outputting progress to cerr and the data to ostr
+ //
+ //int runPlugin(string myname, string soname, string id, string output,int outputNo, string inputFile, ostream& out, bool frames);
+
+
+ //we want to run a specific plugin, outputting progress to a mutex-protected passed variable
+ //and ultimately passing the data back as a string?
+ //or capture it as an array of floats?
+ //get the progress as a float
+ //how to handle errors?
+
+ //debugger fucking up! program stalls after 1 request in debug!?
+
+ string soname="qm-vamp-plugins";
+ string id="qm-tempotracker";
+ string myname="";
+ string output="";
+ int outputNo=0;
+
+ vampHost::rotorRunPlugin(soname,id,output,outputNo,inputFile,beats,progress);
+
+}
- return 0;
+void vampHost::getTimestamps(int output,Plugin::FeatureSet features, vector<float>& out){
+
+ /*
+ vamp-simple-host qm-vamp-plugins:qm-tempotracker 01.wav
+
+ 0.046439908: 156.61 bpm
+ 0.429569160: 156.61 bpm
+ 0.812698412: 161.50 bpm
+ 1.184217686: 152.00 bpm
+
+
+ vamp-simple-host qm-vamp-plugins:qm-segmenter 01.wav
+
+ 0.000000000: 4 4
+ 23.800000000: 6 6
+ 44.600000000: 5 5
+ 55.000000000: 7 7
+ 72.800000000: 1 1
+ 90.600000000: 2 2
+ 109.200000000: 5 5
+ 116.000000000: 3 3
+ 143.800000000: 5 5
+ 153.400000000: 3 3
+ 163.000000000: 8 8
+
+ seems to be FP seconds then another metric
+ for now we can just take the first part
+
+ features[output][i].timestamp is of type RealTime: represents time values to nanosecond precision
+ int sec;
+ int nsec;
+ 1 sec = 10^9 nanosec
+
+ actually maybe this would be the way to go for rotor- avoiding rounding errors etc
+ for now - ideally will get a float representation
+
+ features[output][i].values is a vector of floats + a description
+ WE DON'T CARE ABOUT ANYTHING <.01 seconds
+
+ static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
+
+ get a vector of floats out, using frames, presuming data has a timestamp
+
+
+ this is crashing with "Aborted (core dumped)"
+ if we check for timestamp
+
+ */
+
+ cout << "." << features[output].size();
+
+ //if (!features[output][0].hasTimestamp) {
+ // cerr << output << " channel, getTimestamps: error, featureset doesn't support timestamp" << endl;
+ //}_
+ //else {
+ for (unsigned int i = 0; i < features[output].size(); ++i) {
+ out.push_back( ((float)RealTime::realTime2Frame(features[output][i].timestamp, 1000))*.001f);
+ cout << "feature found.\n";
+ }
+ //}
}
+float vampHost::QMAnalyser::get_progress(){
+ float p;
+ mutex.lock();
+ p=progress;
+ mutex.unlock();
+ return p;
+} \ No newline at end of file