Browse Source

Added a DirectoryWatcher to magSlideShowSource

master
c-mendoza 8 years ago
parent
commit
b6a47bbb28
  1. 86
      src/Sources/magSlideShowSource.cpp
  2. 15
      src/Sources/magSlideShowSource.h

86
src/Sources/magSlideShowSource.cpp

@ -10,15 +10,20 @@
#include "SettingsLoader.h" #include "SettingsLoader.h"
#include "magSlideTransitionFactory.h" #include "magSlideTransitionFactory.h"
magSlideShowSource::magSlideShowSource() magSlideShowSource::magSlideShowSource() {
{
name = "Slide Show Source"; name = "Slide Show Source";
currentSlideIndex = 0; currentSlideIndex = 0;
isPlaying = false; isPlaying = false;
directoryWatcher = 0;
doInit = false;
} }
bool magSlideShowSource::initialize(magSlideShowSource::Settings settings) magSlideShowSource::~magSlideShowSource() {
{ directoryWatcher->endWatch();
delete directoryWatcher;
}
bool magSlideShowSource::initialize(magSlideShowSource::Settings settings) {
this->settings = settings; this->settings = settings;
bool success = true; bool success = true;
@ -45,23 +50,44 @@ bool magSlideShowSource::initialize(magSlideShowSource::Settings settings)
<< settings.slidesFolderPath; << settings.slidesFolderPath;
return success; return success;
} }
{
if (directoryWatcher == 0)
{
using namespace ofx::piMapper;
directoryWatcher = new DirectoryWatcher(settings.slidesFolderPath,
SourceTypeHelper::GetSourceTypeHelperEnum(
SOURCE_TYPE_NAME_IMAGE));
ofAddListener(directoryWatcher->directoryFileAddedEvent, this, &magSlideShowSource::fileAddedListener);
ofAddListener(directoryWatcher->directoryFileRemovedEvent, this,
&magSlideShowSource::fileRemovedListener);
directoryWatcher->beginWatch();
}
}
} }
else if (!settings.slideshowFilePath.empty()) else if (!settings.slideshowFilePath.empty())
{ {
// try to load slide show from xml
success = false; success = false;
} }
return success; return success;
} }
void magSlideShowSource::setup() void magSlideShowSource::setup() {
{
ofx::piMapper::FboSource::setup(); ofx::piMapper::FboSource::setup();
} }
void magSlideShowSource::update() void magSlideShowSource::update() {
// Perform re-initialization if the DirectoryWatcher
// detects file changes:
if (doInit)
{ {
initialize(settings);
doInit = false;
}
if (!isPlaying) return; if (!isPlaying) return;
auto nowTime = ofGetElapsedTimeMillis(); auto nowTime = ofGetElapsedTimeMillis();
@ -96,8 +122,7 @@ void magSlideShowSource::update()
} }
} }
void magSlideShowSource::draw() void magSlideShowSource::draw() {
{
ofBackground(0, 0); ofBackground(0, 0);
ofPushMatrix(); ofPushMatrix();
ofPushStyle(); ofPushStyle();
@ -115,8 +140,7 @@ void magSlideShowSource::draw()
ofDisableAlphaBlending(); ofDisableAlphaBlending();
} }
bool magSlideShowSource::createFromFolderContents(std::string path) bool magSlideShowSource::createFromFolderContents(std::string path) {
{
ofDirectory dir = ofDirectory(path); ofDirectory dir = ofDirectory(path);
slides.clear(); slides.clear();
@ -194,8 +218,7 @@ bool magSlideShowSource::createFromFolderContents(std::string path)
} }
} }
bool magSlideShowSource::loadFromXml() bool magSlideShowSource::loadFromXml() {
{
auto *loader = ofx::piMapper::SettingsLoader::instance(); auto *loader = ofx::piMapper::SettingsLoader::instance();
auto xml = ofxXmlSettings(); auto xml = ofxXmlSettings();
Settings settings; Settings settings;
@ -270,8 +293,7 @@ bool magSlideShowSource::loadFromXml()
return true; return true;
} }
void magSlideShowSource::addSlide(std::shared_ptr<magSlide> slide) void magSlideShowSource::addSlide(std::shared_ptr<magSlide> slide) {
{
// ofLogVerbose("addSlide") << slide->getId(); // ofLogVerbose("addSlide") << slide->getId();
slides.insert(slides.begin(), slide); slides.insert(slides.begin(), slide);
auto rOption = slide->getResizeOption(); auto rOption = slide->getResizeOption();
@ -347,8 +369,7 @@ void magSlideShowSource::addSlide(std::shared_ptr<magSlide> slide)
} }
void magSlideShowSource::play() void magSlideShowSource::play() {
{
if (!isPlaying) if (!isPlaying)
{ {
runningTime = 0; runningTime = 0;
@ -359,13 +380,11 @@ void magSlideShowSource::play()
} }
} }
void magSlideShowSource::pause() void magSlideShowSource::pause() {
{
isPlaying = false; isPlaying = false;
} }
void magSlideShowSource::playNextSlide() void magSlideShowSource::playNextSlide() {
{
//TODO //TODO
// I should check here to see if there are less than two slides. // I should check here to see if there are less than two slides.
// If so, we should probably return // If so, we should probably return
@ -450,27 +469,23 @@ void magSlideShowSource::playNextSlide()
enqueueSlide(slides[currentSlideIndex], ofGetElapsedTimeMillis()); enqueueSlide(slides[currentSlideIndex], ofGetElapsedTimeMillis());
} }
void magSlideShowSource::playPrevSlide() void magSlideShowSource::playPrevSlide() {
{
currentSlideIndex -= (direction*2); currentSlideIndex -= (direction*2);
playNextSlide(); playNextSlide();
} }
void magSlideShowSource::playSlide(int slideIndex) void magSlideShowSource::playSlide(int slideIndex) {
{
currentSlideIndex = slideIndex-direction; currentSlideIndex = slideIndex-direction;
playNextSlide(); playNextSlide();
} }
void magSlideShowSource::enqueueSlide(std::shared_ptr<magSlide> slide, u_int64_t startTime) void magSlideShowSource::enqueueSlide(std::shared_ptr<magSlide> slide, u_int64_t startTime) {
{
// ofLogVerbose() << "Enqueuing slide " << currentSlideIndex << " slide id: " << slide->getId(); // ofLogVerbose() << "Enqueuing slide " << currentSlideIndex << " slide id: " << slide->getId();
slide->start(startTime); slide->start(startTime);
activeSlides.insert(activeSlides.begin(), slide); activeSlides.insert(activeSlides.begin(), slide);
} }
void magSlideShowSource::slideStateChanged(const void *sender, ofEventArgs &args) void magSlideShowSource::slideStateChanged(const void *sender, ofEventArgs &args) {
{
magSlide *slide = (magSlide *) sender; magSlide *slide = (magSlide *) sender;
// ofLogVerbose("slideStateChanged") << "Slide id: " << slide->getId() << " Slide state: " // ofLogVerbose("slideStateChanged") << "Slide id: " << slide->getId() << " Slide state: "
@ -488,11 +503,18 @@ void magSlideShowSource::slideStateChanged(const void *sender, ofEventArgs &args
} }
void magSlideShowSource::slideComplete(const void *sender, ofEventArgs &args) void magSlideShowSource::slideComplete(const void *sender, ofEventArgs &args) {
{
magSlide *slide = (magSlide *) sender; magSlide *slide = (magSlide *) sender;
// ofLogVerbose() << "Slide Complete. id: " << slide->getId(); // ofLogVerbose() << "Slide Complete. id: " << slide->getId();
slide->isComplete = true; slide->isComplete = true;
} }
void magSlideShowSource::fileAddedListener(const void *sender) {
doInit = true;
}
void magSlideShowSource::fileRemovedListener(const void *sender) {
doInit = true;
}

15
src/Sources/magSlideShowSource.h

@ -9,12 +9,12 @@
#include "FboSource.h" #include "FboSource.h"
#include "magSlide.h" #include "magSlide.h"
#include "DirectoryWatcher.h"
class magSlide; class magSlide;
class magSlideShowSource : public ofx::piMapper::FboSource class magSlideShowSource : public ofx::piMapper::FboSource {
{
public: public:
magSlideShowSource(); magSlideShowSource();
struct Settings; // forward declaration struct Settings; // forward declaration
@ -44,15 +44,13 @@ public:
void playPrevSlide(); void playPrevSlide();
void playSlide(int slideIndex); void playSlide(int slideIndex);
enum LoopType : int enum LoopType : int {
{
NONE = 0, NONE = 0,
NORMAL, NORMAL,
PING_PONG PING_PONG
}; };
struct Settings struct Settings {
{
/** /**
* The pixel width of the FBO. * The pixel width of the FBO.
*/ */
@ -119,6 +117,7 @@ public:
//////////////////////////////////////////// ////////////////////////////////////////////
void slideStateChanged(const void *sender, ofEventArgs &args); void slideStateChanged(const void *sender, ofEventArgs &args);
void slideComplete(const void *sender, ofEventArgs &args); void slideComplete(const void *sender, ofEventArgs &args);
virtual ~magSlideShowSource();
/** /**
@ -155,6 +154,10 @@ private:
int currentSlideIndex = 0; int currentSlideIndex = 0;
int direction = 1; int direction = 1;
int loopCount = 0; int loopCount = 0;
ofx::piMapper::DirectoryWatcher* directoryWatcher;
void fileAddedListener(const void *sender);
void fileRemovedListener(const void *sender);
bool doInit;
}; };

Loading…
Cancel
Save