From 6f74f80e4c116c61b4734ffbae86aff881daaf5b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 26 Apr 2014 18:20:21 +0100 Subject: started GLFW version --- le_new/Makefile | 13 ++ le_new/addons.make | 9 + le_new/config.make | 141 +++++++++++++ le_new/le_new.cbp | 90 +++++++++ le_new/le_new.workspace | 9 + le_new/src/layers.cpp | 229 +++++++++++++++++++++ le_new/src/layers.h | 132 +++++++++++++ le_new/src/main.cpp | 17 ++ le_new/src/ofApp.cpp | 514 ++++++++++++++++++++++++++++++++++++++++++++++++ le_new/src/ofApp.h | 198 +++++++++++++++++++ le_new/src/playlist.cpp | 127 ++++++++++++ le_new/src/playlist.h | 30 +++ le_new/src/viewport.cpp | 136 +++++++++++++ le_new/src/viewport.h | 34 ++++ 14 files changed, 1679 insertions(+) create mode 100644 le_new/Makefile create mode 100644 le_new/addons.make create mode 100644 le_new/config.make create mode 100644 le_new/le_new.cbp create mode 100644 le_new/le_new.workspace create mode 100755 le_new/src/layers.cpp create mode 100755 le_new/src/layers.h create mode 100644 le_new/src/main.cpp create mode 100644 le_new/src/ofApp.cpp create mode 100644 le_new/src/ofApp.h create mode 100755 le_new/src/playlist.cpp create mode 100755 le_new/src/playlist.h create mode 100755 le_new/src/viewport.cpp create mode 100755 le_new/src/viewport.h (limited to 'le_new') diff --git a/le_new/Makefile b/le_new/Makefile new file mode 100644 index 0000000..cda22b7 --- /dev/null +++ b/le_new/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../openFrameworks +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/le_new/addons.make b/le_new/addons.make new file mode 100644 index 0000000..c864cb0 --- /dev/null +++ b/le_new/addons.make @@ -0,0 +1,9 @@ +ofxXmlSettings +ofxFenster +ofxMidi +ofxGui0074 +ofxSVGTiny +ofxAssets +ofxSpriteManager +ofxExtras + diff --git a/le_new/config.make b/le_new/config.make new file mode 100644 index 0000000..836fce7 --- /dev/null +++ b/le_new/config.make @@ -0,0 +1,141 @@ +################################################################################ +# CONFIGURE PROJECT MAKEFILE (optional) +# This file is where we make project specific configurations. +################################################################################ + +################################################################################ +# OF ROOT +# The location of your root openFrameworks installation +# (default) OF_ROOT = ../../.. +################################################################################ +# OF_ROOT = ../../.. + +################################################################################ +# PROJECT ROOT +# The location of the project - a starting place for searching for files +# (default) PROJECT_ROOT = . (this directory) +# +################################################################################ +# PROJECT_ROOT = . + +################################################################################ +# PROJECT SPECIFIC CHECKS +# This is a project defined section to create internal makefile flags to +# conditionally enable or disable the addition of various features within +# this makefile. For instance, if you want to make changes based on whether +# GTK is installed, one might test that here and create a variable to check. +################################################################################ +# None + +################################################################################ +# PROJECT EXTERNAL SOURCE PATHS +# These are fully qualified paths that are not within the PROJECT_ROOT folder. +# Like source folders in the PROJECT_ROOT, these paths are subject to +# exlclusion via the PROJECT_EXLCUSIONS list. +# +# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXTERNAL_SOURCE_PATHS = + +################################################################################ +# PROJECT EXCLUSIONS +# These makefiles assume that all folders in your current project directory +# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations +# to look for source code. The any folders or files that match any of the +# items in the PROJECT_EXCLUSIONS list below will be ignored. +# +# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete +# string unless teh user adds a wildcard (%) operator to match subdirectories. +# GNU make only allows one wildcard for matching. The second wildcard (%) is +# treated literally. +# +# (default) PROJECT_EXCLUSIONS = (blank) +# +# Will automatically exclude the following: +# +# $(PROJECT_ROOT)/bin% +# $(PROJECT_ROOT)/obj% +# $(PROJECT_ROOT)/%.xcodeproj +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXCLUSIONS = + +################################################################################ +# PROJECT LINKER FLAGS +# These flags will be sent to the linker when compiling the executable. +# +# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs +# +# Note: Leave a leading space when adding list items with the += operator +# +# Currently, shared libraries that are needed are copied to the +# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to +# add a runtime path to search for those shared libraries, since they aren't +# incorporated directly into the final executable application binary. +################################################################################ +# PROJECT_LDFLAGS=-Wl,-rpath=./libs + +################################################################################ +# PROJECT DEFINES +# Create a space-delimited list of DEFINES. The list will be converted into +# CFLAGS with the "-D" flag later in the makefile. +# +# (default) PROJECT_DEFINES = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_DEFINES = + +################################################################################ +# PROJECT CFLAGS +# This is a list of fully qualified CFLAGS required when compiling for this +# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS +# defined in your platform specific core configuration files. These flags are +# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. +# +# (default) PROJECT_CFLAGS = (blank) +# +# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in +# your platform specific configuration file will be applied by default and +# further flags here may not be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CFLAGS = + +################################################################################ +# PROJECT OPTIMIZATION CFLAGS +# These are lists of CFLAGS that are target-specific. While any flags could +# be conditionally added, they are usually limited to optimization flags. +# These flags are added BEFORE the PROJECT_CFLAGS. +# +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) +# +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) +# +# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the +# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration +# file will be applied by default and further optimization flags here may not +# be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE = +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG = + +################################################################################ +# PROJECT COMPILERS +# Custom compilers can be set for CC and CXX +# (default) PROJECT_CXX = (blank) +# (default) PROJECT_CC = (blank) +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CXX = +# PROJECT_CC = diff --git a/le_new/le_new.cbp b/le_new/le_new.cbp new file mode 100644 index 0000000..84593b2 --- /dev/null +++ b/le_new/le_new.cbp @@ -0,0 +1,90 @@ + + + + + + diff --git a/le_new/le_new.workspace b/le_new/le_new.workspace new file mode 100644 index 0000000..c98a5c1 --- /dev/null +++ b/le_new/le_new.workspace @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/le_new/src/layers.cpp b/le_new/src/layers.cpp new file mode 100755 index 0000000..bd0f1ce --- /dev/null +++ b/le_new/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;i0); +} +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;i0.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;i0.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>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/le_new/src/layers.h b/le_new/src/layers.h new file mode 100755 index 0000000..0ddca29 --- /dev/null +++ b/le_new/src/layers.h @@ -0,0 +1,132 @@ +#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 fills; + vector 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; + float speed,pos; //will this override the base class speed correctly? + +}; + +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/le_new/src/main.cpp b/le_new/src/main.cpp new file mode 100644 index 0000000..fde3a48 --- /dev/null +++ b/le_new/src/main.cpp @@ -0,0 +1,17 @@ +#include "ofMain.h" +#include "testApp.h" +#include "ofxFensterManager.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + //ofxFensterManager::setup(4080,768,OF_WINDOW); + ofxFensterManager::setup(1440,270,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()); + +} diff --git a/le_new/src/ofApp.cpp b/le_new/src/ofApp.cpp new file mode 100644 index 0000000..09eee92 --- /dev/null +++ b/le_new/src/ofApp.cpp @@ -0,0 +1,514 @@ +#include "ofApp.h" + +/* +//-------------------------------------------------------------- +void ofApp::setup(){ + ofSetFrameRate(60); + ofSetWindowPosition(0, 0); + ofSetWindowTitle("MAIN WINDOW"); + ofxFensterManager::get()->setupWindow(&window); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + ofBackground(30, 0, 0); + ofSetColor(255); + ofDrawBitmapString("I am the regular OF window\n\nOver there is another one -->", 10, 30); +} + +//-------------------------------------------------------------- +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){ + +} +*/ + +#include "ofApp.h" + +previewWindow::~previewWindow(){ + cout << "preview window destroyed" << endl; +} +void previewWindow::setup(){ + setWindowShape(600,800); + setWindowPosition(0, 0); + setWindowTitle("PREVIEW"); +} +void previewWindow::setParent(ofApp *p){ + parent=p; +} +void previewWindow::setBuffer(ofFbo *buffer){ + rb=buffer; +} +void previewWindow::draw(){ + + rb->draw(0,0,ofGetWidth(),ofGetHeight()); //why crash? + +} +void previewWindow::keyPressed(int key, ofxFenster* win){ + parent->keyPressed(key); +} +//-------------------------------------------------------------- +guiWindow::~guiWindow(){ + cout << "gui window destroyed" << endl; +} +void guiWindow::setup(){ + setWindowShape(200, 400); + setWindowPosition(610, 0); + setWindowTitle("CONTROL PANEL"); +} +void guiWindow::setParent(ofApp *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"); +} + +//-------------------------------------------------------------- +void testApp::setup(){ + + int midiPort=0; + midiChannel=0; + 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;icreateFenster(0, 0, 600, 800, OF_WINDOW); + ofxFensterManager::get()->setupWindow(&prevWin); + + //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->setParent(this); + prevWin->setBuffer(&viewports[2]->rb2); + + fullscreenoutput=false; + + guiWin=new guiWindow(); + gui.setup("","panel.xml",0,0); + gui.add(reverse.setup("reverse", false)); + 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("decay draw",fadeScale,0,255,255)); + decayTime=1.0f; + gui.add(dT.setup("decay time",decayTime,0,10.0,255)); + fadeBackground=0; + gui.add(fB.setup("decay background",fadeBackground,0,255,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)); + + resetDrawscale.addListener(this,&testApp::resetDrawscalePressed); + resetFBscale.addListener(this,&testApp::resetFBscalePressed); + + //gui window stuff + //ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW); + ofxFensterManager::get()->setupWindow(&guiWin); + + //ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); + + //win2->setWindowTitle("config"); + //win2->addListener(guiWin); + //guiWin->setup(); + guiWin->setParent(this); + + //debug=true; + + +} + +void ofApp::resetDrawscalePressed(bool & pressed){ + scale=1.0f; +} +void ofApp::resetFBscalePressed(bool & pressed){ + fscale=1.0f; +} + +void ofApp::makeColours() { + controller_colours=new ofColor[NUM_CONTROLLERS]; + for (int i=0;iupdate(); +} + +//-------------------------------------------------------------- +void ofApp::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;idraw(lambda,controllers,do_reverse?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,do_reverse?1.0f/(scale+os):scale+os,do_reverse?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f,fadeBackground); + } + + ofSetColor(255,255,255); + if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); + +} + +//-------------------------------------------------------------- +void ofApp::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 ofApp::keyPressed(int key){ + if(key =='q'){ + nmidiMessage(144,127,ofRandom(64)+36); + } + if(key == 's'){ + XML.saveFile("settings.xml"); + printf("settings saved!\n"); + } + if(key == 'f'){ + toggleFPS(); + } + if(key >='0' && key <= '9'){ + mode=key-'0'; + } + if(key == 267||key==OF_KEY_LEFT){ + xshift--; + } + if(key == 268||key==OF_KEY_RIGHT){ + xshift++; + } + if(key == 269||key==OF_KEY_UP){ + yshift--; + } + if(key == 270||key==OF_KEY_DOWN){ + 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 ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + + +} +void ofApp::mousePressed(int x, int y, int button) { +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- + +void ofApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ + dragEvent(dragInfo); +} +void ofApp::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="images/"+dragInfo.files[0].substr(sta,len); + printf("loading %s\n",filename.c_str()); + + list.load(filename); +} +void ofApp::windowEvent(ofResizeEventArgs &args){ + printf("window event\n"); +} + +void ofApp::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 ofApp::keyPressedEvent(ofKeyEventArgs &args) { + //printf("window key pressed: %i (%c)\n",args.key,args.key); + keyPressed(args.key); +} + +void ofApp::toggleFPS(){ + showFPS=!showFPS; +} + +void ofApp::newMidiMessage(ofxMidiMessage& eventArgs){ + if ((midiChannel==0)||(eventArgs.channel==midiChannel)) { + nmidiMessage(eventArgs.status,eventArgs.bytes[0],eventArgs.bytes[1]); + } +} + + //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 ofApp::nmidiMessage(int event,int data1, int data2) { + //printf("midi: %i %i\n",event,data1); + bool noteOn; //this old thing! + int i; + switch(event) { + case 144: //noteon-off channel 0 + //printf("note %i %i %i\n",event,data1,data2); + noteOn=(data1==0?false:true); + //for (int i=0;inote==eventArgs.byteOne) layers[i]->setActive(noteOn); + //} + + note=data2; + lastnoteTime=ofGetElapsedTimef(); + if (list.layers.size()&&list.lock()) { //if playlist is loaded + map::iterator itr; + //for(itr = list.layers.begin(); itr != list.layers.end(); ++itr){ + // list.layers[itr->first]->setNote(note); + //} + if (list.layers.find(note)!=list.layers.end()) 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;imix==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/le_new/src/ofApp.h b/le_new/src/ofApp.h new file mode 100644 index 0000000..fc07f9b --- /dev/null +++ b/le_new/src/ofApp.h @@ -0,0 +1,198 @@ +#pragma once + +#include "ofMain.h" +#include "ofxXmlSettings.h" +#include "ofxFensterManager.h" + +#define OF_ADDON_USING_OFXMIDIIN +#include "ofxMidi.h" + +#include "ofxGui.h" +#include "viewport.h" + +//converting to new fenster +// + +class previewWindow; +class guiWindow; + +class ofApp : 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 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 viewports; + + previewWindow *prevWin; + guiWindow *guiWin; + + int midiChannel; + + ofxMidiIn midiIn; + + void newMidiMessage(ofxMidiMessage& eventArgs); + + playlist list; + + + ofxPanel gui; + ofxToggle reverse; + ofxToggle reversemain; + ofxToggle controlColours; + ofxToggle noteRandomiseColours; + ofxToggle transparentBlack; + ofxButton resetDrawscale; + ofxButton resetFBscale; + ofxIntSlider fS; + ofxParameter fadeScale; + ofxIntSlider fB; + ofxParameter fadeBackground; + ofxFloatSlider dT; + ofxParameter decayTime; + ofxToggle oscScale; + ofxToggle breakOsc; + ofxToggle randomOsc; + ofxFloatSlider sA; + ofxParameter scaleAmplitude; + ofxFloatSlider sF; + ofxParameter scaleFrequency; + + float randOffs; + + void resetDrawscalePressed(bool & pressed); + void resetFBscalePressed(bool & pressed); + + +}; + + +class previewWindow: public ofxFenster{ +public: + ~previewWindow(); + ofFbo *rb; + ofApp *parent; + void setParent(ofApp *p); + void setup(); + void setBuffer(ofFbo *buffer); + void draw(); + void keyPressed(int key, ofxFenster* win); +}; + +class guiWindow: public ofxFenster{ +public: + ~guiWindow(); + ofApp *parent; + void setup(); + void setParent(ofApp *p); + void draw(); + void dragEvent(ofDragInfo dragInfo,ofxFenster* win); + void windowMoved(int x, int y); +}; + +/* +class CustomWindow : public ofxFenster{ +public: + void setup(){ + setWindowShape(1280, 720); + setWindowPosition(310, 0); + setWindowTitle("SECOND WINDOW"); + } + + void update(){ + radius = sin(ofGetFrameNum()*.06)*100; + } + + void draw(){ + ofBackground(0); + + ofNoFill(); + + ofSetColor(100); + ofLine(mouseX, 0, mouseX, getHeight()); + ofLine(0, mouseY, getWidth(), mouseY); + + ofSetColor(255); + ofCircle(getWidth()*.5, getHeight()*.5, radius); + } + + void keyPressed(int key){ + cout << "KEY PRESSED " << (char)key << endl; + } + + void keyReleased(int key){ + cout << "KEY RELEASED " << (char)key << endl; + } + + float radius; +}; + +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); + + CustomWindow window; +}; +*/ \ No newline at end of file diff --git a/le_new/src/playlist.cpp b/le_new/src/playlist.cpp new file mode 100755 index 0000000..ce3beba --- /dev/null +++ b/le_new/src/playlist.cpp @@ -0,0 +1,127 @@ +#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(); + printf("unlocking thread\n"); + } +} + +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;inote) { + for (int j=note+1;jnote) { + 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::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 layers; + string name; + protected: + private: +}; + +#endif // PLAYLIST_H diff --git a/le_new/src/viewport.cpp b/le_new/src/viewport.cpp new file mode 100755 index 0000000..a169146 --- /dev/null +++ b/le_new/src/viewport.cpp @@ -0,0 +1,136 @@ +#include "viewport.h" + + + +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); + + 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,int fadeBG){ + + //http://forum.xfce.org/viewtopic.php?id=6580 + + // 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); + */ + + ofPushMatrix(); + + 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;i0) { + //fadeout part + ofEnableAlphaBlending(); + ofSetColor(0,0,0,fadeBG); + ofRect(0,0,w,h); + ofDisableAlphaBlending(); + } + + float notewidth=w/NUM_NOTES; + float noteheight=h/NUM_CONTROLLERS; + + ofPushStyle(); + + if (note>0) { + switch(mode) { + case BLOCKS: + for (int i=0;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; + } + } + + ofPopStyle(); + + rb1.end(); + + rb2.begin(); + ofSetColor(255,255,255); + rb1.draw(0,0); + rb2.end(); + + ofPopMatrix(); + + ofPushMatrix(); + //ofTranslate(x+(w/2),y+(h/2)); this was the one that was working + //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(x,y); + + ofTranslate(((w/2)*abs(cos(ofDegToRad(r))))+((h/2)*abs(sin(ofDegToRad(r)))), + ((w/2)*abs(sin(ofDegToRad(r))))+((h/2)*abs(cos(ofDegToRad(r))))); + + ofRotate(r); + ofTranslate(-w/2,-h/2); + //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); get rid of this and get the rotation right + + ofDisableAlphaBlending(); + + rb2.draw(0,0); + + ofPopMatrix(); + + + + + +} + +viewport::~viewport() +{ + //dtor +} diff --git a/le_new/src/viewport.h b/le_new/src/viewport.h new file mode 100755 index 0000000..310a7c2 --- /dev/null +++ b/le_new/src/viewport.h @@ -0,0 +1,34 @@ +#ifndef VIEWPORT_H +#define VIEWPORT_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 + + + +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,int fadeBG); + virtual ~viewport(); + ofFbo rb1,rb2; + float r; + protected: + private: + int x, y,w,h,ox,oy; + +}; + +#endif // VIEWPORT_H -- cgit v1.2.3