From: Paul Brossier Date: Sun, 25 Oct 2015 01:03:35 +0000 (+0100) Subject: example_aubioDemo/: add basic demo application X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=a092aa136a46f7f562c856c9408aa80020390553;p=ofxAubio.git example_aubioDemo/: add basic demo application --- diff --git a/example_aubioDemo/src/main.cpp b/example_aubioDemo/src/main.cpp new file mode 100644 index 0000000..91c6b35 --- /dev/null +++ b/example_aubioDemo/src/main.cpp @@ -0,0 +1,13 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main( ){ + ofSetupOpenGL(750, 250,OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp(new ofApp()); + +} diff --git a/example_aubioDemo/src/ofApp.cpp b/example_aubioDemo/src/ofApp.cpp new file mode 100644 index 0000000..f0aa537 --- /dev/null +++ b/example_aubioDemo/src/ofApp.cpp @@ -0,0 +1,131 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + // set the size of the window + ofSetWindowShape(750, 250); + + int nOutputs = 2; + int nInputs = 2; + //int sampleRate = 44100; + //int bufferSize = 256; + //int nBuffers = 4; + + // setup onset object + onset.setup(); + //onset.setup("mkl", 2 * bufferSize, bufferSize, sampleRate); + + // setup pitch object + pitch.setup(); + //pitch.setup("yinfft", 8 * bufferSize, bufferSize, sampleRate); + + // setup beat object + beat.setup(); + //beat.setup("default", 2 * bufferSize, bufferSize, samplerate); + + ofSoundStreamSetup(nOutputs, nInputs, this); + //ofSoundStreamSetup(nOutputs, nInputs, sampleRate, bufferSize, nBuffers); + //ofSoundStreamListDevices(); + + // setup the gui + int start = 0; + beatGui.setup("", "settings.xml", start + 10, 10); + beatGui.add(bpm.setup( "bpm", 0, 0, 250)); + + start += 250; + onsetGui.setup("", "settings.xml", start + 10, 10); + onsetGui.add(gotOnset.setup( "onset", 0, 0, 250)); + + start += 250; + pitchGui.setup("", "settings.xml", start + 10, 10); + pitchGui.add(midiPitch.setup( "midi pitch", 0, 0, 128)); + pitchGui.add(pitchConfidence.setup( "pitch confidence", 0, 0, 1)); + +} + +void ofApp::audioIn(float * input, int bufferSize, int nChannels){ + // compute onset detection + onset.audioIn(input, bufferSize, nChannels); + // compute pitch detection + pitch.audioIn(input, bufferSize, nChannels); + // compute beat location + beat.audioIn(input, bufferSize, nChannels); +} + +void audioOut(){ +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + // get the latest onset + if (beat.received()) { + ofSetHexColor(0x00FF00); + ofRect(90,100,50,50); + } + if (onset.received()) { + ofSetHexColor(0xFF0000); + ofRect(250 + 90,100,50,50); + gotOnset = 1; + } else { + gotOnset = 0; + } + + ofSetHexColor(0x000000); + pitchConfidence = pitch.pitchConfidence; + if (pitchConfidence > 0.7) midiPitch = pitch.latestPitch; + bpm = beat.bpm; + + pitchGui.draw(); + beatGui.draw(); + onsetGui.draw(); +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} diff --git a/example_aubioDemo/src/ofApp.h b/example_aubioDemo/src/ofApp.h new file mode 100644 index 0000000..bc46cd9 --- /dev/null +++ b/example_aubioDemo/src/ofApp.h @@ -0,0 +1,41 @@ +#pragma once + +#include "ofMain.h" +#include "ofxAubio.h" +#include "ofxGui.h" + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + void audioIn(float * input, int bufferSize, int nChannels); + void audioOut(); + + private: + ofxAubioOnset onset; + ofxAubioPitch pitch; + ofxAubioBeat beat; + + ofxPanel pitchGui; + ofxFloatSlider midiPitch; + ofxFloatSlider pitchConfidence; + + ofxPanel beatGui; + ofxFloatSlider bpm; + + ofxPanel onsetGui; + ofxFloatSlider gotOnset; +};