diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index f2f929d..e5753d7 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -482,7 +482,7 @@ void Application::setFboSource(std::string sourceId){ } } -void Application::setVideoSource(std::string fileName){ +void Application::setVideoSource(std::string fileName, bool loop){ vector loadedVideos = getMediaServer()->getVideoNames(); for(auto i = 0; i < loadedVideos.size(); i++){ if(ofIsStringInString(loadedVideos[i], fileName)){ @@ -495,9 +495,9 @@ void Application::setVideoSource(std::string fileName){ } getCmdManager()->exec( - new SetSourceCmd( - SourceType::SOURCE_TYPE_VIDEO, + new SetVideoSourceCmd( getMediaServer()->getVideoPaths()[i], + loop, getSurfaceManager()->getSelectedSurface(), &Gui::instance()->getSourcesEditorWidget())); }else{ diff --git a/src/Application/Application.h b/src/Application/Application.h index 1715d69..e5c5a06 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -40,6 +40,7 @@ #include "SelNextTexCoordCmd.h" #include "SelPrevTexCoordCmd.h" #include "DeselectSurfaceCmd.h" +#include "SetVideoSourceCmd.h" // Modes #include "ApplicationBaseMode.h" @@ -130,7 +131,7 @@ class Application { void duplicateSurface(); void setNextSource(); void setFboSource(std::string sourceId); - void setVideoSource(std::string fileName); + void setVideoSource(std::string fileName, bool loop); void setImageSource(std::string fileName); void addGridRow(); void addGridColumn(); diff --git a/src/Commands/SetVideoSourceCmd.cpp b/src/Commands/SetVideoSourceCmd.cpp new file mode 100644 index 0000000..4a82112 --- /dev/null +++ b/src/Commands/SetVideoSourceCmd.cpp @@ -0,0 +1,51 @@ +#include "SetVideoSourceCmd.h" + +namespace ofx { +namespace piMapper { + +SetVideoSourceCmd::SetVideoSourceCmd(std::string sourceId, + bool loop, + BaseSurface * surface, + SourcesEditorWidget * sourcesEditor){ + _sourceId = sourceId; + _loop = loop; + _surface = surface; + _sourcesEditor = sourcesEditor; +} + +void SetVideoSourceCmd::exec(){ + ofLogNotice("SetVideoSourceCmd", "exec"); + + _oldSourceTypeHelper = _surface->getSource()->getType(); + if(_surface->getSource()->isLoadable()){ + _oldSourceId = _surface->getSource()->getPath(); + }else{ + _oldSourceId = _surface->getSource()->getName(); + } + + _sourcesEditor->setVideoSource(_sourceId); + BaseSource * src = _surface->getSource(); + VideoSource * vid = dynamic_cast(src); + vid->setLoop(_loop); +} + +void SetVideoSourceCmd::undo(){ + ofLogNotice("SetVideoSourceCmd", "undo"); + + if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_IMAGE){ + _sourcesEditor->setImageSource(_oldSourceId); + }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_VIDEO){ + _sourcesEditor->setVideoSource(_oldSourceId); + }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_FBO){ + _sourcesEditor->setFboSource(_oldSourceId); + }else if(_oldSourceTypeHelper == SourceType::SOURCE_TYPE_NONE){ + _sourcesEditor->clearSource(); + } + + _surface = 0; + _sourcesEditor = 0; +} + +} // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/SetVideoSourceCmd.h b/src/Commands/SetVideoSourceCmd.h new file mode 100644 index 0000000..10778d0 --- /dev/null +++ b/src/Commands/SetVideoSourceCmd.h @@ -0,0 +1,39 @@ +// SetVideoSourceCmd +// Set selected surface video source undoable command +// Created by Krisjanis Rijnieks 2018-08-10 + +#pragma once + +#include "BaseCmd.h" +#include "BaseSurface.h" +#include "SourcesEditorWidget.h" + +namespace ofx { +namespace piMapper { + +class SourcesEditorWidget; + +class SetVideoSourceCmd : public BaseUndoCmd { + + public: + SetVideoSourceCmd(std::string sourceId, + bool loop, + BaseSurface * surface, + SourcesEditorWidget * sourcesEditor); + void exec(); + void undo(); + + private: + std::string _sourceId; + bool _loop; + BaseSurface * _surface; + SourcesEditorWidget * _sourcesEditor; + + int _oldSourceTypeHelper; + std::string _oldSourceId; + +}; + +} // namespace piMapper +} // namespace ofx + diff --git a/src/Sources/VideoSource.cpp b/src/Sources/VideoSource.cpp index 75eae49..8c828f2 100644 --- a/src/Sources/VideoSource.cpp +++ b/src/Sources/VideoSource.cpp @@ -36,6 +36,18 @@ void VideoSource::loadVideo(std::string & filePath){ loaded = true; } +void VideoSource::setLoop(bool loop){ + #ifdef TARGET_RASPBERRY_PI + if(_omxPlayer == 0) return; + if(loop) _omxPlayer->enableLooping(); + else _omxPlayer->disableLooping(); + #else + if(_videoPlayer == 0) return; + if(loop) _videoPlayer->setLoopState(OF_LOOP_NORMAL); + else _videoPlayer->setLoopState(OF_LOOP_NONE); + #endif +} + void VideoSource::clear(){ texture = 0; #ifdef TARGET_RASPBERRY_PI diff --git a/src/Sources/VideoSource.h b/src/Sources/VideoSource.h index ec20b98..faee4b5 100644 --- a/src/Sources/VideoSource.h +++ b/src/Sources/VideoSource.h @@ -24,6 +24,7 @@ class VideoSource : public BaseSource { std::string & getPath(); void loadVideo(std::string & path); + void setLoop(bool loop); void clear(); void togglePause(); void stop(); diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index 5f235e2..44fd408 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -186,8 +186,8 @@ void ofxPiMapper::setFboSource(std::string sourceId){ _application.setFboSource(sourceId); } -void ofxPiMapper::setVideoSource(std::string fileName){ - _application.setVideoSource(fileName); +void ofxPiMapper::setVideoSource(std::string fileName, bool loop){ + _application.setVideoSource(fileName, loop); } void ofxPiMapper::setImageSource(std::string fileName){ diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index 704fbb3..a82ef33 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -86,7 +86,7 @@ class ofxPiMapper { // Sources, selected surface void setNextSource(); void setFboSource(std::string sourceId); - void setVideoSource(std::string fileName); + void setVideoSource(std::string fileName, bool loop); void setImageSource(std::string fileName); // System commands