meet rhythm ferret: cute, furry and always on time (ardour build now requires fftw3...
[ardour.git] / libs / ardour / transient_detector.cc
1 #include <ardour/transient_detector.h>
2
3 #include "i18n.h"
4
5 using namespace Vamp;
6 using namespace ARDOUR;
7 using namespace std;
8
9 TransientDetector::TransientDetector (float sr)
10         : AudioAnalyser (sr, X_("vamp-example-plugins:percussiononsets"))
11 {
12         cerr << "plugin in constructor = " << plugin << endl;
13 }
14
15 TransientDetector::~TransientDetector()
16 {
17 }
18
19 int
20 TransientDetector::run (const std::string& path, boost::shared_ptr<Readable> src, uint32_t channel, vector<nframes64_t>& results)
21 {
22         current_results = &results;
23         int ret = analyse (path, src, channel);
24         current_results = 0;
25         return ret;
26 }
27
28 int
29 TransientDetector::use_features (Plugin::FeatureSet& features, ostream* out)
30 {
31         const Plugin::FeatureList& fl (features[0]);
32
33         for (Plugin::FeatureList::const_iterator f = fl.begin(); f != fl.end(); ++f) {
34                 
35                 if ((*f).hasTimestamp) {
36
37                         if (out) {
38                                 (*out) << (*f).timestamp.toString() << endl;
39                         } 
40
41                         current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, sample_rate));
42                 }
43         }
44
45         return 0;
46 }
47
48 void
49 TransientDetector::set_threshold (float val)
50 {
51         if (plugin) {
52                 plugin->setParameter ("threshold", val);
53         }
54 }
55
56 void
57 TransientDetector::set_sensitivity (float val)
58 {
59         if (plugin) {
60                 plugin->setParameter ("sensitivity", val);
61         }
62 }