summaryrefslogtreecommitdiff
path: root/testDir/src/dirscanner.cpp
blob: feb29c1e2ca24b8af08a92b0ddaa2346d4b86389 (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
#include "dirscanner.h"

void playItem::play(){

}
void playItem::draw(){

}
bool playItem::isFinished(){

}

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 (start&&end){
			slots.push_back(timeSlot(dir.getPath(i),start,end));
			ofLogNotice() << "item "<<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(){

}

void dirPlayer::draw(){
	int slot=scanner->getSlotForTime();
	if (slot!=currentslot){
		if (slot>-1){
			ofLogNotice() << "entering slot "<<slot<<": "<<scanner->slots[slot].path;
		}
		else {
			ofLogNotice() << "leaving slots";
		}
		currentslot=slot;
	}
	

}