full range audio fft on click

This commit is contained in:
jrkb 2023-10-24 07:38:06 +02:00
parent 2d43063537
commit f19843bd46

View file

@ -448,18 +448,24 @@ const Audio = function(tp, record) {
max_inputDom.addEventListener('change', updateMappingOptions); max_inputDom.addEventListener('change', updateMappingOptions);
smoothing_inputDom.addEventListener('change', updateMappingOptions); smoothing_inputDom.addEventListener('change', updateMappingOptions);
let setFrequency = false; let setFrequency = false;
let wasMoved = false;
let freq_down = 0; let freq_down = 0;
let freq_up = 0; let freq_up = 0;
let xy_start; let xy_start;
fft_Dom.addEventListener('mousedown', (e) => { fft_Dom.addEventListener('mousedown', (e) => {
setFrequency = true; setFrequency = true;
wasMoved = false;
const bb = fft_imgDom.getBoundingClientRect(); const bb = fft_imgDom.getBoundingClientRect();
const x = e.clientX - bb.x; const x = e.clientX - bb.x;
const y = e.clientY - bb.y; const y = e.clientY - bb.y;
xy_start = {x, y}; xy_start = {
x,
y
};
}); });
fft_Dom.addEventListener('mousemove', (e) => { fft_Dom.addEventListener('mousemove', (e) => {
if (setFrequency) { if (setFrequency) {
wasMoved = true;
const bb = fft_imgDom.getBoundingClientRect(); const bb = fft_imgDom.getBoundingClientRect();
const x_factor = config.audio.fftBandsUsed / bb.width; const x_factor = config.audio.fftBandsUsed / bb.width;
const y_factor = 256.0 / bb.height; const y_factor = 256.0 / bb.height;
@ -488,6 +494,20 @@ const Audio = function(tp, record) {
}); });
const unset = (e) => { const unset = (e) => {
setFrequency = false; setFrequency = false;
if (!wasMoved) {
const bb = fft_imgDom.getBoundingClientRect();
const x_factor = config.audio.fftBandsUsed / bb.width;
const y_factor = 256.0 / bb.height;
let min_x, max_x, min_y, max_y;
min_x = 0;
min_y = 0;
max_x = bb.width;
max_y = bb.height;
mappingOptions.min_freq = min_x * x_factor;
mappingOptions.max_freq = max_x * x_factor;
mappingOptions.min_in = (bb.height - max_y) * y_factor;
mappingOptions.max_in = (bb.height - min_y) * y_factor;
}
}; };
const unsetFromOutside = (e) => { const unsetFromOutside = (e) => {
document.removeEventListener('mouseup', unsetFromOutside); document.removeEventListener('mouseup', unsetFromOutside);