diff --git a/src/MediaServer.cpp b/src/MediaServer.cpp deleted file mode 100644 index be12408..0000000 --- a/src/MediaServer.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// -// MediaServer.cpp -// example -// -// Created by felix on 13.09.14. -// -// - -#include "MediaServer.h" - -namespace ofx { -namespace piMapper { -MediaServer::MediaServer() { - videoWatcher.registerAllEvents(this); - videoWatcher.addPath(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true, - &videoFileFilter); - imageWatcher.registerAllEvents(this); - imageWatcher.addPath(ofToDataPath(DEFAULT_IMAGES_DIR, true), true, - &imageFileFilter); -} -} -} \ No newline at end of file diff --git a/src/MediaServer/DirectoryWatcher.cpp b/src/MediaServer/DirectoryWatcher.cpp new file mode 100644 index 0000000..661792c --- /dev/null +++ b/src/MediaServer/DirectoryWatcher.cpp @@ -0,0 +1,23 @@ +// +// DirectoryWatcher.cpp +// example +// +// Created by felix on 23.09.14. +// +// + +#include "DirectoryWatcher.h" + +namespace ofx { +namespace piMapper { +DirectoryWatcher::DirectoryWatcher(std::string path, bool video) { + if (video) { + filter = CustomVideoPathFilter(); + } else { + filter = CustomImagePathFilter(); + } + dirWatcher.registerAllEvents(this); + dirWatcher.addPath(path, true, &filter); +} +} +} \ No newline at end of file diff --git a/src/MediaServer.h b/src/MediaServer/DirectoryWatcher.h similarity index 71% rename from src/MediaServer.h rename to src/MediaServer/DirectoryWatcher.h index fe5ffc3..a3ee50d 100644 --- a/src/MediaServer.h +++ b/src/MediaServer/DirectoryWatcher.h @@ -1,8 +1,8 @@ // -// MediaServer.h +// DirectoryWatcher.h // example // -// Created by felix on 13.09.14. +// Created by felix on 23.09.14. // // @@ -11,39 +11,46 @@ #include "ofMain.h" #include "ofxIO.h" -#define DEFAULT_IMAGES_DIR "sources/images/" -#define DEFAULT_VIDEOS_DIR "sources/videos/" - namespace ofx { namespace piMapper { -class CustomVideoPathFilter : public ofx::IO::AbstractPathFilter { +class CustomPathFilter : public ofx::IO::AbstractPathFilter { + public: + CustomPathFilter() {}; + virtual ~CustomPathFilter() {}; + virtual bool accept(const Poco::Path& path) const; +}; +class CustomVideoPathFilter : public CustomPathFilter { + public: CustomVideoPathFilter() {}; virtual ~CustomVideoPathFilter() {}; // TODO: Find useful filters e.g. *.mp4, etc - bool const accept(Poco::Path& path) const { + bool accept(const Poco::Path& path) const { return !Poco::File(path).isHidden() && ofIsStringInString(path.toString(), "mp4"); } }; -class CustomImagePathFilter : public ofx::IO::AbstractPathFilter { +class CustomImagePathFilter : public CustomPathFilter { + public: CustomImagePathFilter() {}; virtual ~CustomImagePathFilter() {}; // TODO: Find useful filters e.g. *.png,*.jpeg, etc. - bool const accept(Poco::Path& path) const { + bool accept(const Poco::Path& path) const { return !Poco::File(path).isHidden() && ofIsStringInString(path.toString(), "png"); } }; -class MediaServer { + +class DirectoryWatcher { public: - MediaServer(); + DirectoryWatcher(std::string path, bool video); // TODO make useful stuff with onDirectoryWatcher* void onDirectoryWatcherItemAdded( const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) { ofSendMessage("Added: " + evt.item.path()); + filePaths.push_back(evt.item.path()); } void onDirectoryWatcherItemRemoved( @@ -73,14 +80,11 @@ class MediaServer { << "Error: " << exc.displayText(); } - private: - // Video - ofx::IO::DirectoryWatcherManager videoWatcher; - ofx::IO::HiddenFileFilter videoFileFilter; + std::vector filePaths; - // Images - ofx::IO::DirectoryWatcherManager imageWatcher; - ofx::IO::HiddenFileFilter imageFileFilter; + private: + ofx::IO::DirectoryWatcherManager dirWatcher; + CustomPathFilter filter; }; } -} +} \ No newline at end of file diff --git a/src/MediaServer/MediaServer.cpp b/src/MediaServer/MediaServer.cpp new file mode 100644 index 0000000..1f5f167 --- /dev/null +++ b/src/MediaServer/MediaServer.cpp @@ -0,0 +1,23 @@ +// +// MediaServer.cpp +// example +// +// Created by felix on 13.09.14. +// +// + +#include "MediaServer.h" + +namespace ofx { +namespace piMapper { + +MediaServer::MediaServer() + : videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true), + imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), false) {} + +MediaServer::~MediaServer() {}; + +int MediaServer::getNumImages() { return imageWatcher.filePaths.size(); } +int MediaServer::getNumVideos() { return videoWatcher.filePaths.size(); } +} +} \ No newline at end of file diff --git a/src/MediaServer/MediaServer.h b/src/MediaServer/MediaServer.h new file mode 100644 index 0000000..af5c895 --- /dev/null +++ b/src/MediaServer/MediaServer.h @@ -0,0 +1,35 @@ +// +// MediaServer.h +// example +// +// Created by felix on 13.09.14. +// +// + +#pragma once + +#include "ofMain.h" +#include "DirectoryWatcher.h" + +#define DEFAULT_IMAGES_DIR "sources/images/" +#define DEFAULT_VIDEOS_DIR "sources/videos/" + +namespace ofx { +namespace piMapper { + +class MediaServer { + public: + MediaServer(); + virtual ~MediaServer(); + + int getNumVideos(); + int getNumImages(); + + private: + // Video + ofx::piMapper::DirectoryWatcher videoWatcher; + // Images + ofx::piMapper::DirectoryWatcher imageWatcher; +}; +} +}