#include "ofMain.h" #include "ofxCsv.h" #include "vectortext.h" class ScriptLine{ public: ScriptLine(SVGFont &font,string audiofile,string cols,string message){ vector colours=ofSplitString(cols,","); for (auto c: colours){ palette.push_back(ofColor::fromHex(ofHexToInt(c))); } clear(); vector m=ofSplitString(message," "); width=0; for (auto& word: m){ glyphWord w; int pos=0; for (auto& c: word){ string uniglyph = ofUTF8Substring(word, pos, 1); if (c<0){ //ofLog()<<"got unicode glyph, "<231 hue sat 0->255 brightness 255 ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) )); pos++; w.width+=w.glyphs[w.glyphs.size()-1].width; } words.push_back(w); width+=(w.width+enspace); } if (audio.load(audiofile)){ //requires https://github.com/arturoc/openFrameworks/tree/feature-soundPlayerDuration duration = ((float)audio.getDurationMS())/1000.0f; avgWordDuration = duration / words.size(); ofLog()<<"Line "<& getOutlines(float time){ float wordphase=time/duration; float phase=time/avgWordDuration; float phaseseg=fmod(phase,1.0f); //ofLog()<<"phase "<1.0f) word1amt=1.0f; float word2amt=phaseseg*2.0; if (word2amt>1.0f) word2amt=1.0f; outlines.clear(); float s=0.05f; float p=(-ofGetWidth()/3*s)-(width*wordphase); if (word1>-1&&word1 palette; vector words; ofSoundPlayer audio; float duration; float avgWordDuration; vector outlines; float enspace; float width; }; class Show{ public: bool loadFont(filesystem::path fontpath){ return font.load(fontpath); } Show(){ bisPlaying=false; } Show(filesystem::path fontpath){ font.load(fontpath); Show(); } bool load(string file){ if (!font.isLoaded()){ ofLogError()<<"cannot load show without a font"; return false; } // Load a CSV File. if(csv.load(file,"|")) { for (auto row:csv){ if (row.size()<2){ ofLog()<<"Error, found row with "<audio.isLoaded()){ playline->audio.play(); startTime=ofGetElapsedTimef(); bisPlaying=true; ofLog()<<"Line playing "<duration; } } void stop(){ if (isPlaying()){ playline->audio.stop(); bisPlaying=false; ofLog()<<"Line stopped"; } } void update(){ if (isPlaying()){ if (ofGetElapsedTimef()-startTime> (playline->avgWordDuration* playline->words.size()+2)){ playline->audio.stop(); bisPlaying=false; ofLog()<<"Line ended, "<duration;; playline++; if (playline==script.end()){ ofLog()<<"Show finished!"; } } } } vector& getOutlines(){ return playline->getOutlines(ofGetElapsedTimef()-startTime); } ofxCsv csv; vector script; vector::iterator playline; float startTime; bool bisPlaying; bool isPlaying() { return bisPlaying; } SVGFont font; };