blob: f3aa9740b8aa0ee2e5ba57b3caecdd45b4b56ba5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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();
}
|