1
- import _ from 'lodash'
1
+ import { find , isEmpty , difference , flatten } from 'lodash-es '
2
2
import got from 'got'
3
3
import merge from 'deepmerge'
4
4
import { Enums } from 'atem-connection'
5
- import { EventEmitter } from 'inf-ee'
5
+ // import { EventEmitter } from 'inf-ee'
6
6
7
7
import { ControllerWebServer } from './ControllerWebServer.js'
8
8
import { ControllerAtem } from './ControllerAtem.js'
@@ -118,32 +118,32 @@ export class ControlThemAll {
118
118
midiOnNoteOn ( msg ) {
119
119
console . log ( `NOTE ON:` , msg )
120
120
const { note, velocity : value , channel } = msg
121
- const buttonConfig = _ . find ( this . config . buttons , { note } )
121
+ const buttonConfig = find ( this . config . buttons , { note } )
122
122
console . log ( `buttonConfig:` , buttonConfig )
123
- if ( _ . isEmpty ( buttonConfig ) ) return
123
+ if ( isEmpty ( buttonConfig ) ) return
124
124
const actionConfig = buttonConfig . noteOn
125
125
console . log ( `buttonConfig:` , actionConfig )
126
- if ( _ . isEmpty ( actionConfig ) ) return
126
+ if ( isEmpty ( actionConfig ) ) return
127
127
const buttonActionFunction = this . getButtonAction ( actionConfig . action )
128
128
if ( buttonActionFunction ) buttonActionFunction ( actionConfig , value )
129
129
}
130
130
131
131
midiOnNoteOff ( msg ) {
132
132
console . log ( `NOTE OFF:` , msg )
133
133
const { note, velocity : value , channel } = msg
134
- const buttonConfig = _ . find ( this . config . buttons , { note } )
134
+ const buttonConfig = find ( this . config . buttons , { note } )
135
135
console . log ( `buttonConfig:` , buttonConfig )
136
- if ( _ . isEmpty ( buttonConfig ) ) return
136
+ if ( isEmpty ( buttonConfig ) ) return
137
137
const actionConfig = buttonConfig . noteOff || buttonConfig
138
- if ( _ . isEmpty ( actionConfig ) ) return
138
+ if ( isEmpty ( actionConfig ) ) return
139
139
const buttonActionFunction = this . getButtonAction ( actionConfig . action )
140
140
if ( buttonActionFunction ) buttonActionFunction ( actionConfig , value )
141
141
}
142
142
143
143
midiOnControllerChange ( msg ) {
144
144
console . log ( `CONTROLLER CHANGE:` , msg )
145
145
const { controller : note , value, channel } = msg
146
- const controllerConfig = _ . find ( this . config . controllers , { note } )
146
+ const controllerConfig = find ( this . config . controllers , { note } )
147
147
console . log ( `controllerConfig:` , controllerConfig )
148
148
const controlAction = this . getControllerAction ( controllerConfig . action )
149
149
if ( controlAction ) controlAction ( controllerConfig , value )
@@ -315,10 +315,10 @@ export class ControlThemAll {
315
315
RunMacro : async ( options , value ) => {
316
316
// console.log(`options:`, options)
317
317
const { name } = options
318
- const macroConfig = _ . find ( this . config . macros , { name } )
318
+ const macroConfig = find ( this . config . macros , { name } )
319
319
const { actions } = macroConfig
320
320
for ( const actionConfig of actions ) {
321
- if ( _ . isEmpty ( actionConfig ) || _ . isEmpty ( actionConfig . action ) ) return
321
+ if ( isEmpty ( actionConfig ) || isEmpty ( actionConfig . action ) ) return
322
322
const buttonActionFunction = this . getButtonAction ( actionConfig . action )
323
323
// console.log(`before ${actionConfig.action}`)
324
324
if ( buttonActionFunction ) await buttonActionFunction ( actionConfig , value )
@@ -361,10 +361,10 @@ export class ControlThemAll {
361
361
console . log ( 'url must be present' )
362
362
return
363
363
}
364
- type = ( ! _ . isEmpty ( type ) ) ? type . toLowerCase ( ) : 'get'
364
+ type = ( ! isEmpty ( type ) ) ? type . toLowerCase ( ) : 'get'
365
365
type = [ 'get' , 'post' , 'path' , 'delete' , 'put' , 'head' ] . includes ( type ) ? type : 'get'
366
- body = ( type !== 'get' && ! _ . isEmpty ( body ) ) ? body : undefined
367
- headers = ( ! _ . isEmpty ( headers ) ) ? headers : { 'Content-Type' : 'application/json' }
366
+ body = ( type !== 'get' && ! isEmpty ( body ) ) ? body : undefined
367
+ headers = ( ! isEmpty ( headers ) ) ? headers : { 'Content-Type' : 'application/json' }
368
368
try {
369
369
const response = await got [ type ] ( options . url , { body, headers } )
370
370
console . log ( 'HTTP Request Response: ' , response . body )
@@ -607,23 +607,39 @@ export class ControlThemAll {
607
607
}
608
608
609
609
getButtonsByAction ( action ) {
610
- return _ . map ( _ . filter ( this . config . buttons , ( el ) => el . action === action || el . noteOn ?. action == action || el . noteOff ?. action == action ) , ( el ) => el . note )
610
+ return this . config . buttons
611
+ . filter (
612
+ ( el ) =>
613
+ el . action === action ||
614
+ el . noteOn ?. action == action ||
615
+ el . noteOff ?. action == action
616
+ )
617
+ . map ( ( el ) => el . note ) ;
618
+ // return map(filter(this.config.buttons, (el) => el.action === action || el.noteOn?.action == action || el.noteOff?.action == action), (el) => el.note)
611
619
}
612
620
613
621
getButtonsByNoteOffAction ( action ) {
614
- return _ . map ( _ . filter ( this . config . buttons , ( el ) => el . noteOff ?. action == action ) , ( el ) => el . note )
622
+ this . config . buttons
623
+ . filter ( ( el ) => el . noteOff ?. action == action )
624
+ . map ( ( el ) => el . note ) ;
625
+ // return map(filter(this.config.buttons, (el) => el.noteOff?.action == action), (el) => el.note)
615
626
}
616
627
617
628
getButtonsByNoteOnAction ( action ) {
618
- return _ . map ( _ . filter ( this . config . buttons , ( el ) => el . noteOn ?. action == action ) , ( el ) => el . note )
629
+ return this . config . buttons
630
+ . filter ( ( el ) => el . noteOn ?. action == action )
631
+ . map ( ( el ) => el . note ) ;
632
+ // return map(filter(this.config.buttons, (el) => el.noteOn?.action == action), (el) => el.note)
619
633
}
620
634
621
635
getControllersByAction ( action ) {
622
- return _ . filter ( this . config . controllers , ( el ) => el . action === action )
636
+ return this . config . controllers . filter ( ( el ) => el . action === action ) ;
637
+ // return filter(this.config.controllers, (el) => el.action === action)
623
638
}
624
639
625
640
getControllersByName ( name ) {
626
- return _ . filter ( this . config . controllers , ( el ) => el . name === name )
641
+ return this . config . controllers . filter ( ( el ) => el . name === name ) ;
642
+ // return filter(this.config.controllers, (el) => el.name === name)
627
643
}
628
644
629
645
updateButtonState ( buttonStates , overwrite = { } , via = 'action' ) {
@@ -632,7 +648,7 @@ export class ControlThemAll {
632
648
return { state : 'noteoff' , value : buttonState . defaultValue || 0 , ...buttonState , ...overwrite }
633
649
} )
634
650
this . config . buttons = this . config . buttons . map ( ( button ) => {
635
- let updatedButtonState = _ . find ( buttonStates , ( el ) => el [ via ] === button [ via ] )
651
+ let updatedButtonState = find ( buttonStates , ( el ) => el [ via ] === button [ via ] )
636
652
if ( updatedButtonState ) {
637
653
button . value = updatedButtonState . value
638
654
button . state = updatedButtonState . state
@@ -645,7 +661,7 @@ export class ControlThemAll {
645
661
const buttonsForDveSelection = this . config . feedback . buttonsForActiveUpstreamKeyerFillSource
646
662
const nameOfInput = Object . keys ( this . config . inputMapping ) . find ( key => this . config . inputMapping [ key ] === this . config . dve . fillSource )
647
663
const buttonActiveDveFillSource = buttonsForDveSelection [ nameOfInput ]
648
- this . switchButtonLightOff ( _ . difference ( _ . flatten ( Object . values ( buttonsForDveSelection ) ) , buttonActiveDveFillSource ) )
664
+ this . switchButtonLightOff ( difference ( flatten ( Object . values ( buttonsForDveSelection ) ) , buttonActiveDveFillSource ) )
649
665
this . switchButtonLightOn ( buttonActiveDveFillSource )
650
666
}
651
667
@@ -655,7 +671,7 @@ export class ControlThemAll {
655
671
return { state : 'cc' , value : controllerState . defaultValue || 0 , ...controllerState , ...overwrite }
656
672
} )
657
673
this . config . controllers = this . config . controllers . map ( ( controller ) => {
658
- let updatedControllerState = _ . find ( controllerStates , ( el ) => el [ via ] === controller [ via ] )
674
+ let updatedControllerState = find ( controllerStates , ( el ) => el [ via ] === controller [ via ] )
659
675
if ( updatedControllerState ) {
660
676
controller . value = updatedControllerState . value
661
677
}
@@ -669,7 +685,7 @@ export class ControlThemAll {
669
685
const { controllers } = this . config
670
686
controllerStates = controllerStates . map ( ( controllerState ) => merge ( controllerState , { state : 'cc' , value : controllerState . defaultValue || 0 } ) )
671
687
controllers . map ( ( controller ) => {
672
- let updatedControllerState = _ . find ( controllerStates , ( el ) => el . action === controller . action )
688
+ let updatedControllerState = find ( controllerStates , ( el ) => el . action === controller . action )
673
689
if ( updatedControllerState ) controller . value = updatedControllerState . value
674
690
return controller
675
691
} )
@@ -732,8 +748,8 @@ export class ControlThemAll {
732
748
const buttonsForProgramInputWithDve = this . config . feedback . buttonsForProgramInputWithDve
733
749
const nameOfInput = Object . keys ( this . config . inputMapping ) . find ( key => this . config . inputMapping [ key ] === programInput )
734
750
const buttonsForProgramInput = ( hasDve ) ? buttonsForProgramInputWithDve [ nameOfInput ] : buttonsForProgramInputWithoutDve [ nameOfInput ]
735
- const buttonsForProgramInputAll = [ ..._ . flatten ( Object . values ( buttonsForProgramInputWithoutDve ) ) , ... _ . flatten ( Object . values ( buttonsForProgramInputWithDve ) ) ]
736
- this . switchButtonLightOff ( _ . difference ( buttonsForProgramInputAll , buttonsForProgramInput ) )
751
+ const buttonsForProgramInputAll = [ ...flatten ( Object . values ( buttonsForProgramInputWithoutDve ) ) , ...flatten ( Object . values ( buttonsForProgramInputWithDve ) ) ]
752
+ this . switchButtonLightOff ( difference ( buttonsForProgramInputAll , buttonsForProgramInput ) )
737
753
this . switchButtonLightOn ( buttonsForProgramInput )
738
754
739
755
this . updateDveButtons ( )
@@ -763,7 +779,7 @@ export class ControlThemAll {
763
779
console . log ( 'Server closing: Doing the cleanup.' )
764
780
765
781
if ( this . controllerMidi . isConnected ( ) ) {
766
- this . switchButtonLightOff ( _ . flatten ( this . config . buttons . map ( ( el ) => [ el . note ] ) ) )
782
+ this . switchButtonLightOff ( flatten ( this . config . buttons . map ( ( el ) => [ el . note ] ) ) )
767
783
this . controllerMidi . updateButtonsViaState ( this . config . buttons )
768
784
this . updatecontrollerState ( this . config . controllers . map ( ( el ) => merge ( el , { state : 'cc' , value : 0 } ) ) )
769
785
this . controllerMidi . updateControllersViaState ( this . config . controllers )
0 commit comments