Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / onset_detector.cc
blob28f3a752118752f2bd36bd55e1845af7b6f014b3
1 #include <cmath>
2 #include "ardour/onset_detector.h"
4 #include "i18n.h"
6 using namespace Vamp;
7 using namespace ARDOUR;
8 using namespace std;
10 /* need a static initializer function for this */
12 string OnsetDetector::_op_id = X_("libardourvampplugins:aubioonset:2");
14 OnsetDetector::OnsetDetector (float sr)
15 : AudioAnalyser (sr, X_("libardourvampplugins:aubioonset"))
16 , current_results (0)
18 /* update the op_id */
20 _op_id = X_("libardourvampplugins:aubioonset");
22 // XXX this should load the above-named plugin and get the current version
24 _op_id += ":2";
27 OnsetDetector::~OnsetDetector()
31 string
32 OnsetDetector::operational_identifier()
34 return _op_id;
37 int
38 OnsetDetector::run (const std::string& path, Readable* src, uint32_t channel, AnalysisFeatureList& results)
40 current_results = &results;
41 int ret = analyse (path, src, channel);
43 current_results = 0;
44 return ret;
47 int
48 OnsetDetector::use_features (Plugin::FeatureSet& features, ostream* out)
50 const Plugin::FeatureList& fl (features[0]);
52 for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
54 if ((*f).hasTimestamp) {
56 if (out) {
57 (*out) << (*f).timestamp.toString() << endl;
60 current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (framecnt_t) floor(sample_rate)));
64 return 0;
67 void
68 OnsetDetector::set_silence_threshold (float val)
70 if (plugin) {
71 plugin->setParameter ("silencethreshold", val);
75 void
76 OnsetDetector::set_peak_threshold (float val)
78 if (plugin) {
79 plugin->setParameter ("peakpickthreshold", val);
83 void
84 OnsetDetector::set_function (int val)
86 if (plugin) {
87 plugin->setParameter ("onsettype", (float) val);
91 void
92 OnsetDetector::cleanup_onsets (AnalysisFeatureList& t, float sr, float gap_msecs)
94 if (t.empty()) {
95 return;
98 t.sort ();
100 /* remove duplicates or other things that are too close */
102 AnalysisFeatureList::iterator i = t.begin();
103 AnalysisFeatureList::iterator f, b;
104 const framecnt_t gap_frames = (framecnt_t) floor (gap_msecs * (sr / 1000.0));
106 while (i != t.end()) {
108 // move front iterator to just past i, and back iterator the same place
110 f = i;
111 ++f;
112 b = f;
114 // move f until we find a new value that is far enough away
116 while ((f != t.end()) && (((*f) - (*i)) < gap_frames)) {
117 ++f;
120 i = f;
122 // if f moved forward from b, we had duplicates/too-close points: get rid of them
124 if (b != f) {
125 t.erase (b, f);