diff options
| author | tim <tim@eclectronics.org> | 2017-06-13 21:57:54 +0100 |
|---|---|---|
| committer | tim <tim@eclectronics.org> | 2017-06-13 21:57:54 +0100 |
| commit | e7d2892633ba9761a8ab8cc98f812e2db89e8beb (patch) | |
| tree | f1657ba4a6e449da416051e9851c59b7e4b96cae /testDir/src | |
| parent | 2c3cdaa27878b6dfa23fae35239037f20f3ae6b1 (diff) | |
| parent | a0e8fefd1bf241b805c4542421bdbc6a4447fdc3 (diff) | |
Merge branch 'dirscanner'
Diffstat (limited to 'testDir/src')
| -rw-r--r-- | testDir/src/dirscanner.cpp | 132 | ||||
| -rw-r--r-- | testDir/src/dirscanner.h | 66 | ||||
| -rw-r--r-- | testDir/src/main.cpp | 17 | ||||
| -rw-r--r-- | testDir/src/ofApp.cpp | 88 | ||||
| -rw-r--r-- | testDir/src/ofApp.h | 34 |
5 files changed, 337 insertions, 0 deletions
diff --git a/testDir/src/dirscanner.cpp b/testDir/src/dirscanner.cpp new file mode 100644 index 0000000..f3aa974 --- /dev/null +++ b/testDir/src/dirscanner.cpp @@ -0,0 +1,132 @@ +#include "dirscanner.h" + +void playItem::play(){ + if (video.isLoaded()){ + video.play(); + ofLogNotice() << "playing video: "<<filename; + } + if (image.isAllocated()){ + ofLogNotice() << "playing 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)){ + ofLogNotice() << "loaded clip: "<<filename; + loaded=2; + } + } + return loaded>0; +} +void playItem::draw(){ + if (image.isAllocated()){ + + //ofEnableAlphaBlending(); + //ofSetColor(255,255,255,1.0); + image.draw(0,0); + //ofDisableAlphaBlending(); + + if (ofGetElapsedTimef()-startTime>5.0){ + isFinished=true; + } + } + if (video.isLoaded()){ + video.draw(0,0); + if (video.getIsMovieDone()){ + isFinished=true; + } + } +} + +void dirScanner::scan(){ + /* + parse directories and create structure + showing which folder to check at which time + */ + slots.clear(); + + ofDirectory dir(rootdir); + + dir.allowExt(""); //get directories + + dir.listDir(); + for(int i = 0; i < dir.size(); i++){ + string d=dir.getName(i); + int start = ofToInt(d.substr(0,4)); + int end = ofToInt(d.substr(5,4)); + + if (end){ + slots.push_back(timeSlot(dir.getPath(i),start,end)); + ofLogNotice() << "directory "<<i<<": "<<start<<" - "<<end<<" "<<dir.getPath(i); + + } + } +} + +int dirScanner::getSlotForTime(){ + /* + read vector of slots + 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<=railwaytime&&slots[i].end>=railwaytime){ + return i; + } + } + return -1; +} + +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)){ + items.push_back(item); + } + } + currentItem=0; + ofLogNotice() << "found "<<items.size()<<" items"; + +} + +void dirPlayer::draw(){ + int slot=scanner->getSlotForTime(); + 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(); + } + items[currentItem].draw(); + +}
\ No newline at end of file diff --git a/testDir/src/dirscanner.h b/testDir/src/dirscanner.h new file mode 100644 index 0000000..cddd42f --- /dev/null +++ b/testDir/src/dirscanner.h @@ -0,0 +1,66 @@ +#pragma once + +#include "ofMain.h" + +class timeSlot { + public: + timeSlot(std::string _p,int _s,int _e){ + path=_p; + start=_s; + end=_e; + } + string path; + int start; + int end; +}; + +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; + float startTime; +}; + +class dirScanner { + //todo: compare each item in vector for reload + public: + dirScanner(std::string _d=""){ + rootdir=_d; + } + int getSlotForTime(); + string rootdir; + void scan(); + vector<timeSlot> slots; +}; + +class dirPlayer { + public: + dirPlayer(){ + currentslot=-1; + } + dirPlayer(dirScanner *_s){ + scanner=_s; + dirPlayer(); + } + vector<playItem> items; + string playdir; + int currentslot; + dirScanner *scanner; + void load(std::string path); + void draw(); + int currentItem; +};
\ No newline at end of file diff --git a/testDir/src/main.cpp b/testDir/src/main.cpp new file mode 100644 index 0000000..120f5a0 --- /dev/null +++ b/testDir/src/main.cpp @@ -0,0 +1,17 @@ +#include "ofMain.h" +#include "ofApp.h" + +//======================================================================== +int main( ){ + +#ifdef FULLSCREEN + ofSetupOpenGL(1080,1920,OF_FULLSCREEN); +#else + ofSetupOpenGL(1080,1920,OF_WINDOW); // <-------- setup the GL context +#endif + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new ofApp()); + +} diff --git a/testDir/src/ofApp.cpp b/testDir/src/ofApp.cpp new file mode 100644 index 0000000..9ac9e12 --- /dev/null +++ b/testDir/src/ofApp.cpp @@ -0,0 +1,88 @@ +#include "ofApp.h" + + +//-------------------------------------------------------------- +void ofApp::setup(){ + + scanner=dirScanner(ofFilePath().getUserHomeDir()+"/Dropbox/menugrab"); + + scanner.scan(); + + player=dirPlayer(&scanner); + + ofSetFrameRate(5); +} + +//-------------------------------------------------------------- +void ofApp::update(){ + //ofBackground(255); +} + + +//-------------------------------------------------------------- +void ofApp::draw(){ + ofSetColor(255,255,255); + + player.draw(); + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + +} +//-------------------------------------------------------------- +void ofApp::exit() +{ + +} diff --git a/testDir/src/ofApp.h b/testDir/src/ofApp.h new file mode 100644 index 0000000..2b6ed7d --- /dev/null +++ b/testDir/src/ofApp.h @@ -0,0 +1,34 @@ +#pragma once + +#include "ofMain.h" + +#include "dirscanner.h" + + + +class ofApp : public ofBaseApp{ + + public: + + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + void exit(); + + dirScanner scanner; + dirPlayer player; +}; + + |
