summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortim <tim@eclectronics.org>2017-06-13 21:57:54 +0100
committertim <tim@eclectronics.org>2017-06-13 21:57:54 +0100
commite7d2892633ba9761a8ab8cc98f812e2db89e8beb (patch)
treef1657ba4a6e449da416051e9851c59b7e4b96cae
parent2c3cdaa27878b6dfa23fae35239037f20f3ae6b1 (diff)
parenta0e8fefd1bf241b805c4542421bdbc6a4447fdc3 (diff)
Merge branch 'dirscanner'
-rw-r--r--menuApp/src/ofApp.cpp4
-rw-r--r--menuApp/src/ofApp.h4
-rw-r--r--testDir/Makefile13
-rw-r--r--testDir/config.default141
-rw-r--r--testDir/src/dirscanner.cpp132
-rw-r--r--testDir/src/dirscanner.h66
-rw-r--r--testDir/src/main.cpp17
-rw-r--r--testDir/src/ofApp.cpp88
-rw-r--r--testDir/src/ofApp.h34
9 files changed, 499 insertions, 0 deletions
diff --git a/menuApp/src/ofApp.cpp b/menuApp/src/ofApp.cpp
index 81350ac..25990a1 100644
--- a/menuApp/src/ofApp.cpp
+++ b/menuApp/src/ofApp.cpp
@@ -131,6 +131,10 @@ bool ofApp::loadInstagramFeed(){
//--------------------------------------------------------------
void ofApp::setup(){
+ Dirscanner=dirScanner("/home/tim/Dropbox/menugrab");
+
+ Dirscanner.scan();
+
/*
std::string str ("€");
diff --git a/menuApp/src/ofApp.h b/menuApp/src/ofApp.h
index 17a3d93..a85258e 100644
--- a/menuApp/src/ofApp.h
+++ b/menuApp/src/ofApp.h
@@ -5,6 +5,8 @@
#include "ofxThreadedImageLoader.h"
#include "ofxTextSuite.h"
+#include "dirscanner.h"
+
#define IMAGE_SLOTS 5
//#define FACTOR 1.0 //now in config.make
#define FONTSIZE 13
@@ -66,6 +68,8 @@ class ofApp : public ofBaseApp{
ofImage background;
ofImage overlay;
+
+ dirScanner Dirscanner;
};
diff --git a/testDir/Makefile b/testDir/Makefile
new file mode 100644
index 0000000..8d8e4c0
--- /dev/null
+++ b/testDir/Makefile
@@ -0,0 +1,13 @@
+# Attempt to load a config.make file.
+# If none is found, project defaults in config.project.make will be used.
+ifneq ($(wildcard config.make),)
+ include config.make
+endif
+
+# make sure the the OF_ROOT location is defined
+ifndef OF_ROOT
+ OF_ROOT=$(realpath ../../..)
+endif
+
+# call the project makefile!
+include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
diff --git a/testDir/config.default b/testDir/config.default
new file mode 100644
index 0000000..9c956bf
--- /dev/null
+++ b/testDir/config.default
@@ -0,0 +1,141 @@
+################################################################################
+# CONFIGURE PROJECT MAKEFILE (optional)
+# This file is where we make project specific configurations.
+################################################################################
+
+################################################################################
+# OF ROOT
+# The location of your root openFrameworks installation
+# (default) OF_ROOT = ../../..
+################################################################################
+# OF_ROOT =
+
+################################################################################
+# PROJECT ROOT
+# The location of the project - a starting place for searching for files
+# (default) PROJECT_ROOT = . (this directory)
+#
+################################################################################
+# PROJECT_ROOT = .
+
+################################################################################
+# PROJECT SPECIFIC CHECKS
+# This is a project defined section to create internal makefile flags to
+# conditionally enable or disable the addition of various features within
+# this makefile. For instance, if you want to make changes based on whether
+# GTK is installed, one might test that here and create a variable to check.
+################################################################################
+# None
+
+################################################################################
+# PROJECT EXTERNAL SOURCE PATHS
+# These are fully qualified paths that are not within the PROJECT_ROOT folder.
+# Like source folders in the PROJECT_ROOT, these paths are subject to
+# exlclusion via the PROJECT_EXLCUSIONS list.
+#
+# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_EXTERNAL_SOURCE_PATHS =
+
+################################################################################
+# PROJECT EXCLUSIONS
+# These makefiles assume that all folders in your current project directory
+# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
+# to look for source code. The any folders or files that match any of the
+# items in the PROJECT_EXCLUSIONS list below will be ignored.
+#
+# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
+# string unless teh user adds a wildcard (%) operator to match subdirectories.
+# GNU make only allows one wildcard for matching. The second wildcard (%) is
+# treated literally.
+#
+# (default) PROJECT_EXCLUSIONS = (blank)
+#
+# Will automatically exclude the following:
+#
+# $(PROJECT_ROOT)/bin%
+# $(PROJECT_ROOT)/obj%
+# $(PROJECT_ROOT)/%.xcodeproj
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_EXCLUSIONS =
+
+################################################################################
+# PROJECT LINKER FLAGS
+# These flags will be sent to the linker when compiling the executable.
+#
+# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
+#
+# Note: Leave a leading space when adding list items with the += operator
+#
+# Currently, shared libraries that are needed are copied to the
+# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
+# add a runtime path to search for those shared libraries, since they aren't
+# incorporated directly into the final executable application binary.
+################################################################################
+# PROJECT_LDFLAGS=-Wl,-rpath=./libs
+
+################################################################################
+# PROJECT DEFINES
+# Create a space-delimited list of DEFINES. The list will be converted into
+# CFLAGS with the "-D" flag later in the makefile.
+#
+# (default) PROJECT_DEFINES = (blank)
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+#PROJECT_DEFINES = FULLSCREEN FACTOR=1.0
+
+################################################################################
+# PROJECT CFLAGS
+# This is a list of fully qualified CFLAGS required when compiling for this
+# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
+# defined in your platform specific core configuration files. These flags are
+# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
+#
+# (default) PROJECT_CFLAGS = (blank)
+#
+# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
+# your platform specific configuration file will be applied by default and
+# further flags here may not be needed.
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_CFLAGS =
+
+################################################################################
+# PROJECT OPTIMIZATION CFLAGS
+# These are lists of CFLAGS that are target-specific. While any flags could
+# be conditionally added, they are usually limited to optimization flags.
+# These flags are added BEFORE the PROJECT_CFLAGS.
+#
+# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
+#
+# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
+#
+# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
+#
+# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
+#
+# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
+# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
+# file will be applied by default and further optimization flags here may not
+# be needed.
+#
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
+# PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
+
+################################################################################
+# PROJECT COMPILERS
+# Custom compilers can be set for CC and CXX
+# (default) PROJECT_CXX = (blank)
+# (default) PROJECT_CC = (blank)
+# Note: Leave a leading space when adding list items with the += operator
+################################################################################
+# PROJECT_CXX =
+# PROJECT_CC =
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;
+};
+
+