diff options
| author | Tim Redfern <redfernt@gmail.com> | 2023-09-22 00:23:14 +0100 |
|---|---|---|
| committer | Tim Redfern <redfernt@gmail.com> | 2023-09-22 00:23:14 +0100 |
| commit | 22c0d9bf8339d9c6e667bafd3b12baa867f8a29b (patch) | |
| tree | 72f2302d742e2794414250d815b63bc7b8668c5d /futuregael/src/show.h | |
| parent | cde8fab86a40be5d3c99bfd2d97605638647179f (diff) | |
fixed some bugs
Diffstat (limited to 'futuregael/src/show.h')
| -rw-r--r-- | futuregael/src/show.h | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/futuregael/src/show.h b/futuregael/src/show.h index 45d0023..43e4bad 100644 --- a/futuregael/src/show.h +++ b/futuregael/src/show.h @@ -2,10 +2,25 @@ #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<string> colours=ofSplitString(cols,","); for (auto c: colours){ palette.push_back(ofColor::fromHex(ofHexToInt(c))); @@ -14,6 +29,7 @@ public: clear(); vector<string> m=ofSplitString(message," "); width=0; + for (auto& word: m){ glyphWord w; int pos=0; @@ -22,31 +38,30 @@ public: if (c<0){ //ofLog()<<"got unicode glyph, "<<uniglyph; } - w.glyphs.push_back(font.getGlyph(uniglyph, + auto g=font.getGlyph(uniglyph, palette.size()? palette[ofRandom(palette.size())]: //112->231 hue sat 0->255 brightness 255 - ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) - )); + ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255)); + w.glyphs.push_back(g); + w.width+=g.width; pos++; - w.width+=w.glyphs[w.glyphs.size()-1].width; } 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()<<"Line "<<audiofile<<", duration "<<duration<<"s, "<<words.size()<<" words avg "<<avgWordDuration<<"s"; + ofLog()<<audiofile<<", duration "<<duration<<"s, width: "<<width; } else duration=0.0f; - enspace=font.enspace; - } void clear(){ words.clear(); @@ -97,9 +112,10 @@ public: outlines.clear(); - float s=0.05f; + float s=0.1f; - float p=(-ofGetWidth()/3*s)-(width*wordphase); + float p=((ofGetWidth()/4)*s)-(width*wordphase)-((ofGetWidth()/2)*s*wordphase); + float start=p; if (word1>-1&&word1<words.size()){ for (int i=0;i<word1;i++){ @@ -129,11 +145,16 @@ public: p+=g.width; } } + + if ((wordphase-1.0f)>0.0f&&!printed){ + ofLog()<<"added: "<<p-start<<" width: "<<width; + printed=true; + } return outlines; } - + string name; vector<ofColor> palette; vector<glyphWord> words; ofSoundPlayer audio; @@ -141,6 +162,8 @@ public: float avgWordDuration; vector<colourPolyline> outlines; float enspace; + bool printed; +private: float width; }; @@ -179,6 +202,8 @@ public: playline=script.begin(); + ofLog()<<"Selected "<<playline->name; + return true; } @@ -198,6 +223,7 @@ public: if (playline->audio.isLoaded()){ playline->audio.play(); + playline->printed=false; startTime=ofGetElapsedTimef(); bisPlaying=true; ofLog()<<"Line playing "<<playline->duration; @@ -212,15 +238,35 @@ public: } } + void previous(){ + stop(); + if (script.size()){ + if (playline!=script.begin()){ + playline--; + ofLog()<<"previous line selected, "<<playline->name; + } + } + } + + void next(){ + stop(); + if (script.size()){ + if (playline!=script.end()){ + playline++; + ofLog()<<"next line selected, "<<playline->name; + } + } + } + void update(){ if (isPlaying()){ if (ofGetElapsedTimef()-startTime> (playline->avgWordDuration* - playline->words.size()+2)){ + playline->words.size()+1)){ playline->audio.stop(); bisPlaying=false; - ofLog()<<"Line ended, "<<playline->duration;; playline++; + ofLog()<<"Line ended, selected "<<playline->name; if (playline==script.end()){ ofLog()<<"Show finished!"; } |
