Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Added "loop" parameter to MovieStimulus; if set to a non-zero value, …
Browse files Browse the repository at this point in the history
…movie will repeat indefinitely
  • Loading branch information
cstawarz committed Dec 14, 2010
1 parent 43a2112 commit f1b104b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MoviePlugin/MWLibrary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- Payload -->
<code>
<stimulus type="movie" tag="" stimulus_group="" frames_per_second="10" ended="" />
<stimulus type="movie" tag="" stimulus_group="" frames_per_second="10" ended="" loop="0" />
</code>
</MWElement>
</MWElements>
24 changes: 21 additions & 3 deletions MoviePlugin/MovieStimulus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@
MovieStimulus::MovieStimulus(const std::string &_tag,
shared_ptr<Variable> _frames_per_second,
shared_ptr<StimulusGroup> _stimulus_group,
shared_ptr<Variable> ended) :
shared_ptr<Variable> ended,
shared_ptr<Variable> loop) :
StandardDynamicStimulus(_tag, _frames_per_second),
stimulus_group(_stimulus_group),
ended(ended)
ended(ended),
loop(loop)
{
}

int MovieStimulus::getFrameNumber() {
int frameNumber = DynamicStimulusDriver::getFrameNumber();

if (bool(loop->getValue())) {
int numFrames = stimulus_group->getNElements();
frameNumber %= numFrames;
}

return frameNumber;
}

bool MovieStimulus::needDraw() {
return StandardDynamicStimulus::needDraw() && (getFrameNumber() <= stimulus_group->getNElements());
}
Expand Down Expand Up @@ -53,6 +66,7 @@ shared_ptr<mw::Component> MovieStimulusFactory::createObject(std::map<std::strin
const char *STIMULUS_GROUP = "stimulus_group";
const char *FRAMES_PER_SECOND = "frames_per_second";
const char *ENDED = "ended";
const char *LOOP = "loop";

REQUIRE_ATTRIBUTES(parameters,
TAG,
Expand All @@ -74,11 +88,15 @@ shared_ptr<mw::Component> MovieStimulusFactory::createObject(std::map<std::strin
ended = reg->getVariable(parameters[ENDED]);
CHECK_ATTRIBUTE(ended, parameters, ENDED);
}

shared_ptr<Variable> loop = reg->getVariable(parameters[LOOP], "0");
CHECK_ATTRIBUTE(loop, parameters, LOOP);

shared_ptr <MovieStimulus> new_movie = shared_ptr<MovieStimulus>(new MovieStimulus(tagname,
frames_per_second,
the_group,
ended));
ended,
loop));

shared_ptr <StimulusNode> thisStimNode = shared_ptr<StimulusNode>(new StimulusNode(new_movie));
reg->registerStimulusNode(tagname, thisStimNode);
Expand Down
7 changes: 5 additions & 2 deletions MoviePlugin/MovieStimulus.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ class MovieStimulus : public StandardDynamicStimulus {

boost::shared_ptr<StimulusGroup> stimulus_group;
shared_ptr<Variable> ended;
shared_ptr<Variable> loop;

public:

MovieStimulus(const std::string &_tag,
shared_ptr<Variable> _frames_per_second,
shared_ptr<StimulusGroup> _stimulus_group,
shared_ptr<Variable> ended);

shared_ptr<Variable> ended,
shared_ptr<Variable> loop);

virtual int getFrameNumber();
virtual bool needDraw();
virtual void drawFrame(shared_ptr<StimulusDisplay> display, int frameNumber);
virtual Datum getCurrentAnnounceDrawData();
Expand Down

0 comments on commit f1b104b

Please sign in to comment.