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-type>fbo</source-type>
<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>
<properties>
<perspectiveWarping>1</perspectiveWarping>
</properties>
</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>

14
example/src/ofApp.cpp

@ -18,26 +18,12 @@ void ofApp::setup(){
// Create the slide show source.
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:
piMapper.registerFboSource(crossSource);
piMapper.registerFboSource(customSource);
piMapper.registerFboSource(slideShowSource);
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
// piMapper.showInfo();

35
src/Sources/magSlideShowSource.cpp

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

17
src/Sources/magSlideShowSource.h

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

Loading…
Cancel
Save