From 996ad358e7ffff5cda19b2a868410960baf656d9 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Mon, 1 Apr 2024 17:18:28 +0200 Subject: [PATCH] color fixing measures when alpha is missing dependencies hashes: openFrameworks d78075f4bca6be2a2533c6e51a75cc1f18404501 ofxMsdfgen e14da13d02c4dff04fb69d7923469f606924e6c3 ofxGPUFont d482bb7cbdf6b296fa4ab5abcf73fb5ff8c8b239 ofxVariableLab 0b5f9bdebc1e5550621957e73c040c258ec6317b ofxProfiler a868e34fa1a79189dd4fbdede2938e308535e5e8 theatre 86d3e07f6f2c75fd6e08fca8c97e3617c9e23b18 --- bin/em/variabletime/web/js/audio.js | 29 +++++++++++++++++++++++++++-- bin/em/variabletime/web/js/utils.js | 6 ++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bin/em/variabletime/web/js/audio.js b/bin/em/variabletime/web/js/audio.js index a4a079e..9f07259 100644 --- a/bin/em/variabletime/web/js/audio.js +++ b/bin/em/variabletime/web/js/audio.js @@ -131,14 +131,39 @@ const Audio = function(tp, record) { } }; + const fixColor = (color) => { + if (typeof color === 'object') { + const channels = Object.keys(color); + channels.forEach((channel) => { + if (typeof color[channel] !== 'number') { + console.log('Audio::fixColor', `fixing color.${channel} => 1`); + color[channel] = 1; + } + }); + } + }; + const getAudioMappingOptions = (layer, propTitle) => { if (savedMapping.hasOwnProperty(layer.id()) && savedMapping[layer.id()].hasOwnProperty(propTitle)) { if (tp.isSequenced(propTitle, layer)) { const m = clone(savedMapping[layer.id()][propTitle]); delete m.letterDelay; + if (propTitle.toLowerCase().indexOf('color') >= 0) { + // fix missing alpha in color + fixColor(m.min_out); + fixColor(m.max_out); + fixColor(m.value); + } return m; } - return savedMapping[layer.id()][propTitle]; + const m = savedMapping[layer.id()][propTitle]; + if (propTitle.toLowerCase().indexOf('color') >= 0) { + // fix missing alpha in color + fixColor(m.min_out); + fixColor(m.max_out); + fixColor(m.value); + } + return m; } else { const o = new AudioMappingOptions(); const mm = getDefaultRange(layer, propTitle); @@ -390,7 +415,7 @@ const Audio = function(tp, record) { }); picker.onChange = (color) => { min_preview.style.background = color.rgbaString; - min_inputDom.value = color.hex; + min_inputDom.value = color.hex.padEnd(9, 'f'); updateMappingOptions(); //mappingOptions.min_out = { //r: color.rgba[0] / 255, diff --git a/bin/em/variabletime/web/js/utils.js b/bin/em/variabletime/web/js/utils.js index 2816a47..e26f0e1 100644 --- a/bin/em/variabletime/web/js/utils.js +++ b/bin/em/variabletime/web/js/utils.js @@ -515,8 +515,10 @@ const rgbaToHexa = (rgba) => { }; // NOTE: all output values are range 0-1 -const hexaToRgba = (hexa) => { - const o = hexa[0] === '#' ? 1 : 0; +const hexaToRgba = (hex_a) => { + const o = hex_a[0] === '#' ? 1 : 0; + // if it is hex, we need to add alpha + const hexa = hex_a.padEnd(8 + o, 'F'); return { r: parseInt(hexa.slice(o + 0, o + 2), 16) / 255, g: parseInt(hexa.slice(o + 2, o + 4), 16) / 255,