Browse Source

magSlideShow loads its own xml file.

Also added path so that if an xml file is not specified for the slide show, there are useful defaults that can still create one. 

Updated the example app to reflect these changes.

Updated the example's xml file.

Added an xml file for the slide show in the example.
master
c-mendoza 8 years ago
parent
commit
dad64e384a
  1. 11
      example/bin/data/magslideshow_settings.xml
  2. 22
      example/bin/data/ofxpimapper.xml
  3. 14
      example/src/ofApp.cpp
  4. 35
      src/Sources/magSlideShowSource.cpp
  5. 17
      src/Sources/magSlideShowSource.h

11
example/bin/data/magslideshow_settings.xml

@ -0,0 +1,11 @@
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<SlideDuration>1</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
</Loop>
<Transition></Transition>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>
</magSlideShow>

22
example/bin/data/ofxpimapper.xml

@ -73,31 +73,9 @@
<source> <source>
<source-type>fbo</source-type> <source-type>fbo</source-type>
<source-name>Slide Show Source</source-name> <source-name>Slide Show Source</source-name>
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<SlideDuration>1</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
</Loop>
<Transition></Transition>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>
</magSlideShow>
</source> </source>
<properties> <properties>
<perspectiveWarping>1</perspectiveWarping> <perspectiveWarping>1</perspectiveWarping>
</properties> </properties>
</surface> </surface>
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<SlideDuration>1</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
</Loop>
<Transition></Transition>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>
</magSlideShow>
</surfaces> </surfaces>

14
example/src/ofApp.cpp

