Skip to content
Snippets Groups Projects
Commit a831eb95 authored by William Fish's avatar William Fish
Browse files

consolidating code

parent acc336da
Branches
Tags
No related merge requests found
......@@ -13,8 +13,8 @@ void Visualizer::setup() {
// Setup the audio component
//song.loadSound("C:/Users/Billy/Desktop/house.mp3"); PC song
song.loadSound("C:/Users/Billy/Desktop/fftLED/bin/data/techno.mp3"); //Laptop song
song.loadSound("C:/Users/Billy/Desktop/house.mp3"); // PC song
//song.loadSound("C:/Users/Billy/Desktop/fftLED/bin/data/techno.mp3"); //Laptop song
// TESTING TESTING TESTING
song.setVolume(1.0f);
......@@ -24,7 +24,7 @@ void Visualizer::setup() {
// ofSoundStream soundStream;
//ofSoundStream soundStream;
//soundStream.setup(this, 0, 2, 44100, 256, 4);
//soundStream.getSampleRate();
//ofSoundStreamListDevices();
......@@ -40,7 +40,7 @@ void Visualizer::setup() {
ofEnableSmoothing();
ofSetFrameRate(60); //speed up frame rate
serial.setup("COM5", 57600);
//serial.setup("COM5", 57600);
// Allocate drawing buffer
......
#include "beatDetection.h"
//--------------------------------------------------------------
void beatDetection::setup() {
ofSoundStreamSetup(0, 1, this, 44100, beat.getBufferSize(), 4);
}
float beatDetection::returnBeat() {
beat.update(ofGetElapsedTimeMillis());
float selectedBand = beat.getBand(1);
return selectedBand;
}
float beatDetection::returnSnare() {
float selectedBand = beat.getBand(100);
return selectedBand;
}
void beatDetection::audioReceived(float* input, int bufferSize, int nChannels) {
beat.audioReceived(input, bufferSize, nChannels);
}
#pragma once
#include "ofMain.h"
#include "ofxBeat.h"
class beatDetection : public ofBaseApp {
void audioReceived(float*, int, int);
public:
void setup();
float returnBeat();
float returnSnare();
ofxBeat beat;
ofSoundPlayer song;
};
\ No newline at end of file
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main() {
//ofSetupOpenGL(1024, 768, OF_FULLSCREEN); // <-------- setup the GL context
ofSetupOpenGL(1024, 768, OF_WINDOW);
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
\ No newline at end of file
#include "ofApp.h"
//REQUIRES OFXBEATMASTER ADDON FOR OPENFRAMEWORKS
//Reacts to sound from either mic or line in, we use line in for demonstrating the program
//may have bad results on mic in
//--------------------------------------------------------------
void ofApp::setup() {
ofEnableDepthTest();
newBeat.setup(); //initialise FFT / Beat detection
technoVisual.setup();
ofSoundStreamListDevices();
}
//--------------------------------------------------------------
void ofApp::update() {
}
//--------------------------------------------------------------
void ofApp::draw() {
technoVisual.update(newBeat.returnBeat(),newBeat.returnSnare());
}
//--------------------------------------------------------------
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) {
}
\ No newline at end of file
#pragma once
#include "ofMain.h"
#include "ofxBeat.h"
#include "beatDetection.h"
#include "techno.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);
techno technoVisual;
beatDetection newBeat;
};
\ No newline at end of file
#include "techno.h"
techno::techno() {
barWidth = ofGetScreenWidth();
barHeight = ofGetScreenHeight()/64;
}
//--------------------------------------------------------------
void techno::setup() {
for (int i = 0; i < 17; i++) {
bars.push_back(i);
}
}
//--------------------------------------------------------------
void techno::update(float value, float snare_value) {
ofBackgroundGradient(0, 30, OF_GRADIENT_CIRCULAR);
float snareValue = snare_value;
float flooredValue = value;
if (counter < 16) {
ofSetColor(155);
}
if (flooredValue > 2.5 && prevBeat < 2.2) {
counter += g;
if (counter < 32 && counter> 16) {
ofSetColor(ofRandom(0, 255));
}
}
if (value > 5) {
controlVolume = value * 2;
}
else {
controlVolume = value;
}
float z = 5;
if (counter > 32) {
ofSetColor(155);
counter = 32;
g = g*-1;
}
if (counter < 0) {
counter = 0;
g = g*-1;
loops++;
if (loops == 3) {
loops = 0;
}
std::cout << loops << endl;
}
if (loops == 2) {
for (int i = 0; i < counter&&i < 16; i++) {
if ((i < 8 && counter>16) || (i < 8 && g == -1)) {
z = 17;
}
else if ((i >= 8 && counter > 16) || (i >= 8 && g == -1)) {
z = 3;
}
ofDrawRectangle(barWidth / z, 50 + (i * 64), barWidth / 1.6, barHeight);
}
}
else if (loops == 1) {
cam.begin();
if (flooredValue > 2.5) {
glBegin(GL_LINE_LOOP);
glColor3f(0.8f, 0.8f, 0.8f);
glVertex3f(300, -100, 50);
glVertex3f(100, 300, 50);
glVertex3f(-100, -100, 50);
glEnd();
}
cam.end();
}
else if (loops == 0) {
cam.begin();
if (snareValue > 1) {
glBegin(GL_LINE_LOOP);
scale = 50;
}
else {
glBegin(GL_QUADS);
scale = 0;
}
glColor3f(0.6f, 0.6f, 0.6f);
glVertex3f(0 + scale, 0 + scale, 100 + scale);
glVertex3f(0 + scale, -150 + scale, 0 + scale);
glVertex3f(-150 + scale, -150 + scale, 0 + scale);
glVertex3f(-150 + scale, 0 + scale, 0 + scale);
glVertex3f(0 + scale, 0 + scale, 100 + scale);
glVertex3f(-150 + scale, 0 + scale, 0 + scale);
glVertex3f(-150 + scale, 150 + scale, 0 + scale);
glVertex3f(0 + scale, 150 + scale, 0 + scale);
glVertex3f(0 + scale, 0 + scale, 100 + scale);
glVertex3f(0 + scale, 150 + scale, 0 + scale);
glVertex3f(150 + scale, 150 + scale, 0 + scale);
glVertex3f(150 + scale, 0 + scale, 0 + scale);
glVertex3f(0 + scale, 0 + scale, 100 + scale);
glVertex3f(150 + scale, 0 + scale, 0 + scale);
glVertex3f(150 + scale, -150 + scale, 0 + scale);
glVertex3f(0 + scale, -150 + scale, 0 + scale);
glEnd();
cam.end();
}
prevBeat = value;
}
//--------------------------------------------------------------
void techno::draw() {
}
#pragma once
#include "ofMain.h"
#include "ofxBeat.h"
#include "beatDetection.h"
class techno{
public:
techno();
void setup();
void update(float,float);
void draw();
float controlVolume;
private:
int barWidth;
int barHeight;
vector<float> bars;
vector<float> beats;
int counter = 0;
float prevBeat = 0;
ofEasyCam cam;
float scale = 0;
float g = 1;
float loops = 0;
};
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment