Skip to content

Commit

Permalink
presets
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdadams committed Jul 22, 2024
1 parent 4f35984 commit 0f8da6a
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 31 deletions.
2 changes: 2 additions & 0 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ This module will allow you to control Kiloview NDI devices.
- Input Audio Signal is Online/Offline
- Decoder Feedbacks:
- Selected NDI Source is Online/Offline
- Selected Preset is Enabled
- Selected Preset is Current Preset

## Variables

Expand Down
15 changes: 5 additions & 10 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,16 @@ module.exports = {
name: 'Set Preset',
options: [
{
type: 'textinput',
type: 'dropdown',
label: 'Preset',
id: 'id',
min: 1,
max: 10,
default: 1,
step: 1,
required: true,
range: false,
id: 'preset',
default: self.CHOICES_PRESETS[0].id,
choices: self.CHOICES_PRESETS,
},
],
callback: async function (action) {
let options = action.options
let id = await self.parseVariablesInString(options.id)
self.DEVICE.decoderCurrentSetPreset(id)
self.DEVICE.decoderCurrentSetPreset(options.preset)
},
}

Expand Down
11 changes: 11 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ module.exports = {
if (self.STATE.mode == 'decoder') {
const info = await self.DEVICE.decoderCurrentStatus()
self.STATE.info = info

//get presets
const presets = await self.DEVICE.decoderPresets()
//only update if different
if (JSON.stringify(self.STATE.presets) !== JSON.stringify(presets)) {
self.log('info', 'NDI Presets have changed. Updating Presets...')
self.STATE.presets = presets
self.initActions()
self.initPresets()
}

} else if (self.STATE.mode == 'encoder') {
const info = await self.DEVICE.encoderNdiStatus()
self.STATE.info = info
Expand Down
12 changes: 12 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ module.exports = {
},
],

CHOICES_PRESETS: [
{ id: '1', label: 'Preset 1' },
{ id: '2', label: 'Preset 2' },
{ id: '3', label: 'Preset 3' },
{ id: '4', label: 'Preset 4' },
{ id: '5', label: 'Preset 5' },
{ id: '6', label: 'Preset 6' },
{ id: '7', label: 'Preset 7' },
{ id: '8', label: 'Preset 8' },
{ id: '9', label: 'Preset 9' },
],

INTERVAL: null, //used for polling device for feedbacks
INTERVAL_SOURCES: null, //used for polling for new NDI sources
RECONNECT_INTERVAL: null, //used for reconnecting to device
Expand Down
75 changes: 75 additions & 0 deletions src/feedbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,81 @@ module.exports = {
}
},
}

feedbacks.preset_enabled = {
type: 'boolean',
name: 'Selected Preset is Enabled',
description: 'If selected preset is enabled, change the colors of the button',
defaultStyle: {
color: colorWhite,
bgcolor: colorRed,
},
options: [
{
type: 'dropdown',
label: 'Preset',
id: 'preset',
default: self.CHOICES_PRESETS[0].id,
choices: self.CHOICES_PRESETS,
},
],
callback: function (feedback, bank) {
let options = feedback.options
let preset = self.STATE.presets.data.find(
(preset) => preset.id.toString() === options.preset.toString()
)

if (preset && preset.enable) {
return true
}

return false
},
}

feedbacks.preset_current = {
type: 'boolean',
name: 'Selected Preset is Current Preset',
description: 'If selected preset is the current preset, change the colors of the button',
defaultStyle: {
color: colorWhite,
bgcolor: colorRed,
},
options: [
{
type: 'dropdown',
label: 'Preset',
id: 'preset',
default: self.CHOICES_PRESETS[0].id,
choices: self.CHOICES_PRESETS,
},
{
type: 'dropdown',
label: 'Change color if preset is',
id: 'compare',
default: true,
choices: [
{ id: true, label: 'Current' },
{ id: false, label: 'Not Current' },
],
},
],
callback: function (feedback, bank) {
let options = feedback.options

if (self.STATE.presets && self.STATE.presets.data) {
let preset = self.STATE.presets.data.find(
(preset) => preset.id.toString() === options.preset.toString()
)

if (preset && preset.current == options.compare) {
return true
}
}

return false
},
}
}

self.setFeedbackDefinitions(feedbacks)
Expand Down
12 changes: 12 additions & 0 deletions src/kiloview.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ class kiloviewNDI {
return this.authPost('/decoder/current/set', { name, url })
}

decoderPresets() {
return this.authPost('/decoder/preset/status')
}

decoderPresetAdd(id, name, url, group) {
return this.authPost('/decoder/preset/add', { id, name, url, group })
}

decoderPresetRemove(id) {
return this.authPost('/decoder/preset/remove', { id })
}

