Update plugin version numbers, remove API version back compatibility (API v1 is now...
authorChris Cannam <cannam@all-day-breakfast.com>
Mon, 9 Jul 2012 14:44:07 +0000 (15:44 +0100)
committerChris Cannam <cannam@all-day-breakfast.com>
Mon, 9 Jul 2012 14:44:07 +0000 (15:44 +0100)
Makefile
libmain.cpp
plugins/Notes.cpp
plugins/Notes.h
plugins/Onset.cpp
plugins/Pitch.cpp
plugins/Pitch.h
plugins/Silence.cpp
plugins/Silence.h
plugins/Tempo.cpp

index f10817d..af32756 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,13 @@ PLUGINDIR     = plugins
 
 # Compile flags
 #
-CXXFLAGS       := -I/Users/cannam/code/inst/include $(CXXFLAGS) -fPIC -DNDEBUG -O2 -Wall -I.
+CXXFLAGS       := -I../ -I../inst/include $(CXXFLAGS) -fPIC -DNDEBUG -O2 -Wall -I.
 
 # Libraries required for the plugins.  Note that we can (and actively
 # want to) statically link libstdc++, because our plugin exposes only
 # a C API so there are no boundary compatibility problems.
 #
-PLUGIN_LIBS    = -L/Users/cannam/code/inst/lib -lvamp-sdk -laubio 
+PLUGIN_LIBS    = -L../inst/lib -lvamp-sdk -laubio 
 
 # Flags required to tell the compiler to make a dynamically loadable object
 #
index 007d209..eeff3ed 100644 (file)
 #include "plugins/Tempo.h"
 #include "plugins/Silence.h"
 
-template <typename P>
-class VersionedPluginAdapter : public Vamp::PluginAdapterBase
-{
-public:
-    VersionedPluginAdapter(unsigned int v) : PluginAdapterBase(), m_v(v) { }
-    virtual ~VersionedPluginAdapter() { }
-
-protected:
-    Vamp::Plugin *createPlugin(float inputSampleRate) {
-        P *p = new P(inputSampleRate, m_v);
-        Vamp::Plugin *plugin = dynamic_cast<Vamp::Plugin *>(p);
-        return plugin;
-    }
-    unsigned int m_v;
-};
-
 static Vamp::PluginAdapter<Onset> onsetAdapter;
 static Vamp::PluginAdapter<Pitch> pitchAdapter;
+static Vamp::PluginAdapter<Notes> notesAdapter;
 static Vamp::PluginAdapter<Tempo> tempoAdapter;
-
-// These two plugins both benefit from the Vamp v2 API if available
-static VersionedPluginAdapter<Notes> *notesAdapter = 0;
-static VersionedPluginAdapter<Silence> *silenceAdapter = 0;
-
-struct Tidy
-{
-    ~Tidy() { delete notesAdapter; delete silenceAdapter; }
-};
-static Tidy tidy;
+static Vamp::PluginAdapter<Silence> silenceAdapter;
 
 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int vampApiVersion,
                                                     unsigned int index)
 {
-    if (vampApiVersion < 1) return 0;
+    if (vampApiVersion < 2) return 0;
 
     switch (index) {
     case  0: return onsetAdapter.getDescriptor();
     case  1: return pitchAdapter.getDescriptor();
+    case  2: return notesAdapter.getDescriptor();
     case  3: return tempoAdapter.getDescriptor();
-
-    case  2: 
-        if (!notesAdapter) {
-            notesAdapter = new VersionedPluginAdapter<Notes>(vampApiVersion);
-        }
-        return notesAdapter->getDescriptor();
-
-    case  4:
-        if (!silenceAdapter) {
-            silenceAdapter = new VersionedPluginAdapter<Silence>(vampApiVersion);
-        }
-        return silenceAdapter->getDescriptor();
-
+    case  4: return silenceAdapter.getDescriptor();
     default: return 0;
     }
 }
index e593d38..30ba640 100644 (file)
@@ -24,9 +24,8 @@ using std::vector;
 using std::cerr;
 using std::endl;
 
