MMSPulser Class Reference

This class helps the MMSGUI and user specific applications to get smooth animations. More...

#include <mmspulser.h>

Inheritance diagram for MMSPulser:

List of all members.


Public Member Functions

 MMSPulser ()
 The constructor.
 ~MMSPulser ()
 The destructor.
bool start (bool separate_thread=true, bool wait=false)
 Start the animation.
bool isRunning ()
 Check if the animation is running.
void stop ()
 Signals the animation thread that it has to stop immediately.
bool setStepsPerSecond (int steps_per_second)
 Set animation steps per second.
int getStepsPerSecond ()
 Get steps per second.
bool setMaxCPUUsage (int max_cpu_usage)
 Set maximum CPU usage.
int getMaxCPUUsage ()
 Get maximum CPU usage.
bool setMaxFrameRate (int max_frame_rate)
 Set maximum frame rate.
int getMaxFrameRate ()
 Get maximum frame rate.
int getFrameRate ()
 Get the current frame rate.
int getFrameDelay ()
 Get the delay in milliseconds between two frames.
unsigned int getFrames ()
 Get the frame counter.
int getStepLength ()
 Get the length of the current animation step.
bool setMaxOffset (double max_offset=0, MMSPULSER_SEQ seq_mode=MMSPULSER_SEQ_LINEAR, double seq_range=0)
 Set the maximum offset returned by getOffset().
double getOffset ()
 Get the offset of the animation.
bool setDuration (unsigned int duration)
 Set the requested duration.
unsigned int getDuration ()
 Get the requested duration in milliseconds of the animation.
unsigned int getRealDuration ()
 Get the real duration in milliseconds of the animation.
unsigned int getOnAnimationCounter ()
 Get the number of onAnimation calls after the last onBeforeAnimation call.

Public Attributes

sigc::signal< bool, MMSPulser * >
::accumulated
< bool_accumulator
onBeforeAnimation
 Set one or more callbacks for the onBeforeAnimation event.
sigc::signal< bool, MMSPulser * >
::accumulated
< bool_accumulator
onAnimation
 Set one or more callbacks for the onAnimation event.
sigc::signal< void, MMSPulser * > onAfterAnimation
 Set one or more callbacks for the onAfterAnimation event.

Private Member Functions

void reset ()
 Internal method: Reset all values.
void calcCurve (double &offset, double &offset_curve)
 Internal method: Calculate the offset curve.
void threadMain ()
 Internal method: Main method for the animation timing control.

Private Attributes

MMSMutex startlock
 helper mutex to perform a safe start
bool animRunning
 shows if the animation is running
bool cancel
 true if animation thread should stop
bool recalc_requested
 recalculation requested?
int recalc_interval
 after X loops, recalculate animation values
int recalc_cnt
 recalc loop counter
int step_len
 current step length
double max_offset
 maximum offset
double max_offset_log
 natural logarithm of max_offset
MMSPULSER_SEQ seq_mode
 sequence mode, used in conjunction with max_offset
double seq_range
 sequence range, used in conjunction with max_offset and seq_mode;
double seq_start
 sequence start, used in conjunction with seq_range;
double offset
 current offset
double offset_curve
 current offset, curve calculation in conjunction with seq_mode
int steps_per_second
 animation steps per second
int max_cpu_usage
 maximum cpu usage in percent
int process_time
 duration of the onAnimation callback
int frame_delay
 delay in milliseconds between two frames
int max_frame_rate
 maximum frame rate
int frame_rate
 current frame rate
unsigned int frames
 frame counter
unsigned int times_buf [MMSPULSER_TIMES_BUF_SIZE]
 ring buffer to calculate the CPU average
unsigned int times_buf_pos
 next pos in the ring buffer to write to
unsigned int times_buf_cnt
 filling level of the ring buffer
unsigned int anim_start
 start timestamp of the animation
unsigned int anim_end
 end timestamp of the animation
unsigned int duration
 requested duration in milliseconds of the animation
unsigned int real_duration
 real duration in milliseconds of the animation (calculated after the animation)
unsigned int onAnimation_counter
 counts the onAnimation calls, zero for the first onAnimation call

Detailed Description

This class helps the MMSGUI and user specific applications to get smooth animations.

There are three callbacks: onBeforeAnimation, onAnimation and onAfterAnimation. At least the onAnimation callback should be connected. This callback will be called for each frame which is to draw. The onBeforeAnimation callback can be used to setup something. The onAfterAnimation callback will be called, if the animation is finished. The initiator can be blocked during the animation (see start(false)). But it is also possible that the animation is running in a separate thread (see start(true)).

