Skip to content
This repository was archived by the owner on Dec 17, 2022. It is now read-only.

Commit f3e9127

Browse files
committed
Backup latest state. Note that this is no longer actively developed!
1 parent e6e53f3 commit f3e9127

File tree

7 files changed

+91
-178
lines changed

7 files changed

+91
-178
lines changed

ControlThemAll.js

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import process from 'node:process'
12
import { find, isEmpty, difference, flatten } from 'lodash-es'
23
import got from 'got'
34
import delay from 'delay'
45
import merge from 'deepmerge'
56
import { Enums } from 'atem-connection'
67

7-
import beforeShutdown from './beforeShutdown.js'
8+
import exitHook from 'exit-hook'
9+
// import beforeShutdown from './beforeShutdown.js'
810
import { ControllerWebServer } from './ControllerWebServer.js'
911
import { ControllerAtem } from './ControllerAtem.js'
1012
import { ControllerMidi } from './ControllerMidi.js'
@@ -36,19 +38,16 @@ export class ControlThemAll {
3638

3739
async setup() {
3840
console.log('Setting up ControlThemAll Backend')
39-
// // Do something when app is closing
40-
// process.on('exit', this.exitHandler.bind(this, { exit: true }))
41-
// // catches ctrl+c event
42-
// process.on('SIGINT', this.exitHandler.bind(this, {cleanup: true}));
43-
// // Catches "kill pid" (for example: nodemon restart)
44-
// process.on('SIGUSR1', this.exitHandler.bind(this, {exit: true}));
45-
// process.on('SIGUSR2', this.exitHandler.bind(this, {exit: true, cleanup: true}));
46-
// // Catches uncaught exceptions
47-
// process.on('uncaughtException', this.exitHandler.bind(this, {exit: true}));
48-
// process.on('uncaughtException', (reason) => console.log('UNHANDLED EXCEPTION:', reason))
49-
// process.on('unhandledRejection', reason => console.log('UNHANDLED REJECTION:', reason));
50-
51-
beforeShutdown(this.exitHandler.bind(this, { cleanup: true, exit: true }))
41+
42+
process.on('exit', (t) => console.log('process.on : exit:', t))
43+
process.on('SIGINT', (t) => console.log('process.on : SIGINT:', t))
44+
process.on('SIGUSR1', (t) => console.log('process.on : SIGUSR1:', t))
45+
process.on('SIGUSR2', (t) => console.log('process.on : SIGUSR2:', t))
46+
process.on('uncaughtException', (t) => console.log('process.on : uncaughtException:', t))
47+
process.on('uncaughtException', (t) => console.log('process.on : uncaughtException:', t))
48+
process.on('unhandledRejection', (t) => console.log('process.on : unhandledRejection:', t))
49+
50+
exitHook(this.exitHandler.bind(this))
5251

5352
this.controllerConfig = new ControllerConfig()
5453
this.config = await this.controllerConfig.getConfig()
@@ -1092,57 +1091,43 @@ export class ControlThemAll {
10921091
}
10931092
}
10941093

1095-
async exitHandler(options, exitCode) {
1096-
console.log(`exitHandler with exitCode: ${exitCode || 'NONE'}`)
1097-
1098-
// SetTimeout(error => {
1099-
// // Force close server after timeout (this is if the cleanUp takes too long)
1100-
// console.log('gentle took too long exiting hard');
1101-
// process.exit(1);
1102-
// }, 10 * 1000); // 10 seconds
1094+
exitHandler() {
1095+
console.log(`running exitHandler for cleanup`)
11031096

1104-
if (options.cleanup) {
1105-
console.log('ControlThemAll: Doing the cleanup.')
1106-
1107-
if (this.controllerMidi && this.controllerMidi.isConnected()) {
1108-
this.switchButtonLightOff(flatten(this.config.buttons.map((element) => [element.note])))
1109-
this.controllerMidi.updateButtonsViaState(this.config.buttons)
1110-
this.updateControllerState(this.config.controllers.map((element) => merge(element, { state: 'cc', value: 0 })))
1111-
this.controllerMidi.updateControllersViaState(this.config.controllers)
1112-
}
1113-
1114-
if (this.controllerWebServer) {
1115-
console.log('before web server disconnect')
1116-
console.log(await this.controllerWebServer.disconnect())
1117-
console.log('after web server disconnect')
1118-
}
1119-
1120-
if (this.controllerMidi) {
1121-
console.log('before midi disconnect')
1122-
console.log(await this.controllerMidi.disconnect())
1123-
console.log('after midi disconnect')
1124-
}
1097+
if (this.controllerMidi && this.controllerMidi.isConnected()) {
1098+
this.switchButtonLightOff(flatten(this.config.buttons.map((element) => [element.note])))
1099+
this.controllerMidi.updateButtonsViaState(this.config.buttons)
1100+
this.updateControllerState(this.config.controllers.map((element) => merge(element, { state: 'cc', value: 0 })))
1101+
this.controllerMidi.updateControllersViaState(this.config.controllers)
1102+
}
11251103

1126-
if (this.controllerStreamDeck) {
1127-
console.log('before stream deck disconnect')
1128-
console.log(await this.controllerStreamDeck.disconnect())
1129-
console.log('after stream deck disconnect')
1130-
}
1104+
if (this.controllerWebServer) {
1105+
console.log('before web server disconnect')
1106+
this.controllerWebServer.disconnect()
1107+
delete this.controllerWebServer
1108+
console.log('after web server disconnect')
1109+
}
11311110

1132-
if (this.controllerAtem) {
1133-
console.log('before atem disconnect')
1134-
console.log(await this.controllerAtem.disconnect())
1135-
console.log('after atem disconnect')
1136-
}
1137-
// Await this.controllerHotkeys.disconnect()
1111+
if (this.controllerMidi) {
1112+
console.log('before midi disconnect')
1113+
this.controllerMidi.disconnect()
1114+
delete this.controllerMidi
1115+
console.log('after midi disconnect')
1116+
}
11381117

1139-
console.log('ControlThemAll closed, cleaned, and shutting down!')
1118+
if (this.controllerAtem) {
1119+
console.log('before atem disconnect')
1120+
this.controllerAtem.disconnect()
1121+
delete this.controllerAtem
1122+
console.log('after atem disconnect')
11401123
}
11411124

1142-
// if (options.exit) {
1143-
// console.log('ControlThemAll closed all connections successfully… shuting down…')
1144-
// process.exit()
1145-
// }
1125+
if (this.controllerStreamDeck) {
1126+
console.log('before stream deck disconnect')
1127+
this.controllerStreamDeck.disconnect()
1128+
delete this.controllerStreamDeck
1129+
console.log('after stream deck disconnect')
1130+
}
11461131
}
11471132
}
11481133

ControllerStreamDeck.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,19 @@ export class ControllerStreamDeck extends EventEmitter {
8282
}
8383

8484
async disconnect() {
85-
console.log('stream deck disconnecting?!')
86-
await this._streamDeck.resetToLogo()
87-
this._streamDeck.removeAllListeners()
88-
await this._streamDeck.close()
89-
delete this._streamDeck
90-
this.emit('disconnect', { sessionId: this.sessionId })
85+
try {
86+
this._streamDeck.resetToLogo()
87+
this._streamDeck.removeAllListeners()
88+
if (this._streamDeck) {
89+
this._streamDeck.close()
90+
delete this._streamDeck
91+
}
92+
93+
this.emit('disconnect', { sessionId: this.sessionId })
94+
return { sessionId: this.sessionId }
95+
} catch (error) {
96+
console.log('error while closing stream deck', error)
97+
}
9198
}
9299

93100
async send(options) {

beforeShutdown.js

Lines changed: 0 additions & 94 deletions
This file was deleted.

config.default.yaml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ streamDeck:
132132

133133
atem:
134134
enabled: false
135-
address: 192.168.10.240
135+
address: 192.168.178.240
136136

137137
hotkeys:
138138
enabled: false
@@ -499,14 +499,17 @@ buttons:
499499
noteOff:
500500
action: ChangeProgramSource
501501
programInput: cam2
502+
withUpstreamKeyer: true
502503
- note: 10
503504
noteOff:
504505
action: ChangeProgramSource
505506
programInput: cam3
507+
withUpstreamKeyer: true
506508
- note: 11
507509
noteOff:
508510
action: ChangeProgramSource
509511
programInput: cam4
512+
withUpstreamKeyer: true
510513
- note: 12
511514
noteOff:
512515
action: ChangeDveStyle
@@ -572,17 +575,14 @@ buttons:
572575
noteOff:
573576
action: ChangeProgramSource
574577
programInput: cam2
575-
withUpstreamKeyer: true
576578
- note: 18
577579
noteOff:
578580
action: ChangeProgramSource
579581
programInput: cam3
580-
withUpstreamKeyer: true
581582
- note: 19
582583
noteOff:
583584
action: ChangeProgramSource
584585
programInput: cam4
585-
withUpstreamKeyer: true
586586
- note: 20
587587
noteOff:
588588
action: ChangeUpstreamKeyerFillSource
@@ -653,12 +653,12 @@ buttons:
653653
- note: 34
654654
noteOff:
655655
action: ChangeProgramSource
656-
programInput: cam4
656+
programInput: cam2
657657
withUpstreamKeyer: true
658658
- note: 35
659659
noteOff:
660660
action: ChangeProgramSource
661-
programInput: cam2
661+
programInput: cam4
662662
withUpstreamKeyer: true
663663
- note: 36
664664
noteOff:
@@ -681,7 +681,12 @@ buttons:
681681
action: SwitchProgramAndUpstreamKeyerFillSource
682682
- note: 39
683683
noteOff:
684-
action: FadeToBlack
684+
# action: FadeToBlack'
685+
action: ToggleAudioSourceMixOption
686+
audioIndex: 1301
687+
channels: ['-65280'] # stereo split channels: ['-255', '-256'] | joined channel: ['-65280']
688+
defaultValue: on
689+
toggle: ['on', 'off']
685690
# LAYER B - BUTTONS LOWER ROW
686691
- note: 40
687692
noteOff:
@@ -694,11 +699,11 @@ buttons:
694699
- note: 42
695700
noteOff:
696701
action: ChangeProgramSource
697-
programInput: cam4
702+
programInput: cam2
698703
- note: 43
699704
noteOff:
700705
action: ChangeProgramSource
701-
programInput: cam2
706+
programInput: cam4
702707
- note: 44
703708
noteOff:
704709
action: ChangeUpstreamKeyerFillSource
@@ -754,18 +759,18 @@ feedback:
754759

755760
buttonsForProgramInputWithoutDve:
756761
cam1: [16, 40]
757-
cam2: [9, 43]
758-
cam3: [10, 41]
759-
cam4: [11, 42]
762+
cam2: [17, 42]
763+
cam3: [18, 41]
764+
cam4: [19, 43]
760765

761766
buttonsForProgramInputWithDve:
762767
cam1: [8, 32]
763-
cam2: [17, 35]
764-
cam3: [18, 33]
765-
cam4: [19, 34]
768+
cam2: [9, 34]
769+
cam3: [10, 33]
770+
cam4: [11, 35]
766771

767772
buttonsForActiveUpstreamKeyerFillSource:
768773
cam1: [20, 44]
769-
cam2: [21, 47]
774+
cam2: [21, 46]
770775
cam3: [22, 45]
771-
cam4: [23, 46]
776+
cam4: [23, 47]

config.user.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ webServer:
22
enabled: false
33

44
midi:
5-
enabled: false
5+
enabled: true
66

77
atem:
8-
enabled: false
8+
enabled: true
99

1010
streamDeck:
1111
enabled: false
12+
model: 'original-mk2'
13+
serialNumber: 'DL42K1A08814'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"delay": "^5.0.0",
2828
"detect-port": "^1.3.0",
2929
"easymidi": "^2.1.0",
30+
"exit-hook": "^3.0.0",
3031
"express": "^4.17.2",
3132
"fabric": "^4.6.0",
3233
"got": "^12.0.1",

0 commit comments

Comments
 (0)