diff options
| author | Tim Redfern <tim@eclectronics.org> | 2015-04-12 22:20:30 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2015-04-12 22:20:30 +0100 |
| commit | 8c86c8e56d5948f44ba7524284824bbc6eff952b (patch) | |
| tree | 704dc88be2f22c69b4d16838092bc83cf692a75b /liveengine | |
Diffstat (limited to 'liveengine')
| -rwxr-xr-x | liveengine/Makefile | 2 | ||||
| -rwxr-xr-x | liveengine/addons.make | 9 | ||||
| -rwxr-xr-x | liveengine/config.make | 56 | ||||
| -rwxr-xr-x | liveengine/liveengine.cbp | 87 | ||||
| -rwxr-xr-x | liveengine/liveengine.layout | 49 | ||||
| -rwxr-xr-x | liveengine/src/layers.cpp | 229 | ||||
| -rwxr-xr-x | liveengine/src/layers.h | 131 | ||||
| -rwxr-xr-x | liveengine/src/main.cpp | 20 | ||||
| -rwxr-xr-x | liveengine/src/playlist.cpp | 126 | ||||
| -rwxr-xr-x | liveengine/src/playlist.h | 30 | ||||
| -rwxr-xr-x | liveengine/src/testApp.cpp | 646 | ||||
| -rwxr-xr-x | liveengine/src/testApp.h | 243 | ||||
| -rwxr-xr-x | liveengine/src/viewport.cpp | 458 | ||||
| -rwxr-xr-x | liveengine/src/viewport.h | 69 |
14 files changed, 2155 insertions, 0 deletions
diff --git a/liveengine/Makefile b/liveengine/Makefile new file mode 100755 index 0000000..2d83a77 --- /dev/null +++ b/liveengine/Makefile @@ -0,0 +1,2 @@ +include config.make +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples diff --git a/liveengine/addons.make b/liveengine/addons.make new file mode 100755 index 0000000..8d01bd5 --- /dev/null +++ b/liveengine/addons.make @@ -0,0 +1,9 @@ +ofxXmlSettings +ofxMidi +ofxSVGTiny +ofxFenster +ofxGui +ofxAssets +ofxExtras +ofxSpriteManager +ofxOpenNI diff --git a/liveengine/config.make b/liveengine/config.make new file mode 100755 index 0000000..821a73a --- /dev/null +++ b/liveengine/config.make @@ -0,0 +1,56 @@ +# add custom variables to this file + +# OF_ROOT allows to move projects outside apps/* just set this variable to the +# absoulte path to the OF root folder + +OF_ROOT = ../../openFrameworks + + +# USER_CFLAGS allows to pass custom flags to the compiler +# for example search paths like: +# USER_CFLAGS = -I src/objects + +USER_CFLAGS = -I $(OF_ROOT)/addons/ofxOpenNI/include/openni -I $(OF_ROOT)/addons/ofxOpenNI/include/nite -I $(OF_ROOT)/addons/ofxOpenNI/src + + +# USER_LDFLAGS allows to pass custom flags to the linker +# for example libraries like: +# USER_LDFLAGS = libs/libawesomelib.a + +USER_LDFLAGS = -lOpenNI + + +EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj" + +# change this to add different compiler optimizations to your project + +USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os + + +# android specific, in case you want to use different optimizations +USER_LIBS_ARM = +USER_LIBS_ARM7 = +USER_LIBS_NEON = + +# android optimizations + +ANDROID_COMPILER_OPTIMIZATION = -Os + +NDK_PLATFORM = android-8 + +# uncomment this for custom application name (if the folder name is different than the application name) +#APPNAME = folderName + +# uncomment this for custom package name, must be the same as the java package that contains OFActivity +#PKGNAME = cc.openframeworks.$(APPNAME) + + + + + +# linux arm flags + +LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp + + + diff --git a/liveengine/liveengine.cbp b/liveengine/liveengine.cbp new file mode 100755 index 0000000..6dd6db0 --- /dev/null +++ b/liveengine/liveengine.cbp @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="liveengine" /> + <Option makefile_is_custom="1" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Option virtualFolders="addons/;src/;build config/;" /> + <Build> + <Target title="Debug"> + <Option output="bin/$(PROJECT_NAME)_debug" prefix_auto="1" extension_auto="1" /> + <Option working_dir="bin" /> + <Option object_output="obj/Debug/" /> + <Option external_deps="../../../libs/openFrameworksCompiled/lib/linux/libopenFrameworksDebug.a;" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Option projectLinkerOptionsRelation="2" /> + </Target> + <Target title="Release"> + <Option output="bin/$(PROJECT_NAME)" prefix_auto="1" extension_auto="1" /> + <Option working_dir="bin" /> + <Option object_output="obj/Release/" /> + <Option external_deps="../../../libs/openFrameworksCompiled/lib/linux/libopenFrameworks.a;" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Option projectLinkerOptionsRelation="2" /> + </Target> + </Build> + <Unit filename="addons.make"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="bin/data/dancing.xml"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="bin/data/settings.xml"> + <Option virtualFolder="build config/" /> + </Unit> + <Unit filename="config.make"> + <Option virtualFolder="build config" /> + </Unit> + <Unit filename="src/keyVar.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/keyVar.h"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/layers.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/layers.h"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/main.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/playlist.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/playlist.h"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/testApp.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/testApp.h"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/threadNI.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/threadNI.h"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/viewport.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/viewport.h"> + <Option virtualFolder="src/" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/liveengine/liveengine.layout b/liveengine/liveengine.layout new file mode 100755 index 0000000..b42382b --- /dev/null +++ b/liveengine/liveengine.layout @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="Debug" /> + <File name="addons.make" open="0" top="0" tabpos="7"> + <Cursor position="92" topLine="0" /> + </File> + <File name="bin/data/dancing.xml" open="0" top="0" tabpos="1"> + <Cursor position="0" topLine="0" /> + </File> + <File name="bin/data/settings.xml" open="0" top="0" tabpos="8"> + <Cursor position="354" topLine="0" /> + </File> + <File name="config.make" open="0" top="0" tabpos="1"> + <Cursor position="451" topLine="3" /> + </File> + <File name="src/keyVar.cpp" open="0" top="0" tabpos="9"> + <Cursor position="510" topLine="8" /> + </File> + <File name="src/keyVar.h" open="0" top="0" tabpos="10"> + <Cursor position="0" topLine="3" /> + </File> + <File name="src/layers.cpp" open="0" top="0" tabpos="2"> + <Cursor position="2434" topLine="46" /> + </File> + <File name="src/layers.h" open="0" top="0" tabpos="3"> + <Cursor position="3260" topLine="76" /> + </File> + <File name="src/main.cpp" open="0" top="0" tabpos="7"> + <Cursor position="258" topLine="0" /> + </File> + <File name="src/playlist.cpp" open="0" top="0" tabpos="0"> + <Cursor position="1621" topLine="40" /> + </File> + <File name="src/playlist.h" open="0" top="0" tabpos="0"> + <Cursor position="536" topLine="0" /> + </File> + <File name="src/testApp.cpp" open="0" top="0" tabpos="4"> + <Cursor position="7003" topLine="0" /> + </File> + <File name="src/testApp.h" open="0" top="0" tabpos="1"> + <Cursor position="3691" topLine="159" /> + </File> + <File name="src/viewport.cpp" open="0" top="0" tabpos="6"> + <Cursor position="4344" topLine="34" /> + </File> + <File name="src/viewport.h" open="0" top="0" tabpos="5"> + <Cursor position="42" topLine="36" /> + </File> +</CodeBlocks_layout_file> diff --git a/liveengine/src/layers.cpp b/liveengine/src/layers.cpp new file mode 100755 index 0000000..a0fb213 --- /dev/null +++ b/liveengine/src/layers.cpp @@ -0,0 +1,229 @@ +#include "layers.h"
+
+svglayer::svglayer() { + xo=0;yo=0; +}
+svglayer::svglayer(string _f)
+{
+ load(_f);
+}
+
+void svglayer::load(string _f){ + //check if files exits
+ svg.load(_f);
+ printf("%s: %i paths\n",_f.c_str(),svg.getNumPath());
+ for (int i=0;i<svg.getNumPath();i++) { + fills.push_back(svg.getPathAt(i).getFillColor()); + strokes.push_back(svg.getPathAt(i).getStrokeColor());
+ //printf(" path %i: fill %08x stroke %08x\n",i,svg.getPathAt(i).getFillColor().getHex(),svg.getPathAt(i).getStrokeColor().getHex());
+ } + isLoaded= (svg.getNumPath()>0);
+}
+void svglayer::getCentre(int cx,int cy) {
+ if (svg.getNumPath()>0) {
+ xo=(cx-svg.getWidth())/2;
+ yo=(cy-svg.getHeight())/2;
+ }
+}
+
+void svglayer::draw(float a,int cx,int cy,float colShift) {
+ getCentre(cx,cy); + for (int i=0;i<svg.getNumPath();i++) {
+ ofColor c=fills[i]*a;
+ if (colShift>0.0f) {
+ c.setHue(fmod(c.getHue()+colShift,255.0f));
+ //printf ("shift from %f to %f\n",c.getHue(),c.getHue()+colShift);
+ } + svg.getPathAt(i).setFillColor(c); + svg.getPathAt(i).draw(xo,yo); + }
+} +/* +void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift) {
+ getCentre(cx,cy); + //draw layers tinted by controllers
+ for (int i=0;i<svg.getNumPath();i++) { + float h=fmod(fills[i].getHue()+colShift,255.0f); + float ha=h/42.7; //0-5 + int h1=(((int)ha)+2)%6; + int h2=h1+1; + float f2=ha-h1; + float f1=1.0f-f2; + //if (transparentBlack) printf("transparent black draw %f\n",(a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0))); + + svg.getPathAt(i).setFillColor(fills[i]*a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0));; + if (!transparentBlack||(a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0))>0.1) { + svg.getPathAt(i).draw(xo,yo); + } + }
+}
+*/
+
+void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift) {
+ getCentre(cx,cy);
+ //draw layers grouped by controllers
+ float layerspercontroller=((float)svg.getNumPath())/6.0f;
+
+ for (int i=0;i<6;i++) {
+ //for (int j=(int)((i+1)*layerspercontroller)-1;j>(int)(i*layerspercontroller);j--) { + for (int j=(int)(i*layerspercontroller);j<(int)((i+1)*layerspercontroller);j++) {
+ svg.getPathAt(j).setFillColor(fills[j]*a*(((float)controllers[5-i])/127.0f)); //try to reverse order of these
+ if (!transparentBlack||((a*controllers[5-i])/127.0f)>0.1) {
+ svg.getPathAt(j).draw(xo,yo);
+ }
+ }
+ } + //printf("counted %i layers of %i\n",(int)(6*layerspercontroller),svg.getNumPath());
+} +
+
+svglayer::~svglayer()
+{
+ //dtor
+} + +//------------------------------------------------------------------------ +imglayer::imglayer() { + //sprite.setUseTexture(false); +}
+imglayer::imglayer(string _filename,int _frames,int _start,float _rate,int n, int e){
+ load(_filename,_frames,_start,_rate,n,e);
+}
+
+void imglayer::load(string _filename,int _frames,int _start,float _rate,int n, int e){ + startNote=n; + endNote=e;
+ sprite.load(_filename,_frames,_start);
+ sprite.setFrameRate(_rate);
+}
+ +
+void imglayer::draw(float a,int cx,int cy,float colShift) { + //if (sprite.isAllocated()) if (!sprite.isUsingTexture()) sprite.setUseTexture(true); //has to be done from the main thread? still doesn't work
+ + sprite.update();
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)sprite.getWidth())/sprite.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)sprite.getHeight())/sprite.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)sprite.getWidth())/sprite.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending(); + sprite.draw(x,y,w,h);
+ ofDisableAlphaBlending();
+} + +void imglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) { + imglayer::draw(a,cx,cy,colShift);
+}
+
+void imglayer::setNote(int note)
+{ + //is called rerpeatedly no startNote,endNote + //printf("note %i (%i - %i)\n",note,startNote,endNote);
+ if ((startNote<=note)&&(endNote>=note)) {
+ if (!sprite.getIsPlaying()) {
+
+ sprite.play();
+
+ } + //printf("triggered frame %i of %i\n",(int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()),sprite.getTotalFrames());
+ sprite.setCurrentFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ }
+ else {
+ if (sprite.getIsPlaying()) {
+ sprite.stop();
+ }
+ }
+
+}; +
+
+imglayer::~imglayer()
+{
+ //sprite.setUseTexture(false); //free texture
+} +//------------------------------------------------------------------------ +videolayer::videolayer() { + //sprite.setUseTexture(false); +}
+videolayer::videolayer(string _f,int n,int e,float s)
+{ + startNote=n; + endNote=e;
+ speed=s;
+ load(_f);
+}
+
+void videolayer::load(string _f){
+ name=_f;
+ mov.setPixelFormat(OF_PIXELS_BGRA);
+ mov.setUseTexture(false);
+ bool success=mov.loadMovie(_f);
+ if (success) {
+ mov.stop();
+ }
+ printf("%s %s %i bpp\n",success?"loaded":"not loaded",_f.c_str(),success?mov.getPixelsRef().getBytesPerPixel():0);
+}
+
+void videolayer::draw(float a,int cx,int cy,float colShift) { + if (mov.isPlaying()) { + mov.update();
+ //unsigned char *pix=mov.getPixels();
+ //for (int i=0;i<mov.getWidth()*mov.getHeight()*4;i+=4) pix[i+3]=(pix[i]>>2)+(pix[i+1]>>1)+(pix[i+2]>>2);
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)mov.getWidth())/mov.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)mov.getHeight())/mov.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)mov.getWidth())/mov.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending();
+ mov.draw(x,y,w,h);
+ ofDisableAlphaBlending(); + }
+} + +void videolayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) { + draw(a,cx,cy,colShift);
+} + +void videolayer::setNote(int note) +{
+ + if ((startNote<=note)&&(endNote>=note)) { + if (!mov.isPlaying()) {
+ //printf("starting movie!\n");
+ mov.setUseTexture(true);
+ mov.play();
+ mov.setSpeed(speed);
+ } + mov.setFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames())); + } + else { + if (mov.isPlaying()) { + mov.stop(); + } + } + +}; +
+
+videolayer::~videolayer()
+{
+}
diff --git a/liveengine/src/layers.h b/liveengine/src/layers.h new file mode 100755 index 0000000..f8ed650 --- /dev/null +++ b/liveengine/src/layers.h @@ -0,0 +1,131 @@ +#ifndef SVGLAYER_H
+#define SVGLAYER_H
+
+#include "ofxSVGTiny.h" +#include "ofMain.h"
+#include "ofxSprite.h"
+
+class layer
+{
+ public:
+ layer(){};
+ layer(string _f) {load(_f);};
+ virtual ~layer(){};
+ virtual void load(string _f){};
+ virtual void draw(float a,int cx,int cy,float colShift){}; + virtual void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f){ draw(a,cx,cy,colShift);}; + bool getLoaded() {return isLoaded;}; + virtual void setNote(int note) {};
+ string name;
+ int startNote,endNote;
+ protected: + bool isLoaded;
+ private:
+
+};
+
+class svglayer: public layer
+{
+ public:
+ svglayer();
+ svglayer(string _f);
+ virtual ~svglayer();
+ void load(string _f);
+ void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f);
+ void getCentre(int cx,int cy);
+ protected:
+ private:
+ ofxSVGTiny svg; + vector <ofColor> fills; + vector <ofColor> strokes; + float xo,yo;
+};
+ +class sunkenSprite: public ofxSprite { + public: + float playhead,frameRate;
+ void setFrameRate(float frameRate) { this->frameRate = frameRate;}; + void play() { + startTime=ofGetElapsedTimef(); + ofxSprite::play(); + } + void update() { + if (!getIsPlaying()) return;
+ playhead=fmod(speed * frameRate * (ofGetElapsedTimef()-startTime),(float)getTotalFrames()); + ofxSprite::setCurrentFrame(playhead); + + } + void setCurrentFrame(float frame) {
+ //this idea doesn't work - fucks up when frameRate is 0 -
+ //need to rethink
+
+ //when frameRate is 0 startTime doesn't matter
+ //this still might not be not entirely correct
+ if (frameRate>0) startTime-=(frame-pos) / ((float)(frameRate * speed ));
+ //printf("sunkensprite setting frame %i of %i\n",(int)frame,getTotalFrames());
+ //printf("1 checking frame %i of %i\n",(int)frame,getTotalFrames()); + ofxSprite::setCurrentFrame(frame);
+ /*
+ pos = frame;
+ printf("2 checking frame %i of %i\n",(int)frame,getTotalFrames());
+ printf("requesting movie frame %i of %i\n",(int)pos,getTotalFrames());
+ if (pos<0) if (loop) { pos += totalFrames; } else stop();
+ if (pos>=totalFrames) if (loop) {
+ while (pos>=totalFrames) pos -= totalFrames;
+ } else { pos = totalFrames-.00001f; isPlaying=false; }
+ printf("set movie frame %i of %i\n",(int)pos,totalFrames);
+ */ + } + void draw(int x,int y,int w,int h) { + + int f=playhead; + float fr=fmod(playhead,1.0); + ofSetColor(255,255,255,(1.0-fr)*255); + //not always? + getImageAtFrame(f).setUseTexture(true); + getImageAtFrame(f).reloadTexture();
+ getImageAtFrame(f).draw(x,y,w,h); + ofSetColor(255,255,255,fr*255);
+ f=(f+1)%getTotalFrames(); + getImageAtFrame(f).setUseTexture(true);
+ getImageAtFrame(f).reloadTexture();
+ getImageAtFrame(f).draw(x,y,w,h); + } + + private: + float startTime; + +}; +
+class imglayer: public layer
+{
+ public:
+ imglayer();
+ imglayer(string _f,int _frames=1,int _start=1,float _rate=0,int note=0,int endnote=0);
+ virtual ~imglayer();
+ void load(string _filename,int _frames=1,int _start=1,float _rate=0.0,int note=0,int endnote=0);
+ void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift);
+ void setNote(int n);
+ protected:
+ private:
+ sunkenSprite sprite;
+}; + +class videolayer: public layer
+{
+ public:
+ videolayer();
+ videolayer(string _f,int n,int e,float s);
+ virtual ~videolayer();
+ void load(string _f);
+ void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift); + void setNote(int n); + protected:
+ private: + float speed;
+ ofVideoPlayer mov;
+};
+#endif // SVGLAYER_H
diff --git a/liveengine/src/main.cpp b/liveengine/src/main.cpp new file mode 100755 index 0000000..d22025f --- /dev/null +++ b/liveengine/src/main.cpp @@ -0,0 +1,20 @@ +#include "ofMain.h" +#include "testApp.h" +#include "ofxFensterManager.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(ofxFensterManager::get(),4080,768, OF_WINDOW); //2048,768 + //ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context + //ofSetupOpenGL(&window, 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 testApp()); + ofRunFensterApp( new testApp()); + +} diff --git a/liveengine/src/playlist.cpp b/liveengine/src/playlist.cpp new file mode 100755 index 0000000..683cd3c --- /dev/null +++ b/liveengine/src/playlist.cpp @@ -0,0 +1,126 @@ +#include "playlist.h"
+
+playlist::playlist()
+{ + name=""; + thumbnail.allocate(128,128,GL_RGB); + thumbnailed=false;
+} + +void playlist::load(string _name){ + //printf("loading %s\n",_name.c_str()); + + + if( !XML.loadFile(_name) ){
+ printf("unable to load %s check data/ folder\n",_name.c_str());
+ }else { + printf("starting loader thread\n"); + loadimg(); //how to do this from the worker thread??? + startThread(false, false); //blocking, verbose + } + + + +} + +void playlist::threadedFunction(){ + if( lock() ){ + loadLayers(); + unlock(); + } +}
+ +void playlist::loadLayers(){ + int numLayers=0; + layers.clear(); + name=XML.getAttribute("playlist", "name", ""); + float speed=XML.getAttribute("playlist", "speed", 0); + if(XML.pushTag("playlist")) {
+ numLayers=XML.getNumTags("svglayer");
+ if(numLayers) {
+ for (int i=0;i<numLayers;i++) {
+ string s=XML.getAttribute("svglayer", "file", "",i);
+ printf("loading %s: \n",s.c_str());
+ layers[XML.getAttribute("svglayer", "note", 0,i)]=new svglayer(XML.getAttribute("svglayer", "file", "",i));
+ } + thumbnailed=false;
+ } + numLayers=XML.getNumTags("movlayer");
+ if(numLayers) {
+ for (int i=0;i<numLayers;i++) {
+ string s=XML.getAttribute("movlayer", "file", "",i);
+ printf("loading %s: \n",s.c_str()); + int note=XML.getAttribute("movlayer", "note", 0,i); + int endnote=XML.getAttribute("movlayer", "endnote", 0,i);
+ layers[note]=new videolayer(XML.getAttribute("movlayer", "file", "",i),note,endnote,speed); + if (endnote>note) { + for (int j=note+1;j<endnote;j++) { + layers[j]=layers[note]; + } + }
+ } + thumbnailed=false;
+ } + numLayers=XML.getNumTags("imglayer"); + if(numLayers) { + for (int i=0;i<numLayers;i++) { + string s=XML.getAttribute("imglayer", "files", "",i); + printf("loading %s: \n",s.c_str()); + int note=XML.getAttribute("imglayer", "note", 0,i); + int endnote=XML.getAttribute("imglayer", "endnote", 0,i); + float rate=XML.getAttribute("imglayer", "rate", 0.0,i); + int frames=XML.getAttribute("imglayer", "frames", 0,i); + int start=XML.getAttribute("imglayer", "start", 1,i); + layers[note]=new imglayer(s,frames,start,rate,note,endnote); + if (endnote>note) { + for (int j=note+1;j<=endnote;j++) { + layers[j]=layers[note]; + } + } + } + thumbnailed=false; + } + XML.popTag();
+ } + +} + +void playlist::makeThumbnail(){ + if (layers.size()) { + thumbnail.begin(); + ofBackground(0,0,0); + ofPushMatrix(); + ofTranslate(64,64); + ofScale(0.2,0.2,0.2); + ofTranslate(-64,-64); + map<int,layer*>::iterator i=layers.begin(); + i->second->draw(1.0,64,64,0.0); + ofPopMatrix(); + thumbnail.end(); + thumbnailed=true; + } +} + + +void playlist::loadimg(){ + int numLayers=0; + layers.clear(); + if(XML.pushTag("playlist")) {
+ numLayers=XML.getNumTags("imglayer");
+ if(numLayers) {
+ for (int i=0;i<numLayers;i++) {
+ string s=XML.getAttribute("imglayer", "file", "",i);
+ printf("%s: ",s.c_str());
+ layers[XML.getAttribute("imglayer", "note", 0,i)]=new imglayer(XML.getAttribute("imglayer", "file", "",i));
+ }
+ }
+ else printf("no IMG layers loaded!\n"); + XML.popTag();
+ } + +} +
+playlist::~playlist()
+{
+ //dtor
+}
diff --git a/liveengine/src/playlist.h b/liveengine/src/playlist.h new file mode 100755 index 0000000..2790835 --- /dev/null +++ b/liveengine/src/playlist.h @@ -0,0 +1,30 @@ +#ifndef PLAYLIST_H
+#define PLAYLIST_H
+
+#include "ofThread.h" +#include "ofxXmlSettings.h" + +#include "layers.h" +#include "ofMain.h"
+
+class playlist : public ofThread {
+ public:
+ playlist();
+ virtual ~playlist(); + void loadimg(); + void loadLayers(); + void load(string _name); + void threadedFunction();
+ void makeThumbnail(); +
+ ofFbo thumbnail;
+ bool thumbnailed;
+ + ofxXmlSettings XML; + map<int,layer*> layers;
+ string name;
+ protected:
+ private:
+};
+
+#endif // PLAYLIST_H
diff --git a/liveengine/src/testApp.cpp b/liveengine/src/testApp.cpp new file mode 100755 index 0000000..ced71d4 --- /dev/null +++ b/liveengine/src/testApp.cpp @@ -0,0 +1,646 @@ +#include "testApp.h" +previewWindow::~previewWindow(){ + cout << "preview window destroyed" << endl; +} +void previewWindow::setup(){} +void previewWindow::setBuffer(ofFbo *buffer){ + rb=buffer; +} +void previewWindow::draw(){ + + rb->draw(0,0,ofGetWidth(),ofGetHeight()); //why crash? + +} +//-------------------------------------------------------------- +guiWindow::~guiWindow(){ + cout << "gui window destroyed" << endl; +} +void guiWindow::setup(){} +void guiWindow::setParent(testApp *p){ + parent=p; +} +void guiWindow::draw(){ + + parent->gui.draw(); + if (parent->list.lock()) { //if loaded + if (!parent->list.thumbnailed) parent->list.makeThumbnail(); + if (parent->list.thumbnailed) parent->list.thumbnail.draw(20,ofGetHeight()-150); + parent->list.unlock(); + } + ofDrawBitmapString(parent->list.name,20,ofGetHeight()-10); + +} +void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ + parent->dragEvent(dragInfo); +} +void guiWindow::windowMoved(int x,int y){ + //printf("window moved!\n"); +} + +//---------------------------------------------------------------------- + +kinectWindow::~kinectWindow(){ + cout << "kinect window destroyed" << endl; +} +void kinectWindow::setup(){ + ofSetBackgroundAuto(false); +} +void kinectWindow::setParent(testApp *p){ + parent=p; +} +void kinectWindow::draw(){ + //parent->NIinstance.drawpreview(); + //parent->NIinstance.recordDepth.draw(0,0,ofGetWidth(),ofGetHeight()); + parent->NIinstance.recordUser.draw(ofGetWidth(),ofGetHeight()); +} + + +//-------------------------------------------------------------- +void testApp::setup(){
+ int midiPort=0;
+ midiChannel=0;
+ useKinect=false;
+ if( !XML.loadFile("settings.xml") ){
+ printf("unable to load settings.xml check data/ folder\n");
+ }else{
+ printf("settings loaded!\n");
+ midiPort=ofToInt(XML.getAttribute("liveEngine", "port", "0")); //default to 0/all
+ midiChannel=ofToInt(XML.getAttribute("liveEngine", "channel", "0"));
+ if (midiChannel) printf("listening on port %d, midi channel %d\n",midiPort,midiChannel);
+ else printf("listening on port %d, all midi channels\n",midiPort); + if(XML.pushTag("liveEngine")) { + int numViews=XML.getNumTags("viewport"); + if(numViews) { + for (int i=0;i<numViews;i++) { + int w=XML.getAttribute("viewport", "w",0,i); + int h=XML.getAttribute("viewport", "h",0,i); + int x=XML.getAttribute("viewport", "x",0,i); + int y=XML.getAttribute("viewport", "y",0,i); + int rot=XML.getAttribute("viewport", "rot",0,i); + int ox=XML.getAttribute("viewport", "ox",0,i); + int oy=XML.getAttribute("viewport", "oy",0,i); + int mapped=XML.getAttribute("viewport", "mapped",0,i); + printf("viewport %i: %ix%i %s\n",i,w,h,mapped==1?"mapped":"unmapped"); + if (mapped==1) { + if (!useKinect) { + //set up preview window and kinect classes + useKinect=true; + kinectWin=new kinectWindow(); + ofxFenster* kw=ofxFensterManager::get()->createFenster(0, 0, 320, 240, OF_WINDOW); + kw->setWindowTitle("kinect"); + kw->addListener(kinectWin); + kinectWin->setup(); + kinectWin->setParent(this); + + NIinstance.start(); + + } + viewports.push_back(new viewport(w,h,x,y,rot,ox,oy)); + viewports[i]->setUG(&NIinstance.recordUser); + + XML.pushTag("viewport",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + map<string,string>settings; + for (int k=0;k<keys.size();k++) { + settings[keys[k]]=XML.getAttribute("settings",keys[k],"none",0); + } + viewports[i]->setcam(settings); + XML.popTag(); + + } + else viewports.push_back(new viewport(w,h,x,y,rot,ox,oy)); + } + } + else printf("no viewports!\n"); + + XML.popTag(); + + }
+ } +
+ activeView=-1; +
+ midiIn.listPorts();
+ midiIn.openPort(midiPort);
+ midiIn.addListener(this);
+
+ // to register only to one controller pass the id as first argument
+ // midiIn.addListener(84,this);
+ // to debug
+ // midiIn.setVerbose(true); + + controllers=new unsigned char[NUM_CONTROLLERS]; + memset(controllers,NUM_CONTROLLERS,0); + note=0; + + makeColours(); + + colShift=0; + + controlColours=false; + debug=false; + noteRandomiseColours=false; + transparentBlack=false; + reversemain=false; + + //vp1.setup(768,1024,1024,0,-90,-256,-384); + //vp2.setup(1024,768,0,0,0,-512,-384); +
+ showFPS=false;
+ ofBackground(0,0,0); + + ofSetBackgroundAuto(false);
+
+ xshift=-1;
+ yshift=-1; + + fadetime=0; +
+ mode=BLOCKS; + + lastnoteTime=ofGetElapsedTimef(); + decayTime=1.0f;
+
+ //ofSetVerticalSync(true); deosn't seem effective
+ //glXSwapIntervalSGI(1); + /* + printf("hue of red is %f\n",ofColor(255,0,0).getHue()); + printf("hue of green is %f\n",ofColor(0,255,0).getHue()); + printf("hue of blue is %f\n",ofColor(0,0,255).getHue()); + hue is float from 0.0-255.0 + */ + ofSetFrameRate(60); + rotate=-90; + scale=1.0f; + fscale=1.0f; + + + //preview window stuff + prevWin=new previewWindow(); + win=ofxFensterManager::get()->createFenster(0, 0, 600, 800, OF_WINDOW); + ofAddListener(win->events.mouseDragged, this, &testApp::mousePressedEvent); + ofAddListener(win->events.mousePressed, this, &testApp::mousePressedEvent); + ofAddListener(win->events.keyPressed, this, &testApp::keyPressedEvent); + win->setWindowTitle("preview"); + win->addListener(prevWin); + prevWin->setup(); + prevWin->setBuffer(&viewports[0]->rb2); + + fullscreenoutput=false; + + guiWin=new guiWindow(); + gui.setup("","panel.xml",0,0); + gui.add(reversemain.setup("reverse main", false)); + gui.add(controlColours.setup("control colours", false)); + gui.add(noteRandomiseColours.setup("randomise note colours", false)); + gui.add(transparentBlack.setup("transparent black", false)); + gui.add(resetDrawscale.setup("reset draw scale")); + gui.add(resetFBscale.setup("reset FB scale")); + fadeScale=128; + gui.add(fS.setup("fade scale",fadeScale,0,255,255)); + decayTime=1.0f; + gui.add(dT.setup("decay time",decayTime,0,10.0,255)); + + gui.add(oscScale.setup("scale size LFO", false)); + gui.add(breakOsc.setup("break oscillators", false)); + gui.add(randomOsc.setup("randomise oscillators", false)); + scaleAmplitude=0.5f; + gui.add(sA.setup("fade scale",scaleAmplitude,0,2.0,255)); + scaleFrequency=1.0f; + gui.add(sF.setup("fade freq",scaleFrequency,0,5.0,255)); + gui.add(drawCloud.setup("draw pointCloud",false)); + gui.add(drawSkel.setup("draw Skeleton",false)); + + resetDrawscale.addListener(this,&testApp::resetDrawscalePressed); + resetFBscale.addListener(this,&testApp::resetFBscalePressed); + + //gui window stuff + ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW); + + ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); + + win2->setWindowTitle("config"); + win2->addListener(guiWin); + guiWin->setup(); + guiWin->setParent(this); + + debug=false; +
+} + +void testApp::resetDrawscalePressed(bool & pressed){ + scale=1.0f; +} +void testApp::resetFBscalePressed(bool & pressed){ + fscale=1.0f; +} + +void testApp::makeColours() { + controller_colours=new ofColor[NUM_CONTROLLERS]; + for (int i=0;i<NUM_CONTROLLERS;i++) controller_colours[i]=ofColor::fromHsb(ofRandom(255), 255, 255); + colShift=ofRandom(255.0f); +} +//-------------------------------------------------------------- +void testApp::update(){
+ //for (int i=0;i<numLayers;i++) layers[i]->update(); +} +void testApp::saveSettings(string filename){ + + if(XML.pushTag("liveEngine")) { + for (int i=0;i<viewports.size();i++){ + if (viewports[i]->isMapped) { + XML.pushTag("viewport",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + for (int k=0;k<keys.size();k++) { + XML.setAttribute("settings", keys[k], viewports[i]->getSetting(keys[k]),0); + } + XML.popTag(); + } + } + XML.popTag(); + } + XML.saveFile(filename); + printf("saved %s\n",filename.c_str()); +} +//-------------------------------------------------------------- +void testApp::draw(){ + + float lambda=max(0.0f,1.0f-((ofGetElapsedTimef()-lastnoteTime)/decayTime)); + + int ft=255-(fadetime*((float)fadeScale)*0.1f); + //if(ofGetFrameNum()%25==0) printf("fadeScale %i\n",(int)fadeScale); + ofSetColor(ft,ft,ft); //for feedback
+ + float os=oscScale?(sin((breakOsc?ofGetElapsedTimef()-(randomOsc?randOffs:lastnoteTime):ofGetElapsedTimef()))*scaleFrequency)*scaleAmplitude:0.0f; + //vp1.draw(lambda,controllers,xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,scale,fscale,noteRandomiseColours?colShift:0.0f); + //vp2.draw(lambda,controllers,reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,reversemain?1.0f/scale:scale,reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); + for (int i=0;i<viewports.size();i++) { + bool even=!(i%2); + if (viewports[i]->isMapped) viewports[i]->mapdraw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/(scale+os):scale+os,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f,drawCloud,drawSkel); + else viewports[i]->draw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/(scale+os):scale+os,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); + } + + ofSetColor(255,255,255); + if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); + + /* + rb1.begin(); + + + // can this work? + //grab.setAnchorPoint(xshift,yshift); + //grab.setTextureWrap( GL_WRAP_BORDER, GL_WRAP_BORDER); + //grab.draw(0,0); // xshift,yshift); + + ofSetColor(255-fadetime,255-fadetime,255-fadetime); + for (int i=(xshift>0?xshift-rb1.getWidth():xshift);i<rb1.getWidth()*2;i+=ofGetWidth()) { + for (int j=(yshift>0?yshift-rb1.getHeight():yshift);j<rb1.getHeight()*2;j+=rb1.getHeight()) { + rb2.draw(i,j); + } + } + + float notewidth=rb1.getWidth()/NUM_NOTES; + float noteheight=rb1.getHeight()/NUM_CONTROLLERS; + + +
+ if (note>0) {
+ switch(mode) {
+ case BLOCKS: + for (int i=0;i<NUM_CONTROLLERS;i++){ + ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); + ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight); + }
+ break;
+ case LIST: + if (list.lock()) { //if playlist is loaded
+ ofPushMatrix(); + ofTranslate(rb1.getWidth()/2,rb1.getHeight()/2); + ofScale(scale,scale,scale); + ofRotate(rotate); + ofTranslate(-rb1.getWidth()/2,-rb1.getHeight()/2);
+ if (list.layers.find(note)!=list.layers.end()) { + if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack); + else list.layers[note]->draw(lamda,512,384); + }
+ ofPopMatrix(); + list.unlock(); + }
+ break;
+ }
+ }
+ + //for (int i=0;i<numLayers;i++) layers[i]->draw();
+ ofSetColor(255,255,255);
+ if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); + + rb1.end(); + + rb2.begin(); + ofSetColor(255,255,255); + rb1.draw(0,0); + rb2.end(); + + rb2.draw(1024,0); + + rb3.begin(); //landscape + + + + ofSetColor(255-fadetime,255-fadetime,255-fadetime); + for (int i=(xshift>0?xshift-rb3.getWidth():xshift);i<rb3.getWidth()*2;i+=ofGetWidth()) { + for (int j=(yshift>0?yshift-rb3.getHeight():yshift);j<rb3.getHeight()*2;j+=rb3.getHeight()) { + rb4.draw(i,j); + } + } + + notewidth=rb3.getHeight()/NUM_NOTES; + noteheight=rb3.getWidth()/NUM_CONTROLLERS; + + ofPushMatrix(); + ofTranslate(rb3.getWidth(),rb3.getHeight()/2); + ofRotate(90); + ofTranslate(-rb3.getWidth()/2,-rb3.getHeight()/2); + + if (note>0) { + switch(mode) { + case BLOCKS: + for (int i=0;i<NUM_CONTROLLERS;i++){ + ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); + ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight); + } + break; + case LIST: + if (list.lock()) { //if playlist is loaded + ofPushMatrix(); + ofTranslate(rb3.getWidth()/2,rb3.getHeight()/2); + ofScale(scale,scale,scale); + ofRotate(rotate); + ofTranslate(-rb3.getWidth()/2,-rb3.getHeight()/2); + if (list.layers.find(note)!=list.layers.end()) { + if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack); + else list.layers[note]->draw(lamda,512,384); + } + ofPopMatrix(); + list.unlock(); + } + break; + } + } + + ofPopMatrix(); + + //for (int i=0;i<numLayers;i++) layers[i]->draw(); + ofSetColor(255,255,255); + if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); + + rb3.end(); + + rb4.begin(); + ofSetColor(255,255,255); + rb3.draw(0,0); + rb4.end(); + + rb4.draw(0,0); + + */ + + /* test screen shape + ofSetColor(255,0,0); + ofRect(0,0,1024,768); + ofSetColor(0,255,0); + ofRect(1024,0,1024,768); + */
+ +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key, ofxFenster* win){ + if(key == ' '){ + fullscreenoutput=!fullscreenoutput; + win->setFullscreen(fullscreenoutput); + printf("resolution: %ix%i %s\n",win->getWidth(),win->getHeight(),fullscreenoutput?"fullscreen":"windowed"); + } + else keyPressed(key); +} +void testApp::keyPressed(int key){ + + if (activeView==-1) { + for (int i=0;i<viewports.size();i++) if (viewports[i]->isMapped) viewports[i]->keyPressed(key); + } + else if (activeView>-1&&activeView<viewports.size()&&viewports[activeView]->isMapped) viewports[activeView]->keyPressed(key); + + + if (key>='0' && key <='5'){ + activeView=min(key-'2',(int)viewports.size()-1); + switch (activeView){ + case -2: + printf("deactivating viewport adjustment\n"); + break; + case -1: + printf("adjusting all viewports\n"); + break; + case 0: + case 1: + case 2: + case 3: + printf("adjusting viewport %i of %i\n",activeView,viewports.size()); + break; + } + } + if(key =='q'){
+ nmidiMessage(144,ofRandom(64)+36,127); + } + if(key == 'p'){ + saveSettings("settings.xml"); + printf("settings saved!\n"); + }
+ if(key == 'f'){
+ toggleFPS();
+ }
+ if(key >='6' && key <= '9'){
+ mode=key-'6';
+ }
+ if(key == 267){
+ xshift--;
+ }
+ if(key == 268){
+ xshift++;
+ }
+ if(key == 269){
+ yshift--;
+ }
+ if(key == 270){
+ yshift++; + }
+ if(key == '='){
+ makeColours();
+ } + if(key == '+'){
+ fadetime=min(128,fadetime+1);
+ } + if(key == '_'){
+ fadetime=max(0,fadetime-1);
+ } + if(key == ']'){
+ scale*=1.01;
+ } + if(key == '['){
+ scale/=1.01;
+ } + if(key == '}'){
+ rotate+=90;
+ } + if(key == '{'){
+ rotate-=90;
+ } + + + if(key == 'd'){ + debug=!debug; + } + + if (key=='j') { + fscale=1.0f; + } + if (key=='h') { + scale=1.0f; + } + +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + if (activeView<0) for (int i=0;i<viewports.size();i++) viewports[i]->keyReleased(key); + else if (activeView<viewports.size()) viewports[activeView]->keyReleased(key); +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + + +} +void testApp::mousePressed(int x, int y, int button) {
+} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void testApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- + +void testApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ + dragEvent(dragInfo); +} +void testApp::dragEvent(ofDragInfo dragInfo){ + printf("got draginfo: %s\n",dragInfo.files[0].c_str()); + int sta=dragInfo.files[0].find_last_of("\\/")+1; + int len=(dragInfo.files[0].find_last_of(".")+4)-sta; + string filename=dragInfo.files[0].substr(sta,len); + printf("loading %s\n",filename.c_str()); + + list.load(filename); +} +void testApp::windowEvent(ofResizeEventArgs &args){ + printf("window event\n"); +} + +void testApp::mousePressedEvent(ofMouseEventArgs &args) { + //printf("mouse: %i,%i %i of %ix%i\n",args.x,args.y,args.button,win->getWidth(),win->getHeight()); + //0-2 + switch (args.button) { + case 0: + xshift=args.x-(win->getWidth()/2); + yshift=args.y-(win->getHeight()/2); + break; + case 1: + scale=pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()*.1); + break; + case 2: + fscale=(pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()))+0.5; + break; + } +} + +void testApp::keyPressedEvent(ofKeyEventArgs &args) { + //printf("window key pressed: %i (%c)\n",args.key,args.key); + keyPressed(args.key); +}
+
+void testApp::toggleFPS(){
+ showFPS=!showFPS;
+} +
+void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){ + if ((midiChannel==0)||(eventArgs.channel==midiChannel)) { + nmidiMessage(eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo); + } +}
+
+ //newMessage(eventArgs.port, eventArgs.channel, eventArgs.byteTwo, eventArgs.timestamp);
+
+//byteOne : message type
+
+ /*
+ int port;
+ int channel;
+ int status;
+ int byteOne;
+ int byteTwo;
+ double timestamp;
+ */
+
+ //printf("%d %d %d %d %d\n",eventArgs.port,eventArgs.channel,eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo);
+void testApp::nmidiMessage(int event,int data1, int data2) { + if (debug) printf("midi: %i %i\n",event,data1);
+ bool noteOn; //this old thing!
+ int i;
+ switch(event) {
+ case 144: //noteon-off channel 0
+ noteOn=(data2==0?false:true);
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
+ //} + + note=data1; + lastnoteTime=ofGetElapsedTimef(); + if (list.layers.size()&&list.lock()) { //if playlist is loaded + map<int, layer*>::iterator itr; + //for(itr = list.layers.begin(); itr != list.layers.end(); ++itr){ + // list.layers[itr->first]->setNote(note); + //} + list.layers[note]->setNote(note); + list.unlock();
+ } + if (noteRandomiseColours) { + makeColours(); // + } + randOffs=ofRandom(100.0f);
+ break;
+ case 176: //control change channel 0
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->mix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f);
+ //} + if (debug) printf("cc: %i %i\n",data1,data2); + if (data1>=START_CONTROLLER) controllers[data1-START_CONTROLLER]=data2;
+ }
+}
+ diff --git a/liveengine/src/testApp.h b/liveengine/src/testApp.h new file mode 100755 index 0000000..fa04e0b --- /dev/null +++ b/liveengine/src/testApp.h @@ -0,0 +1,243 @@ +#pragma once + +//#include <GL/glxew.h> + +#include "ofMain.h" +#include "ofxXmlSettings.h" + +/* +modprobe snd-virmidi +have had problems with it not being recognised - rebuild seemed to fix it + + +6 controllers +each note switches in 6 new visuals which are at the same strengths +as the previous bunch + +is it necessary to represent them seperately? + +maybe take them all in, but initially modulate one picture on the strength of the strongest + +maybe each object is a plugin and the 6 controllers affect 6 parameters of it +ie speed, matting type, colour tweak + +object that plays when a note is received can be called a track, a sample, a bank, a layer? + +object remembers playback head/ heads + +initial footage set for each track: program change? +(does this leave any room for creative input) or set via gui? + +video playback object +still image object + +load files in gui - loadable area + +creative input - alter layers live via AVS compatible system which also allows local MIDI control, +scripting, manipulating layers etc + +probably pretty tricky to create a .ape loader - difficulty in recreating the windows GUI + +probably a lot easier to think about a way of making a modular editor that can be manipulated live +nice to think about making scripted layers - using nseel or other + +initially - divide screen into grid - play notes with fade + +class that loads an svg and maps controllers to layers +layers are there but maybe its best to draw all of the colours mapped in some way rather than cutting out layers - colour transformation based on a hue angle + + +fix feedback - direction etc +all drawn/ scaled from middle +colours for svgs +multi screen +loader/ programme changer - seperate xml for main programme and for each content section +script engine for scaling +more specific colour filtering for photos +auto masks based on colour + +wrap around/ scale textures + +3d blocks +non random colours + +option to randomise colours on each note + +--make transparent + +--interface for exploring and saving - swapping? + + +*/ + + + +#define OF_ADDON_USING_OFXMIDIIN + + +#include "ofxMidi.h" +#include "ofxFensterManager.h" + +#include "ofxGui.h" + + +#include "viewport.h" +#include "threadNI.h" + + +/* +enum PropertyAttribute { + None = 0, + ReadOnly = 1 << 0, + DontEnum = 1 << 1, + DontDelete = 1 << 2 +}; +*/ + +class previewWindow; +class guiWindow; +class kinectWindow; + +//#define GRAB_TEXTURE + +class testApp : public ofxFensterListener, public ofxMidiListener{ + + public: + + void setup(); + void update(); + void draw(); + + void keyPressed(int key, ofxFenster* win); + 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 gotMessage(ofMessage msg); + void dragEvent(ofDragInfo dragInfo); + void dragEvent(ofDragInfo dragInfo,ofxFenster* win); + + void saveSettings(string filename); + + void mousePressedEvent(ofMouseEventArgs &args); + void keyPressedEvent(ofKeyEventArgs &args); + void windowEvent(ofResizeEventArgs &args); + + void nmidiMessage(int event,int data1, int data2); + + void makeColours(); + + void toggleFPS(); + bool showFPS; + + ofxXmlSettings XML; + + unsigned char* controllers; + int note, mode; + + //to be moved into svg object gui + + bool debug; + + bool fullscreenoutput; + + float lastnoteTime; + + int fadetime; + int rotate; + float scale,fscale; + + int xshift,yshift; + + ofColor* controller_colours; + + float colShift; + + viewport vp1,vp2; + vector<viewport*> viewports; + int activeView; + + previewWindow *prevWin; + guiWindow *guiWin; + kinectWindow *kinectWin; + + ofxFenster* win; + + int midiChannel; + + ofxMidiIn midiIn; + + void newMidiMessage(ofxMidiEventArgs& eventArgs); + + playlist list; + + + ofxPanel gui; + ofxToggle reversemain; + ofxToggle controlColours; + ofxToggle noteRandomiseColours; + ofxToggle transparentBlack; + ofxButton resetDrawscale; + ofxButton resetFBscale; + ofxIntSlider fS; + ofxParameter<int> fadeScale; + ofxFloatSlider dT; + ofxParameter<float> decayTime; + ofxToggle oscScale; + ofxToggle breakOsc; + ofxToggle randomOsc; + ofxFloatSlider sA; + ofxParameter<float> scaleAmplitude; + ofxFloatSlider sF; + ofxParameter<float> scaleFrequency; + ofxToggle drawCloud; + ofxToggle drawSkel; + + float randOffs; + + void resetDrawscalePressed(bool & pressed); + void resetFBscalePressed(bool & pressed); + + + //kinect stuff + + bool useKinect; + + threadNI NIinstance; + +}; + +class kinectWindow: public ofxFensterListener{ +public: + ~kinectWindow(); + testApp *parent; + void setup(); + void setParent(testApp *p); + void draw(); +}; + + +class previewWindow: public ofxFensterListener{ +public: + ~previewWindow(); + ofFbo *rb; + void setup(); + void setBuffer(ofFbo *buffer); + void draw(); +}; + +class guiWindow: public ofxFensterListener{ +public: + ~guiWindow(); + testApp *parent; + void setup(); + void setParent(testApp *p); + void draw(); + void dragEvent(ofDragInfo dragInfo,ofxFenster* win); + void windowMoved(int x, int y); +}; + + diff --git a/liveengine/src/viewport.cpp b/liveengine/src/viewport.cpp new file mode 100755 index 0000000..f86110f --- /dev/null +++ b/liveengine/src/viewport.cpp @@ -0,0 +1,458 @@ +#include "viewport.h"
+#define DEBUG 0
+
+//texture binding with normalised coords
+void bindTexture(ofBaseHasTexture &t) {
+ ofTexture &tex = t.getTextureReference();
+ tex.bind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
+
+ ofTextureData texData = tex.getTextureData();
+ if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
+ glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
+ } else {
+ glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
+ }
+
+ glMatrixMode(GL_MODELVIEW);
+}
+void unbindTexture(ofBaseHasTexture &t) {
+ t.getTextureReference().unbind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+}
+void bindTex(ofTexture &tex) {
+ tex.bind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
+
+ ofTextureData texData = tex.getTextureData();
+ if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
+ glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
+ } else {
+ glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
+ }
+
+ glMatrixMode(GL_MODELVIEW);
+}
+void unbindTex(ofTexture &tex) {
+ tex.unbind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+}
+//--------------------------------------------------
+
+viewport::viewport()
+{
+
+ //ctor
+}
+viewport::viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ setup(_w,_h,_x,_y,_r,_ox,_oy);
+}
+
+void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ r=_r;
+ w=_w;
+ h=_h;
+ x=_x;
+ y=_y;
+ ox=_ox;
+ oy=_oy;
+ rb1.allocate(w,h,GL_RGB);
+ rb2.allocate(w,h,GL_RGB);
+ rb3.allocate(w,h,GL_RGB);
+ isMapped=false;
+ printf("%ix%i, vp offset: %f,%f\n",w,h,-(sin(ofDegToRad(r))*h/2)-(cos(ofDegToRad(r))*w/2),-(sin(ofDegToRad(r))*w/2)-(cos(ofDegToRad(r))*h/2));
+}
+
+void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift){
+
+
+
+ // test screen shape
+ /*
+ ofSetColor(255,0,0);
+ ofRect(0,0,w/2,h/2);
+ ofRect(w/2,h/2,w/2,h/2);
+ ofSetColor(0,255,0);
+ ofRect(0,h/2,w/2,h/2);
+ ofRect(w/2,0,w/2,h/2);
+ */
+
+ rb1.begin();
+
+ //can be done with texture offset?
+
+ int startx=((w-(w*fscale))/2)+xshift;
+ while (startx>0) startx-=(w*fscale);
+ int starty=((h-(h*fscale))/2)+yshift;
+ while (starty>0) starty-=(h*fscale);
+
+ for (int i=startx;i<w*2;i+=(w*fscale)) {
+ for (int j=starty;j<h*2;j+=(h*fscale)) {
+ rb2.draw(i,j,w*fscale,h*fscale);
+ }
+ }
+
+ float notewidth=w/NUM_NOTES;
+ float noteheight=h/NUM_CONTROLLERS;
+
+ ofPushStyle();
+
+ if (note>0||mode==SOLID) {
+ switch(mode) {
+ case SOLID: + ofSetColor(255,0,0); + ofRect(0,0,ofGetWidth(),ofGetHeight()); + break;
+ case BLOCKS:
+ for (int i=0;i<NUM_CONTROLLERS;i++){
+ ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
+ ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
+ }
+ break;
+ case LIST:
+ if (list.lock()) { //if playlist is loaded
+ if (list.layers.find(note)!=list.layers.end()) {
+ ofPushMatrix();
+ ofTranslate(w/2,h/2);
+ ofScale(scale,scale,scale);
+ ofTranslate(-w/2,-h/2);
+ ofSetColor(255,255,255);
+ if (controlColours) list.layers[note]->draw(a,controllers,w,h,transparentBlack,colShift);
+ else list.layers[note]->draw(a,w,h,colShift);
+ ofPopMatrix();
+ }
+ list.unlock();
+ }
+ break;
+ }
+ }
+
+ rb1.end();
+
+ rb2.begin();
+ ofSetColor(255,255,255);
+ rb1.draw(0,0);
+ rb2.end();
+
+ ofPushMatrix();
+ ofTranslate(x+(w/2),y+(h/2));
+ ofRotate(r);
+ //ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
+ ofTranslate(ox,oy);
+
+ rb2.draw(0,0);
+
+ ofPopStyle();
+
+ ofPopMatrix();
+
+}
+
+viewport::~viewport()
+{
+ //dtor
+}
+
+void viewport::setUG(ofxUserGenerator *_rUser){
+ rUser=_rUser;
+ isMapped=true;
+}
+
+//-------------------------
+mappedviewport::mappedviewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ setup(_w,_h,_x,_y,_r,_ox,_oy);
+}
+void mappedviewport::setUG(ofxUserGenerator *_rUser){
+ rUser=_rUser;
+} +void viewport::setcam(map<string,string>&settings){ + + vars=new keyVar[9]; + vars[0].set('w','s',ofToFloat(settings["fov"]),0.2,1.0,3.0); + vars[1].set('g','d',ofToFloat(settings["targX"]),10,1.0,3.0); + vars[2].set('r','v',ofToFloat(settings["targY"]),10,1.0,3.0); + vars[3].set('t','c',ofToFloat(settings["targZ"]),10,1.0,3.0); + vars[4].set('u','n',ofToFloat(settings["lat"]),.03,1.0,3.0); + vars[5].set('j','h',ofToFloat(settings["lng"]),.03,1.0,3.0); + vars[6].set(',','m',ofToFloat(settings["roll"]),0.03,1.0,3.0); + vars[7].set('o','l',ofToFloat(settings["dolly"]),25,1.0,3.0); + vars[8].set('q','a',ofToFloat(settings["distort"]),.00001,1.0,3.0); +} +double viewport::getSetting(const string& setting){ + if (setting=="fov") return vars[0].getVal(); + if (setting=="targX") return vars[1].getVal(); + if (setting=="targY") return vars[2].getVal(); + if (setting=="targZ") return vars[3].getVal(); + if (setting=="lat") return vars[4].getVal(); + if (setting=="lng") return vars[5].getVal(); + if (setting=="roll") return vars[6].getVal(); + if (setting=="dolly") return vars[7].getVal(); + if (setting=="distort") return vars[8].getVal(); + return 0.0; +}
+void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,bool drawCloud,bool drawSkel){
+
+ //printf("drawing mapped frame %i\n",ofGetFrameNum()); + ofNode c=ofNode(); + ofNode t=ofNode(); + t.setParent(c); + t.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal()); + //make target controls relative to rotation + c.rotate(vars[5].getVal(), ofVec3f(0, 1, 0)); + + target.setPosition(t.getGlobalPosition()); + //camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[7].getVal(), target); + camera.setFov(vars[0].getVal()); + ofVec3f p(0, 0, vars[7].getVal()); + //p.rotate(ofClamp(vars[2].getVal(), -89, 89), ofVec3f(1, 0, 0)); + p.rotate(vars[4].getVal(), ofVec3f(1, 0, 0)); + p.rotate(vars[5].getVal(), ofVec3f(0, 1, 0)); + p += target.getPosition(); + camera.setPosition(p); + camera.lookAt(target,ofVec3f(0,1,0).rotate(vars[6].getVal(),ofVec3f(0,0,1)).rotate(vars[5].getVal(),ofVec3f(0,1,0))); + + rb1.begin(); + +
+ int startx=((w-(w*fscale))/2)+xshift;
+ while (startx>0) startx-=(w*fscale);
+ int starty=((h-(h*fscale))/2)+yshift;
+ while (starty>0) starty-=(h*fscale);
+
+ for (int i=startx;i<w*2;i+=(w*fscale)) {
+ for (int j=starty;j<h*2;j+=(h*fscale)) {
+ rb2.draw(i,j,w*fscale,h*fscale);
+ }
+ }
+
+ float notewidth=w/NUM_NOTES;
+ float noteheight=h/NUM_CONTROLLERS;
+
+ ofPushStyle();
+
+ if (note>0||mode==SOLID) {
+ switch(mode) { + case SOLID: + ofSetColor(255,0,0); + ofRect(0,0,ofGetWidth(),ofGetHeight()); + break;
+ case BLOCKS:
+ for (int i=0;i<NUM_CONTROLLERS;i++){
+ ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
+ ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
+ }
+ break;
+ case LIST:
+ if (list.lock()) { //if playlist is loaded
+ if (list.layers.find(note)!=list.layers.end()) {
+ ofPushMatrix();
+ ofTranslate(w/2,h/2);
+ ofScale(scale,scale,scale);
+ ofTranslate(-w/2,-h/2);
+ if (controlColours) list.layers[note]->draw(a,controllers,w,h,transparentBlack,colShift);
+ else list.layers[note]->draw(a,w,h,colShift);
+ ofPopMatrix();
+ }
+ list.unlock();
+ }
+ break;
+ }
+ } +
+
+ rb1.end();
+
+ rb2.begin();
+ ofSetColor(255,255,255);
+ rb1.draw(0,0);
+ rb2.end();
+
+ rb3.begin();
+ ofSetColor(255,255,255);
+ ofBackground(0,0,0);
+ //rb1.draw(0,0);
+
+ //map onto kinect skeleton
+ + + camera.begin(); + + if (drawCloud) { + int step = 1; + glBegin(GL_POINTS); + for(int y = 0; y < 480; y += step) { + for(int x = 0; x < 640; x += step) { + ofPoint pos = rUser->getWorldCoordinateAt(x, y, 0); //userID); + //if (pos.z == 0 ) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd + ofColor color = rUser->getWorldColorAt(x,y, 0); //userID); + glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + glVertex3f(pos.x, pos.y, pos.z); + } + } + glEnd(); + glColor3f(1.0f, 1.0f, 1.0f); + }
+ if (drawSkel) {
+ ofSetColor(255,0,0);
+ glBegin(GL_LINES);
+ for (int i=0;i<rUser->getNumberOfTrackedUsers();i++) {
+ ofxTrackedUser *u=rUser->getTrackedUser(i);
+ glVertex3f(u->left_shoulder.position[0].X,u->left_shoulder.position[0].Y,u->left_shoulder.position[0].Z);
+ glVertex3f(u->left_shoulder.position[1].X,u->left_shoulder.position[1].Y,u->left_shoulder.position[1].Z);
+
+ glVertex3f(u-> left_upper_arm.position[0].X,u->left_upper_arm.position[0].Y,u-> left_upper_arm.position[0].Z);
+ glVertex3f(u-> left_upper_arm.position[1].X,u->left_upper_arm.position[1].Y,u-> left_upper_arm.position[1].Z);
+
+ glVertex3f(u-> left_lower_arm.position[0].X,u->left_lower_arm.position[0].Y,u-> left_lower_arm.position[0].Z);
+ glVertex3f(u-> left_lower_arm.position[1].X,u->left_lower_arm.position[0].Y,u-> left_lower_arm.position[1].Z);
+
+ glVertex3f(u-> right_shoulder.position[0].X,u->right_shoulder.position[0].Y,u-> right_shoulder.position[0].Z);
+ glVertex3f(u-> right_shoulder.position[1].X,u->right_shoulder.position[1].Y,u-> right_shoulder.position[1].Z);
+
+ glVertex3f(u-> right_upper_arm.position[0].X,u-> right_upper_arm.position[0].Y,u-> right_upper_arm.position[0].Z);
+ glVertex3f(u-> right_upper_arm.position[1].X,u-> right_upper_arm.position[1].Y,u-> right_upper_arm.position[1].Z);
+
+ glVertex3f(u-> right_lower_arm.position[0].X,u-> right_lower_arm.position[0].Y,u-> right_lower_arm.position[0].Z);
+ glVertex3f(u-> right_lower_arm.position[1].X,u-> right_lower_arm.position[1].Y,u-> right_lower_arm.position[1].Z);
+
+ glVertex3f(u-> left_upper_torso.position[0].X,u-> left_upper_torso.position[0].Y,u-> left_upper_torso.position[0].Z);
+ glVertex3f(u-> left_upper_torso.position[1].X,u-> left_upper_torso.position[1].Y,u-> left_upper_torso.position[1].Z);
+
+ glVertex3f(u->right_upper_torso.position[0].X,u->right_upper_torso.position[0].Y,u->right_upper_torso.position[0].Z);
+ glVertex3f(u->right_upper_torso.position[1].X,u->right_upper_torso.position[1].Y,u->right_upper_torso.position[1].Z);
+
+ glVertex3f(u->left_lower_torso.position[0].X,u->left_lower_torso.position[0].Y,u->left_lower_torso.position[0].Z);
+ glVertex3f(u->left_lower_torso.position[1].X,u->left_lower_torso.position[1].Y,u->left_lower_torso.position[1].Z);
+
+ glVertex3f(u->left_upper_leg.position[0].X,u->left_upper_leg.position[0].Y,u->left_upper_leg.position[0].Z);
+ glVertex3f(u->left_upper_leg.position[1].X,u->left_upper_leg.position[1].Y,u->left_upper_leg.position[1].Z);
+
+ glVertex3f(u->left_lower_leg.position[0].X,u->left_lower_leg.position[0].Y,u->left_lower_leg.position[0].Z);
+ glVertex3f(u->left_lower_leg.position[1].X,u->left_lower_leg.position[1].Y,u->left_lower_leg.position[1].Z);
+
+ glVertex3f(u->right_lower_torso.position[0].X,u->right_lower_torso.position[0].Y,u->right_lower_torso.position[0].Z);
+ glVertex3f(u->right_lower_torso.position[1].X,u->right_lower_torso.position[1].Y,u->right_lower_torso.position[1].Z);
+
+ glVertex3f(u->right_upper_leg.position[0].X,u->right_upper_leg.position[0].Y,u->right_upper_leg.position[0].Z);
+ glVertex3f(u->right_upper_leg.position[1].X,u->right_upper_leg.position[1].Y,u->right_upper_leg.position[1].Z);
+
+ glVertex3f(u->right_lower_leg.position[0].X,u->right_lower_leg.position[0].Y,u->right_lower_leg.position[0].Z);
+ glVertex3f(u->right_lower_leg.position[1].X,u->right_lower_leg.position[1].Y,u->right_lower_leg.position[1].Z);
+
+ glVertex3f(u->hip.position[0].X,u->hip.position[0].Y,u->hip.position[0].Z);
+ glVertex3f(u->hip.position[1].X,u->hip.position[1].Y,u->hip.position[1].Z);
+ }
+ glEnd();
+ ofSetColor(255,255,255);
+ } + + bindTexture(rb1); +
+ for (int i=0;i<rUser->getNumberOfTrackedUsers();i++){
+
+ ofxTrackedUser* u=(rUser->getTrackedUser(i+1));
+
+ if (u->neck.found) { + + float ratio=16.0f/9.0f; + float heightratio=0.8f; + float widthratio=0.8f; + + float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip vector + float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); + float az=((float)(u->hip.position[1].Z-u->hip.position[0].Z)); + + float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips + float cy=(float)(u->hip.position[0].Y)+(ay*0.5f); + float cz=(float)(u->hip.position[0].Z)+(az*0.5f); + + float hx=(((float)(u->left_shoulder.position[0].X))-cx); //torso vector + float hy=(((float)(u->left_shoulder.position[0].Y))-cy); + float hz=(((float)(u->left_shoulder.position[0].Z))-cz); + + float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom + float p1y=cy+(hy*(1.0f-heightratio)*0.5f); + float p1z=cz+(hz*(1.0f-heightratio)*0.5f); + + float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top + float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f))); + float p2z=cz+(hz*(1.0f-((1.0f-heightratio)*0.5f))); + + ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio), p2z-(az*0.5*widthratio)); + ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio), p2z+(az*0.5*widthratio)); + ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio), p1z-(az*0.5*widthratio)); + ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio), p1z+(az*0.5*widthratio)); + + ofMesh targ; + targ.addVertex(c1); + targ.addTexCoord(ofVec2f(0,0)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c4); + targ.addTexCoord(ofVec2f(1,1)); + targ.draw(); + + }
+ } +
+ camera.end(); +
+ unbindTexture(rb1);
+
+
+ rb3.end();
+
+ ofPushMatrix();
+ ofTranslate(x+(w/2),y+(h/2));
+ ofRotate(r);
+ //ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
+ ofTranslate(ox,oy);
+
+ rb3.draw(0,0);
+
+ ofPopStyle();
+
+ ofPopMatrix();
+
+} +//-------------------------------------------------------------- +void viewport::setDefaults(){ + vars[0].setVal(17.25); + vars[1].setVal(0.0); + vars[2].setVal(112.0); + vars[3].setVal(0.0); + vars[4].setVal(0.0); + vars[5].setVal(0.0); + vars[6].setVal(0.0); + vars[7].setVal(1000.0); + vars[8].setVal(0.0); +} +//-------------------------------------------------------------- + +void viewport::keyPressed(int key){ + for (int i=0;i<8;i++) vars[i].keyPressed(key); + if (DEBUG) printf("fov: %f distort: %f\n",vars[0].getVal(),vars[7].getVal()); + if (key=='!') setDefaults(); +} +//-------------------------------------------------------------- +void viewport::keyReleased(int key){ + for (int i=0;i<8;i++) vars[i].keyReleased(key); +}
diff --git a/liveengine/src/viewport.h b/liveengine/src/viewport.h new file mode 100755 index 0000000..c401c17 --- /dev/null +++ b/liveengine/src/viewport.h @@ -0,0 +1,69 @@ +#ifndef VIEWPORT_H
+#define VIEWPORT_H
+
+#include "ofxOpenNI.h"
+#include "ofMain.h"
+#include "playlist.h"
+
+#define NUM_NOTES 64
+#define START_NOTE 36
+#define NUM_CONTROLLERS 26
+#define START_CONTROLLER 102
+
+#define NOTHING 0
+#define BLOCKS 1
+#define LIST 2
+#define SOLID 3
+
+void bindTexture(ofBaseHasTexture &t);
+void unbindTexture(ofBaseHasTexture &t);
+void bindTex(ofTexture &tex);
+void unbindTex(ofTexture &tex); +
+#include "keyVar.h"
+
+class viewport
+{
+ public:
+ viewport();
+ viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy);
+ void setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy);
+ void draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift);
+ void mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,bool drawCloud,bool drawSkel);
+ void setcam(map<string,string>&settings); + double getSetting(const string& setting); +
+ ofImage testtexture;
+ virtual ~viewport();
+ void setUG(ofxUserGenerator *_rUser);
+ ofFbo rb1,rb2,rb3;
+ float r;
+ bool isMapped; + + void setDefaults(); + void keyPressed(int key); + void keyReleased(int key); +
+ protected:
+ int x, y,w,h,ox,oy;
+ ofxUserGenerator *rUser;
+ private:
+ keyVar* vars; + + ofCamera camera; + ofNode target;
+
+};
+
+class mappedviewport: public viewport {
+ public: +
+ mappedviewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy);
+ void setUG(ofxUserGenerator *_rUser);
+ void mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift);
+ ofxUserGenerator *rUser; + private: +
+};
+
+#endif // VIEWPORT_H
|
