Browse Source

Fix SourceType, replace all int vars with decent type

Divide SourceType class into SourceType enum and SourceTypeHelper class
master
Krisjanis Rijnieks 9 years ago
parent
commit
518bb76182
  1. 4
      src/Application/SettingsLoader.cpp
  2. 30
      src/Commands/SetNextSourceCmd.cpp
  3. 10
      src/Commands/SetSourceCmd.cpp
  4. 2
      src/Commands/SetSourceCmd.h
  5. 2
      src/Sources/BaseSource.cpp
  6. 6
      src/Sources/BaseSource.h
  7. 6
      src/Sources/ImageSource.cpp
  8. 21
      src/Sources/SourceType.h

4
src/Application/SettingsLoader.cpp

@ -71,7 +71,7 @@ bool SettingsLoader::load(
if(sourceName != "" && sourceName != "none" && sourceType != ""){ if(sourceName != "" && sourceName != "none" && sourceType != ""){
// Load source depending on type // Load source depending on type
int typeEnum = SourceType::GetSourceTypeEnum(sourceType); SourceType typeEnum = SourceTypeHelper::GetSourceTypeHelperEnum(sourceType);
if(typeEnum == SourceType::SOURCE_TYPE_FBO){ if(typeEnum == SourceType::SOURCE_TYPE_FBO){
// Load FBO source using sourceName // Load FBO source using sourceName
@ -200,7 +200,7 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->addTag("source"); xmlSettings->addTag("source");
xmlSettings->pushTag("source"); xmlSettings->pushTag("source");
string sourceTypeName = SourceType::GetSourceTypeName(surface->getSource()->getType()); string sourceTypeName = SourceTypeHelper::GetSourceTypeHelperName(surface->getSource()->getType());
xmlSettings->addValue("source-type", sourceTypeName); xmlSettings->addValue("source-type", sourceTypeName);
string sourceName = surface->getSource()->getName(); string sourceName = surface->getSource()->getName();

30
src/Commands/SetNextSourceCmd.cpp

@ -72,23 +72,6 @@ void SetNextSourceCmd::exec(){
_nextSourceIndex = 0; _nextSourceIndex = 0;
} }
// Load new source
/*
BaseSource * newSource;
if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_IMAGE){
newSource = mediaServer->loadImage(_sources[_nextSourceIndex].id);
}else{
newSource = mediaServer->loadMedia(
_sources[_nextSourceIndex].id,
_sources[_nextSourceIndex].type);
}
_surface->setSource(newSource);
// Unload old one
mediaServer->unloadMedia(sourceId);
*/
if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_IMAGE){ if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_sources[_nextSourceIndex].id); _sourcesEditor->setImageSource(_sources[_nextSourceIndex].id);
}else if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_VIDEO){ }else if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_VIDEO){
@ -105,19 +88,6 @@ void SetNextSourceCmd::exec(){
void SetNextSourceCmd::undo(){ void SetNextSourceCmd::undo(){
ofLogNotice("SetNextSourceCmd", "undo"); ofLogNotice("SetNextSourceCmd", "undo");
/*
MediaServer * mediaServer = _sourcesEditor->getMediaServer();
// Load back old source
BaseSource * prevSource = mediaServer->loadMedia(
_sources[_sourceIndex].id,
_sources[_sourceIndex].type);
_surface->setSource(prevSource);
mediaServer->unloadMedia(_sources[_nextSourceIndex].id);
*/
if(_sources[_sourceIndex].type == SourceType::SOURCE_TYPE_IMAGE){ if(_sources[_sourceIndex].type == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_sources[_sourceIndex].id); _sourcesEditor->setImageSource(_sources[_sourceIndex].id);
}else if(_sources[_sourceIndex].type == SourceType::SOURCE_TYPE_VIDEO){ }else if(_sources[_sourceIndex].type == SourceType::SOURCE_TYPE_VIDEO){

10
src/Commands/SetSourceCmd.cpp

@ -17,7 +17,7 @@ SetSourceCmd::SetSourceCmd(int sourceType,
void SetSourceCmd::exec(){ void SetSourceCmd::exec(){
ofLogNotice("SetSourceCmd", "exec"); ofLogNotice("SetSourceCmd", "exec");
_oldSourceType = _surface->getSource()->getType(); _oldSourceTypeHelper = _surface->getSource()->getType();
if(_surface->getSource()->isLoadable()){ if(_surface->getSource()->isLoadable()){
_oldSourceId = _surface->getSource()->getPath(); _oldSourceId = _surface->getSource()->getPath();
}else{ }else{
@ -38,13 +38,13 @@ void SetSourceCmd::exec(){
void SetSourceCmd::undo(){ void SetSourceCmd::undo(){
ofLogNotice("SetSourceCmd", "undo"); ofLogNotice("SetSourceCmd", "undo");
if(_oldSourceType == SourceType::SOURCE_TYPE_IMAGE){ if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_oldSourceId); _sourcesEditor->setImageSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_VIDEO){ }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_VIDEO){
_sourcesEditor->setVideoSource(_oldSourceId); _sourcesEditor->setVideoSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_FBO){ }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_FBO){
_sourcesEditor->setFboSource(_oldSourceId); _sourcesEditor->setFboSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_NONE){ }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_NONE){
_sourcesEditor->clearSource(); _sourcesEditor->clearSource();
} }

2
src/Commands/SetSourceCmd.h

@ -29,7 +29,7 @@ class SetSourceCmd : public BaseUndoCmd {
BaseSurface * _surface; BaseSurface * _surface;
SourcesEditorWidget * _sourcesEditor; SourcesEditorWidget * _sourcesEditor;
int _oldSourceType; int _oldSourceTypeHelper;
string _oldSourceId; string _oldSourceId;
}; };

2
src/Sources/BaseSource.cpp

@ -31,7 +31,7 @@ bool BaseSource::isLoaded(){
return loaded; return loaded;
} }
int BaseSource::getType(){ SourceType BaseSource::getType(){
return type; return type;
} }

6
src/Sources/BaseSource.h

@ -8,7 +8,6 @@ namespace piMapper {
// Use this for adding generative sources to your surfaces // Use this for adding generative sources to your surfaces
class BaseSource { class BaseSource {
public: public:
BaseSource(); BaseSource();
BaseSource(ofTexture * newTexture); // Only one clean way of passing the texture BaseSource(ofTexture * newTexture); // Only one clean way of passing the texture
@ -17,7 +16,7 @@ class BaseSource {
string & getName(); string & getName();
bool isLoadable(); // Maybe the loading features shoud go to a derrived class bool isLoadable(); // Maybe the loading features shoud go to a derrived class
bool isLoaded(); // as BaseSourceLoadable bool isLoaded(); // as BaseSourceLoadable
int getType(); SourceType getType();
string & getPath(); string & getPath();
virtual void clear(){} virtual void clear(){}
virtual void togglePause(){} virtual void togglePause(){}
@ -36,8 +35,7 @@ class BaseSource {
string path; // This is set only if loadable is true string path; // This is set only if loadable is true
bool loadable; // If the source can be loaded from disk like image and video bool loadable; // If the source can be loaded from disk like image and video
bool loaded; // Is the source loaded? bool loaded; // Is the source loaded?
int type; SourceType type;
}; };
} // namespace piMapper } // namespace piMapper

6
src/Sources/ImageSource.cpp

@ -4,7 +4,6 @@ namespace ofx {
namespace piMapper { namespace piMapper {
ImageSource::ImageSource(){ ImageSource::ImageSource(){
//cout << "ImageSource" << endl;
loadable = true; loadable = true;
loaded = false; loaded = false;
type = SourceType::SOURCE_TYPE_IMAGE; type = SourceType::SOURCE_TYPE_IMAGE;
@ -14,9 +13,7 @@ ImageSource::~ImageSource(){}
void ImageSource::loadImage(string & filePath){ void ImageSource::loadImage(string & filePath){
path = filePath; path = filePath;
//cout << "loading image: " << filePath << endl;
setNameFromPath(filePath); setNameFromPath(filePath);
//cout << "path: " << path << endl;
image = new ofImage(); image = new ofImage();
#if (OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR >= 9) || OF_VERSION_MAJOR > 0 #if (OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR >= 9) || OF_VERSION_MAJOR > 0
if(!image->load(filePath)){ if(!image->load(filePath)){
@ -24,7 +21,6 @@ void ImageSource::loadImage(string & filePath){
if(!image->loadImage(filePath)){ if(!image->loadImage(filePath)){
#endif #endif
ofLogWarning("ImageSource") << "Could not load image"; ofLogWarning("ImageSource") << "Could not load image";
//exit(EXIT_FAILURE);
} }
#if (OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR >= 9) || OF_VERSION_MAJOR > 0 #if (OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR >= 9) || OF_VERSION_MAJOR > 0
texture = &image->getTexture(); texture = &image->getTexture();
@ -39,8 +35,6 @@ void ImageSource::clear(){
image->clear(); image->clear();
delete image; delete image;
image = 0; image = 0;
//path = "";
//name = "";
loaded = false; loaded = false;
} }

21
src/Sources/SourceType.h

@ -10,14 +10,16 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourceType { enum SourceType {
SOURCE_TYPE_NONE,
public: SOURCE_TYPE_IMAGE,
enum { SOURCE_TYPE_VIDEO,
SOURCE_TYPE_NONE, SOURCE_TYPE_IMAGE, SOURCE_TYPE_VIDEO, SOURCE_TYPE_FBO SOURCE_TYPE_FBO
}; };
static string GetSourceTypeName(int sourceTypeEnum){ class SourceTypeHelper {
public:
static string GetSourceTypeHelperName(SourceType sourceTypeEnum){
if(sourceTypeEnum == SOURCE_TYPE_IMAGE){ if(sourceTypeEnum == SOURCE_TYPE_IMAGE){
return SOURCE_TYPE_NAME_IMAGE; return SOURCE_TYPE_NAME_IMAGE;
}else if(sourceTypeEnum == SOURCE_TYPE_VIDEO){ }else if(sourceTypeEnum == SOURCE_TYPE_VIDEO){
@ -29,12 +31,12 @@ class SourceType {
}else{ }else{
stringstream ss; stringstream ss;
ss << "Invalid source type: " << sourceTypeEnum; ss << "Invalid source type: " << sourceTypeEnum;
ofLogFatalError("SourceType") << ss.str(); ofLogFatalError("SourceTypeHelper") << ss.str();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
static int GetSourceTypeEnum(string sourceTypeName){ static SourceType GetSourceTypeHelperEnum(string sourceTypeName){
if(sourceTypeName == SOURCE_TYPE_NAME_IMAGE){ if(sourceTypeName == SOURCE_TYPE_NAME_IMAGE){
return SOURCE_TYPE_IMAGE; return SOURCE_TYPE_IMAGE;
}else if(sourceTypeName == SOURCE_TYPE_NAME_VIDEO){ }else if(sourceTypeName == SOURCE_TYPE_NAME_VIDEO){
@ -46,11 +48,10 @@ class SourceType {
}else{ }else{
stringstream ss; stringstream ss;
ss << "Invalid source type name: " << sourceTypeName; ss << "Invalid source type name: " << sourceTypeName;
ofLogFatalError("SourceType") << ss.str(); ofLogFatalError("SourceTypeHelper") << ss.str();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
}; };
} // namespace piMapper } // namespace piMapper

Loading…
Cancel
Save