Skip to content

Commit

Permalink
fix volume calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
sphlabs committed Apr 3, 2023
1 parent 1e9b8dc commit dfeb14b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
20 changes: 11 additions & 9 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default {
this.sendGetRequest(opt.endpoint + '/' + opt.action)
},
}

actions['audioLayer'] = {
name: 'Audio - Set Layer Volume',
description: 'Set or adjust the volume of a layer',
Expand All @@ -169,7 +169,7 @@ export default {
id: 'volume',
default: '100',
tooltip: 'Volume range is 0-100. Enter a number of variable',
}
},
],
callback: async (action) => {
const opt = action.options
Expand All @@ -178,18 +178,20 @@ export default {
let newVol
switch (opt.adjustment) {
case 'increase':
newVol = (parseFloat(layer.volume) + parseFloat(vol)) / 100
break;
newVol = layer.volume + parseFloat(vol) / 100
break
case 'decrease':
newVol = (parseFloat(layer.volume) - parseFloat(vol)) / 100
break;
newVol = layer.volume - parseFloat(vol) / 100
break
default:
newVol = parseFloat(vol) / 100
break;
break
}
const payload = JSON.parse(`{ "volume": ${newVol} }`)
console.log(`Volume: ${newVol}`)
const payload = { volume: newVol }
this.sendPutRequest(`documents/${layer.document}/layers/${layer.id}`, payload)
}
// layer.volume = newVol
},
}

actions['endpoint'] = {
Expand Down
24 changes: 12 additions & 12 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ export default {
variants: [],
activeVariant: message.data.relationships['active-variant'].data.id,
liveState: message.data.attributes['live-state'],
volume: parseInt(message.data.attributes['volume'] * 100),
volume: message.data.attributes['volume'],
}
} else {
parentDocument.layers[layerIndex].id = message.id
parentDocument.layers[layerIndex].label = message.data.attributes.name
parentDocument.layers[layerIndex].activeVariant = message.data.relationships['active-variant'].data.id
parentDocument.layers[layerIndex].liveState = message.data.attributes['live-state']
parentDocument.layers[layerIndex].volume = parseInt(message.data.attributes['volume'] * 100)
parentDocument.layers[layerIndex].volume = message.data.attributes['volume']
}
this.log('debug', `Layer: ${message.data.attributes.name} is ${message.data.attributes['live-state']}`)
this.updateLayerVariables()
Expand Down Expand Up @@ -300,9 +300,9 @@ export default {
},

/**
* Send a REST GET request to the player and handle errorcodes
* @param {} cmd
*/
* Send a REST GET request to the player and handle errorcodes
* @param {} cmd
*/
sendGetRequest: async function (cmd) {
// Trim off any leading / characters
while (cmd.startsWith('/')) {
Expand All @@ -324,12 +324,12 @@ export default {
}
this.processResult(response)
},

/**
* Send a REST PUT request to the player and handle errorcodes
* @param {} cmd
* @param {} payload
*/
* Send a REST PUT request to the player and handle errorcodes
* @param {} cmd
* @param {} payload
*/
sendPutRequest: async function (cmd, payload) {
// Trim off any leading / characters
while (cmd.startsWith('/')) {
Expand All @@ -353,7 +353,7 @@ export default {
this.gotOptions.json = undefined
this.processResult(response)
},

/**
* INTERNAL: Callback for REST calls to process the return
*
Expand Down Expand Up @@ -433,7 +433,7 @@ export default {
// liveVariant: data[layer].relationships['live-variant'].data.id,
liveVariant: '',
liveState: data[layer].attributes['live-state'],
volume: parseInt(data[layer].attributes['volume'] * 100),
volume: data[layer].attributes['volume'],
}
this.sendGetRequest(`documents/${parentDocId}/layers/${data[layer].id}/variants`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {
}
}
if (layer.volume != null) {
list[`layer_${docIndex + 1}_${index + 1}_volume`] = layer.volume
list[`layer_${docIndex + 1}_${index + 1}_volume`] = (layer.volume * 100).toFixed()
}
//this.debug('- -', layer.label)
})
Expand Down

0 comments on commit dfeb14b

Please sign in to comment.