diff --git a/src/MediaServer/MediaServer.cpp b/src/MediaServer/MediaServer.cpp index 01a6aeb..8b22544 100644 --- a/src/MediaServer/MediaServer.cpp +++ b/src/MediaServer/MediaServer.cpp @@ -40,13 +40,13 @@ void MediaServer::setup(){ void MediaServer::update(){ for(int i = 0; i < fboSources.size(); ++i){ - fboSources[i]->updateFbo(); + if (fboSources[i]->isActive() || fboSources[i]->runsInBackground()) fboSources[i]->updateFbo(); } } void MediaServer::draw(){ for(int i = 0; i < fboSources.size(); ++i){ - fboSources[i]->drawFbo(); + if (fboSources[i]->isActive() || fboSources[i]->runsInBackground()) fboSources[i]->drawFbo(); } } @@ -366,7 +366,8 @@ BaseSource * MediaServer::loadFboSource(std::string & fboSourceName){ // Is loaded, increase reference count and return existing loadedSources[fboSourceName]->referenceCount++; ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount; - return loadedSources[fboSourceName]; + source->setActive(true); + return loadedSources[fboSourceName]; } // else // Not loaded, add to loaded sources and activate @@ -375,7 +376,8 @@ BaseSource * MediaServer::loadFboSource(std::string & fboSourceName){ source->referenceCount = 1; ofLogNotice("MediaServer") << "Current " << fboSourceName << " reference count: " << source->referenceCount; loadedSources[fboSourceName] = source; - return loadedSources[fboSourceName]; + source->setActive(true); + return loadedSources[fboSourceName]; } // loadFboSource void MediaServer::unloadFboSource(std::string & fboSourceName){ @@ -395,6 +397,7 @@ void MediaServer::unloadFboSource(std::string & fboSourceName){ if(source->referenceCount <= 0){ ofLogNotice("MediaServer") << fboSourceName << " reference count <= 0, removing from loaded sources"; source->referenceCount = 0; + source->setActive(false); //source->removeAppListeners(); map ::iterator it = loadedSources.find(fboSourceName); loadedSources.erase(it); diff --git a/src/Sources/BaseSource.cpp b/src/Sources/BaseSource.cpp index 507583e..fdba7f4 100644 --- a/src/Sources/BaseSource.cpp +++ b/src/Sources/BaseSource.cpp @@ -6,6 +6,8 @@ namespace piMapper { BaseSource::BaseSource(){ //std::cout << "BaseSource" << std::endl; init(); + runInBackground = false; + displayed = false; } BaseSource::BaseSource(ofTexture * newTexture){ @@ -49,13 +51,26 @@ void BaseSource::init(){ referenceCount = 1; // We have one instance on init } +void BaseSource::setActive(bool value){ + displayed = value; +} + +bool BaseSource::isActive(){ + return displayed; +} + +bool BaseSource::runsInBackground(){ + return runInBackground; +} + void BaseSource::setNameFromPath(std::string & fullPath){ std::vector pathParts; //std::cout << "fullPath: " << fullPath << std::endl; + pathParts = ofSplitString(fullPath, "/"); // Maybe on win "/" is "\", have to test //std::cout << "lastPathPart: " << pathParts[pathParts.size() - 1] << std::endl; name = pathParts[pathParts.size() - 1]; } } // namespace piMapper -} // namespace ofx \ No newline at end of file +} // namespace ofx diff --git a/src/Sources/BaseSource.h b/src/Sources/BaseSource.h index 84f8e42..e637251 100644 --- a/src/Sources/BaseSource.h +++ b/src/Sources/BaseSource.h @@ -20,6 +20,9 @@ class BaseSource { std::string & getPath(); virtual void clear(){} virtual void togglePause(){} + bool isActive(); + bool runsInBackground(); + void setActive(bool); virtual void reset(){} // called by surfaceManager to optionally allow users to reset a source's variables @@ -28,7 +31,7 @@ class BaseSource { int referenceCount; private: - void init(); + void init(); protected: void setNameFromPath(std::string & fullPath); @@ -38,6 +41,8 @@ class BaseSource { bool loadable; // If the source can be loaded from disk like image and video bool loaded; // Is the source loaded? SourceType type; + bool displayed; + bool runInBackground; }; } // namespace piMapper diff --git a/src/Surfaces/SurfaceManager.cpp b/src/Surfaces/SurfaceManager.cpp index dda8eca..f05815f 100644 --- a/src/Surfaces/SurfaceManager.cpp +++ b/src/Surfaces/SurfaceManager.cpp @@ -134,6 +134,12 @@ bool SurfaceManager::loadXmlSettings(std::string fileName){ exit(EXIT_FAILURE); } bool success = SettingsLoader::instance()->load(*this, *mediaServer, fileName); + + for (int i=0; i<_presets.size(); i++){ + setPresetSourcesActiveState(i, false); + } + + setPresetSourcesActiveState(_activePresetIndex, true); return success; } @@ -451,7 +457,16 @@ void SurfaceManager::setNextPreset(){ // TODO: Create command for this. } +void SurfaceManager::setPresetSourcesActiveState(unsigned int presetIndex, bool state){ + // tell sources associated with current preset that they are not displayed any more + // this is so that we can optionally update the buffers or not. + for (int j=0; j<_presets[presetIndex]->getSurfaces().size(); j++){ + _presets[presetIndex]->getSurfaces()[j]->getSource()->setActive(state); + } +} + void SurfaceManager::setPreset(unsigned int i){ + cout << "CALLED IT" << endl; if(_presets.size() <= 1){ throw runtime_error("ofxPiMapper: No presets to set."); } @@ -460,7 +475,14 @@ void SurfaceManager::setPreset(unsigned int i){ throw runtime_error("ofxPiMapper: Preset index out of bounds."); } - _activePresetIndex = i; + //let sources associated with all preset know that they are not being displayed any more + setPresetSourcesActiveState(_activePresetIndex, false); + + //change preset + _activePresetIndex = i; + //let sources associated with NEW preset know that they are now being displayed + setPresetSourcesActiveState(_activePresetIndex, true); + //when preset it changed, call reset on all sources, if it's defined for (int i=0; i<_presets[_activePresetIndex]->getSurfaces().size(); i++){ diff --git a/src/Surfaces/SurfaceManager.h b/src/Surfaces/SurfaceManager.h index d798037..1150e17 100644 --- a/src/Surfaces/SurfaceManager.h +++ b/src/Surfaces/SurfaceManager.h @@ -77,6 +77,7 @@ class SurfaceManager { void setPreset(unsigned int i); void cloneActivePreset(); void eraseActivePreset(); + void setPresetSourcesActiveState(unsigned int presetIndex, bool state); private: BaseSurface * selectedSurface;