diff options
| author | tim <tim@eclectronics.org> | 2017-06-13 23:34:14 +0100 |
|---|---|---|
| committer | tim <tim@eclectronics.org> | 2017-06-13 23:34:14 +0100 |
| commit | 87c535995a59391b50a242a9a71bc0c420da399c (patch) | |
| tree | d25050c3bd3168c4fbc15654693edaaeb61893ab | |
| parent | edeccbd160c72553d789516b40d4b922df848aac (diff) | |
looking gooddevelop
| -rw-r--r-- | menuApp/src/dirscanner.cpp | 107 | ||||
| -rw-r--r-- | menuApp/src/dirscanner.h | 26 | ||||
| -rw-r--r-- | menuApp/src/ofApp.cpp | 175 | ||||
| -rw-r--r-- | menuApp/src/ofApp.h | 3 |
4 files changed, 207 insertions, 104 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 diff --git a/menuApp/src/dirscanner.h b/menuApp/src/dirscanner.h index 1e70ed8..4512842 100644 --- a/menuApp/src/dirscanner.h +++ b/menuApp/src/dirscanner.h @@ -16,15 +16,22 @@ class timeSlot { class playItem { public: + playItem(){ + loaded=0; + isFinished=false; + } playItem(std::string _n){ filename=_n; + playItem(); } string filename; ofImage image; ofVideoPlayer video; + int loaded; //0- none, 1- image, 2- mov + bool load(string filename); void play(); void draw(); - bool isFinished(); + bool isFinished; float startTime; }; @@ -34,7 +41,7 @@ class dirScanner { dirScanner(std::string _d=""){ rootdir=_d; } - int getSlotForTime(int time); + int getSlotForTime(); string rootdir; void scan(); vector<timeSlot> slots; @@ -42,11 +49,18 @@ class dirScanner { class dirPlayer { public: - dirPlayer(std::string _d){ - playdir=_d; + dirPlayer(){ + currentslot=-1; + } + dirPlayer(dirScanner *_s){ + scanner=_s; + dirPlayer(); } vector<playItem> items; string playdir; - void load(); - void draw(); + int currentslot; + dirScanner *scanner; + void load(std::string path); + bool draw(); + int currentItem; };
\ No newline at end of file diff --git a/menuApp/src/ofApp.cpp b/menuApp/src/ofApp.cpp index 47e0967..14ce45f 100644 --- a/menuApp/src/ofApp.cpp +++ b/menuApp/src/ofApp.cpp @@ -131,9 +131,11 @@ bool ofApp::loadInstagramFeed(){ //-------------------------------------------------------------- void ofApp::setup(){ - //Dirscanner=dirScanner("/home/tim/Dropbox/menugrab"); + scanner=dirScanner(ofFilePath().getUserHomeDir()+"/Dropbox/menugrab"); - //Dirscanner.scan(); + scanner.scan(); + + player=dirPlayer(&scanner); /* std::string str ("€"); @@ -186,96 +188,99 @@ void ofApp::update(){ void ofApp::draw(){ ofSetColor(255,255,255); - if(ofGetElapsedTimef()-lastPoll>POLL_INTERVAL) { - loadInstagramFeed(); - } + if (!player.draw()){ -ofPushMatrix(); + if(ofGetElapsedTimef()-lastPoll>POLL_INTERVAL) { + loadInstagramFeed(); + } - if(ROTATION>0){ - ofTranslate(540*FACTOR,960*FACTOR); - ofRotate(-ROTATION); - ofTranslate(-120*FACTOR,-540*FACTOR); - } - -ofPushMatrix(); //Store the coordinate system nexessary for some reason - background.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); -ofPopMatrix(); //Restore the coordinate system - - int colinitialoffset=40; - int rowinitialoffset=60; - int coloffset=520; - int imgsize=480; - int rowoffset=615; - int col=0; - int row=0; - int cols=2; - int textcolinset=10; - int textrowinset=50; + ofPushMatrix(); - - //some kind of rendering bug with textsuite means it has to go last or everything is dim - - bool imageWaiting=false; - - if (!items.empty()) { - for (int i = 0; i < items.size(); i++) { - - if (items[i].image->isAllocated()) { - - int imgx=(colinitialoffset+(col*coloffset))*FACTOR; - int imgy=(rowinitialoffset+(row*rowoffset))*FACTOR; - items[i].image->draw(imgx,imgy,imgsize*FACTOR,imgsize*FACTOR); - myText.setText(items[i].caption); - myText.wrapTextX(imgsize*FACTOR); - myText.setColor(255,255,255,255); - myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset)*FACTOR),2); - - myText.setText(items[i].price); - myText.wrapTextX(imgsize*FACTOR); - myText.setColor(255,255,255,255); - myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset+(FONTSPACING*2))*FACTOR),2); - } - else imageWaiting=true; - - col++; - if (col==cols){ - col=0; - row++; - } - } - } + if(ROTATION>0){ + ofTranslate(540*FACTOR,960*FACTOR); + ofRotate(-ROTATION); + ofTranslate(-120*FACTOR,-540*FACTOR); + } + + ofPushMatrix(); //Store the coordinate system nexessary for some reason + background.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); + ofPopMatrix(); //Restore the coordinate system + + int colinitialoffset=40; + int rowinitialoffset=60; + int coloffset=520; + int imgsize=480; + int rowoffset=615; + int col=0; + int row=0; + int cols=2; + int textcolinset=10; + int textrowinset=50; + + + //some kind of rendering bug with textsuite means it has to go last or everything is dim + + bool imageWaiting=false; + + if (!items.empty()) { + for (int i = 0; i < items.size(); i++) { + + if (items[i].image->isAllocated()) { + + int imgx=(colinitialoffset+(col*coloffset))*FACTOR; + int imgy=(rowinitialoffset+(row*rowoffset))*FACTOR; + items[i].image->draw(imgx,imgy,imgsize*FACTOR,imgsize*FACTOR); + myText.setText(items[i].caption); + myText.wrapTextX(imgsize*FACTOR); + myText.setColor(255,255,255,255); + myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset)*FACTOR),2); + + myText.setText(items[i].price); + myText.wrapTextX(imgsize*FACTOR); + myText.setColor(255,255,255,255); + myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset+(FONTSPACING*2))*FACTOR),2); + } + else imageWaiting=true; + + col++; + if (col==cols){ + col=0; + row++; + } + } + } + + ofEnableAlphaBlending(); + overlay.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); //don't work on a horiz screen?? + ofDisableAlphaBlending(); + + //for some reason the final is only drawn on the frame AFTER all 5 images become allocated + //hence the "primed" mechanism + if (primed){ + ofImage img; + //float rotation=ofDegToRad(ROTATION); + //int width=(1920*FACTOR*sin(rotation))+(1080*FACTOR*cos(rotation)); + //int height=(1920*FACTOR*cos(rotation))+(1080*FACTOR*sin(rotation)); + img.grabScreen(0, 0,1920*FACTOR,1920*FACTOR); + if(ROTATION>0){ + img.rotate90(1); + img.crop(860*FACTOR,0,1080*FACTOR,1920*FACTOR); + } + else { + img.crop(0,0,1080*FACTOR,1920*FACTOR); + } + img.save(SCREENGRABFILEPATH); + primed=false; + } - ofEnableAlphaBlending(); - overlay.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); //don't work on a horiz screen?? - ofDisableAlphaBlending(); - - //for some reason the final is only drawn on the frame AFTER all 5 images become allocated - //hence the "primed" mechanism - if (primed){ - ofImage img; - //float rotation=ofDegToRad(ROTATION); - //int width=(1920*FACTOR*sin(rotation))+(1080*FACTOR*cos(rotation)); - //int height=(1920*FACTOR*cos(rotation))+(1080*FACTOR*sin(rotation)); - img.grabScreen(0, 0,1920*FACTOR,1920*FACTOR); - if(ROTATION>0){ - img.rotate90(1); - img.crop(860*FACTOR,0,1080*FACTOR,1920*FACTOR); - } - else { - img.crop(0,0,1080*FACTOR,1920*FACTOR); - } - img.save(SCREENGRABFILEPATH); - primed=false; - } + if (!isGrabbed&&!imageWaiting) { + primed=true; + isGrabbed=true; + } - if (!isGrabbed&&!imageWaiting) { - primed=true; - isGrabbed=true; + ofPopMatrix(); } -ofPopMatrix(); - } //-------------------------------------------------------------- diff --git a/menuApp/src/ofApp.h b/menuApp/src/ofApp.h index 1b94c06..0cb3705 100644 --- a/menuApp/src/ofApp.h +++ b/menuApp/src/ofApp.h @@ -69,7 +69,8 @@ class ofApp : public ofBaseApp{ ofImage background; ofImage overlay; - //dirScanner Dirscanner; + dirScanner scanner; + dirPlayer player; }; |
