summaryrefslogtreecommitdiff
path: root/gui/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main.cpp2
-rw-r--r--gui/src/ofApp.cpp304
-rw-r--r--gui/src/ofApp.h85
3 files changed, 339 insertions, 52 deletions
diff --git a/gui/src/main.cpp b/gui/src/main.cpp
index 763fb73..1221d37 100644
--- a/gui/src/main.cpp
+++ b/gui/src/main.cpp
@@ -21,7 +21,7 @@ int main(int argc, char *argv[]){
mainWindow->setVerticalSync(false);
settings.width = 600;
- settings.height = 900;
+ settings.height = 1000;
settings.setPosition(ofVec2f(0,0));
settings.resizable = true;
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index 14e669d..e684254 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -5,13 +5,20 @@ const ofPoint outputWindowSize=ofPoint(1200,900);
const float guiScale=560.0f/4096.0f;
+string sourcenames[5]={
+ "TEST",
+// "NDI",
+ "Player",
+ "SVG outlines",
+ "SVG segmenters",
+ "Audio"
+};
+
//--------------------------------------------------------------
void ofApp::setup(){
- gui.setup();
-
- source=SVG_outlines;
-
+ source=Audio;
+/*
//==================================================== ofxNDI
senderName[0] = 0; // The sender name used for display
@@ -26,33 +33,74 @@ void ofApp::setup(){
// For received frame fps calculations - independent of the rendering rate
startTime = lastTime = frameTime = 0;
fps = frameRate = 1; // starting value
-
- //============================ GUI
-
- gui.add(contour_threshold.setup("threshold", 140, 0, 255));
- gui.add(contour_simplify.setup("simplify", 0.8, 0.0, 1.0));
- gui.add(contour_useColour.setup("use colour", true));
- gui.add(laser_R.setup("red", 140, 0, 255));
- gui.add(laser_G.setup("green", 140, 0, 255));
- gui.add(laser_B.setup("blue", 140, 0, 255));
- gui.add(laser_intensity.setup("intensity", 30, 0, 255));
- gui.add(laser_points.setup("points", 20000, 0, 40000));
- gui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0));
- gui.add(shapes_randomise.setup("randomise shapes", true));
- gui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8));
- gui.add(shapes_duration.setup("shape duration", 5, 0, 25));
- gui.add(use_mask.setup("use mask", true));
- gui.add(invert_mask.setup("invert mask", false));
- gui.add(use_segmenter.setup("use segmenter", false));
- gui.add(segmenter_speed.setup("segmenter speed", 0.2, -1.0, 1.0));
- gui.add(segmenter_length.setup("segmenter length", 0.2, 0.0, 1.0));
- gui.add(segmenter_number.setup("segmenter number", 1, 1, 8));
- gui.add(use_rotate.setup("XF rotate", false));
- gui.add(xf_rotate.setup("rotate speed", 0.0, -1.0, 1.0));
- gui.add(use_scale.setup("XF scale", false));
- gui.add(xf_scale_speed.setup("scale speed", 1.0, 0.0, 10.0));
- gui.add(xf_scale_min.setup("scale min", 1.0, 0.0, 3.0));
- gui.add(xf_scale_max.setup("scale max", 2.0, 0.0, 3.0));
+*/
+
+ //============================= Audio
+
+ plotter.setup(5,true);
+
+ bufferSize = 2048;
+ sampleRate = 44100;
+
+ gist.setUseForOnsetDetection(GIST_PEAK_ENERGY);
+ gist.setThreshold(GIST_PEAK_ENERGY, .05);//
+
+ ofAddListener(GistEvent::ON,this,&ofApp::onNoteOn);
+ ofAddListener(GistEvent::OFF,this,&ofApp::onNoteOff);
+
+ // ofAddListener(ofApp::useMic->Value,this,&ofApp::useMicChanged);
+
+ soundStream.setup(this,0, 1, sampleRate, bufferSize, 1);
+
+ //loadSong("12 Ferric Appetite.aiff");
+ loadSong("passades/1 The Ninth Set-sector1:sector2pt.1.aiff");
+
+ //============================ gui
+
+ lasergui.setup("laser");
+ lasergui.add(laser_power.set("power", false));
+ lasergui.add(laser_intensity.set("intensity", 30, 0, 255));
+ lasergui.add(laser_points.set("points", 30000, 0, 40000));
+ lasergui.add(laser_subdivide.set("subdivide", 15, 1, 100));
+ lasergui.add(laser_blank_num.set("blank points", 8, 0, 32));
+ lasergui.add(laser_max_angle.set("max angle", 15.0f, 1.0f, 90.0f));
+
+ drawgui.setup("drawing","",10,150);
+ drawgui.add(contour_threshold.setup("threshold", 140, 0, 255));
+ drawgui.add(contour_simplify.setup("simplify", 0.8, 0.0, 1.0));
+ drawgui.add(contour_useColour.setup("use colour", true));
+ drawgui.add(laser_R.setup("red", 140, 0, 255));
+ drawgui.add(laser_G.setup("green", 140, 0, 255));
+ drawgui.add(laser_B.setup("blue", 140, 0, 255));
+ drawgui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0));
+ drawgui.add(shapes_randomise.setup("randomise shapes", true));
+ drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8));
+ drawgui.add(shapes_duration.setup("shape duration", 5, 0, 25));
+ drawgui.add(use_mask.setup("use mask", true));
+ drawgui.add(invert_mask.setup("invert mask", false));
+ drawgui.add(use_segmenter.setup("use segmenter", false));
+ drawgui.add(segmenter_speed.setup("segmenter speed", 0.2, -1.0, 1.0));
+ drawgui.add(segmenter_length.setup("segmenter length", 0.2, 0.0, 1.0));
+ drawgui.add(segmenter_number.setup("segmenter number", 1, 1, 8));
+ drawgui.add(use_rotate.setup("XF rotate", false));
+ drawgui.add(xf_rotate.setup("rotate speed", 0.0, -1.0, 1.0));
+ drawgui.add(use_scale.setup("XF scale", false));
+ drawgui.add(xf_scale_speed.setup("scale speed", 1.0, 0.0, 10.0));
+ drawgui.add(xf_scale_min.setup("scale min", 1.0, 0.0, 3.0));
+ drawgui.add(xf_scale_max.setup("scale max", 2.0, 0.0, 3.0));
+
+ audiogui.setup("audio","",10,600);
+ audiogui.add(useMic.set("mic",true));
+ audiogui.add(useFft.set("fft",false));
+ audiogui.add(scalePlot.set("scale plot", 0.1f, 0.0f, 1.0f ));
+ audiogui.add(decayPlot.set("decay", 0.9f, 0.0f, 1.0f ));
+ audiogui.add(plotter.joined.set("joined",true));
+ audiogui.add(plotter.bars.set("bars",true));
+ audiogui.add(plotter.width.set("point width", 2, 1, 256));
+ audiogui.add(plotter.num_points.set("num points", 50, 1, 512));
+ audiogui.add(plotter.history_size.set("num plots", 5, 1, 100));
+ audiogui.add(plotter.startColour.set("start",ofColor(255,255,255)));
+ audiogui.add(plotter.endColour.set("end",ofColor(0,0,0)));
framecounter=0;
@@ -110,6 +158,109 @@ void ofApp::setup(){
}
+//====================== audio functions
+
+void ofApp::loadSong(string str){
+
+ cout<<"loadSong "<<str<<endl;
+
+ player.stop();
+ player.loadSound(str);
+ player.setLoop(true);
+ player.play();
+ useMic = 0;
+ gist.clearHistory();
+}
+
+void ofApp::onNoteOn(GistEvent &e){
+
+ //noteOnRadius = 100;
+};
+
+
+void ofApp::onNoteOff(GistEvent &e){
+
+ //noteOnRadius = 0;
+};
+
+void ofApp::processAudio(float * input, int bufferSize, int nChannels){
+ //convert float array to vector
+
+
+ left.resize(bufferSize/nChannels);
+ right.resize(bufferSize/nChannels);
+ centre.resize(bufferSize/nChannels);
+
+ float max=0.0f;
+
+
+ if (nChannels==2){
+
+
+ for (int i = 0; i < bufferSize/nChannels; i++){
+ left[i] = input[i*nChannels];
+ right[i] = input[i*nChannels+1];
+ centre[i] = (left[i]+right[i])*0.5;
+ if (centre[i]>max){
+ max=centre[i];
+ }
+ }
+
+
+ }
+ else if (nChannels==1){
+ for (int i = 0; i < bufferSize;i++){
+ left[i] = input[i];
+ right[i] = input[i];
+ centre[i] = input[i];
+ if (centre[i]>max){
+ max=centre[i];
+ }
+ }
+ }
+
+ //ofLog()<<"audio data max "<<max;
+ //float audio data is +- 0.5
+
+
+ vector<float>buffer;
+ buffer.assign(&input[0],&input[bufferSize]);
+
+ gist.processAudio(buffer, bufferSize, nChannels,sampleRate);
+}
+
+
+void ofApp::audioIn(float * input, int bufferSize, int nChannels){
+ if(!useMic){
+ return;
+ }
+
+ //ofLog() << "processing "<<bufferSize<<" samples from mic";
+
+ processAudio(input, bufferSize, nChannels);
+
+}
+
+void ofApp::useMicChanged(){
+ if (useMic) {
+ player.stop();
+ }
+ else {
+ player.play();
+ }
+}
+
+//====================== settings
+
+void ofApp::default_settings(){
+ warpframe[0]=glm::vec2(0,0);
+ warpframe[1]=glm::vec2(outputWindowSize.x,0);
+ warpframe[2]=glm::vec2(outputWindowSize.x,outputWindowSize.y);
+ warpframe[3]=glm::vec2(0,outputWindowSize.y);
+ outputPosition=ofPoint(0,0);
+ outputScale=1.0f;
+}
+
void ofApp::save_settings(){
XML.setValue("WARP:p0:X", warpframe[0].x);
XML.setValue("WARP:p0:Y", warpframe[0].y);
@@ -131,15 +282,72 @@ void ofApp::save_settings(){
//--------------------------------------------------------------
void ofApp::updateOutput(ofEventArgs & args){
+//todo: set up listener for laser params or move them into a lasergui class
laser.set_pts(laser_points);
+ laser.set_subdivide(laser_subdivide);
+ laser.set_blanknum(laser_blank_num);
+ laser.set_maxangle(laser_max_angle);
+
laser.set_intensity(laser_intensity);
movie.setSpeed(video_speed);
+ if(!useMic){
+ if(player.isLoaded()){
+ if (player.isPlaying()){
+ vector<float> output = player.getCurrentBuffer(bufferSize);
+ processAudio(&output[0], bufferSize, 2);
+ //
+ if (useFft){
+ fftSmoothed = player.getFFT();
+ /*
+ float * fft = ofSoundGetSpectrum(plotter.num_points);
+ fftSmoothed.resize(plotter.num_points);
+ //printf("fft: ");
+ for (int i=0;i<plotter.num_points;i++){
+ fftSmoothed[i]=fft[i];
+ //printf("%f,",fftSmoothed[i]);
+ }
+ //printf("\r\n");
+ */
+ plotter.addpoints(fftSmoothed);
+ }
+ else {
+ plotter.addpoints(centre);
+ }
+ }
+ else {
+ player.play();
+ }
+ }
+
+ }
+ else {
+ if (player.isPlaying()){
+ player.stop();
+ }
+ if (centre.size()){
+ if (useFft){
+ float * fft = ofSoundGetSpectrum(plotter.num_points);
+ fftSmoothed.resize(plotter.num_points);
+ printf("fft: ");
+ for (int i=0;i<plotter.num_points;i++){
+ fftSmoothed[i]=fft[i];
+ printf("%f,",fftSmoothed[i]);
+ }
+ printf("\r\n");
+ plotter.addpoints(fftSmoothed);
+ }
+ else {
+ plotter.addpoints(centre);
+ }
+ }
+ }
+
}
void ofApp::update(){
-
+/*
// Update the NDI sender list to find new senders
// There is no delay if no new senders are found
nSenders = ndiReceiver.FindSenders();
@@ -230,7 +438,7 @@ void ofApp::update(){
}
}
-
+*/
if (movie.isLoaded()){
movie.update();
}
@@ -278,8 +486,9 @@ void ofApp::draw(){
glPopMatrix();
}
else {
-
- gui.draw();
+ lasergui.draw();
+ drawgui.draw();
+ audiogui.draw();
//================================== NDI
/*
@@ -448,6 +657,7 @@ void ofApp::drawOutput(ofEventArgs & args){
polyOutput.push_back(colourPolyline(poly,ofColor(laser_R,laser_G,laser_B)));
}
+/*
case NDI:{
ofPoint scale=ofPoint(outputWindowSize.x/ndiImage.getWidth(),outputWindowSize.x/ndiImage.getHeight());
@@ -480,6 +690,7 @@ void ofApp::drawOutput(ofEventArgs & args){
break;
}
+*/
case Player:{
if (movie.isLoaded()){
ofPoint scale=ofPoint(outputWindowSize.x/movie.getWidth(),outputWindowSize.y/movie.getHeight());
@@ -538,6 +749,17 @@ void ofApp::drawOutput(ofEventArgs & args){
}
break;
}
+ case Audio:{
+ ofMatrix4x4 x=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f,
+ 0.0f,1.0f,0.0f,0.0f,
+ 0.0f,0.0f,1.0f,0.0f,
+ 0.0f,0.0f,0.0f,1.0f);
+ polyOutput=plotter.output(x,scalePlot,decayPlot);
+ break;
+ }
+ default: {
+ break;
+ }
}
vector <colourPolyline> transformedOutput;
@@ -618,7 +840,9 @@ void ofApp::drawOutput(ofEventArgs & args){
int pnum=0;
if (polyOutput.size()){
- num=laser.draw(scaledWarpedOutput);
+ if (laser_power) {
+ num=laser.draw(scaledWarpedOutput);
+ }
for (auto& shape:warpedOutput){
shape.draw();
pnum+=shape.size();
@@ -630,11 +854,11 @@ void ofApp::drawOutput(ofEventArgs & args){
}
if (num>0){
- ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num));
+ ofSetWindowTitle(sourcenames[source]+": "+ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num));
}
else {
- ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser error points: "+ofToString(pnum));
+ ofSetWindowTitle(sourcenames[source]+": "+ofToString(ofGetFrameRate(), 2)+" fps laser error points: "+ofToString(pnum));
}
}
@@ -679,8 +903,8 @@ void ofApp::keyPressed(ofKeyEventArgs &args){
bDrawFrame=!bDrawFrame;
break;
}
- case OF_KEY_COMMAND:{
- commandPressed=true;
+ case 'd':{
+ default_settings();
break;
}
case 's':{
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
index 33c855a..c9b1c4f 100644
--- a/gui/src/ofApp.h
+++ b/gui/src/ofApp.h
@@ -1,26 +1,42 @@
#pragma once
#include "ofMain.h"
-#include "lineTransformer.h"
-#include "ofxNDI.h"
+
+//#include "ofxNDI.h"
#include "ofxGui.h"
-#include "ofxHelios.h"
+#include "ofxXmlSettings.h"
#include "ofxOpenCv.h"
#include "ofxSVG.h"
-#include "lineSegmenter.h"
-#include "ofxXmlSettings.h"
#include "ofxClipper.h"
#include "ofxMidi.h"
+#include "ofxHelios.h"
+#include "lineTransformer.h"
+#include "lineSegmenter.h"
+
+#include "ofxGist.h"
+//This is included only as a way of getting buffer out of loaded sound.
+//There are many other ways you can do that.
+//This player includes a version of kissFFT. You can remove the one included in Gist.
+//https://github.com/borg/ofxOpenALSoundPlayer
+#include "ofxOpenALSoundPlayer.h"
+//Slightly modified to add a dynamic getVariable method to be able to plot based on
+//gist feature list
+//https://github.com/local-projects/ofxHistoryPlot
+#include "ofxHistoryPlot.h"
+#include "Audioplotter.h"
+
enum Source{
TEST,
- NDI,
+// NDI,
Player,
SVG_outlines,
SVG_segmenters,
+ Audio,
Source_end
};
+
class ofApp: public ofBaseApp, public ofxMidiListener {
public:
@@ -52,6 +68,8 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
void outputWindowResized(ofResizeEventArgs &resizeargs);
void select_random_shapes();
+
+ void default_settings();
void save_settings();
bool commandPressed;
@@ -60,12 +78,46 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
int select_warpframe;
bool bDrawFrame;
- ofxPanel gui;
ofxHelios laser;
int source;
+ //======================================== //audio
+
+ ofxGist gist;
+ void onNoteOn(GistEvent &e);
+ void onNoteOff(GistEvent &e);
+
+ ofSoundStream soundStream;
+ ofxOpenALSoundPlayer player;
+
+ void processAudio(float * input, int bufferSize, int nChannels);
+ void audioIn(float * input, int bufferSize, int nChannels);
+
+ void loadSong(string str);
+
+ int bufferSize;
+ int sampleRate;
+
+ vector<float>fftSmoothed;
+ vector <float> left;
+ vector <float> right;
+ vector <float> centre;
+
+ Audioplotter plotter;
+
+ //======== audio gui
+
+ ofxPanel audiogui;
+ ofParameter<bool> useMic;
+ ofParameter<bool> useFft;
+ ofParameter<float> scalePlot;
+ ofParameter<float> decayPlot;
+
+ void useMicChanged();
+
+
//======================================== //thresholding
ofxCvColorImage colorImg;
@@ -73,7 +125,7 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
ofxCvContourFinder contourFinder;
//======================================== //ofxNDI
-
+/*
ofxNDIreceiver ndiReceiver;
ofImage ndiImage;
char senderName[256];
@@ -84,8 +136,10 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
// For received frame fps calculations
double startTime, lastTime, frameTime, frameRate, fps;
+*/
+ //====== drawing gui
- //====== gui
+ ofxPanel drawgui;
ofxIntSlider contour_threshold;
ofxFloatSlider contour_simplify;
@@ -93,8 +147,6 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
ofxIntSlider laser_R;
ofxIntSlider laser_G;
ofxIntSlider laser_B;
- ofxIntSlider laser_intensity;
- ofxIntSlider laser_points;
//====== video
@@ -121,6 +173,17 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
ofxFloatSlider xf_scale_min;
ofxFloatSlider xf_scale_max;
+
+ //======= laser gui
+
+ ofxPanel lasergui;
+ ofParameter<bool> laser_power;
+ ofParameter<int> laser_intensity;
+ ofParameter<int> laser_points;
+ ofParameter<int> laser_subdivide;
+ ofParameter<int> laser_blank_num;
+ ofParameter<float> laser_max_angle;
+
//======================================= //MIDI
ofxMidiIn midiIn;