From fbdaf645583ca1f5a042a03c8b74561d764ef573 Mon Sep 17 00:00:00 2001 From: knicolas22 Date: Sat, 21 Jun 2025 18:15:58 +0200 Subject: [PATCH] C21/06/25 Commit du 21 05 2025 --- src/feedbacks.ts | 69 +++++++++++++++++++++++----------------- src/main.ts | 32 ++++++++++++++++++- src/moduloplayer.ts | 65 +++++++++++++------------------------- src/mpconnection.ts | 8 ++--- src/presets.ts | 65 +++++++++++++++----------------------- src/sdconnection.ts | 2 +- src/variables.ts | 77 +++++++++++++++++++++++++++++++++++++++------ 7 files changed, 191 insertions(+), 127 deletions(-) diff --git a/src/feedbacks.ts b/src/feedbacks.ts index 841f0db..b00eb3a 100755 --- a/src/feedbacks.ts +++ b/src/feedbacks.ts @@ -5,42 +5,52 @@ const colorGreenMP = [88, 201, 23] export function UpdateFeedbacks(self: MPinstance): void { self.setFeedbackDefinitions({ - color_cue: { - name: 'PlayList Color Cue', - type: 'boolean', - defaultStyle: { - bgcolor: combineRgb(255, 0, 0), - color: combineRgb(0, 0, 0), - }, + color_task: { + name: 'Color Task', + type: 'advanced', options: [ { - id: 'current_Cue', - type: 'number', - label: 'ID', - default: 1, - min: 1, - max: 10000, - }, - { - id: 'pl', type: 'textinput', - label: 'Playlist UUID', + label: 'UUID', + id: 'uuid', default: '', - }, + isVisible: () => (false), + } ], callback: (feedback) => { - console.log( - 'FEEDBACK | Color Cue: ' + - feedback.options.current_Cue + " >>> " + - feedback.options.pl + " >>> " + - self.states[`pl_${feedback.options.pl}_currentIndex`] - + " >>> " + (self.states[`pl_${feedback.options.pl}_currentIndex`] !== feedback.options.current_Cue) - ) - if (self.states[`pl_${feedback.options.pl}_currentIndex`] !== feedback.options.current_Cue) { - return true - } else { - return false + const uuid = feedback.options.uuid + const colorStr = self.getVariableValue(`tl_${uuid}_color`) // string "16750848" + if (typeof colorStr === 'string') { + const bgColor = parseInt(colorStr, 10) + return { + bgcolor: bgColor, + } } + return {} + }, + }, + color_cue: { + name: 'Color Cue', + type: 'advanced', + options: [ + { + type: 'textinput', + label: 'UUID', + id: 'uuid', + default: '', + isVisible: () => (false), + } + ], + callback: (feedback) => { + const uuid = feedback.options.uuid + const colorStr = self.getVariableValue(`cue_${uuid}_color`) // string "16750848" + if (typeof colorStr === 'string') { + const bgColor = parseInt(colorStr, 10) + return { + bgcolor: bgColor, + } + } + return {} }, }, current_Cue: { @@ -64,6 +74,7 @@ export function UpdateFeedbacks(self: MPinstance): void { type: 'textinput', label: 'Playlist UUID', default: '', + isVisible: () => (false), }, ], callback: (feedback) => { diff --git a/src/main.ts b/src/main.ts index e9241f9..9115f5b 100755 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import { InstanceBase, runEntrypoint, InstanceStatus, SomeCompanionConfigField } from '@companion-module/base' import { GetConfigFields, type ModuloPlayConfig } from './configFields.js' import { UpdateVariableDefinitions } from './variables.js' +import { InitVariableDefinitions } from './variables.js' import { UpgradeScripts } from './upgrades.js' import { UpdateActions } from './actions.js' import { UpdateFeedbacks } from './feedbacks.js' @@ -27,7 +28,7 @@ export class MPinstance extends InstanceBase { moduloplayer: ModuloPlayer | undefined spydog: SpyDog | undefined - public pollAPI: NodeJS.Timer | null = null + public pollAPI: NodeJS.Timeout | null = null // MODULO PLAYER DATA public tasksList = [] @@ -125,6 +126,7 @@ export class MPinstance extends InstanceBase { updatPolling() { if (this.mpConnected) this.moduloplayer?.getPlaylistsCurrentCues() + if (this.mpConnected) this.moduloplayer?.getTaskListModuloPlayer() if (this.mpConnected) this.moduloplayer?.getPlaylistModuloPlayer() if (this.sdConnected) this.spydog?.getDynamicInfo() } @@ -144,7 +146,35 @@ export class MPinstance extends InstanceBase { updateVariableDefinitions(): void { UpdateVariableDefinitions(this) + InitVariableDefinitions(this) } + + cleanUUID(uuid: String) { + return uuid.replaceAll("{", "").replaceAll("}", "") + } + + cleanName(name: String) { + return name.replaceAll(" ", "-") + } + + getColorFromHex(colorHex: any) { + let couleurRgb = [0, 0, 0] + if (colorHex !== '') { + couleurRgb = this.hexToRgb(`${colorHex}`) + } + return couleurRgb + } + + hexToRgb(hex: any) { + const normal = hex.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i) + if (normal) return normal.slice(1).map((e: string) => parseInt(e, 16)) + + const shorthand = hex.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i) + if (shorthand) return shorthand.slice(1).map((e: string) => 0x11 * parseInt(e, 16)) + + return null + } + } runEntrypoint(MPinstance, UpgradeScripts) diff --git a/src/moduloplayer.ts b/src/moduloplayer.ts index bdfa10b..36591d0 100755 --- a/src/moduloplayer.ts +++ b/src/moduloplayer.ts @@ -8,8 +8,6 @@ import { getPresets } from './presets.js' // 100 = CURRENT CUE LIST // 110 = ACTION GOTO -// 200 = SPYDOG DYNAMIC INFO -// 201 = SPYDOG STATIC INFO export class ModuloPlayer { instance: MPinstance @@ -20,7 +18,7 @@ export class ModuloPlayer { public messageManager(data: String): void { const datas = JSON.parse(data.toString()) - this.instance.log('debug', 'MODULO PLAYER | MESSAGE MANAGER | DATA ID >>> ' + datas['id']) + //this.instance.log('debug', 'MODULO PLAYER | MESSAGE MANAGER | DATA ID >>> ' + datas['id']) if (datas['id'] == 1) { //console.log('debug', 'MODULO PLAYER | MESSAGE MANAGER | DATA >>> ' + data.toString()) this.tasksListManager(datas['result']) @@ -35,69 +33,50 @@ export class ModuloPlayer { // TASK LIST public tasksListManager(obj: any): void { - this.instance.tasksList = obj - //this.instance.log('info', 'MODULO PLAYER | TESK LIST MANAGER| TESKS LIST >>> ' + JSON.stringify(this.instance.tasksList)) - this.instance.setPresetDefinitions(getPresets(this.instance)) + const tlInstance: any[] = this.instance.tasksList + const tlNew: any[] = obj + const checkTL = areJsonArraysEqual(tlInstance, tlNew) + this.instance.log('debug', `MODULO PLAYER | CHECK TL >>> ${checkTL}`) + if (!checkTL) { + this.instance.tasksList = obj + this.instance.setPresetDefinitions(getPresets(this.instance)) + this.instance.updateInstance() + } } + + // PLAY LISTS CUES public playListCuesManager(obj: any): void { const plInstance: any[] = this.instance.playLists const plNew: any[] = obj const checkPL = areJsonArraysEqual(plInstance, plNew) - if (checkPL) { - - } else { + this.instance.log('debug', `MODULO PLAYER | CHECK PL >>> ${checkPL}`) + if (!checkPL) { this.instance.playLists = obj this.instance.setPresetDefinitions(getPresets(this.instance)) this.instance.updateInstance() } - - - // this.instance.log( - // 'warn', - // 'MODULO PLAYER |PLAYLISTS & CUES MANAGER| PLAYLISTS >>> ' + JSON.stringify(this.instance.playLists, null, 4), - // ) - // for (let plID = 0; plID < obj.length; plID++) { - // const cuesList: any[] = obj[plID]["cues"] - // // this.instance.log( - // // 'warn', - // // 'MODULO PLAYER |PLAYLISTS & CUES MANAGER | CUES LIST >>> ' + JSON.stringify(cuesList, null, 4), - // // ) - // for (let cuesID = 0; cuesID < cuesList.length; cuesID++) { - // //const cue = cuesList[cuesID] - // // this.instance.log( - // // 'warn', - // // 'MODULO PLAYER |PLAYLISTS & CUES MANAGER | CUES >>> ' + JSON.stringify(cue, null, 4), - // // ) - // // this.instance.setVariableDefinitions([ - // // { variableId: `cue_${cue["uuid"]}_color`, name: 'Cue Color' }, - // // // { variableId: 'variable2', name: 'My second variable' }, - // // // { variableId: 'variable3', name: 'Another variable' }, - - // // ]) - // } - // } - - // this.instance.setPresetDefinitions(getPresets(this.instance)) - // this.instance.updateInstance() } // GET CURRENT CUE INDEX async getPlaylistsCurrentCues() { - this.instance.log('info', `MODULO PLAYER | GET PLAYLISTS CURRENT CUE !`) + //this.instance.log('info', `MODULO PLAYER | GET PLAYLISTS CURRENT CUE !`) this.instance.mpConnection?.sendMessage('get.list.playlists', 100) } async setPlayListCurrentCueIndex(obj: any) { const pls: any[] = obj for (let playlist = 0; playlist < pls.length; playlist++) { - let uuid: String = pls[playlist]['uuid']//.slice(1, -1) - this.instance.log('warn', `MODULO PLAYER | GET CURRENT INDEX >>> ${uuid} >>> ` + pls[playlist]['index']) + let uuid: String = this.instance.cleanUUID(pls[playlist]['uuid']) + //this.instance.log('warn', `MODULO PLAYER | GET CURRENT INDEX >>> ${uuid} >>> ${pls[playlist]['index']} >>> ${pls[playlist]['grandMasterFader']}`) + let grandMasterFader = (pls[playlist]['grandMasterFader']*100).toFixed(0) var obj: any = { [`pl_${uuid}_currentIndex`]: parseInt(pls[playlist]['index']), + [`pl_${uuid}_grandMasterFader`]: grandMasterFader } this.instance.states[`pl_${uuid}_currentIndex`] = parseInt(pls[playlist]['index']) + this.instance.states[`pl_${uuid}_grandMasterFader`] = grandMasterFader this.instance.setVariableValues(obj) this.instance.checkFeedbacks() } @@ -129,12 +108,12 @@ export class ModuloPlayer { } async getTaskListModuloPlayer() { - this.instance.log('info', 'GET TASKS LIST') + //this.instance.log('info', 'GET TASKS LIST') this.instance.mpConnection?.sendMessage('get.list.tasks', 1) } async getPlaylistModuloPlayer() { - this.instance.log('info', 'GET PLAY LIST') + //this.instance.log('info', 'GET PLAY LIST') this.instance.mpConnection?.sendMessagePlaylistsCues() } } diff --git a/src/mpconnection.ts b/src/mpconnection.ts index 374ecde..aca8cbb 100755 --- a/src/mpconnection.ts +++ b/src/mpconnection.ts @@ -89,7 +89,7 @@ export class MPconnection { if (this.websocket?.readyState === 1) { var m = `{"jsonrpc":"2.0","method":"${method}","id": ${id}}` this.websocket?.send(m) - this.instance.log('debug', 'SENDING WS MESSAGE ' + this.websocket.url + ' ' + m) + //this.instance.log('debug', 'SENDING WS MESSAGE ' + this.websocket.url + ' ' + m) } } @@ -100,14 +100,14 @@ export class MPconnection { "action": "launch" },"id": ${id}}` this.websocket?.send(m) - this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + m) + //this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + m) } } sendJsonMessage(message: String) { if (this.websocket?.readyState === 1 && message !== '') { this.websocket?.send(message) - this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + message) + //this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + message) } } @@ -118,7 +118,7 @@ export class MPconnection { "level": "cue"}, "id": 3}` this.websocket?.send(m) - this.instance.log('debug', 'SENDING WS MESSAGE GET PLAYLISTS CUES ' + this.websocket.url + ' ' + m) + //this.instance.log('debug', 'SENDING WS MESSAGE GET PLAYLISTS CUES ' + this.websocket.url + ' ' + m) } } diff --git a/src/presets.ts b/src/presets.ts index 0a63637..14ff234 100755 --- a/src/presets.ts +++ b/src/presets.ts @@ -31,19 +31,17 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { // TASK const getTasksPresets = (): mpPresetArray => { const tasksPresets: mpPresetArray = [] - //instance.log("warn", "GET TASKS PRESETS 0 >>> " + instance.tasksList.length) - for (let task = 0; task < instance.tasksList.length; task++) { - let color = [0, 0, 0] - if (instance.tasksList[task]['uiColor'] !== '') { - color = hexToRgb(`${instance.tasksList[task]['uiColor']}`) - } - //instance.log("warn", "GET TASKS PRESETS COLOR >>> " + color) + const tls: any[] = instance.tasksList + for (let task = 0; task < tls.length; task++) { + let color = instance.getColorFromHex(tls[task]['uiColor']) // [0, 0, 0] + // if (tls[task]['uiColor'] !== '') { color = hexToRgb(`${tls[task]['uiColor']}`) } + let uuid: String = instance.cleanUUID(tls[task]['uuid']) //.replaceAll("{", "").replaceAll("}", "") tasksPresets.push({ category: `Tasks List` as PresetCategory, - name: `${instance.tasksList[task]['name']}`, + name: `$(Modulo_Player:tl_${uuid}_name)`, type: 'button', style: { - text: `${instance.tasksList[task]['name']}`, + text: `$(Modulo_Player:tl_${uuid}_name)`, size: '24', color: combineRgb(255, 255, 255), bgcolor: combineRgb(color[0], color[1], color[2]), @@ -60,21 +58,15 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { }, ], feedbacks: [ - // { - // feedbackId: 'inputPreview', - // options: { - // mix: (mix - 1) as MixOptionEntry, - // mixVariable: '', - // input: input.toString(), - // fg: combineRgb(255, 255, 255), - // bg: combineRgb(0, 255, 0), - // tally: '', - // }, - // }, + { + feedbackId: 'color_task', + options: { + uuid: uuid, + }, + }, ], }) } - //instance.log("warn", "GET TASKS PRESETS 1 >>> " + tasksPresets.length) return tasksPresets } @@ -88,26 +80,25 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { let uuid: String = pls[playlist]['uuid']//.slice(1, -1) let plName = pls[playlist]['name'] //instance.log('warn', 'GET CUES PRESETS >>> ' + uuid) + playlistsPresets.push({ + category: `Playlists`, + name: `${plName}`, + type: 'text', + //text: 'Inputs 1 to 8', + }) for (let cue = 0; cue < cl.length; cue++) { + const cuuid = instance.cleanUUID(cl[cue]['uuid']) // COLOR let color = [0, 0, 0] if (cl[cue]['uiColor'] !== '') { color = hexToRgb(`${cl[cue]['uiColor']}`) } - //instance.log('warn', 'GET CUES PRESETS COLOR >>> ' + color) - // NAME - let n = cl[cue]['name'] - if (n === '') { - n = `Cue ${cue + 1}` - } - - //instance.log('warn', 'GET CUES PRESETS NAME >>> ' + n) playlistsPresets.push({ - category: `${pls[playlist]['name']}`, - name: n, //`${cl[cue]['name']}`, + category: `Playlists`, + name: `$(Modulo_Player:cue_${cuuid}_name)`, //n, //`${cl[cue]['name']}`, type: 'button', style: { - text: n, //`${cl[cue]['name']}`, + text: `$(Modulo_Player:cue_${cuuid}_name)`, //n, //`${cl[cue]['name']}`, size: textSize, color: combineRgb(255, 255, 255), bgcolor: combineRgb(color[0], color[1], color[2]), @@ -127,11 +118,7 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { { feedbackId: 'color_cue', options: { - current_Cue: cue + 1, - pl: uuid, - }, - style: { - bgcolor: combineRgb(color[0], color[1], color[2]), + uuid: cuuid, }, }, { @@ -150,7 +137,7 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { // GRAND MASTER 0% playlistsPresets.push({ - category: `${pls[playlist]['name']}`, + category: `Playlists`, name: `${plName} GM 0`, type: 'button', style: { @@ -175,7 +162,7 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions { // GRAND MASTER 100% playlistsPresets.push({ - category: `${pls[playlist]['name']}`, + category: `Playlists`, name: `${plName} GM`, type: 'button', style: { diff --git a/src/sdconnection.ts b/src/sdconnection.ts index 3a30cc8..2a29e57 100755 --- a/src/sdconnection.ts +++ b/src/sdconnection.ts @@ -89,7 +89,7 @@ export class SDconnection { sendJsonMessage(message: String) { if (this.websocket?.readyState === 1 && message !== '') { this.websocket?.send(message) - this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + message) + //this.instance.log('debug', 'SPYDOD | SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + message) } } diff --git a/src/variables.ts b/src/variables.ts index 270bb72..bcf1f31 100755 --- a/src/variables.ts +++ b/src/variables.ts @@ -1,13 +1,36 @@ +import { CompanionVariableValues, combineRgb } from '@companion-module/base/dist/index.js' import type { MPinstance } from './main.js' export function UpdateVariableDefinitions(instance: MPinstance): void { instance.log('info', 'VARIABLES DEFINITIONS !') + // CUES const pls: any[] = instance.playLists const variables = [] - for (let playlist = 0; playlist < pls.length; playlist++) { - let uuid: String = pls[playlist]['uuid']//.slice(1, -1) - //instance.log('warn', `VARIABLES DEFINITIONS | GET CURRENT INDEX >>> ${uuid} >>> ` + pls[playlist]['index']) - variables.push({ variableId: `pl_${uuid}_currentIndex`, name: `${pls[playlist]['name']} Current Cue ` }) + for (let pl = 0; pl < pls.length; pl++) { + // CURRENT PL + const cpl = pls[pl]; + const uuidPL: String = instance.cleanUUID(cpl['uuid']) + variables.push({ variableId: `pl_${uuidPL}_currentIndex`, name: `${cpl['name']} Current Cue ` }) + variables.push({ variableId: `pl_${uuidPL}_grandMasterFader`, name: `${cpl['name']} Grand Master Fader ` }) + + // CUES LIST + const cueslist: any = cpl["cues"] + //instance.log('warn', `VARIABLES DEFINITIONS | GET CUES LIST >>> ${instance.playLists}`) + for (let cue = 0; cue < cueslist.length; cue++) { + const c = cueslist[cue]; + const uuidCue: String = instance.cleanUUID(c['uuid']) + variables.push({ variableId: `cue_${uuidCue}_name`, name: `Cue Name` }) + variables.push({ variableId: `cue_${uuidCue}_color`, name: `Cue Color` }) + } + } + + // TASKS + const tls: any[] = instance.tasksList + for (let tl = 0; tl < tls.length; tl++) { + let tlUuid: String = instance.cleanUUID(tls[tl]['uuid']) + //instance.log('warn', `VARIABLES DEFINITIONS | GET TASK NAME >>> ${tlUuid} >>> ${tls[tl]['name']}`) + variables.push({ variableId: `tl_${tlUuid}_name`, name: `Task Name` }) + variables.push({ variableId: `tl_${tlUuid}_color`, name: `Task Color` }) } // SPYDOG STATIC INFO @@ -42,10 +65,44 @@ export function UpdateVariableDefinitions(instance: MPinstance): void { variables.push({ variableId: 'upTime', name: 'UP Time' }) instance.setVariableDefinitions(variables) - // instance.setVariableDefinitions([ - // { variableId: 'variable1', name: 'My first variable' }, - // { variableId: 'variable2', name: 'My second variable' }, - // { variableId: 'variable3', name: 'Another variable' }, - - // ]) +} + +export function InitVariableDefinitions(instance: MPinstance): void { + instance.log('info', 'INIT VARIABLES DEFINITIONS !') + // CUES + const pls: any[] = instance.playLists + const variables: CompanionVariableValues = {}; + for (let pl = 0; pl < pls.length; pl++) { + // CURRENT PL + const cpl = pls[pl]; + // CUES LIST + const cueslist: any = cpl["cues"] + //instance.log('warn', `VARIABLES DEFINITIONS | GET CUES LIST >>> ${instance.playLists}`) + for (let cue = 0; cue < cueslist.length; cue++) { + const c = cueslist[cue]; + const uuidCue: String = instance.cleanUUID(c['uuid']) + let n = c['name'] + if (n === '') { n = `Cue ${cue + 1}` } + const id = `cue_${uuidCue}_name` + const idColor = `cue_${uuidCue}_color` + const couleurRgb = instance.getColorFromHex(`${c['uiColor']}`) + variables[id] = `${n}`; + variables[idColor] = combineRgb(couleurRgb[0], couleurRgb[1], couleurRgb[2]).toString(); + } + } + + // TASKS + const tls: any[] = instance.tasksList + for (let tl = 0; tl < tls.length; tl++) { + const tlUuid: String = instance.cleanUUID(tls[tl]['uuid']) + const tlName: String = tls[tl]['name'] + //const tlColor: String = tls[tl]['uiColor'] + const id = `tl_${tlUuid}_name` + const idColor = `tl_${tlUuid}_color` + const couleurRgb = instance.getColorFromHex(`${tls[tl]['uiColor']}`) + variables[id] = `${tlName}`; + variables[idColor] = combineRgb(couleurRgb[0], couleurRgb[1], couleurRgb[2]).toString(); + } + + instance.setVariableValues(variables) }