// color: #aabbcc with #
decoderPresetSetBlank(color) {
return this.authPost('/decoder/preset/set_blank', { color })
Expand Down
87 changes: 66 additions & 21 deletions src/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {

const colorWhite = combineRgb(255, 255, 255) // White
const colorBlack = combineRgb(0, 0, 0) // Black
const colorRed = combineRgb(255, 0, 0) // Red
const colorGreen = combineRgb(0, 255, 0) // Green

presets = [
{
Expand Down Expand Up @@ -38,6 +40,10 @@ module.exports = {
options: {
mode: 'encoder',
},
style: {
color: colorWhite,
bgcolor: colorRed,
},
},
],
},
Expand Down Expand Up @@ -70,6 +76,10 @@ module.exports = {
options: {
mode: 'decoder',
},
style: {
color: colorWhite,
bgcolor: colorRed,
},
},
],
},
Expand Down Expand Up @@ -127,12 +137,20 @@ module.exports = {
options: {
compare: 'online',
},
style: {
color: colorWhite,
bgcolor: colorGreen,
},
},
{
feedbackId: 'video_signal',
options: {
compare: 'offline',
},
style: {
color: colorWhite,
bgcolor: colorRed,
},
},
],
})
Expand All @@ -154,36 +172,63 @@ module.exports = {
options: {
compare: 'online',
},
style: {
color: colorWhite,
bgcolor: colorGreen,
},
},
{
feedbackId: 'online',
options: {
compare: 'offline',
},
},
],
})
}
for (let i = 1; i <= 10; ++i) {
presets.push({
category: 'Decoder',
type: 'button',
name: 'Go to Preset ' + i,
style: {
text: String(i),
size: 'auto',
color: colorWhite,
bgcolor: colorBlack,
},
steps: [
{
actionId: 'setPreset',
options: {
id: String(i),
style: {
color: colorWhite,
bgcolor: colorRed,
},
},
],
})

for (let i = 1; i <= self.CHOICES_PRESETS.length; i++) {
presets.push({
category: 'Decoder',
type: 'button',
name: 'Go to Preset ' + i,
style: {
text: `$(kiloview:preset${i}_channel_name)`,
size: '14',
color: colorWhite,
bgcolor: colorBlack,
},
steps: [
{
down: [
{
actionId: 'setPreset',
options: {
preset: String(i),
},
},
],
up: [],
},
],
feedbacks: [
{
feedbackId: 'preset_current',
options: {
preset: String(i),
compare: true,
},
style: {
color: colorWhite,
bgcolor: colorRed,
},
},
],
})
}
}

presets.push({
Expand All @@ -210,7 +255,7 @@ module.exports = {
color: colorWhite,
bgcolor: colorBlack,
},
actions: [],
steps: [],
feedbacks: [],
})

Expand Down
35 changes: 35 additions & 0 deletions src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ module.exports = {
variables.push({ variableId: 'codec', name: 'NDI Codec' })
variables.push({ variableId: 'streamname', name: 'NDI Stream Name' })
variables.push({ variableId: 'online_state', name: 'NDI Source Online' })

//presets 1-9
for (let i = 1; i <= self.CHOICES_PRESETS.length; i++) {
//enabled, group, name, device_name, channel_name, url, ip, online, current
variables.push({ variableId: 'preset' + i + '_enabled', name: 'Preset ' + i + ' Enabled' })
variables.push({ variableId: 'preset' + i + '_group', name: 'Preset ' + i + ' Group' })
variables.push({ variableId: 'preset' + i + '_name', name: 'Preset ' + i + ' Name' })
variables.push({ variableId: 'preset' + i + '_device_name', name: 'Preset ' + i + ' Device Name' })
variables.push({ variableId: 'preset' + i + '_channel_name', name: 'Preset ' + i + ' Channel Name' })
variables.push({ variableId: 'preset' + i + '_url', name: 'Preset ' + i + ' URL' })
variables.push({ variableId: 'preset' + i + '_ip', name: 'Preset ' + i + ' IP' })
variables.push({ variableId: 'preset' + i + '_online', name: 'Preset ' + i + ' Online' })
variables.push({ variableId: 'preset' + i + '_current', name: 'Preset ' + i + ' Current' })
}
}

variables.push({ variableId: 'cpu_cores', name: 'CPU Cores' })
Expand Down Expand Up @@ -50,6 +64,27 @@ module.exports = {
variableObj.codec = self.STATE.info.data.codec
variableObj.streamname = self.STATE.info.data.name || ''
variableObj.online_state = self.STATE.info.data.online ? 'True' : 'False'

if (self.STATE.presets) {
//presets 1-9
for (let i = 1; i <= self.CHOICES_PRESETS.length; i++) {
//find the preset by id in self.STATE.presets
let presetObj = self.STATE.presets.data.find(
(preset) => preset.id.toString() == i.toString()
)
if (presetObj) {
variableObj['preset' + i + '_enabled'] = presetObj.enable ? 'True' : 'False'
variableObj['preset' + i + '_group'] = presetObj.group
variableObj['preset' + i + '_name'] = presetObj.name
variableObj['preset' + i + '_device_name'] = presetObj.device_name
variableObj['preset' + i + '_channel_name'] = presetObj.channel_name
variableObj['preset' + i + '_url'] = presetObj.url
variableObj['preset' + i + '_ip'] = presetObj.ip
variableObj['preset' + i + '_online'] = presetObj.online ? 'True' : 'False'
variableObj['preset' + i + '_current'] = presetObj.current ? 'True' : 'False'
}
}
}
}
}

Expand Down

0 comments on commit 0f8da6a

Please sign in to comment.