-Notes::Notes(float inputSampleRate, unsigned int apiVersion) :
+Notes::Notes(float inputSampleRate) :
     Plugin(inputSampleRate),
-    m_apiVersion(apiVersion),
     m_ibuf(0),
     m_fftgrain(0),
     m_onset(0),
@@ -45,12 +44,6 @@ Notes::Notes(float inputSampleRate, unsigned int apiVersion) :
     m_avoidLeaps(false),
     m_prevPitch(-1)
 {
-    if (apiVersion == 1) {
-        cerr << "vamp-aubio: WARNING: using compatibility version 1 of the Vamp API for note\n"
-             << "tracker plugin: upgrade your host to v2 for proper duration support" << endl;
-    } else {
-        cerr << "vamp-aubio: NOTE: using v2 API for true durations" << endl;
-    }
 }
 
 Notes::~Notes()
@@ -91,8 +84,7 @@ Notes::getMaker() const
 int
 Notes::getPluginVersion() const
 {
-    if (m_apiVersion == 1) return 2;
-    return 3;
+    return 4;
 }
 
 string
@@ -330,17 +322,10 @@ Notes::getOutputDescriptors() const
     d.unit = "Hz";
     d.hasFixedBinCount = true;
 
-    if (m_apiVersion == 1) {
-        d.binCount = 3;
-        d.binNames.push_back("Frequency");
-        d.binNames.push_back("Duration");
-        d.binNames.push_back("Velocity");
-    } else {
-        d.binCount = 2;
-        d.binNames.push_back("Frequency");
-        d.binNames.push_back("Velocity");
-        d.hasDuration = true;
-    }
+    d.binCount = 2;
+    d.binNames.push_back("Frequency");
+    d.binNames.push_back("Velocity");
+    d.hasDuration = true;
 
     d.hasKnownExtents = false;
     d.isQuantized = false;
@@ -448,17 +433,12 @@ Notes::pushNote(FeatureSet &fs, const Vamp::RealTime &offTime)
     feature.timestamp = m_currentOnset - m_delay;
     feature.values.push_back(freq);
 
-    if (m_apiVersion == 1) {
-        feature.values.push_back
-            (Vamp::RealTime::realTime2Frame
-             (offTime, lrintf(m_inputSampleRate)) -
-             Vamp::RealTime::realTime2Frame
-             (m_currentOnset, lrintf(m_inputSampleRate)));
-        feature.hasDuration = false;
-    } else {
-        feature.hasDuration = true;
-        feature.duration = offTime - m_currentOnset;
-    }
+    feature.values.push_back
+        (Vamp::RealTime::realTime2Frame
+         (offTime, lrintf(m_inputSampleRate)) -
+         Vamp::RealTime::realTime2Frame
+         (m_currentOnset, lrintf(m_inputSampleRate)));
+    feature.hasDuration = false;
 
     feature.values.push_back(m_currentLevel);
     fs[0].push_back(feature);