@ -18,26 +18,12 @@ void ofApp::setup(){
// Create the slide show source. // Create the slide show source.
slideShowSource = new magSlideShowSource(); slideShowSource = new magSlideShowSource();
// Create the settings struct for the slide show.
// Initialize the slide show with our settings.
// If it fails, initialize from default settings
// Register our sources: // Register our sources:
piMapper.registerFboSource(crossSource); piMapper.registerFboSource(crossSource);
piMapper.registerFboSource(customSource); piMapper.registerFboSource(customSource);
piMapper.registerFboSource(slideShowSource); piMapper.registerFboSource(slideShowSource);
piMapper.setup(); piMapper.setup();
// Slide show needs to be loaded after piMapper is set up:
if (!slideShowSource->loadFromXml())
{
ofLogNotice("setup") << "loading magSlideShowSource XML settings failed. Initializing from default values";
magSlideShowSource::Settings sets;
slideShowSource->initialize(sets);
}
// The info layer is hidden by default, press <i> to toggle // The info layer is hidden by default, press <i> to toggle
// piMapper.showInfo(); // piMapper.showInfo();

35
src/Sources/magSlideShowSource.cpp

@ -10,12 +10,20 @@
#include "SettingsLoader.h" #include "SettingsLoader.h"
#include "magSlideTransitionFactory.h" #include "magSlideTransitionFactory.h"
const std::string magSlideShowSource::SettingsFileName = "magslideshow_settings.xml";
magSlideShowSource::magSlideShowSource() { magSlideShowSource::magSlideShowSource() {
name = "Slide Show Source"; name = "Slide Show Source";
currentSlideIndex = 0; currentSlideIndex = 0;
isPlaying = false; isPlaying = false;
directoryWatcher = 0; directoryWatcher = 0;
doInit = false; doInit = false;
if (!loadFromXml(SettingsFileName))
{
ofLogError("magSlideShowSource") << "Could not find slide show settings file " << SettingsFileName;
Settings sets;
initialize(sets);
}
} }
magSlideShowSource::~magSlideShowSource() { magSlideShowSource::~magSlideShowSource() {
@ -218,21 +226,20 @@ bool magSlideShowSource::createFromFolderContents(std::string path) {
} }
} }
bool magSlideShowSource::loadFromXml() { bool magSlideShowSource::loadFromXml(std::string path) {
auto *loader = ofx::piMapper::SettingsLoader::instance();
auto xml = ofxXmlSettings(); auto xml = ofxXmlSettings();
Settings settings; Settings settings;
if (!xml.load(loader->getLastLoadedFilename())) if (!xml.load(path))
{ {
ofLogError("magSlideShowSource") << "Could not load settings file " << loader->getLastLoadedFilename(); ofLogError("magSlideShowSource") << "Could not load settings file " << path;
return false; return false;
} }
xml.pushTag("surfaces"); // xml.pushTag("surfaces");
if (!xml.pushTag("magSlideShow")) if (!xml.pushTag("magSlideShow"))
{ {
ofLogError("magSlideShowSource") << "Slide show settings not found in " << loader->getLastLoadedFilename(); ofLogError("magSlideShowSource") << "Slide show settings not found in " << path;
return false; return false;
} }
@ -349,20 +356,18 @@ void magSlideShowSource::addSlide(std::shared_ptr<magSlide> slide) {
// Add transitions: // Add transitions:
if (!settings.transitionName.empty()) static ofParameterGroup bogusParamGroup; // This is temporary so that things compile
{
static ofParameterGroup bogusParamGroup; // This is temporary so that things compile
auto tf = magSlideTransitionFactory::instance(); auto tf = magSlideTransitionFactory::instance();
// slide->buildIn = tf->createTransition(settings.transitionName, // slide->buildIn = tf->createTransition(settings.transitionName,
// slide, // slide,
// bogusParamGroup, // bogusParamGroup,
// slide->buildInDuration); // slide->buildInDuration);
slide->transition = tf->createTransition(settings.transitionName, slide->transition = tf->createTransition(settings.transitionName,
slide, slide,
bogusParamGroup, bogusParamGroup,
slide->buildOutDuration); slide->buildOutDuration);
}
//// void method(const void * sender, ArgumentsType &args) //// void method(const void * sender, ArgumentsType &args)
ofAddListener(slide->slideStateChangedEvent, this, &magSlideShowSource::slideStateChanged); ofAddListener(slide->slideStateChangedEvent, this, &magSlideShowSource::slideStateChanged);
ofAddListener(slide->slideCompleteEvent, this, &magSlideShowSource::slideComplete); ofAddListener(slide->slideCompleteEvent, this, &magSlideShowSource::slideComplete);

17
src/Sources/magSlideShowSource.h

@ -17,6 +17,11 @@ class magSlide;
class magSlideShowSource : public ofx::piMapper::FboSource { class magSlideShowSource : public ofx::piMapper::FboSource {
public: public:
magSlideShowSource(); magSlideShowSource();
/**
* Default settings file name.
*/
static const std::string SettingsFileName;
struct Settings; // forward declaration struct Settings; // forward declaration
bool initialize(magSlideShowSource::Settings settings); bool initialize(magSlideShowSource::Settings settings);
void setup() override; void setup() override;
@ -35,8 +40,7 @@ class magSlideShowSource : public ofx::piMapper::FboSource {
* otherwise. Check the console for the specific error. * otherwise. Check the console for the specific error.
*/ */
bool createFromFolderContents(std::string path); bool createFromFolderContents(std::string path);
bool loadFromXml(std::string path);
bool loadFromXml();
void addSlide(std::shared_ptr<magSlide> slide); void addSlide(std::shared_ptr<magSlide> slide);
void play(); void play();
void pause(); void pause();
@ -67,15 +71,14 @@ class magSlideShowSource : public ofx::piMapper::FboSource {
float slideDuration = 5; float slideDuration = 5;
/** /**
* An optional default transition for the slide show. * The default transition for the slide show.
*/ */
std::string transitionName = ""; std::string transitionName = "Dissolve";
/** /**
* An optional default transition duration. If no transition * Default transition duration.
* is specified, this value is ignored;
*/ */
float transitionDuration = 0; float transitionDuration = 1;
/** /**
* If specified, all applicable files in the folder will * If specified, all applicable files in the folder will

Loading…
Cancel
Save