Author:
Jens Schneider

Definition at line 82 of file mmspulser.h.


Constructor & Destructor Documentation

MMSPulser::MMSPulser (  ) 

The constructor.

Definition at line 38 of file mmspulser.cpp.

MMSPulser::~MMSPulser (  ) 

The destructor.

Definition at line 56 of file mmspulser.cpp.


Member Function Documentation

void MMSPulser::reset (  )  [private]

Internal method: Reset all values.

Definition at line 59 of file mmspulser.cpp.

void MMSPulser::calcCurve ( double &  offset,
double &  offset_curve 
) [private]

Internal method: Calculate the offset curve.

Definition at line 105 of file mmspulser.cpp.

void MMSPulser::threadMain (  )  [private, virtual]

Internal method: Main method for the animation timing control.

Implements MMSThread.

Definition at line 208 of file mmspulser.cpp.

bool MMSPulser::start ( bool  separate_thread = true,
bool  wait = false 
)

Start the animation.

Parameters:
separate_thread true: a new thread will be started, false: the animation is running in callers thread context and the start() method will return if the animation is finished
wait waiting for end of animation and then start the new one
Returns:
true or false

Definition at line 379 of file mmspulser.cpp.

bool MMSPulser::isRunning (  )  [virtual]

Check if the animation is running.

Returns:
true or false

Reimplemented from MMSThread.

Definition at line 421 of file mmspulser.cpp.

void MMSPulser::stop (  ) 

Signals the animation thread that it has to stop immediately.

Definition at line 432 of file mmspulser.cpp.

bool MMSPulser::setStepsPerSecond ( int  steps_per_second  ) 

Set animation steps per second.

Parameters:
steps_per_second 1..255 steps per second, default are 25 steps
Returns:
true, if parameter is accepted
See also:
getStepsPerSecond()

Definition at line 438 of file mmspulser.cpp.

int MMSPulser::getStepsPerSecond (  ) 

Get steps per second.

Returns:
steps per second
See also:
setStepsPerSecond()

Definition at line 451 of file mmspulser.cpp.

bool MMSPulser::setMaxCPUUsage ( int  max_cpu_usage  ) 

Set maximum CPU usage.

Parameters:
max_cpu_usage 10..100 percent, default is 100%
Returns:
true, if parameter is accepted
See also:
getMaxCPUUsage()

Definition at line 455 of file mmspulser.cpp.

int MMSPulser::getMaxCPUUsage (  ) 

Get maximum CPU usage.

Returns:
max CPU usage
See also:
setMaxCPUUsage()

Definition at line 468 of file mmspulser.cpp.

bool MMSPulser::setMaxFrameRate ( int  max_frame_rate  ) 

Set maximum frame rate.

Parameters:
max_frame_rate 10..100 frames per second, default are 25 fps
Returns:
true, if parameter is accepted
See also:
getMaxFrameRate()

Definition at line 472 of file mmspulser.cpp.

int MMSPulser::getMaxFrameRate (  ) 

Get maximum frame rate.

Returns:
max frame rate
See also:
setMaxFrameRate()

Definition at line 485 of file mmspulser.cpp.

int MMSPulser::getFrameRate (  ) 

Get the current frame rate.

Returns:
current frame rate
Note:
This value is valid during the animation (e.g. in the onAnimation callback).

Definition at line 489 of file mmspulser.cpp.

int MMSPulser::getFrameDelay (  ) 

Get the delay in milliseconds between two frames.

Returns:
delay in milliseconds
Note:
This value is valid during the animation (e.g. in the onAnimation callback).

Definition at line 493 of file mmspulser.cpp.

unsigned int MMSPulser::getFrames (  ) 

Get the frame counter.

Returns:
frame counter
Note:
This value is zero for the first time onAnimation callback is called.

Definition at line 497 of file mmspulser.cpp.

int MMSPulser::getStepLength (  ) 

Get the length of the current animation step.

Returns:
length of the step
Note:
This value is valid during the animation (e.g. in the onAnimation callback).

This value is zero for the first time onAnimation callback is called.

See also:
getOffset()

Definition at line 501 of file mmspulser.cpp.

bool MMSPulser::setMaxOffset ( double  max_offset = 0,
MMSPULSER_SEQ  seq_mode = MMSPULSER_SEQ_LINEAR,
double  seq_range = 0 
)