index 66d7f98..9550350 100644 (file)
@@ -27,7 +27,7 @@
 class Notes : public Vamp::Plugin
 {
 public:
-    Notes(float inputSampleRate, unsigned int apiVersion);
+    Notes(float inputSampleRate);
     virtual ~Notes();
 
     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
@@ -57,7 +57,6 @@ public:
     FeatureSet getRemainingFeatures();
 
 protected:
-    int m_apiVersion;
     fvec_t *m_ibuf;
     cvec_t *m_fftgrain;
     fvec_t *m_onset;
index d475b11..daf0567 100644 (file)
@@ -74,7 +74,7 @@ Onset::getMaker() const
 int
 Onset::getPluginVersion() const
 {
-    return 1;
+    return 2;
 }
 
 string
index 191a8a7..054c69c 100644 (file)
@@ -32,8 +32,7 @@ Pitch::Pitch(float inputSampleRate) :
     Plugin(inputSampleRate),
     m_ibuf(0),
     m_pitchdet(0),
-    m_pitchtype(aubio_pitch_yinfft),
-    m_pitchmode(aubio_pitchm_freq),
+    m_pitchtype(PitchYinFFT),
     m_minfreq(getFrequencyForMIDIPitch(32)),
     m_maxfreq(getFrequencyForMIDIPitch(95)),
     m_silence(-90),
@@ -46,7 +45,7 @@ Pitch::Pitch(float inputSampleRate) :
 
 Pitch::~Pitch()
 {
-    if (m_pitchdet) del_aubio_pitchdetection(m_pitchdet);
+    if (m_pitchdet) del_aubio_pitch(m_pitchdet);
     if (m_ibuf) del_fvec(m_ibuf);
 }
 
@@ -77,7 +76,7 @@ Pitch::getMaker() const
 int
 Pitch::getPluginVersion() const
 {
-    return 2;
+    return 3;
 }
 
 string
index 1541f18..f8d7b48 100644 (file)
@@ -20,6 +20,8 @@
 #include <vamp-sdk/Plugin.h>
 #include <aubio/aubio.h>
 
+#include "Types.h"
+
 class Pitch : public Vamp::Plugin
 {
 public:
index 57a0420..084ac02 100644 (file)
@@ -21,9 +21,8 @@ using std::vector;
 using std::cerr;
 using std::endl;
 
-Silence::Silence(float inputSampleRate, unsigned int apiVersion) :
+Silence::Silence(float inputSampleRate) :
     Plugin(inputSampleRate),
-    m_apiVersion(apiVersion),
     m_ibuf(0),
     m_pbuf(0),
     m_tmpptrs(0),
@@ -31,10 +30,6 @@ Silence::Silence(float inputSampleRate, unsigned int apiVersion) :
     m_prevSilent(false),
     m_first(true)
 {
-    if (m_apiVersion == 1) {
-        cerr << "vamp-aubio: WARNING: using compatibility version 1 of the Vamp API for silence\n"
-             << "detector plugin: upgrade your host to v2 for proper duration support" << endl;
-    }
 }
 
 Silence::~Silence()
@@ -71,8 +66,7 @@ Silence::getMaker() const
 int
 Silence::getPluginVersion() const
 {
-    if (m_apiVersion == 1) return 2;
-    return 3;
+    return 4;
 }
 
 string
@@ -157,52 +151,27 @@ Silence::getOutputDescriptors() const
 
     OutputDescriptor d;
 
-    if (m_apiVersion == 1) {
-
-        d.identifier = "silencestart";
-        d.name = "Beginnings of Silent Regions";
-        d.description = "Return a single instant at the point where each silent region begins";
-        d.hasFixedBinCount = true;
-        d.binCount = 0;
-        d.hasKnownExtents = false;
-        d.sampleType = OutputDescriptor::VariableSampleRate;
-        d.sampleRate = 0;
-        list.push_back(d);
-
-        d.identifier = "silenceend";
-        d.name = "Ends of Silent Regions";
-        d.description = "Return a single instant at the point where each silent region ends";
-        d.hasFixedBinCount = true;
-        d.binCount = 0;
-        d.hasKnownExtents = false;
-        d.sampleType = OutputDescriptor::VariableSampleRate;
-        d.sampleRate = 0;
-        list.push_back(d);
-
-    } else {
+    d.identifier = "silent";
+    d.name = "Silent Regions";
+    d.description = "Return an interval covering each silent region";
+    d.hasFixedBinCount = true;
+    d.binCount = 0;
+    d.hasKnownExtents = false;
+    d.sampleType = OutputDescriptor::VariableSampleRate;
+    d.sampleRate = 0;
+    d.hasDuration = true;
+    list.push_back(d);
 
-        d.identifier = "silent";
-        d.name = "Silent Regions";
-        d.description = "Return an interval covering each silent region";
-        d.hasFixedBinCount = true;
-        d.binCount = 0;
-        d.hasKnownExtents = false;
-        d.sampleType = OutputDescriptor::VariableSampleRate;
-        d.sampleRate = 0;
-        d.hasDuration = true;
-        list.push_back(d);
-
-        d.identifier = "noisy";
-        d.name = "Non-Silent Regions";
-        d.description = "Return an interval covering each non-silent region";
-        d.hasFixedBinCount = true;
-        d.binCount = 0;
-        d.hasKnownExtents = false;
-        d.sampleType = OutputDescriptor::VariableSampleRate;
-        d.sampleRate = 0;
-        d.hasDuration = true;
-        list.push_back(d);
-    }
+    d.identifier = "noisy";
+    d.name = "Non-Silent Regions";
+    d.description = "Return an interval covering each non-silent region";
+    d.hasFixedBinCount = true;
+    d.binCount = 0;
+    d.hasKnownExtents = false;
+    d.sampleType = OutputDescriptor::VariableSampleRate;
+    d.sampleRate = 0;
+    d.hasDuration = true;
+    list.push_back(d);
 
     d.identifier = "silencelevel";
     d.name = "Silence Test";
@@ -288,31 +257,21 @@ Silence::process(const float *const *inputBuffers,
 
         feature.values.clear();
 
-        if (m_apiVersion == 1) {
+        if (!m_first) {
+            feature.timestamp = m_lastChange;
+            feature.hasDuration = true;
+            feature.duration = featureStamp - m_lastChange;
             if (silent) {
-                // silencestart feature
-                returnFeatures[0].push_back(feature);
-            } else {
-                // silenceend feature
+                // non-silent regions feature
+                // (becoming silent, so this is a non-silent region)
                 returnFeatures[1].push_back(feature);
-            }
-        } else {
-            if (!m_first) {
-                feature.timestamp = m_lastChange;
-                feature.hasDuration = true;
-                feature.duration = featureStamp - m_lastChange;
-                if (silent) {
-                    // non-silent regions feature
-                    // (becoming silent, so this is a non-silent region)
-                    returnFeatures[1].push_back(feature);
-                } else {
-                    // silent regions feature
-                    // (becoming non-silent, so this is a silent region)
-                    returnFeatures[0].push_back(feature);
-                }                    
-            }
-            m_lastChange = featureStamp;
+            } else {
+                // silent regions feature
+                // (becoming non-silent, so this is a silent region)
+                returnFeatures[0].push_back(feature);
+            }                    
         }
+        m_lastChange = featureStamp;
 
         m_prevSilent = silent;
         m_first = false;
@@ -342,24 +301,15 @@ Silence::getRemainingFeatures()
         Feature feature;
         feature.hasTimestamp = true;
 
-        if (m_apiVersion == 1) {
-            if (m_prevSilent) {
-                // silenceend feature
-                feature.timestamp = m_lastTimestamp;
-                returnFeatures[1].push_back(feature);
-            }
+        feature.timestamp = m_lastChange;
+        feature.hasDuration = true;
+        feature.duration = m_lastTimestamp - m_lastChange;
+        if (m_prevSilent) {
+            // silent regions feature
+            returnFeatures[0].push_back(feature);
         } else {
-
-            feature.timestamp = m_lastChange;
-            feature.hasDuration = true;
-            feature.duration = m_lastTimestamp - m_lastChange;
-            if (m_prevSilent) {
-                // silent regions feature
-                returnFeatures[0].push_back(feature);
-            } else {
-                // non-silent regions feature
-                returnFeatures[1].push_back(feature);
-            }                
+            // non-silent regions feature
+            returnFeatures[1].push_back(feature);
         }
 
         if (!m_prevSilent) {
index eb7c89e..2a3faca 100644 (file)
@@ -23,7 +23,7 @@
 class Silence : public Vamp::Plugin
 {
 public:
-    Silence(float inputSampleRate, unsigned int apiVersion);
+    Silence(float inputSampleRate);
     virtual ~Silence();
 
     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
@@ -53,7 +53,6 @@ public:
     FeatureSet getRemainingFeatures();
 
 protected:
-    unsigned int m_apiVersion;
     fvec_t *m_ibuf;
     fvec_t *m_pbuf;
     smpl_t **m_tmpptrs;
index dcadd10..58b35f0 100644 (file)
@@ -83,7 +83,7 @@ Tempo::getMaker() const
 int
 Tempo::getPluginVersion() const
 {
-    return 1;
+    return 2;
 }
 
 string