// js/utils.js export function getTotalSteps() { const barsInput = document.getElementById("bars-input"); const compassoAInput = document.getElementById("compasso-a-input"); const compassoBInput = document.getElementById("compasso-b-input"); const numberOfBars = parseInt(barsInput.value, 10) || 1; const beatsPerBar = parseInt(compassoAInput.value, 10) || 4; const noteValue = parseInt(compassoBInput.value, 10) || 4; const subdivisions = Math.round(16 / noteValue); return numberOfBars * beatsPerBar * subdivisions; } export function enforceNumericInput(event) { event.target.value = event.target.value.replace(/[^0-9]/g, ""); } export function adjustValue(inputElement, step) { let currentValue = parseInt(inputElement.value, 10) || 0; let min = parseInt(inputElement.dataset.min, 10); let max = parseInt(inputElement.dataset.max, 10); let newValue = currentValue + step; if (!isNaN(min) && newValue < min) newValue = min; if (!isNaN(max) && newValue > max) newValue = max; inputElement.value = newValue; // Dispara um evento 'input' para que outros listeners (como o que redesenha o sequenciador) sejam acionados. inputElement.dispatchEvent(new Event("input", { bubbles: true })); }