Set the maximum offset returned by getOffset().

The animation will be stopped, if the maximum offset is exceeded. Additionally you can set the sequence mode and a sequence range. With these parameters you have influence to the return value of getOffset().

Parameters:
max_offset maximum offset (2..n), default 0 means that no maximum is set if maximum offset is not set (value 0), the seq_mode and seq_range will be ignored
seq_mode sequence mode, default is MMSPULSER_SEQ_LINEAR
seq_range the seq_range for the curve calculation (2..max_offset), default 0 is equal to max_offset
Returns:
true, if parameters are accepted
Note:
If your onAnimation callback returns false, the Animation will be stopped at any time.

The seq_mode has NO influence to the return value of getStepLength().

With the parameter seq_range, you can get a flat curve at the end of the animation.

See also:
getOffset()

Definition at line 505 of file mmspulser.cpp.

double MMSPulser::getOffset (  ) 

Get the offset of the animation.

After each onAnimation call the offset will be increased or decreased dependent on the seq_mode set with setMaxOffset().

Returns:
offset
Note:
This value is valid during the animation (e.g. in the onAnimation callback).
See also:
setMaxOffset()

getStepLength()

Definition at line 579 of file mmspulser.cpp.

bool MMSPulser::setDuration ( unsigned int  duration  ) 

Set the requested duration.

Parameters:
duration 0..n milliseconds, default is 0 and means endless animation
Returns:
true, if parameter is accepted
Note:
If your onAnimation callback returns false, the Animation will be stopped at any time.
See also:
getDuration()

Definition at line 583 of file mmspulser.cpp.

unsigned int MMSPulser::getDuration (  ) 

Get the requested duration in milliseconds of the animation.

Returns:
requested duration in milliseconds
See also:
setDuration()

Definition at line 588 of file mmspulser.cpp.

unsigned int MMSPulser::getRealDuration (  ) 

Get the real duration in milliseconds of the animation.

Returns:
real duration in milliseconds
Note:
This value will be increased during the animation and has its final state at the end of the animation (e.g. in onAfterAnimation callback).

Definition at line 592 of file mmspulser.cpp.

unsigned int MMSPulser::getOnAnimationCounter (  ) 

Get the number of onAnimation calls after the last onBeforeAnimation call.

Returns:
number of calls
Note:
This value is zero for the first time onAnimation is called.

Definition at line 596 of file mmspulser.cpp.


Member Data Documentation

helper mutex to perform a safe start

Reimplemented from MMSThread.

Definition at line 85 of file mmspulser.h.

bool MMSPulser::animRunning [private]

shows if the animation is running

Definition at line 88 of file mmspulser.h.

bool MMSPulser::cancel [private]

true if animation thread should stop

Definition at line 91 of file mmspulser.h.

recalculation requested?

Definition at line 94 of file mmspulser.h.

after X loops, recalculate animation values

Definition at line 97 of file mmspulser.h.

int MMSPulser::recalc_cnt [private]

recalc loop counter

Definition at line 100 of file mmspulser.h.

int MMSPulser::step_len [private]

current step length

Definition at line 103 of file mmspulser.h.

double MMSPulser::max_offset [private]

maximum offset

Definition at line 106 of file mmspulser.h.

double MMSPulser::max_offset_log [private]

natural logarithm of max_offset

Definition at line 109 of file mmspulser.h.

sequence mode, used in conjunction with max_offset

Definition at line 112 of file mmspulser.h.

double MMSPulser::seq_range [private]

sequence range, used in conjunction with max_offset and seq_mode;

Definition at line 115 of file mmspulser.h.

double MMSPulser::seq_start [private]

sequence start, used in conjunction with seq_range;

Definition at line 118 of file mmspulser.h.

double MMSPulser::offset [private]

current offset

Definition at line 121 of file mmspulser.h.

double MMSPulser::offset_curve [private]

current offset, curve calculation in conjunction with seq_mode

Definition at line 124 of file mmspulser.h.

animation steps per second

Definition at line 127 of file mmspulser.h.

int MMSPulser::max_cpu_usage [private]

maximum cpu usage in percent

Definition at line 130 of file mmspulser.h.

int MMSPulser::process_time [private]

duration of the onAnimation callback

Definition at line 133 of file mmspulser.h.

int MMSPulser::frame_delay [private]

delay in milliseconds between two frames

Definition at line 136 of file mmspulser.h.

