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

Commit

Permalink
Derive MovieStimulus from StandardDynamicStimulus
Browse files Browse the repository at this point in the history
  • Loading branch information
cstawarz committed Aug 18, 2010
1 parent 2dd1759 commit 49ebf43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
41 changes: 10 additions & 31 deletions MoviePlugin/MovieStimulus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@
#define STIM_MOVIE_CURRENT_FRAME "current_frame"

MovieStimulus::MovieStimulus(const std::string &_tag,
const shared_ptr<Scheduler> &_scheduler,
const shared_ptr<StimulusDisplay> &_display,
const shared_ptr<Variable> &_frames_per_second,
const shared_ptr<StimulusGroup> &_stimulus_group) :
DynamicStimulusDriver(_scheduler,
_display,
_frames_per_second),
Stimulus(_tag)
shared_ptr<Variable> _frames_per_second,
shared_ptr<StimulusGroup> _stimulus_group) :
StandardDynamicStimulus(_tag, _frames_per_second)
{
stimulus_group = _stimulus_group;
}

void MovieStimulus::draw(shared_ptr<StimulusDisplay> display) {
int currentFrame = getFrameNumber();

if (currentFrame < 0) {
// Not playing, so there's nothing to draw
} else if (currentFrame < stimulus_group->getNElements()) {
// Draw the current frame
stimulus_group->getElement(currentFrame)->draw(display);
} else {
// Out of frames; end the movie
stop();
bool MovieStimulus::needDraw() {
return StandardDynamicStimulus::needDraw() && (getFrameNumber() < stimulus_group->getNElements());
}

void MovieStimulus::drawFrame(shared_ptr<StimulusDisplay> display, int frameNumber) {
if (frameNumber < stimulus_group->getNElements()) {
stimulus_group->getElement(frameNumber)->draw(display);
}
}

Expand Down Expand Up @@ -71,19 +62,7 @@ shared_ptr<mw::Component> MovieStimulusFactory::createObject(std::map<std::strin
shared_ptr<Variable> frames_per_second = reg->getVariable(parameters.find(FRAMES_PER_SECOND)->second);
checkAttribute(frames_per_second, parameters.find("reference_id")->second, FRAMES_PER_SECOND, parameters[FRAMES_PER_SECOND]);

boost::shared_ptr <Scheduler> scheduler = Scheduler::instance();
if(scheduler == 0) {
throw SimpleException("Attempt to create movie stimulus without a valid scheduler");
}

boost::shared_ptr <StimulusDisplay> display = GlobalCurrentExperiment->getStimulusDisplay();
if(display == 0) {
throw SimpleException("Attempt to create movie stimulus without a valid stimulus display");
}

shared_ptr <MovieStimulus> new_movie = shared_ptr<MovieStimulus>(new MovieStimulus(tagname,
scheduler,
display,
frames_per_second,
the_group));

Expand Down
14 changes: 6 additions & 8 deletions MoviePlugin/MovieStimulus.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#ifndef MOVIE_STIMULUS_H_
#define MOVIE_STIMULUS_H_

#include "MWorksCore/DynamicStimulusDriver.h"
#include "MWorksCore/Stimulus.h"
#include "MWorksCore/StandardDynamicStimulus.h"
#include "MWorksCore/ComponentRegistry.h"
using namespace mw;


class MovieStimulus : public DynamicStimulusDriver, public Stimulus {
class MovieStimulus : public StandardDynamicStimulus {

protected:

Expand All @@ -25,12 +24,11 @@ class MovieStimulus : public DynamicStimulusDriver, public Stimulus {
public:

MovieStimulus(const std::string &_tag,
const boost::shared_ptr<Scheduler> &_scheduler,
const boost::shared_ptr<StimulusDisplay> &_display,
const boost::shared_ptr<Variable> &_frames_per_second,
const boost::shared_ptr<StimulusGroup> &_stimulus_group);
shared_ptr<Variable> _frames_per_second,
shared_ptr<StimulusGroup> _stimulus_group);

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

};
Expand Down

0 comments on commit 49ebf43

Please sign in to comment.