Browse Source

Add loop option to setVideoSource

master
Krisjanis Rijnieks 7 years ago
parent
commit
c6487b25be
  1. 6
      src/Application/Application.cpp
  2. 3
      src/Application/Application.h
  3. 51
      src/Commands/SetVideoSourceCmd.cpp
  4. 39
      src/Commands/SetVideoSourceCmd.h
  5. 12
      src/Sources/VideoSource.cpp
  6. 1
      src/Sources/VideoSource.h
  7. 4
      src/ofxPiMapper.cpp
  8. 2
      src/ofxPiMapper.h

6
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<std::string> 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{

3
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();

51
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<VideoSource *>(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

39
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

12
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

1
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();

4
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){

2
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

Loading…
Cancel
Save