ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kbanim.h
Go to the documentation of this file.
1 #ifndef KBANIM_H
2 #define KBANIM_H
3 
4 #include <QObject>
5 #include "ckbsettings.h"
6 #include "animscript.h"
7 #include "keymap.h"
8 
9 // Animation instance for a lighting mode.
10 
11 class KbAnim : public QObject
12 {
13  Q_OBJECT
14  Q_ENUMS(Mode)
15 public:
16  // Blending modes
17  enum Mode {
19  Add,
23  };
24 
25  // Load an animation from settings
26  KbAnim(QObject* parent, const KeyMap& map, const QUuid id, CkbSettings& settings);
27  // Save an animation to settings
28  void save(CkbSettings& settings);
29  inline bool needsSave() const { return _needsSave; }
30 
31  // Create a new animation
32  KbAnim(QObject* parent, const KeyMap& map, const QString& name, const QStringList& keys, const AnimScript* script);
33  // Copy an existing animation
34  KbAnim(QObject *parent, const KeyMap& map, const KbAnim& other);
35 
36  // Key map
37  inline const KeyMap& map() { return _map; }
38  void map(const KeyMap& newMap);
39  // Keys to animate
40  inline const QStringList& keys() { return _keys; }
41  void keys(const QStringList& newKeys);
42 
43  // Gets a parameter value
44  inline bool hasParameter(const QString& name) const { return _parameters.contains(name); }
45  inline QVariant parameter(const QString& name) const { return _parameters.value(name); }
46  // Sets a parameter value. Parameter changes are not permanent until commited.
47  void parameter(const QString& name, const QVariant& value);
48  // Commits unsaved parameters
49  void commitParams();
50  // Discards unsaved parameters
51  void resetParams();
52  // Re-initialize the animation. Useful for doing a hard restart.
53  void reInit();
54 
55  // Begins or re-triggers the animation
56  // Normally this will only start the animation if specified in the parameters. To ignore this and start it no matter what, use ignoreParameter.
57  void trigger(quint64 timestamp, bool ignoreParameter = false);
58  // Triggers a keypress in the animation
59  void keypress(const QString& key, bool pressed, quint64 timestamp);
60  // Stops the animation
61  void stop();
62  // Whether or not the animation is currently active
63  bool isActive() const { return _isActive || _isActiveKp; }
64  // Whether or not the animation script is responding
65  bool isRunning() const;
66 
67  // Blends the animation into a color map, taking opacity and mode into account
68  void blend(ColorMap &animMap, quint64 timestamp);
69 
70  // Animation properties
71  inline const QUuid& guid() const { return _guid; }
72  inline void newId() { _needsSave = true; _guid = QUuid::createUuid(); }
73  inline const QString& name() const { return _name; }
74  inline void name(const QString& newName) { _needsSave = true; _name = newName; }
75  inline float opacity() const { return _opacity; }
76  inline void opacity(float newOpacity) { _needsSave = true; _opacity = newOpacity; }
77  inline Mode mode() const { return _mode; }
78  inline void mode(Mode newMode) { _needsSave = true; _mode = newMode; }
79 
80  // Animation script properties
81  const AnimScript* script() const { return _script; }
82  const QString& scriptName() const { return _scriptName; }
83 
84 private:
85  // Script (null if not loaded)
87  // GUID and name (duplicated here in case the load fails)
88  QUuid _scriptGuid;
89  QString _scriptName;
90 
92  QStringList _keys;
93  // Committed parameters
94  QMap<QString, QVariant> _parameters;
95  // Uncommitted parameters
96  QMap<QString, QVariant> _tempParameters;
97 
98  // Effective parameters (including unsaved)
99  QMap<QString, QVariant> effectiveParams();
100  // Updates parameters to animation if live params are enabled
101  void updateParams();
102 
103  // Repeat/stop info (set from parameters)
104  QString repeatKey;
107  // Catch up to the current timestamp, performing repeats/stops as necessary
108  void catchUp(quint64 timestamp);
109 
110  QUuid _guid;
111  QString _name;
112  float _opacity;
116 };
117 
118 #endif // KBANIM_H
void stop()
Definition: kbanim.cpp:312
void mode(Mode newMode)
Definition: kbanim.h:78
const QStringList & keys()
Definition: kbanim.h:40
void catchUp(quint64 timestamp)
Definition: kbanim.cpp:166
bool isActive() const
Definition: kbanim.h:63
void updateParams()
Definition: kbanim.cpp:132
Mode mode() const
Definition: kbanim.h:77
quint64 repeatTime
Definition: kbanim.h:105
QMap< QString, QVariant > _parameters
Definition: kbanim.h:94
bool hasParameter(const QString &name) const
Definition: kbanim.h:44
void opacity(float newOpacity)
Definition: kbanim.h:76
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
const QString & name() const
Definition: kbanim.h:73
Mode _mode
Definition: kbanim.h:113
quint64 stopTime
Definition: kbanim.h:105
QString repeatKey
Definition: kbanim.h:104
QUuid _scriptGuid
Definition: kbanim.h:88
Definition: keymap.h:49
const KeyMap & map()
Definition: kbanim.h:37
int repeatMsec
Definition: kbanim.h:106
void name(const QString &newName)
Definition: kbanim.h:74
bool isRunning() const
Definition: kbanim.cpp:325
void newId()
Definition: kbanim.h:72
int kpRepeatMsec
Definition: kbanim.h:106
const QString & scriptName() const
Definition: kbanim.h:82
void save(CkbSettings &settings)
Definition: kbanim.cpp:64
bool _isActive
Definition: kbanim.h:114
QMap< QString, QVariant > effectiveParams()
Definition: kbanim.cpp:138
QString _name
Definition: kbanim.h:111
KbAnim(QObject *parent, const KeyMap &map, const QUuid id, CkbSettings &settings)
Definition: kbanim.cpp:8
bool _needsSave
Definition: kbanim.h:115
Definition: kbanim.h:11
const QUuid & guid() const
Definition: kbanim.h:71
bool needsSave() const
Definition: kbanim.h:29
QUuid _guid
Definition: kbanim.h:110
float _opacity
Definition: kbanim.h:112
void reInit()
Definition: kbanim.cpp:149
float opacity() const
Definition: kbanim.h:75
Definition: keymap.h:49
QString _scriptName
Definition: kbanim.h:89
QStringList _keys
Definition: kbanim.h:92
quint64 kpRepeatTime
Definition: kbanim.h:105
AnimScript * _script
Definition: kbanim.h:86
void resetParams()
Definition: kbanim.cpp:127
quint64 kpStopTime
Definition: kbanim.h:105
KeyMap _map
Definition: kbanim.h:91
QMap< QString, QVariant > _tempParameters
Definition: kbanim.h:96
void keypress(const QString &key, bool pressed, quint64 timestamp)
Definition: kbanim.cpp:250
Mode
Definition: kbanim.h:17
const AnimScript * script() const
Definition: kbanim.h:81
void blend(ColorMap &animMap, quint64 timestamp)
Definition: kbanim.cpp:365
QVariant parameter(const QString &name) const
Definition: kbanim.h:45
void commitParams()
Definition: kbanim.cpp:121
bool _isActiveKp
Definition: kbanim.h:114