summaryrefslogtreecommitdiff
path: root/liveengine/src/layers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'liveengine/src/layers.cpp')
-rwxr-xr-xliveengine/src/layers.cpp160
1 files changed, 137 insertions, 23 deletions
diff --git a/liveengine/src/layers.cpp b/liveengine/src/layers.cpp
index 4ac0c59..a0fb213 100755
--- a/liveengine/src/layers.cpp
+++ b/liveengine/src/layers.cpp
@@ -63,53 +63,167 @@ void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transp
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[i]*a*controllers[i]);
- if (!transparentBlack||((a*controllers[i])/127.0)>0.1) {
+ 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() {
- //img.setUseTexture(false);
+ //sprite.setUseTexture(false);
}
-imglayer::imglayer(string _f)
-{
- load(_f);
+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 _f){
- bool success=img.loadImage(_f);
- printf("%s\n",success?"loaded":"not loaded");
+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);
}
-/*
-WTF is going on with the image drawing
-
-
-*/
+
void imglayer::draw(float a,int cx,int cy,float colShift) {
- //if (img.isAllocated()) if (!img.isUsingTexture()) img.setUseTexture(true); //has to be done from the main thread? still doesn't work
- img.draw(0,0,ofGetWidth(),ofGetHeight());
- printf("drawing %f\n",ofGetElapsedTimef());
+ //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()
{
- //img.setUseTexture(false); //free texture
+ //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()
+{
}