From 04041870dabc3a5d19ed3a3c69b7ac0f159ab8e5 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 10 Oct 2023 12:34:52 +0200 Subject: [PATCH] ignore outboundfrequencies and pitchcombine --- bin/web/js/audio.js | 74 +++++++++++++++++++++++++++++++------------- bin/web/js/config.js | 2 ++ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/bin/web/js/audio.js b/bin/web/js/audio.js index 55e709d..e71a740 100644 --- a/bin/web/js/audio.js +++ b/bin/web/js/audio.js @@ -406,12 +406,12 @@ const Audio = function(tp, record) { // otherwise the ui is not there if (layer.isSelected()) { if (config.audio.colorSeparateRGBA && propTitle === 'color') { - delete canvasCombos[layer.id()]['color.r']; - delete canvasCombos[layer.id()]['color.g']; - delete canvasCombos[layer.id()]['color.b']; - delete canvasCombos[layer.id()]['color.a']; + delete canvasCombos['color.r']; + delete canvasCombos['color.g']; + delete canvasCombos['color.b']; + delete canvasCombos['color.a']; } else { - delete canvasCombos[layer.id()][propTitle]; + delete canvasCombos[propTitle]; } const audioOptions = panel.querySelectorAll(toCssClass(`audioOptions${propTitle}`,'.')); if (audioOptions.length > 0) { @@ -731,21 +731,41 @@ const Audio = function(tp, record) { let x = 0; let max_i = 0; + let max_ri = 0; + let total_v = 0; let max_v = 0; - let min_v = 9999999; + for (let k = 0; k < canvasKeys.length; k++) { + const layerID = canvasCombos[canvasKeys[k]][2]; + const m = mapping[layerID][canvasKeys[k]]; + m.max_v = max_v; + m.max_i = max_i; + m.max_ri = max_ri; + m.total_v = total_v; + } for (let i = 0; i < w; i++) { barHeight = dataArrayAlt[i]; + total_v += barHeight; + max_ri = barHeight * i; if (barHeight > max_v) { max_v = barHeight; max_i = i; } - if (barHeight < min_v) { - min_v = barHeight; - } - for (let i = 0; i < canvasKeys.length; i++) { - canvasCombos[canvasKeys[i]][1].fillStyle = "rgb(200,200,200)"; // AUDIO COLOR - canvasCombos[canvasKeys[i]][1].fillRect( + for (let k = 0; k < canvasKeys.length; k++) { + const layerID = canvasCombos[canvasKeys[k]][2]; + const m = mapping[layerID][canvasKeys[k]]; + let fillStyle = "rgb(200,200,200)"; // AUDIO COLOR + if (m.min_freq <= i && m.max_freq >= i) { + m.total_v += barHeight; + if (barHeight > m.max_v) { + m.max_v = barHeight; + m.max_i = i; + m.max_ri = barHeight * i; + } + fillStyle = "rgb(255,255,255)"; // AUDIO COLOR + } + canvasCombos[canvasKeys[k]][1].fillStyle = fillStyle; + canvasCombos[canvasKeys[k]][1].fillRect( x, h - (barHeight * verticalFactor), barWidth, @@ -755,24 +775,28 @@ const Audio = function(tp, record) { x += barWidth; } - for (let i = 0; i < canvasKeys.length; i++) { - const layerID = canvasCombos[canvasKeys[i]][2]; - const m = mapping[layerID][canvasKeys[i]]; + max_ri /= total_v; + for (let k = 0; k < canvasKeys.length; k++) { + const layerID = canvasCombos[canvasKeys[k]][2]; + const m = mapping[layerID][canvasKeys[k]]; + m.max_ri /= m.total_v; if (m.sync === 'volume') { const sx = m.min_freq; const sw = m.max_freq - m.min_freq; const sy = h - (m.max_in * verticalFactor); const sh = (m.max_in - m.min_in) * verticalFactor; - canvasCombos[canvasKeys[i]][1].strokeStyle = "rgb(255, 255, 255)"; // AUDIO COLOR - canvasCombos[canvasKeys[i]][1].strokeRect(sx, sy, sw, sh); + canvasCombos[canvasKeys[k]][1].lineWidth = 1; // AUDIO COLOR + canvasCombos[canvasKeys[k]][1].strokeStyle = "rgb(255,255,255)"; // AUDIO COLOR + canvasCombos[canvasKeys[k]][1].strokeRect(sx, sy, sw, sh); } else if (m.sync === 'pitch') { - const m = mapping[layerID][canvasKeys[i]]; + const m = mapping[layerID][canvasKeys[k]]; const sx = m.min_freq; const sw = m.max_freq - m.min_freq; const sy = 0; const sh = h; - canvasCombos[canvasKeys[i]][1].strokeStyle = "rgb(255, 255, 255)"; // AUDIO COLOR - canvasCombos[canvasKeys[i]][1].strokeRect(sx, sy, sw, sh); + canvasCombos[canvasKeys[k]][1].lineWidth = 1; // AUDIO COLOR + canvasCombos[canvasKeys[k]][1].strokeStyle = "rgb(255,255,255)"; // AUDIO COLOR + canvasCombos[canvasKeys[k]][1].strokeRect(sx, sy, sw, sh); } } const propsToSet = []; @@ -782,7 +806,7 @@ const Audio = function(tp, record) { const m = mapping[layer.id()][propTitle]; switch (m.sync) { case 'volume': { - let a = mapValue(max_v, m.min_in, m.max_in, m.min_out, m.max_out, true); + let a = mapValue(m.max_v, m.min_in, m.max_in, m.min_out, m.max_out, true); m.value = m.value * m.smoothing + (1.0 - m.smoothing) * a; propsToSet.push({ layer, @@ -794,7 +818,10 @@ const Audio = function(tp, record) { break; } case 'pitch': { - let a = mapValue(max_i, m.min_freq, m.max_freq, m.min_out, m.max_out, true); + const mi = config.audio.ignoreOutboundFrequencies ? m.max_i : max_i; + const ri = config.audio.ignoreOutboundFrequencies ? m.max_ri : max_ri; + const fi = config.audio.pitchCombineFrequencies ? ri : mi; + let a = mapValue(fi, m.min_freq, m.max_freq, m.min_out, m.max_out, true); m.value = m.value * m.smoothing + (1.0 - m.smoothing) * a; propsToSet.push({ layer, @@ -994,6 +1021,9 @@ const Audio = function(tp, record) { this.addAudioOptions = addAudioOptions; this.removeAudioOptions = removeAudioOptions; this.AudioMappingOptions = AudioMappingOptions; + + // debug + this.canvasCombos = canvasCombos; }; export { diff --git a/bin/web/js/config.js b/bin/web/js/config.js index 9376b64..7553156 100644 --- a/bin/web/js/config.js +++ b/bin/web/js/config.js @@ -89,6 +89,8 @@ const config = { fftBandsUsed: 256 / 2, fftHeight: 256 / 4, colorSeparateRGBA: true, + ignoreOutboundFrequencies: true, + pitchCombineFrequencies: false, }, record: { ignoreProps: ['transformOrigin', 'fontFamily', 'text', 'mirror_x', 'mirror_y', 'mirror_xy'],