#ifndef _SLIDE_APP
#define _SLIDE_APP

// openframeworks
#define OF_ADDON_USING_OFXXMLSETTINGS
#define OF_ADDON_USING_OFXOSC

#include "ofMain.h"
#include "ofAddons.h"

// project
#include "util.h"
#include "textdisplay.h"
#include "markov.h"

// stdlib
#include <string.h>
using namespace std;




////////////////////////////////////////
// CLASSES
////////////////////////////////////////
class SlideApp : public ofSimpleApp{
		
	private:
		// loading
		ofTrueTypeFont messageFont;
		char *statusmessage;
		float msgX;
		float msgY;
	
	
		bool showdata;
		// scenes
		int scene;
		bool playing;
	
		// time
		int nowtime;
		int timeout;
		bool doingtime;
		
		// settings
		bool fullscreen;
		bool autorun;
		bool fromtop;
		bool pauseatstart;
		int pausetime;
		int imagedisplay;
		int imagetimeout;
		int framesperletter;
		int letterframe;
		int texttimeout;
		
		// colours
		Colour *colourpalette;
		int totalcolours;
		Colour screencolour;
		Colour bgcolour;
		Colour forecolour;
	
		// statements
		Statement *statements;
		int totalStatements;
		int currentStatement;
		int maxdisplaylines;
		MultilineText displayText;
		int *statementlookup;
		Markov statementprobabilities;
		
		// slide images
		SlideImage *slideimages;
		int totalSlideImages;
		int currentslideimage;
		int *slidelookup;
		bool preloadimages;
		float slideX;
		float slideY;
		float slideWidth;
		float slideHeight;
		Markov slideprobabilities;
		int nextimagetimeout;
		
		// dims
		float width;
		float height;
		
		// OSC
		string oscname;
		int oscport;
		bool receiveosc;
		ofxOscReceiver	receiver;
		ofxOscSender *senders;
		int totalSenders;
		
	
	public:
		
		void setup();
		void prepareToRun();
		void loadSettings(char * filename);
		void update();
		void draw();
		void exit();
	
		// colours
		int getColourIndex(string name);
		void setColourTo(Colour *colour, string name);
		
		// slide images
		void preloadSlideImage(int slideIndex);
		void displaySlideImage(int slideIndex);
		void nextSlideImage();
		void setSlideImage(int imageID);
	
		// statements
		void nextStatement();
		void setStatement(int textID);
	
		void enterScene(int newscene);
		void endScene();
		
		void enterPlaystate(int newstate);
	
		void setTimeout(int duration);
		void cancelTimeout();
		void updateTimeout();
		void callTimeout();
		
		
		// OSC
		void sendPlaystate(int playstate);
		void sendEnterScene(int newscene);
		void sendNewSlideImage(int imageID);
		void sendNewStatement(int textID);
		void updateIncomingOSC();
		
		// util
		void statusMessage(char *msg);
	
		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();
	
};

#endif
	
