-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppWaveLink.js
349 lines (291 loc) · 16.9 KB
/
AppWaveLink.js
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/// <reference path="libs/js/stream-deck.js" />
debugMode = false;
class AppWaveLink {
static instance;
secondaryIconType = [];
constructor() {
if (AppWaveLink.instance)
return AppWaveLink.instance;
AppWaveLink.instance = this;
}
init() {
this.profile = "local";
this.actions = [];
this.keyIconWarning = new SVGIconWL({ icons: `./images/key/warning.svg`, icon: `warning`});
this.keyIconsInput = {
'default': new SVGIconWL({ icons: `./images/key/inputActions/default.svg`, icon: `default`}),
'increase': new SVGIconWL({ icons: `./images/key/increase.svg`, icon: `increase`}),
'decrease': new SVGIconWL({ icons: `./images/key/decrease.svg`, icon: `decrease`})
};
this.keyIconsOutput = {
'default': new SVGIconWL({ icons: `./images/key/outputActions/default.svg`, icon: `default`}),
'increase': new SVGIconWL({ icons: `./images/key/increase.svg`, icon: `increase`}),
'decrease': new SVGIconWL({ icons: `./images/key/decrease.svg`, icon: `decrease`}),
'toggleOutputMonitor': new SVGIconWL({ icons: `./images/key/outputActions/toggleOutputMonitor.svg`, icon: `toggleOutputMonitor`}),
'toggleOutputStream': new SVGIconWL({ icons: `./images/key/outputActions/toggleOutputStream.svg`, icon: `toggleOutputStream`}),
};
this.keyIconsHardware = {};
this.loadImage(`./images/key/hardwareActions/default.svg`).then((svg) => { this.keyIconsHardware[`default`] = svg; });
this.loadImage(`./images/key/hardwareActions/setOutputDevice.svg`).then((svg) => { this.keyIconsHardware[`setOutputDevice`] = svg; });
this.loadImage(`./images/key/hardwareActions/toggleOutputDeviceFirst.svg`).then((svg) => { this.keyIconsHardware[`toggleOutputDeviceFirst`] = svg; });
this.loadImage(`./images/key/hardwareActions/toggleOutputDeviceSecond.svg`).then((svg) => { this.keyIconsHardware[`toggleOutputDeviceSecond`] = svg; });
this.keyIconsEffect = {
'default': new SVGIconWL({ icons: `./images/key/effectActions/default.svg`, icon: `default`}),
'toggleEffectOn': new SVGIconWL({ icons: `./images/key/effectActions/toggleEffectOn.svg`, icon: `toggleEffectOn`}),
'toggleEffectOff': new SVGIconWL({ icons: `./images/key/effectActions/toggleEffectOff.svg`, icon: `toggleEffectOff`}),
'toggleEffectChainOn': new SVGIconWL({ icons: `./images/key/effectActions/toggleEffectChainOn.svg`, icon: `toggleEffectChainOn`}),
'toggleEffectChainOff': new SVGIconWL({ icons: `./images/key/effectActions/toggleEffectChainOff.svg`, icon: `toggleEffectChainOff`})
};
this.touchIconWarning;
this.loadImage(`./images/touchPanel/warning.svg`).then((svg) => { this.touchIconWarning = svg; });
this.touchIconsInput = {};
this.loadImage(`./images/touchPanel/input/default.svg`).then((svg) => { this.touchIconsInput[`default`] = svg; });
this.touchIconsOutput = {}
this.loadImage(`./images/touchPanel/output/default.svg`).then((svg) => { this.touchIconsOutput[`default`] = svg; });
this.touchIconsHardware = {}
this.loadImage(`./images/touchPanel/hardware/adjustHardwareGain.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustGain] = svg; });
this.loadImage(`./images/touchPanel/hardware/adjustHardwareGainMute.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustGain + kPropertySuffixMuted] = svg; });
this.loadImage(`./images/touchPanel/hardware/adjustHardwareVolume.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustOutput] = svg; });
this.loadImage(`./images/touchPanel/hardware/adjustHardwareVolumeMute.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustOutput + kPropertySuffixMuted] = svg; });
this.loadImage(`./images/touchPanel/hardware/hardwareBalancePC.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustMicPcBalance + kPropertySuffixPlus] = svg; });
this.loadImage(`./images/touchPanel/hardware/hardwareBalancePCMute.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustMicPcBalance + kPropertySuffixPlus + kPropertySuffixMuted] = svg; });
this.loadImage(`./images/touchPanel/hardware/hardwareBalanceMic.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustMicPcBalance + kPropertySuffixMinus] = svg; });
this.loadImage(`./images/touchPanel/hardware/hardwareBalanceMicMute.svg`).then((svg) => { this.touchIconsHardware[kPropertyAdjustMicPcBalance + kPropertySuffixMinus + kPropertySuffixMuted] = svg; });
this.secondaryIconType = [ 'Monitor', 'MonitorMute', 'Stream', 'StreamMute', 'All', 'AllMute', 'Set', 'Add' ];
const primaryIconTypeInput = [ 'wave', 'system', 'music', 'browser', 'voiceChat', 'sfx', 'game', 'aux' ];
const primaryIconTypeOutput = [ 'output' ];
const primaryIconTypeHardware = [
[ 'setHardwareGain', kPropertySetGain ],
[ 'setHardwareVolume', kPropertySetOutput ],
[ 'setHardwareBalance', kPropertySetMicPcBalance ],
[ 'adjustHardwareGain', kPropertyAdjustGain ],
[ 'adjustHardwareGainMute', kPropertyAdjustGain + kPropertySuffixMuted ],
[ 'adjustHardwareGainPlus', kPropertyAdjustGain + kPropertySuffixPlus ],
[ 'adjustHardwareGainMinus', kPropertyAdjustGain + kPropertySuffixMinus ],
[ 'adjustHardwareVolume', kPropertyAdjustOutput ],
[ 'adjustHardwareVolumeMute', kPropertyAdjustOutput + kPropertySuffixMuted ],
[ 'adjustHardwareVolumePlus', kPropertyAdjustOutput + kPropertySuffixPlus ],
[ 'adjustHardwareVolumeMinus', kPropertyAdjustOutput + kPropertySuffixMinus ],
[ 'adjustHardwareBalance', kPropertyAdjustMicPcBalance ],
[ 'adjustHardwareBalanceMute', kPropertyAdjustMicPcBalance + kPropertySuffixMuted ],
[ 'hardwareBalanceToPC', kPropertyAdjustMicPcBalance + kPropertySuffixPlus ],
[ 'hardwareBalanceToMic', kPropertyAdjustMicPcBalance + kPropertySuffixMinus ],
[ 'hardwareLowcutOn', kPropertyToggleLowcut + kPropertySuffixOn ],
[ 'hardwareLowcutOff', kPropertyToggleLowcut + kPropertySuffixOff ],
[ 'hardwareClipguardOn', kPropertyToggleClipguard + kPropertySuffixOn ],
[ 'hardwareClipguardOff', kPropertyToggleClipguard + kPropertySuffixOff ],
[ 'hardwareGainLockOn', kPropertytoggleGainLock + kPropertySuffixOn ],
[ 'hardwareGainLockOff', kPropertytoggleGainLock + kPropertySuffixOff ],
[ 'toggleHardwareOn', kPropertyToggleHardwareMute + kPropertySuffixOn ],
[ 'toggleHardwareOff', kPropertyToggleHardwareMute + kPropertySuffixOff ],
];
primaryIconTypeInput.forEach ( primType => {
this.secondaryIconType.forEach(secType => {
const icon = `${primType}${secType}`;
switch (primType) {
case 'wave':
if (secType == 'Add')
return;
default:
break;
}
if (secType != 'Set' && secType != 'Add' && !secType.includes('All')) {
if (primType == 'wave') {
const macOSIcon = new SVGIconWL({ icons: { [primType]: `./images/touchPanel/input/${primType}All.svg` }, icon: `${primType}`, layerOrder: [ 'icon', `overlayTouch${secType}` ] });
macOSIcon.layerProps['icon'].transform = 'scale(3.6, 3.6)';
this.touchIconsInput[`${icon}MacOS`] = macOSIcon.toBase64(true);
}
this.touchIconsInput[`${icon}`] = new SVGIconWL({ icons: { [icon]: `./images/touchPanel/input/${icon}.svg` }, icon: `${icon}` });
this.touchIconsInput[`${icon}`].layerProps['icon'].transform = 'scale(3.6, 3.6)';
this.touchIconsInput[`${icon}`] = this.touchIconsInput[`${icon}`].toBase64(true);
}
this.keyIconsInput[`${icon}`] = new SVGIconWL({ icons: `./images/key/inputActions/${icon}.svg`, icon: `${icon}`, layerOrder: [ 'background', 'icon' ] });
});
});
primaryIconTypeOutput.forEach ( primType => {
this.secondaryIconType.forEach(secType => {
const icon = `${primType}${secType}`;
if (secType == 'Add')
return;
if (secType != 'Set')
this.loadImage(`./images/touchPanel/output/${icon}.svg`).then((svg) => { this.touchIconsOutput[`${icon}`] = svg; });
this.keyIconsOutput[`${icon}`] = new SVGIconWL({ icons: `./images/key/outputActions/${icon}.svg`, icon: `${icon}`});
});
});
primaryIconTypeHardware.forEach ( icon => {
this.loadImage(`./images/key/hardwareActions/hardwareSettings/${icon[0]}.svg`).then((svg) => { this.keyIconsHardware[`${icon[1]}`] = svg; });
});
$SD.onConnected(({ appInfo }) => {
const { application } = appInfo;
const { platform } = application;
const { devices } = appInfo;
new WaveLinkClient().init(platform, devices);
this.initActions();
logInfo('Connected with Stream Deck');
setTimeout(() => {
const wlc = new WaveLinkClient();
wlc.connect();
}, 1000)
});
$SD.onApplicationDidLaunch(() => {
logInfo('Wave Link launched');
setTimeout(() => {
const wlc = new WaveLinkClient();
wlc.connect();
}, 1000)
});
$SD.onSystemDidWakeUp(() => {
logInfo('System woke up');
setTimeout(() => {
const wlc = new WaveLinkClient();
wlc.connect();
}, 1000);
});
$SD.onApplicationDidTerminate(() => {
logInfo('Wave Link closed');
const wlc = new WaveLinkClient();
wlc.setConnectionState(false);
wlc.disconnect();
});
}
initActions() {
this.actionClasses = [
// New merged OutputAction
new OutputAction("com.elgato.wavelink.outputaction"),
// Old output actions
new OutputAction("com.elgato.wavelink.monitormute"),
new OutputAction("com.elgato.wavelink.setvolumemonitor"),
new OutputAction("com.elgato.wavelink.adjustvolumemonitor"),
new OutputAction("com.elgato.wavelink.switchmonitoring"),
// New merged InputAction
new InputAction("com.elgato.wavelink.inputaction"),
// Old input actions
new InputAction("com.elgato.wavelink.mixermute"),
new InputAction("com.elgato.wavelink.setvolumemixer"),
new InputAction("com.elgato.wavelink.adjustvolumemixer"),
// New merged EffectAction
new EffectAction("com.elgato.wavelink.effectaction"),
// Old effect actions
new EffectAction("com.elgato.wavelink.seteffect"),
new EffectAction("com.elgato.wavelink.seteffectchain"),
// New merged HardwareAction
new HardwareAction("com.elgato.wavelink.hardwareaction"),
// Old microphone and output actions
new HardwareAction("com.elgato.wavelink.setmonitormixoutput"),
new HardwareAction("com.elgato.wavelink.togglemonitormixoutput"),
new HardwareAction("com.elgato.wavelink.setmicsettings"),
new SwitchProfile("com.elgato.wavelink.switchprofiles")
]
}
switchProfile(profile, device)
{
var switchProfile = "";
switch (profile) {
case "WL1":
switchProfile = "Wave Link 1";
break;
case "WL2":
switchProfile = "Wave Link 2";
break;
case "WLMonitoring":
switchProfile = "Wave Link Monitoring";
break;
case "WLStream":
switchProfile = "Wave Link Stream";
break;
case "WLXLMonitoring":
switchProfile = "Wave Link XL Monitoring";
break;
case "WLXLStream":
switchProfile = "Wave Link XL Stream";
break;
default:
break;
}
$SD.switchToProfile(device, switchProfile);
}
// Taken from common.js (Control Center), adjusted to fit
loadImage (inUrl, inCanvas, inFillcolor = '') {
return new Promise((resolve, reject) => {
/** Convert to array, so we may load multiple images at once */
const aUrl = !Array.isArray(inUrl) ? [inUrl] : inUrl;
const canvas = inCanvas && inCanvas instanceof HTMLCanvasElement ? inCanvas : document.createElement('canvas');
var imgCount = aUrl.length - 1;
const imgCache = {};
var ctx = canvas.getContext('2d');
ctx.globalCompositeOperation = 'source-over';
for (let url of aUrl) {
let image = new Image();
let cnt = imgCount;
let w = 144, h = 144;
let resize = 0;
image.onload = function() {
imgCache[url] = this;
// look at the size of the second image
//if (url === aUrl[0]) {
canvas.width = w; //this.naturalWidth; // or 'width' if you want a special/scaled size
canvas.height = h; //this.naturalHeight; // or 'height' if you want a special/scaled size
//}
// if (Object.keys(imgCache).length == aUrl.length) {
if (cnt < 1) {
if (inFillcolor) {
ctx.fillStyle = inFillcolor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
// draw in the proper sequence FIFO
aUrl.forEach(e => {
if (!imgCache[e]) {
debug(imgCache[e], imgCache);
reject('error');
}
if (e == aUrl[0]) {
if (imgCache[e]) {
//ctx.drawImage(imgCache[e], 0 + (resize / 2), 0 + (resize / 2), w - resize, h - resize);
// Use height as
ctx.drawImage(imgCache[e], (this.naturalWidth - this.naturalHeight) / 2, 0, this.naturalHeight, this.naturalHeight, 0, 0, w - resize, h - resize);
/*
let imgData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
let pixels = imgData.data;
for (var i = 0; i < pixels.length; i += 4) {
let lightness = parseInt((pixels[i] + pixels[i + 1] + pixels[i + 2])/3);
pixels[i] = lightness;
pixels[i + 1] = lightness;
pixels[i + 2] = lightness;
}
ctx.putImageData(imgData, 0, 0);
*/
//ctx.drawImage(imgCache[e], 0, (this.naturalHeight - this.naturalWidth) / 2, this.naturalWidth, this.naturalWidth, 0, 0, w - resize, h - resize);
ctx.save();
}
} else {
if (imgCache[e]) {
ctx.drawImage(imgCache[e], 0, 0, w, h);
ctx.save();
}
}
});
//callback(canvas.toDataURL('image/png'));
var img = canvas.toDataURL('image/png');
resolve(img);
// or to get raw image data
// callback && callback(canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, ''));
}
};
imgCount--;
image.src = url;
}
});
};
}
function debug(...args) {
if (debugMode) console.log(...args)
}
function logInfo(string) {
debug(` Info ${string}`);
$SD.logMessage(` Info ${string}`);
}
function logError(string) {
debug(` Error ${string}`);
$SD.logMessage(` Error ${string}`);
}
const $AWL = new AppWaveLink().init()