From 72a286d0e0a074f407d3f73bb2df13cce9517eea Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 19 Jan 2016 16:17:39 +0100 Subject: [PATCH] example_aubioDemo/src/: use onset event --- example_aubioDemo/src/ofApp.cpp | 13 ++++++++++--- example_aubioDemo/src/ofApp.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/example_aubioDemo/src/ofApp.cpp b/example_aubioDemo/src/ofApp.cpp index 5b80bb6..fbbf270 100644 --- a/example_aubioDemo/src/ofApp.cpp +++ b/example_aubioDemo/src/ofApp.cpp @@ -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; +} diff --git a/example_aubioDemo/src/ofApp.h b/example_aubioDemo/src/ofApp.h index 5376022..a907971 100644 --- a/example_aubioDemo/src/ofApp.h +++ b/example_aubioDemo/src/ofApp.h @@ -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; -- 2.11.0