summaryrefslogtreecommitdiff
path: root/menuApp/src/dirscanner.cpp
diff options
context:
space:
mode:
authortim <tim@eclectronics.org>2017-06-13 23:34:14 +0100
committertim <tim@eclectronics.org>2017-06-13 23:34:14 +0100
commit87c535995a59391b50a242a9a71bc0c420da399c (patch)
treed25050c3bd3168c4fbc15654693edaaeb61893ab /menuApp/src/dirscanner.cpp
parentedeccbd160c72553d789516b40d4b922df848aac (diff)
looking gooddevelop
Diffstat (limited to 'menuApp/src/dirscanner.cpp')
-rw-r--r--menuApp/src/dirscanner.cpp107
1 files changed, 95 insertions, 12 deletions
diff --git a/menuApp/src/dirscanner.cpp b/menuApp/src/dirscanner.cpp
index 5798e55..d0f80a0 100644
--- a/menuApp/src/dirscanner.cpp
+++ b/menuApp/src/dirscanner.cpp
@@ -1,13 +1,56 @@
#include "dirscanner.h"
void playItem::play(){
-
+ //ofLogNotice() << "playing----->"<<filename;
+ if (video.isLoaded()){
+ video.play();
+ //ofLogNotice() << "video: "<<filename;
+ }
+ if (image.isAllocated()){
+ //ofLogNotice() << "still: "<<filename;
+ }
+ startTime=ofGetElapsedTimef();
+}
+bool playItem::load(string _filename){
+ filename=_filename;
+ ofFile file(filename);
+ string ext=ofToLower(file.getExtension());
+ loaded=0;
+ if (ext=="jpg"||ext=="png"){
+ if (image.load(filename)){
+ ofLogNotice() << "loaded image: "<<filename;
+ loaded=1;
+ }
+ }
+ if (ext=="mp4"||ext=="mov"){
+ if (video.load(filename)){
+ video.setLoopState(OF_LOOP_NONE);
+ ofLogNotice() << "loaded clip: "<<filename;
+ loaded=2;
+ }
+ }
+ return loaded>0;
}
void playItem::draw(){
+ if (image.isAllocated()){
-}
-bool playItem::isFinished(){
+ //ofEnableAlphaBlending();
+ //ofSetColor(255,255,255,1.0);
+ image.draw(0,0,ofGetWidth(),ofGetHeight());
+ //ofDisableAlphaBlending();
+ if (ofGetElapsedTimef()-startTime>5.0){
+ isFinished=true;
+ }
+ }
+ if (video.isLoaded()){
+ video.update();
+ video.draw(0,0,ofGetWidth(),ofGetHeight());
+ //ofLogNotice() << "position: "<<video.getPosition();
+ if (video.getIsMovieDone()){
+ isFinished=true;
+ }
+ }
}
void dirScanner::scan(){
@@ -27,31 +70,71 @@ void dirScanner::scan(){
int start = ofToInt(d.substr(0,4));
int end = ofToInt(d.substr(5,4));
- if (start&&end){
+ if (end){
slots.push_back(timeSlot(dir.getPath(i),start,end));
- ofLogNotice() << "item "<<i<<": "<<start<<" - "<<end<<" "<<dir.getPath(i);
+ ofLogNotice() << "directory "<<i<<": "<<start<<" - "<<end<<" "<<dir.getPath(i);
}
}
}
-int dirScanner::getSlotForTime(int time){
+int dirScanner::getSlotForTime(){
/*
read vector of slots
- return index of requested time
+ return index of current time
+ naive approach? assuming that the list is valid
*/
+ int railwaytime=(ofGetHours()*100)+ofGetMinutes();
+
for(int i = 0; i < slots.size(); i++){
- if (slots[i].start<=time&&slots[i].end>=time){
+ if (slots[i].start<=railwaytime&&slots[i].end>=railwaytime){
return i;
}
}
return -1;
}
-void dirPlayer::load(){
-
+void dirPlayer::load(std::string path){
+ items.clear();
+ ofDirectory dir(path);
+ dir.allowExt("mp4");
+ dir.allowExt("mov");
+ dir.allowExt("jpg");
+ dir.allowExt("png");
+ dir.listDir();
+ for(int i = 0; i < dir.size(); i++){
+ string d=dir.getPath(i);
+ playItem item;
+ if (item.load(d)){
+ ofLogNotice() << "pushing back: "<<i;
+ items.push_back(item);
+ }
+ }
+ ofLogNotice() << "found "<<items.size()<<" items";
+ currentItem=items.size()-1;
+ items[currentItem].isFinished=true;
+
}
-void dirPlayer::draw(){
-
+bool dirPlayer::draw(){
+ int slot=scanner->getSlotForTime();
+ if(slot==-1) return false;
+ if (slot!=currentslot){
+ if (slot>-1){
+ ofLogNotice() << "entering slot "<<slot<<": "<<scanner->slots[slot].path;
+ load(scanner->slots[slot].path);
+ }
+ else {
+ ofLogNotice() << "leaving slot";
+ }
+ currentslot=slot;
+ }
+ if (items[currentItem].isFinished){
+ items[currentItem].isFinished=false;
+ currentItem=(currentItem+1)%items.size();
+ items[currentItem].play();
+ ofLogNotice() << "playing clip "<<currentItem<<" - "<<(items[currentItem].loaded==0?"none":items[currentItem].loaded==1?"image":"mov");
+ }
+ items[currentItem].draw();
+ return true;
} \ No newline at end of file