From: Paul Brossier Date: Tue, 19 Jan 2016 20:50:57 +0000 (+0100) Subject: example_aubioDemo/src/ofApp.h: add beatClass X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=cdd8c5a951316d979bc4b2f8a538d9bbe93393cf;p=ofxAubio.git example_aubioDemo/src/ofApp.h: add beatClass --- diff --git a/example_aubioDemo/src/ofApp.cpp b/example_aubioDemo/src/ofApp.cpp index 4fa0fac..d93dd16 100644 --- a/example_aubioDemo/src/ofApp.cpp +++ b/example_aubioDemo/src/ofApp.cpp @@ -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 << " "; +} diff --git a/example_aubioDemo/src/ofApp.h b/example_aubioDemo/src/ofApp.h index eeaadc8..530d2a2 100644 --- a/example_aubioDemo/src/ofApp.h +++ b/example_aubioDemo/src/ofApp.h @@ -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 index 58785fb..0000000 --- a/src/ofxAubioOnsetClass.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (C) 2015 Paul Brossier - - 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 . - -*/ - -#include "ofxAubioOnsetClass.h" -#include "ofLog.h" - -ofEvent ofxAubioOnsetClass::gotGlobalOnsetClass = ofEvent(); - -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 index 57c7251..0000000 --- a/src/ofxAubioOnsetClass.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (C) 2015 Paul Brossier - - 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 . - -*/ - -#pragma once - -#include -#include -#include "ofEvents.h" -#include "ofxAubioBlock.h" -#include "ofxAubioOnset.h" -#include "ofxAubioMelBands.h" - -class ofxAubioOnsetClass : public ofxAubioBlock { - - public: - - ofxAubioOnsetClass(); - ~ofxAubioOnsetClass(); - - ofEvent gotOnsetClass; - static ofEvent gotGlobalOnsetClass; - - void onsetEvent(float & time); - - ofxAubioOnset *onset; - void setOnset(ofxAubioOnset & onset); - ofxAubioMelBands *bands; - void setBands(ofxAubioMelBands & bands); - - int currentClass; - std::vectorenergies; - - void setup(); - void setup(std::string method, int buf_s, int hop_s, int samplerate); - - void audioIn(); - - void onsetClassify(); - - private: - int lag; - int startSelection; -};