forked from chloelle/DMX_CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightGroup.cpp
208 lines (177 loc) · 6.29 KB
/
lightGroup.cpp
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
196
197
198
199
200
201
202
203
204
205
206
207
208
//class implementation for group of DMX lights (making up your DMX universe)
#include "stdafx.h"
#include "lightGroup.h"
#include "DMXLight.h"
#include <iostream>
#include <time.h>
lightGroup::lightGroup(){
std::vector<DMXLight*> lights_;
lights = lights_;
}
void lightGroup::addLight(DMXLight &light){
lights.push_back(&light);
}
bool lightGroup::removeLight(DMXLight &light){
bool notFound = true;
for (unsigned int p = 0; p < lights.size(); p++){
if (&light == lights[p]){
lights.erase(lights.begin() + p);
return false;
}
}
return notFound;
}
int parseRGBAWStringInput(std::string input){
if ( input == "r" || input == "R" || input == "red" || input == "Red"){
return 0; //red
}
else if (input == "g" || input == "G" || input == "green" || input == "Green"){
return 1;
}
else if(input == "b" || input == "B" || input == "blue" || input == "Blue"){
return 2;
}
else if(input == "a" || input == "A" || input == "amber" || input == "Amber"){
return 3;
}
else if(input == "w" || input == "W" || input == "white" || input == "White"){
return 4;
}
else{
std::cout << "invalid input color name." << std::endl;
return -1;
}
}
void lightGroup::allOnSingleColor(OpenDMX &myOpenDMX, std::string colorChannel, int numLoops, DWORD milliseconds){
int channel = parseRGBAWStringInput(colorChannel);
if (channel >= 0){
for (int i = 0; i < numLoops; i++){
int p = 0;
while (p <= 50){
myOpenDMX.initOpenDMX();
myOpenDMX.zerosDMXValue();
for (unsigned int q = 0; q < lights.size(); q++){ //loop through lights
if (lights[q]->getHasDimmingChannel()){
myOpenDMX.setDMXValue(lights[q]->getDimmingChannel(), 255);
}
switch(channel){
case 0: myOpenDMX.setDMXValue(lights[q]->getRChannel(), 255); break;
case 1: myOpenDMX.setDMXValue(lights[q]->getGChannel(), 255); break;
case 2: myOpenDMX.setDMXValue(lights[q]->getBChannel(), 255); break;
case 3: if (lights[q]->getHasAmberChannel()){
myOpenDMX.setDMXValue(lights[q]->getAChannel(), 255); }
break;
case 4: if (lights[q]->getHasWhiteChannel()){
myOpenDMX.setDMXValue(lights[q]->getWChannel(), 255); }
break;
default: ;
}
}
myOpenDMX.writeData();
Sleep(milliseconds);
p++;
}
}
}
}
void lightGroup::crossDissolve(OpenDMX &myOpenDMX, int numSteps, DWORD milliseconds, RGBxx &firstColor, RGBxx &lastColor){
RGBxx difference = lastColor - firstColor;
RGBxx stepVector = scalarMultiply(difference, float(1.0)/float(numSteps));
for (int i = 0; i < numSteps; i++){
int p = 0;
RGBxx updateColor = firstColor + scalarMultiply(stepVector, float(i));
while (p <= 2){
myOpenDMX.initOpenDMX();
myOpenDMX.zerosDMXValue();
for (unsigned int q = 0; q < lights.size(); q++){
if (lights[q]->getHasDimmingChannel()){
myOpenDMX.setDMXValue(lights[q]->getDimmingChannel(), 255);
}
myOpenDMX.setDMXValue(lights[q]->getRChannel(), updateColor.R);
myOpenDMX.setDMXValue(lights[q]->getGChannel(), updateColor.G);
myOpenDMX.setDMXValue(lights[q]->getBChannel(), updateColor.B);
if (lights[q]->getHasWhiteChannel()){
myOpenDMX.setDMXValue(lights[q]->getWChannel(), updateColor.W);
}
if (lights[q]->getHasAmberChannel()){
myOpenDMX.setDMXValue(lights[q]->getAChannel(), updateColor.A);
}
}
//myOpenDMX.setDMXValue(A_channel, 0);
myOpenDMX.writeData();
Sleep(milliseconds);
p++;
}
}
}
void lightGroup::rainbowCrossDissolve(OpenDMX &myOpenDMX, int numLoops, DWORD milliseconds){
//RGBxx(int numChannels_, int r, int g, int b, int a, int w);
RGBxx red = RGBxx::RGBxx(4, 255, 0, 0, 0, 0);
RGBxx yellow = RGBxx::RGBxx(4, 128, 128, 0, 0, 0);
RGBxx green = RGBxx::RGBxx(4, 0, 255, 0, 0, 0);
RGBxx cyan = RGBxx::RGBxx(4, 0, 128, 128, 0, 0);
RGBxx blue = RGBxx::RGBxx(4, 0, 0, 255, 0, 0);
RGBxx violet = RGBxx::RGBxx(4, 128, 0, 128, 0, 0);
for (int i = 0; i < numLoops; i++){
crossDissolve(myOpenDMX, 20, milliseconds, red, yellow);
crossDissolve(myOpenDMX, 20, milliseconds, yellow, green);
crossDissolve(myOpenDMX, 20, milliseconds, green, cyan);
crossDissolve(myOpenDMX, 20, milliseconds, cyan, blue);
crossDissolve(myOpenDMX, 20, milliseconds, blue, red);
}
}
void lightGroup::allColorsRampDown(OpenDMX &myOpenDMX, int numLoops, DWORD milliseconds){
for (int i = 0; i < numLoops; i++){
int p = 0;
while (p <= 255){
//this is for an example with an 8-channel DMX light
myOpenDMX.initOpenDMX();
myOpenDMX.zerosDMXValue();
for (unsigned int q = 0; q < lights.size(); q++){
if (lights[q]->getHasDimmingChannel()){
myOpenDMX.setDMXValue(lights[q]->getDimmingChannel(), 255); //4 /255
}
myOpenDMX.setDMXValue(lights[q]->getRChannel(), 255-p); //5 R
myOpenDMX.setDMXValue(lights[q]->getGChannel(), 255-p); //6 G
myOpenDMX.setDMXValue(lights[q]->getBChannel(), 255-p); //7 B
if (lights[q]->getHasWhiteChannel()){
myOpenDMX.setDMXValue(lights[q]->getWChannel(), 255-p); //8 W
}
if (lights[q]->getHasAmberChannel()){
myOpenDMX.setDMXValue(lights[q]->getAChannel(), 255-p); //8 W
}
}
myOpenDMX.writeData();
Sleep(milliseconds);
p++;
}
}
}
void lightGroup::randomPattern(OpenDMX &myOpenDMX, int numLoops, DWORD milliseconds){
srand (time(NULL));
for (int i = 0; i < numLoops; i++){
int p = 0;
while (p <= 255){
//this is for an example with an 8-channel DMX light
myOpenDMX.initOpenDMX();
myOpenDMX.zerosDMXValue();
for (unsigned int q = 0; q < lights.size(); q++){
if (lights[q]->getHasDimmingChannel()){
myOpenDMX.setDMXValue(lights[q]->getDimmingChannel(), 255); //4 /255
}
myOpenDMX.setDMXValue(lights[q]->getRChannel(), rand() % 256); //5 R
myOpenDMX.setDMXValue(lights[q]->getGChannel(), rand() % 256); //6 G
myOpenDMX.setDMXValue(lights[q]->getBChannel(), rand() % 256); //7 B
if (lights[q]->getHasWhiteChannel()){
myOpenDMX.setDMXValue(lights[q]->getWChannel(), rand() % 256); //8 W
}
if (lights[q]->getHasAmberChannel()){
myOpenDMX.setDMXValue(lights[q]->getAChannel(), rand() % 256); //8 W
}
}
myOpenDMX.writeData();
Sleep(milliseconds);
p++;
}
}
}