example_aubioDemo/src/: use onset event
authorPaul Brossier <piem@piem.org>
Tue, 19 Jan 2016 15:17:39 +0000 (16:17 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 19 Jan 2016 15:17:39 +0000 (16:17 +0100)
example_aubioDemo/src/ofApp.cpp
example_aubioDemo/src/ofApp.h

index 5b80bb6..fbbf270 100644 (file)
@@ -1,4 +1,5 @@
 #include "ofApp.h"
+#include "ofEventUtils.h"
 
 //--------------------------------------------------------------
 void ofApp::setup(){
@@ -14,6 +15,8 @@ void ofApp::setup(){
     // setup onset object
     onset.setup();
     //onset.setup("mkl", 2 * bufferSize, bufferSize, sampleRate);
+    // listen to onset event
+    ofAddListener(onset.gotOnset, this, &ofApp::onsetEvent);
 
     // setup pitch object
     pitch.setup();
@@ -88,11 +91,9 @@ void ofApp::draw(){
     }
 
     // update onset info
-    if (onset.received()) {
+    if (gotOnset) {
         ofSetColor(ofColor::red);
         ofRect(250 + 90,150,50,50);
-        gotOnset = 1;
-    } else {
         gotOnset = 0;
     }
     onsetNovelty = onset.novelty;
@@ -162,3 +163,9 @@ void ofApp::gotMessage(ofMessage msg){
 void ofApp::dragEvent(ofDragInfo dragInfo){
 
 }
+
+//----
+void ofApp::onsetEvent(float & time) {
+    ofLog() << "got onset at " << time << " s";
+    gotOnset = 1;
+}
index 5376022..a907971 100644 (file)
@@ -26,6 +26,8 @@ class ofApp : public ofBaseApp{
         void audioIn(float * input, int bufferSize, int nChannels);
         void audioOut();
 
+        void onsetEvent(float & time);
+
     private:
         ofxAubioOnset onset;
         ofxAubioPitch pitch;