From e4ca41c2f053e0dcec58432856bfe2232ba4bbe0 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 24 Oct 2023 23:57:49 +0200 Subject: [PATCH] various little audio fixes --- bin/web/js/audio.js | 18 +++++++++++++++--- bin/web/js/layer.js | 24 ++++++++++++------------ bin/web/js/main.js | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/bin/web/js/audio.js b/bin/web/js/audio.js index f39c8b0..7200f7b 100644 --- a/bin/web/js/audio.js +++ b/bin/web/js/audio.js @@ -292,10 +292,19 @@ const Audio = function(tp, record) { source_mic.value = 'microphone'; source_mic.innerHTML = 'microphone'; source_Dom.append(source_mic); + let selectedSource = 'microphone'; + if (typeof audio.getSavedMapping()[layer.id()] === 'object') { + if (typeof audio.getSavedMapping()[layer.id()][propTitle] === 'object') { + selectedSource = audio.getSavedMapping()[layer.id()][propTitle].source; + } + } FS.readdir(config.fs.idbfsAudioDir) .forEach((file) => { if (file[0] !== '.') { const source_file = document.createElement('option'); + if (file === selectedSource) { + source_file.setAttribute('selected','true'); + } source_file.value = file; if (file.length > config.audio.maxFilenameLength) { source_file.innerHTML = file.substr(0,6) + '..' + file.substr(file.length - 6, 6); @@ -331,7 +340,9 @@ const Audio = function(tp, record) { min_inputDom.type = 'number'; min_inputDom.name = toCssClass(`audio_min${propTitle}`); min_inputDom.id = toCssClass(`audio_min${propTitle}`); - min_inputDom.title = `default: ${defaultRange[0]}`; + if (Array.isArray(defaultRange) && defaultRange.length >= 2) { + min_inputDom.title = `default: ${defaultRange[0]}`; + } min_inputDom.value = `${mappingOptions.min_out}`; const max_Cont = document.createElement('div'); max_Cont.classList.add('audio_max_Cont'); @@ -342,7 +353,9 @@ const Audio = function(tp, record) { max_inputDom.type = 'number'; max_inputDom.name = toCssClass(`audio_max${propTitle}`); max_inputDom.id = toCssClass(`audio_max${propTitle}`); - max_inputDom.title = `default: ${defaultRange[1]}`; + if (Array.isArray(defaultRange) && defaultRange.length >= 2) { + max_inputDom.title = `default: ${defaultRange[1]}`; + } max_inputDom.value = `${mappingOptions.max_out}`; const smoothing_inputDom_label = document.createElement('label'); smoothing_inputDom_label.for = 'audio_smoothing'; @@ -652,7 +665,6 @@ const Audio = function(tp, record) { const layerType = layer.id().split('-')[0]; const props = Object.keys(flatValues); props.forEach((propTitle) => { - console.log('injecting prop', propTitle); if (config.audio.ignoreProps[layerType].indexOf(propTitle) < 0) { let isActive = false; if (mapping.hasOwnProperty(layer.id())) { diff --git a/bin/web/js/layer.js b/bin/web/js/layer.js index ca5be60..988caa1 100644 --- a/bin/web/js/layer.js +++ b/bin/web/js/layer.js @@ -101,7 +101,7 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) { let axes = fontsAndAxes[selectedFontIndex].axes; if (axes.length > 0) { let variationAxes = {}; - let doThese = []; + //let doThese = []; for (let a = 0; a < axes.length; a++) { const sanity_minMax = axes[a].minValue < axes[a].maxValue; const sanity_minDefault = axes[a].minValue <= axes[a].defaultValue; @@ -118,23 +118,23 @@ const Layer = function(tp, layerID, fontsAndAxes, autoInit = true) { typeof audio.getMapping()[this.id()] === 'object' && typeof audio.getMapping()[this.id()][`fontVariationAxes.${axes[a].name}`] === 'object' && tp.getPanel() !== null) { - doThese.push(() => { - audio.removeAudioOptions(this, `fontVariationAxes.${axes[a].name}`); - audio.removeAudioMapping(this, `fontVariationAxes.${axes[a].name}`); - audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].min_out = axes[a].minValue; - audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].max_out = axes[a].maxValue; - audio.addAudioMapping(this, `fontVariationAxes.${axes[a].name}`); - audio.addAudioOptions(this, `fontVariationAxes.${axes[a].name}`); - }); + //doThese.push(() => { + //audio.removeAudioOptions(this, `fontVariationAxes.${axes[a].name}`); + //audio.removeAudioMapping(this, `fontVariationAxes.${axes[a].name}`); + //audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].min_out = axes[a].minValue; + //audio.getSavedMapping()[this.id()][`fontVariationAxes.${axes[a].name}`].max_out = axes[a].maxValue; + //audio.addAudioMapping(this, `fontVariationAxes.${axes[a].name}`); + //audio.addAudioOptions(this, `fontVariationAxes.${axes[a].name}`); + //}); } } else { console.log('js::layer::selectFont', 'this axis is insane, abort', axes[a]); } } props.fontVariationAxes = tp.core.types.compound(variationAxes); - doThese.forEach((d) => { - d(); - }); + //doThese.forEach((d) => { + //d(); + //}); } else { delete props.fontVariationAxes; } diff --git a/bin/web/js/main.js b/bin/web/js/main.js index 0ed0135..88314f3 100644 --- a/bin/web/js/main.js +++ b/bin/web/js/main.js @@ -508,6 +508,20 @@ const deleteLayer = (id, saveProject = true) => { index = i; } } + // delete from audio + if (typeof audio.getMapping() === 'object' && typeof audio.getMapping()[id] === 'object') { + delete audio.getMapping()[id]; + } + if (typeof audio.getSavedMapping() === 'object' && typeof audio.getSavedMapping()[id] === 'object') { + delete audio.getSavedMapping()[id]; + } + if (typeof audio.canvasCombos === 'object') { + Object.keys(audio.canvasCombos).forEach((propTitle) => { + if (audio.canvasCombos[propTitle][2] === id) { + delete audio.canvasCombos[propTitle]; + } + }); + } layers[index].prepareForDepartureFromThisBeautifulExperience(); layers.splice(index, 1); delete layersById[id];