#include "ofMain.h" #include "ofxCsv.h" #include "vectortext.h" /* [notice ] 1b Briseadh Bualadh Bos.wav, duration 1.709s, 3, width: 8003 [notice ] 1b Briseadh Bualadh Bos.wav, duration 1.709s, 3, width: 9137 [notice ] 1b Briseadh Bualadh Bos.wav, duration 1.709s, 3, width: 9137 the first time we load a scriptline the width comes out too short. why>>??? //this was caused becauase enspace=font.enspace was at the end of the initialiser //how did this make it work out the 2nd time? */ class ScriptLine{ public: ScriptLine(SVGFont &font,string audiofile,string cols,string message){ enspace=font.enspace; 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)); w.glyphs.push_back(g); w.width+=g.width; pos++; } words.push_back(w); width+=(w.width+enspace); } if (audio.load(audiofile)){ name=audiofile; //requires https://github.com/arturoc/openFrameworks/tree/feature-soundPlayerDuration duration = ((float)audio.getDurationMS())/1000.0f; avgWordDuration = duration / words.size(); ofLog()<& 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.1f; float p=((ofGetWidth()/8)/s)-(width*wordphase)-(((ofGetWidth()/4)*wordphase)/s); float start=p; if (word1>-1&&word10.0f&&!printed){ ofLog()<<"added: "< palette; vector words; ofSoundPlayer audio; float duration; float avgWordDuration; vector outlines; float enspace; bool printed; private: 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 "<name; return true; } playline=script.end(); return false; } void play(){ if (playline==script.end()){ if (script.size()){ playline=script.begin(); ofLog()<<"Restarted!"; } else return; } if (playline->audio.isLoaded()){ playline->audio.play(); playline->printed=false; startTime=ofGetElapsedTimef(); bisPlaying=true; ofLog()<<"Line playing "<duration; } } void stop(){ if (isPlaying()){ playline->audio.stop(); bisPlaying=false; ofLog()<<"Line stopped"; } } void previous(){ stop(); if (script.size()){ if (playline!=script.begin()){ playline--; ofLog()<<"previous line selected, "<name; } } } void next(){ stop(); if (script.size()){ if (playline!=script.end()){ playline++; ofLog()<<"next line selected, "<name; } } } void update(){ if (isPlaying()){ if (ofGetElapsedTimef()-startTime> (playline->avgWordDuration* playline->words.size()+1)){ playline->audio.stop(); bisPlaying=false; playline++; ofLog()<<"Line ended, selected "<name; if (playline==script.end()){ ofLog()<<"Show finished!"; } } for (int i=0;iwords.size();i++){ for (auto& g:playline->words[i].glyphs){ if (ofRandom(100)<1.0) { //speed g.colour=playline->palette[ofRandom(playline->palette.size())]; } } } } } vector& getOutlines(){ return playline->getOutlines(ofGetElapsedTimef()-startTime); } ofxCsv csv; vector script; vector::iterator playline; float startTime; bool bisPlaying; bool isPlaying() { return bisPlaying; } SVGFont font; };