maximum frame rate

Definition at line 139 of file mmspulser.h.

int MMSPulser::frame_rate [private]

current frame rate

Definition at line 142 of file mmspulser.h.

unsigned int MMSPulser::frames [private]

frame counter

Definition at line 145 of file mmspulser.h.

unsigned int MMSPulser::times_buf[MMSPULSER_TIMES_BUF_SIZE] [private]

ring buffer to calculate the CPU average

Definition at line 148 of file mmspulser.h.

unsigned int MMSPulser::times_buf_pos [private]

next pos in the ring buffer to write to

Definition at line 151 of file mmspulser.h.

unsigned int MMSPulser::times_buf_cnt [private]

filling level of the ring buffer

Definition at line 154 of file mmspulser.h.

unsigned int MMSPulser::anim_start [private]

start timestamp of the animation

Definition at line 157 of file mmspulser.h.

unsigned int MMSPulser::anim_end [private]

end timestamp of the animation

Definition at line 160 of file mmspulser.h.

unsigned int MMSPulser::duration [private]

requested duration in milliseconds of the animation

Definition at line 163 of file mmspulser.h.

unsigned int MMSPulser::real_duration [private]

real duration in milliseconds of the animation (calculated after the animation)

Definition at line 166 of file mmspulser.h.

unsigned int MMSPulser::onAnimation_counter [private]

counts the onAnimation calls, zero for the first onAnimation call

Definition at line 169 of file mmspulser.h.

sigc::signal<bool, MMSPulser*>::accumulated<bool_accumulator> MMSPulser::onBeforeAnimation

Set one or more callbacks for the onBeforeAnimation event.

The connected callbacks will be called during threadMain(). If at least one of the callbacks returns false, the animation will be stopped.

A callback method must be defined like this:

bool myclass::mycallbackmethod(MMSPulser *pulser);

Parameters:
pulser is the pointer to the caller (the pulser thread)
Returns:
true if the animation should continue, else false if the animation should stop
To connect your callback to onBeforeAnimation do this:

sigc::connection connection; connection = mypulser->onBeforeAnimation.connect(sigc::mem_fun(myobject,&myclass::mycallbackmethod));

To disconnect your callback do this:

connection.disconnect();

Please note:

You HAVE TO disconnect myobject from onBeforeAnimation BEFORE myobject will be deleted!!! Else an abnormal program termination can occur. You HAVE TO call the disconnect() method of sigc::connection explicitly. The destructor will NOT do this!!!

Definition at line 369 of file mmspulser.h.

sigc::signal<bool, MMSPulser*>::accumulated<bool_accumulator> MMSPulser::onAnimation

Set one or more callbacks for the onAnimation event.

The connected callbacks will be called during threadMain(). If at least one of the callbacks returns false, the animation will be stopped.

A callback method must be defined like this:

bool myclass::mycallbackmethod(MMSPulser *pulser);

Parameters:
pulser is the pointer to the caller (the pulser thread)
Returns:
true if the animation should continue, else false if the animation should stop
To connect your callback to onAnimation do this:

sigc::connection connection; connection = mypulser->onAnimation.connect(sigc::mem_fun(myobject,&myclass::mycallbackmethod));

To disconnect your callback do this:

connection.disconnect();

Please note:

You HAVE TO disconnect myobject from onAnimation BEFORE myobject will be deleted!!! Else an abnormal program termination can occur. You HAVE TO call the disconnect() method of sigc::connection explicitly. The destructor will NOT do this!!!

Definition at line 399 of file mmspulser.h.

sigc::signal<void, MMSPulser*> MMSPulser::onAfterAnimation

Set one or more callbacks for the onAfterAnimation event.

The connected callbacks will be called during threadMain().

A callback method must be defined like this:

void myclass::mycallbackmethod(MMSPulser *pulser);

Parameters:
pulser is the pointer to the caller (the pulser thread)
To connect your callback to onAfterAnimation do this:

sigc::connection connection; connection = mypulser->onAfterAnimation.connect(sigc::mem_fun(myobject,&myclass::mycallbackmethod));

To disconnect your callback do this:

connection.disconnect();

Please note:

You HAVE TO disconnect myobject from onAfterAnimation BEFORE myobject will be deleted!!! Else an abnormal program termination can occur. You HAVE TO call the disconnect() method of sigc::connection explicitly. The destructor will NOT do this!!!

Definition at line 426 of file mmspulser.h.


The documentation for this class was generated from the following files: