versão 2.0
This commit is contained in:
1 parent
d506332268
commit
fe735bf0a6
16 files changed
+1735
-1626
No files matched your search
@@ -1,5 +1,23 @@
|
||||
// js/utils.js
|
||||
import { appState } from './state.js';
|
||||
import { PIXELS_PER_STEP, ZOOM_LEVELS } from './config.js';
|
||||
|
||||
/**
|
||||
* Calcula a quantidade de pixels que representa um segundo na timeline,
|
||||
* levando em conta o BPM e o nível de zoom atual.
|
||||
* @returns {number} A quantidade de pixels por segundo.
|
||||
*/
|
||||
export function getPixelsPerSecond() {
|
||||
const bpm = parseInt(document.getElementById("bpm-input").value, 10) || 120;
|
||||
const stepsPerSecond = (bpm / 60) * 4;
|
||||
const zoomFactor = ZOOM_LEVELS[appState.global.zoomLevelIndex];
|
||||
return stepsPerSecond * PIXELS_PER_STEP * zoomFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcula o número total de steps no sequenciador de patterns.
|
||||
* @returns {number} O número total de steps.
|
||||
*/
|
||||
export function getTotalSteps() {
|
||||
const barsInput = document.getElementById("bars-input");
|
||||
const compassoAInput = document.getElementById("compasso-a-input");
|
||||
@@ -13,19 +31,29 @@ export function getTotalSteps() {
|
||||
return numberOfBars * beatsPerBar * subdivisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Garante que apenas números sejam inseridos em um campo de input.
|
||||
* @param {Event} event - O evento de input.
|
||||
*/
|
||||
export function enforceNumericInput(event) {
|
||||
event.target.value = event.target.value.replace(/[^0-9]/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajusta o valor de um elemento de input com base em um passo (step),
|
||||
* respeitando os limites de min/max definidos no elemento.
|
||||
* @param {HTMLInputElement} inputElement - O elemento de input a ser ajustado.
|
||||
* @param {number} step - O valor a ser adicionado (pode ser negativo).
|
||||
*/
|
||||
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.value = newValue;
|
||||
inputElement.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}
|
||||
Reference in new issue
Block a user