example_aubioDemo/src/ofApp.h: add beatClass
authorPaul Brossier <piem@piem.org>
Tue, 19 Jan 2016 20:50:57 +0000 (21:50 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 19 Jan 2016 20:50:57 +0000 (21:50 +0100)
example_aubioDemo/src/ofApp.cpp
example_aubioDemo/src/ofApp.h
src/ofxAubioOnsetClass.cpp [deleted file]
src/ofxAubioOnsetClass.h [deleted file]

index 4fa0fac..d93dd16 100644 (file)
@@ -34,10 +34,19 @@ void ofApp::setup(){
 
     // setup onsetClass object
     onsetClass.setup();
-    onsetClass.setOnset(onset);
     onsetClass.setBands(bands);
+
+    onsetClass.setOnset(onset);
     ofAddListener(onsetClass.gotOnsetClass, this, &ofApp::onsetClassEvent);
 
+    onsetClass.setBeat(beat);
+    ofAddListener(onsetClass.gotBeatClass, this, &ofApp::beatClassEvent);
+
+    beatClass.setup();
+    beatClass.setBeat(beat);
+    beatClass.setBands(bands);
+    ofAddListener(beatClass.gotBeatClass, this, &ofApp::beatClassEvent);
+
     ofSoundStreamSetup(nOutputs, nInputs, this);
     //ofSoundStreamSetup(nOutputs, nInputs, sampleRate, bufferSize, nBuffers);
     //ofSoundStreamListDevices();
@@ -137,7 +146,11 @@ void ofApp::draw(){
     }
     bandPlot.draw();
 
+    // onset class
     ofRect(250 + 190 + onsetClass.currentClass * 7, 150, 50, 50);
+
+    // beat class
+    ofRect(190 + beatClass.currentClass * 7, 150, 50, 50);
 }
 
 //--------------------------------------------------------------
@@ -207,3 +220,8 @@ void ofApp::tatumEvent(int & t) {
 void ofApp::onsetClassEvent(int & t) {
     //ofLog() << "got onset class event at " << t << " ";
 }
+
+//---
+void ofApp::beatClassEvent(int & t) {
+    ofLog() << "got beat class event of class " << t << " ";
+}
index eeaadc8..530d2a2 100644 (file)
@@ -30,13 +30,15 @@ class ofApp : public ofBaseApp{
         void beatEvent(float & time);
         void tatumEvent(int & t);
         void onsetClassEvent(int & t);
+        void beatClassEvent(int & t);
 
     private:
         ofxAubioOnset onset;
         ofxAubioPitch pitch;
         ofxAubioBeat beat;
         ofxAubioMelBands bands;
-        ofxAubioOnsetClass onsetClass;
+        ofxAubioAttackClass onsetClass;
+        ofxAubioAttackClass beatClass;
 
         ofxPanel pitchGui;
         ofxFloatSlider midiPitch;
diff --git a/src/ofxAubioOnsetClass.cpp b/src/ofxAubioOnsetClass.cpp
deleted file mode 100644 (file)
index 58785fb..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
-
-  This file is part of ofxAubio.
-
-  ofxAubio is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  aubio is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "ofxAubioOnsetClass.h"
-#include "ofLog.h"
-
-ofEvent<int> ofxAubioOnsetClass::gotGlobalOnsetClass = ofEvent<int>();
-
-ofxAubioOnsetClass::ofxAubioOnsetClass()
-    : bands(NULL)
-{
-    lag = 3;
-}
-
-ofxAubioOnsetClass::~ofxAubioOnsetClass()
-{
-}
-
-void ofxAubioOnsetClass::setup()
-{
-    setup("default", 512, 256, 44100);
-}
-void ofxAubioOnsetClass::setup(string method, int buf_s, int hop_s, int samplerate)
-{
-    //setup("default", 512, 256, 44100);
-}
-
-void ofxAubioOnsetClass::setBands(ofxAubioMelBands & _bands) {
-    bands = &_bands;
-}
-
-void ofxAubioOnsetClass::setOnset(ofxAubioOnset & _onset) {
-    onset = &_onset;
-    ofAddListener(onset->gotOnset, this, &ofxAubioOnsetClass::onsetEvent);
-}
-
-void ofxAubioOnsetClass::audioIn()
-{
-    energies.push_back(bands->energies);
-    if (energies.size() > lag - 1) {
-        energies.erase (energies.begin());
-    }
-    // hack to add a counter to delay lag * blockSize frames
-    if (startSelection > 0) {
-        startSelection--;
-        if (startSelection == 1) {
-            onsetClassify();
-        }
-    }
-}
-
-void ofxAubioOnsetClass::onsetEvent(float & time)
-{
-    //ofLog() << "ofxAubioOnsetClass got onset at " << time;
-    // hack to add a counter to delay lag * blockSize frames
-    int delay = 0;
-    startSelection = lag + delay;
-}
-
-void ofxAubioOnsetClass::onsetClassify() {
-    if (energies.size() == lag - 1) {
-        int max_band = 0;
-        float max_energy = 0;
-        for (int i = 0; i < bands->nBands; i ++) {
-            float band_sum = 0;
-            for (int j = 0; j < energies.size(); j ++) {
-                band_sum += energies[j][i];
-            }
-            if (max_energy < band_sum) {
-                max_energy = band_sum;
-                max_band = i;
-            }
-        }
-        currentClass = max_band;
-        ofNotifyEvent(gotOnsetClass, currentClass, this);
-        ofNotifyEvent(gotGlobalOnsetClass, currentClass);
-    }
-}
diff --git a/src/ofxAubioOnsetClass.h b/src/ofxAubioOnsetClass.h
deleted file mode 100644 (file)
index 57c7251..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
-
-  This file is part of ofxAubio.
-
-  ofxAubio is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  aubio is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#pragma once
-
-#include <iostream>
-#include <aubio/aubio.h>
-#include "ofEvents.h"
-#include "ofxAubioBlock.h"
-#include "ofxAubioOnset.h"
-#include "ofxAubioMelBands.h"
-
-class ofxAubioOnsetClass : public ofxAubioBlock {
-
-    public:
-
-       ofxAubioOnsetClass();
-       ~ofxAubioOnsetClass();
-
-       ofEvent<int> gotOnsetClass;
-       static ofEvent<int> gotGlobalOnsetClass;
-
-       void onsetEvent(float & time);
-
-       ofxAubioOnset *onset;
-       void setOnset(ofxAubioOnset & onset);
-       ofxAubioMelBands *bands;
-       void setBands(ofxAubioMelBands & bands);
-
-       int currentClass;
-       std::vector<float *>energies;
-
-       void setup();
-       void setup(std::string method, int buf_s, int hop_s, int samplerate);
-
-       void audioIn();
-
-       void onsetClassify();
-
-    private:
-       int lag;
-       int startSelection;
-};