summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/src/layers.h
blob: 0ddca295c41b72700ded46fbc298277cf30f9330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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 <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;
        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