#include <mmspulser.h>
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 |
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)).
Definition at line 82 of file mmspulser.h.
MMSPulser::MMSPulser | ( | ) |
MMSPulser::~MMSPulser | ( | ) |
void MMSPulser::reset | ( | ) | [private] |
void MMSPulser::calcCurve | ( | double & | offset, | |
double & | offset_curve | |||
) | [private] |
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.
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 |
Definition at line 379 of file mmspulser.cpp.
bool MMSPulser::isRunning | ( | ) | [virtual] |
Check if the animation is running.
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.
steps_per_second | 1..255 steps per second, default are 25 steps |
Definition at line 438 of file mmspulser.cpp.
int MMSPulser::getStepsPerSecond | ( | ) |
Get steps per second.
Definition at line 451 of file mmspulser.cpp.
bool MMSPulser::setMaxCPUUsage | ( | int | max_cpu_usage | ) |
Set maximum CPU usage.
max_cpu_usage | 10..100 percent, default is 100% |
Definition at line 455 of file mmspulser.cpp.
int MMSPulser::getMaxCPUUsage | ( | ) |
Get maximum CPU usage.
Definition at line 468 of file mmspulser.cpp.
bool MMSPulser::setMaxFrameRate | ( | int | max_frame_rate | ) |
Set maximum frame rate.
max_frame_rate | 10..100 frames per second, default are 25 fps |
Definition at line 472 of file mmspulser.cpp.
int MMSPulser::getMaxFrameRate | ( | ) |
Get maximum frame rate.
Definition at line 485 of file mmspulser.cpp.
int MMSPulser::getFrameRate | ( | ) |
Get the current frame rate.
Definition at line 489 of file mmspulser.cpp.
int MMSPulser::getFrameDelay | ( | ) |
Get the delay in milliseconds between two frames.
Definition at line 493 of file mmspulser.cpp.
unsigned int MMSPulser::getFrames | ( | ) |
Get the frame counter.
Definition at line 497 of file mmspulser.cpp.
int MMSPulser::getStepLength | ( | ) |
Get the length of the current animation step.
This value is zero for the first time onAnimation callback is called.
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().
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 |
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.
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().
Definition at line 579 of file mmspulser.cpp.
bool MMSPulser::setDuration | ( | unsigned int | duration | ) |
Set the requested duration.
duration | 0..n milliseconds, default is 0 and means endless animation |
Definition at line 583 of file mmspulser.cpp.
unsigned int MMSPulser::getDuration | ( | ) |
Get the requested duration in milliseconds of the animation.
Definition at line 588 of file mmspulser.cpp.
unsigned int MMSPulser::getRealDuration | ( | ) |
Get the real duration in milliseconds of the animation.
Definition at line 592 of file mmspulser.cpp.
unsigned int MMSPulser::getOnAnimationCounter | ( | ) |
Get the number of onAnimation calls after the last onBeforeAnimation call.
Definition at line 596 of file mmspulser.cpp.
MMSMutex MMSPulser::startlock [private] |
helper mutex to perform a safe start
Reimplemented from MMSThread.
Definition at line 85 of file mmspulser.h.
bool MMSPulser::animRunning [private] |
bool MMSPulser::cancel [private] |
bool MMSPulser::recalc_requested [private] |
int MMSPulser::recalc_interval [private] |
int MMSPulser::recalc_cnt [private] |
int MMSPulser::step_len [private] |
double MMSPulser::max_offset [private] |
double MMSPulser::max_offset_log [private] |
MMSPULSER_SEQ MMSPulser::seq_mode [private] |
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] |
double MMSPulser::offset [private] |
double MMSPulser::offset_curve [private] |
current offset, curve calculation in conjunction with seq_mode
Definition at line 124 of file mmspulser.h.
int MMSPulser::steps_per_second [private] |
int MMSPulser::max_cpu_usage [private] |
int MMSPulser::process_time [private] |
int MMSPulser::frame_delay [private] |
int MMSPulser::max_frame_rate [private] |
int MMSPulser::frame_rate [private] |
unsigned int MMSPulser::frames [private] |
unsigned int MMSPulser::times_buf[MMSPULSER_TIMES_BUF_SIZE] [private] |
unsigned int MMSPulser::times_buf_pos [private] |
unsigned int MMSPulser::times_buf_cnt [private] |
unsigned int MMSPulser::anim_start [private] |
unsigned int MMSPulser::anim_end [private] |
unsigned int MMSPulser::duration [private] |
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);
pulser | is the pointer to the caller (the pulser thread) |
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);
pulser | is the pointer to the caller (the pulser thread) |
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);
pulser | is the pointer to the caller (the pulser thread) |
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.