summaryrefslogtreecommitdiff
path: root/futuregael/src
diff options
context:
space:
mode:
authorTim Redfern <redfernt@gmail.com>2023-09-17 20:14:53 +0100
committerTim Redfern <redfernt@gmail.com>2023-09-17 20:14:53 +0100
commit495cc57aaa5a00fccdee92ff6a3328fb62e2c319 (patch)
tree9dcec87edffb8630f8fd9224183276034bd6b83e /futuregael/src
parent797f54530edb7804fbb4b9b4bec3bce44749afd4 (diff)
reading durations
Diffstat (limited to 'futuregael/src')
-rw-r--r--futuregael/src/ofApp.cpp6
-rw-r--r--futuregael/src/ofApp.h43
2 files changed, 43 insertions, 6 deletions
diff --git a/futuregael/src/ofApp.cpp b/futuregael/src/ofApp.cpp
index fe007e8..c912916 100644
--- a/futuregael/src/ofApp.cpp
+++ b/futuregael/src/ofApp.cpp
@@ -61,10 +61,10 @@ void ofApp::keyReleased(int key){
break;
}
case ' ':{
- if (playline->audio.isPlaying()){
- playline->audio.stop();
+ if (playline->isPlaying()){
+ playline->stop();
}
- else playline->audio.play();
+ else playline->play();
break;
}
default:{
diff --git a/futuregael/src/ofApp.h b/futuregael/src/ofApp.h
index f627e48..d656bf1 100644
--- a/futuregael/src/ofApp.h
+++ b/futuregael/src/ofApp.h
@@ -6,17 +6,54 @@
class scriptLine{
public:
- scriptLine(string audiofile,string cols,string words){
- audio.load(audiofile);
- text=words;
+ scriptLine(string audiofile,string cols,string wrds){
+ if (audio.load(audiofile)){
+ //requires https://github.com/arturoc/openFrameworks/tree/feature-soundPlayerDuration
+ duration = ((float)audio.getDurationMS())/1000.0f;
+
+ vector<string> words=ofSplitString(wrds," ");
+
+ avgWordDuration = duration / words.size();
+
+ ofLog()<<"loaded "<<audiofile<<", duration "<<duration<<"s, avg "<<avgWordDuration;
+ }
+ else duration=0.0f;
+
+ text=wrds;
vector<string> colours=ofSplitString(cols,",");
for (auto c: colours){
palette.push_back(ofColor::fromHex(ofHexToInt(c)));
}
+
+ bisPlaying=false;
+
+ }
+ void play(){
+ if (audio.isLoaded()){
+ audio.play();
+ startTime=ofGetElapsedTimef();
+ }
+ }
+ bool isPlaying(){
+ return audio.isPlaying();
+ }
+ void stop(){
+ if (isPlaying()){
+ audio.stop();
+ }
+ }
+ void update(){
+ if (isPlaying()){
+ //if (ofGetElapsedTimef()){}
+ }
}
vector<ofColor> palette;
string text;
ofSoundPlayer audio;
+ float duration;
+ float avgWordDuration;
+ bool bisPlaying;
+ float startTime;
};
class ofApp : public ofBaseApp{