From c02378a381cbb23ba56099a33fab38686c8d2b5b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 19 Sep 2023 19:01:30 +0100 Subject: loading vector data --- futuregael/src/show.h | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 futuregael/src/show.h (limited to 'futuregael/src/show.h') diff --git a/futuregael/src/show.h b/futuregael/src/show.h new file mode 100644 index 0000000..7261d8d --- /dev/null +++ b/futuregael/src/show.h @@ -0,0 +1,143 @@ +#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," "); + 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++; + } + words.push_back(w); + } + + 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 "< palette; + vector words; + ofSoundPlayer audio; + float duration; + float avgWordDuration; + +}; + + +class Show{ +public: + bool loadFont(filesystem::path fontpath){ + return font.load(fontpath); + } + Show(){ + isPlaying=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(); + isPlaying=true; + ofLog()<<"Line playing "<duration; + } + } + + void stop(){ + if (isPlaying){ + playline->audio.stop(); + isPlaying=false; + ofLog()<<"Line stopped"; + } + } + + void update(){ + if (isPlaying){ + if (ofGetElapsedTimef()-startTime>playline->duration){ + playline->audio.stop(); + isPlaying=false; + ofLog()<<"Line finished! "<duration;; + playline++; + if (playline==script.end()){ + ofLog()<<"Show finished!"; + } + } + } + } + + ofxCsv csv; + + vector script; + + vector::iterator playline; + + float startTime; + bool isPlaying; + + SVGFont font; +}; \ No newline at end of file -- cgit v1.2.3