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

32
src/Commands/SetNextSourceCmd.cpp

@ -71,24 +71,7 @@ void SetNextSourceCmd::exec(){
if(_nextSourceIndex >= _sources.size()){
_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){
_sourcesEditor->setImageSource(_sources[_nextSourceIndex].id);
}else if(_sources[_nextSourceIndex].type == SourceType::SOURCE_TYPE_VIDEO){
@ -104,20 +87,7 @@ void SetNextSourceCmd::exec(){
void 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){
_sourcesEditor->setImageSource(_sources[_sourceIndex].id);
}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(){
ofLogNotice("SetSourceCmd", "exec");
_oldSourceType = _surface->getSource()->getType();
_oldSourceTypeHelper = _surface->getSource()->getType();
if(_surface->getSource()->isLoadable()){
_oldSourceId = _surface->getSource()->getPath();
}else{
@ -38,13 +38,13 @@ void SetSourceCmd::exec(){
void SetSourceCmd::undo(){
ofLogNotice("SetSourceCmd", "undo");
if(_oldSourceType == SourceType::SOURCE_TYPE_IMAGE){
if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_VIDEO){
}else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_VIDEO){
_sourcesEditor->setVideoSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_FBO){
}else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_FBO){
_sourcesEditor->setFboSource(_oldSourceId);
}else if(_oldSourceType == SourceType::SOURCE_TYPE_NONE){
}else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_NONE){
_sourcesEditor->clearSource();
}

2
src/Commands/SetSourceCmd.h

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

2
src/Sources/BaseSource.cpp

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

6
src/Sources/BaseSource.h

@ -8,7 +8,6 @@ namespace piMapper {
// Use this for adding generative sources to your surfaces
class BaseSource {
public:
BaseSource();
BaseSource(ofTexture * newTexture); // Only one clean way of passing the texture
@ -17,7 +16,7 @@ class BaseSource {
string & getName();
bool isLoadable(); // Maybe the loading features shoud go to a derrived class
bool isLoaded(); // as BaseSourceLoadable
int getType();
SourceType getType();
string & getPath();
virtual void clear(){}
virtual void togglePause(){}
@ -36,8 +35,7 @@ class BaseSource {
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 loaded; // Is the source loaded?
int type;
SourceType type;
};
} // namespace piMapper

6
src/Sources/ImageSource.cpp

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

21
src/Sources/SourceType.h

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

Loading…
Cancel
Save