-
-
Notifications
You must be signed in to change notification settings - Fork 347
/
fadechannel.h
195 lines (148 loc) · 5.57 KB
/
fadechannel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
Q Light Controller
fadechannel.h
Copyright (c) Heikki Junnila
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef FADECHANNEL_H
#define FADECHANNEL_H
#include <QtGlobal>
#include "qlcchannel.h"
#include "fixture.h"
#include "doc.h"
/** @addtogroup engine Engine
* @{
*/
/**
* FadeChannel represents one fixture channel that is to be faded from $start to
* $target, with X steps between, determined by $fadeTime. The actual fading process
* is controlled by GenericFader, but the $current value is calculated each time
* by FadeChannel.
*/
class FadeChannel
{
/************************************************************************
* Initialization
************************************************************************/
public:
enum ChannelFlag
{
HTP = (1 << 0), /** Highest takes precedence */
LTP = (1 << 1), /** Latest takes precedence */
Intensity = (1 << 2), /** Intensity channel (dimmer, RGB, CMY, etc) */
CanFade = (1 << 3), /** Subject to fade transitions */
Flashing = (1 << 4), /** Is flashing */
Relative = (1 << 5), /** Relative position */
Override = (1 << 6), /** Override the current universe value */
Autoremove = (1 << 7), /** Automatically remove the channel once value is written */
CrossFade = (1 << 8) /** Channel subject to crossfade */
};
/** Create a new FadeChannel with empty/invalid values */
FadeChannel();
/** Copy constructor */
FadeChannel(const FadeChannel& ch);
/** Create a new FadeChannel and set fixture ID and channel */
FadeChannel(const Doc *doc, quint32 fxi, quint32 channel);
/** Destructor */
virtual ~FadeChannel();
FadeChannel& operator=(const FadeChannel& fc);
/** Comparison operator (true if fixture & channel match) */
bool operator==(const FadeChannel& fc) const;
/** Get/Set the channel flags listed in ChannelFlag */
int flags() const;
void setFlags(int flags);
/** Add/Remove a single flag */
void addFlag(int flag);
void removeFlag(int flag);
protected:
void autoDetect(const Doc *doc);
private:
/** Bitmask including the channel type
* and, if needed, more flags */
int m_flags;
/************************************************************************
* Values
************************************************************************/
public:
/** Set the Fixture that is being controlled. */
void setFixture(const Doc *doc, quint32 id);
/** Get the Fixture that is being controlled. */
quint32 fixture() const;
/** Get the universe of the Fixture that is being controlled. */
quint32 universe() const;
/** Set channel within the Fixture. */
void setChannel(const Doc* doc, quint32 num);
/** Get channel within the Fixture. */
quint32 channel() const;
/** Get the absolute address for this channel. */
quint32 address() const;
/** Get the absolute address in its universe for this channel. */
quint32 addressInUniverse() const;
/** Set starting value. */
void setStart(uchar value);
/** Get starting value. */
uchar start() const;
/** Set target value. */
void setTarget(uchar value);
/** Get target value. */
uchar target() const;
/** Set the current value. */
void setCurrent(uchar value);
/** Get the current value. */
uchar current() const;
/** Get the current value, modified by $intensity. */
uchar current(qreal intensity) const;
/** Mark this channel as ready (useful for writing LTP values only once). */
void setReady(bool rdy);
/** Check if this channel is ready. Default is false. */
bool isReady() const;
/** Returns if a channel can be faded or not */
bool canFade() const;
/** Set the fade time in milliseconds. */
void setFadeTime(uint ms);
/** Get the fade time in milliseconds. */
uint fadeTime() const;
/** Set the elapsed time for this channel. */
void setElapsed(uint time);
/** Get the elapsed time for this channel. */
uint elapsed() const;
/**
* Increment elapsed() by $ms milliseconds, calculate the next step and
* return the new current() value.
*/
uchar nextStep(uint ms);
/**
* Calculate current value based on fadeTime and elapsedTime. Basically:
* "what m_current should be, if you were given $fadeTime ticks to fade
* from m_start to m_target when $elapsedTime ticks have already passed."
*
* Also, if a channel has been marked ready (isReady() == true), this method
* returns the target value.
*
* @param fadeTime Number of ms to fade from start to target
* @param elapsedTime Number of ms already spent
* @return New current value
*/
uchar calculateCurrent(uint fadeTime, uint elapsedTime);
private:
quint32 m_fixture;
quint32 m_universe;
quint32 m_channel;
quint32 m_address;
int m_start;
int m_target;
int m_current;
bool m_ready;
uint m_fadeTime;
uint m_elapsed;
};
/** @} */
#endif