From daa1a186017bef8991e113b82844d42d8be6b7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87A=C4=9EAN=20TURGUT?= Date: Sun, 29 Nov 2026 17:19:58 +0300 Subject: [PATCH] fix(lighting): restore a linear default and follow the selected band Level balance, the noise gate and the light curve stay adjustable. Their default is the previous linear response, so the lamps are no longer crushed in the middle. Auto, mid and treble drive the light from that band's own level instead of a bass-weighted mix. 4802 unit tests. Isolated smoke passed. Co-authored-by: caganturgut <271973834+caganturgut@users.noreply.github.com> --- README.md | 4 +- README.tr.md | 4 +- ROADMAP.md | 2 +- src/admin/lighting-general.js | 24 +++- src/admin/modulation-panel.js | 1 + src/shared/i18n.js | 5 + src/shared/lighting-render.js | 146 +++++++++++++++------ tests/fixtures-lighting.json | 240 +++++++++++++++++----------------- tests/lighting-render.test.js | 83 +++++++++++- 9 files changed, 335 insertions(+), 174 deletions(-) diff --git a/README.md b/README.md index cb981141..2b26053e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ in and out, **projection mapping**, **RGB lighting**, a **timeline and clip deck [![Downloads](https://img.shields.io/github/downloads/CaYatur/SoundVisualizer/total?label=downloads)](https://github.com/CaYatur/SoundVisualizer/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-e11d2a.svg)](LICENSE) [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-111997.svg)](#download) -[![Tests](https://img.shields.io/badge/tests-4801%20passing-2ea043.svg)](#tests) +[![Tests](https://img.shields.io/badge/tests-4802%20passing-2ea043.svg)](#tests) [![Electron](https://img.shields.io/badge/Electron-44-47848F.svg)](https://www.electronjs.org/) Download for Windows @@ -2341,7 +2341,7 @@ npm test npm start -- --smoke ``` -**4801 unit tests, all passing.** They are written to check answers, not to exercise lines: +**4802 unit tests, all passing.** They are written to check answers, not to exercise lines: _The count is the runner's total (`# tests`). A few tests depend on the environment (a git checkout, Node 22's built-in WebSocket, the electron-builder schema); where that is missing they are reported as skipped, not passed, so `pass + skipped` always equals this number and the skipped count may be 0 on one machine and 1–4 on another._ diff --git a/README.tr.md b/README.tr.md index 14fb583e..80417780 100644 --- a/README.tr.md +++ b/README.tr.md @@ -20,7 +20,7 @@ kontrolü**. [![İndirme](https://img.shields.io/github/downloads/CaYatur/SoundVisualizer/total?label=indirme)](https://github.com/CaYatur/SoundVisualizer/releases) [![Lisans: MIT](https://img.shields.io/badge/Lisans-MIT-e11d2a.svg)](LICENSE) [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-111997.svg)](#hızlı-başlangıç) -[![Test](https://img.shields.io/badge/test-4801%20geçiyor-2ea043.svg)](#testler) +[![Test](https://img.shields.io/badge/test-4802%20geçiyor-2ea043.svg)](#testler) [![Electron](https://img.shields.io/badge/Electron-44-47848F.svg)](https://www.electronjs.org/) Windows için indir @@ -2357,7 +2357,7 @@ npm test npm start -- --smoke ``` -**4801 birim testi, hepsi geçiyor.** Satır çalıştırmak için değil, cevap denetlemek için yazıldılar: +**4802 birim testi, hepsi geçiyor.** Satır çalıştırmak için değil, cevap denetlemek için yazıldılar: _Sayı koşunun toplamıdır (`# tests`). Birkaç test ortama bağlı (git çalışma kopyası, Node 22'nin yerleşik WebSocket'i, electron-builder şeması); bunlar eksikse geçti değil atlandı sayılır. Yani `geçen + atlanan` hep bu sayıya eşittir; atlanan sayısı bir makinede 0, başka birinde 1–4 olabilir._ diff --git a/ROADMAP.md b/ROADMAP.md index ac307f06..b7c3562d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -203,7 +203,7 @@ npm test npm start -- --smoke ``` -- **4801 unit tests, all passing** on `main`. 703 of those shipped in v3.1.0; +- **4802 unit tests, all passing** on `main`. 703 of those shipped in v3.1.0; 105 came with v3.1.1; 163 came with v3.1.2; 157 came with v3.1.3 — 1128 at that tag — 469 more with v3.1.4, most of them from the MilkDrop work — 1597 at that tag — 1402 more with v3.1.5 — 2999 at that tag — and 667 diff --git a/src/admin/lighting-general.js b/src/admin/lighting-general.js index e8d739bd..60fd0cce 100644 --- a/src/admin/lighting-general.js +++ b/src/admin/lighting-general.js @@ -76,6 +76,17 @@ const el = P().el; const cfg = P().cfg(); const lighting = cfg.lighting || (cfg.lighting = window.SV.defaultConfig().lighting); + /* Kayıtlı 0.75 / 0.04, eğri yokken motorun kendi kısma varsayılanıydı. + Panelde de eski doğrusal yanıt görünsün. Elle seçilmiş eğriye dokunulmaz. */ + if (lighting.responseCurve == null && lighting.normalize != null && lighting.squelch != null) { + const norm = Number(lighting.normalize); + const gate = Number(lighting.squelch); + if (Number.isFinite(norm) && Number.isFinite(gate) + && Math.abs(norm - 0.75) < 0.001 && Math.abs(gate - 0.04) < 0.001) { + lighting.normalize = 0; + lighting.squelch = 0; + } + } const apply = (rebuild) => { P().push(!!rebuild); if (rebuild) P().rerender(); @@ -193,8 +204,13 @@ { value: 'per-device', label: 'Her Aygıtta Baştan Başla' }, { value: 'uniform', label: 'Tüm LED\'lerde Aynı Ton' }, ]), [WDL, ORGB])); - nodes.push(wrap(rangeRow('normalize', 'Seviye Dengeleme', 0, 1, 0.01, true, 0.75), [WDL, ORGB])); - nodes.push(wrap(rangeRow('squelch', 'Gürültü Kapısı', 0, 0.45, 0.01, true, 0.04), [WDL, ORGB])); + nodes.push(wrap(rangeRow('responseCurve', 'Işık Eğrisi', 1, 2.6, 0.05, false, 1), [WDL, ORGB])); + nodes.push(el('div', { + class: 'lighting-mode-help', + text: 'Işık eğrisi 1 iken parlaklık sesle doğru orantılıdır (eski yanıt). Yükseldikçe orta seviyeler kararır.', + })); + nodes.push(wrap(rangeRow('normalize', 'Seviye Dengeleme', 0, 1, 0.01, true, 0), [WDL, ORGB])); + nodes.push(wrap(rangeRow('squelch', 'Gürültü Kapısı', 0, 0.45, 0.01, true, 0), [WDL, ORGB])); if (lighting.mode !== 'threshold-background-burst') { nodes.push(wrap(rangeRow('intensity', 'Ses Tepkisi', 0, 1, 0.01, true), [WDL, ORGB])); nodes.push(wrap(rangeRow('smoothing', 'Yumuşatma', 0, 0.95, 0.01, true), [WDL, ORGB])); @@ -285,6 +301,10 @@ { value: 'level', label: 'Genel Ses Seviyesi' }, { value: 'auto', label: 'En Güçlü Frekansı Otomatik Seç' }, ]), [WDL, ORGB])); + nodes.push(el('div', { + class: 'lighting-mode-help', + text: 'Seçilen bant ışığı o frekanstan sürer. Otomatik seçim bas, orta ve tizi eşit tartıp en güçlüsünü izler.', + })); nodes.push(wrap(rangeRow('flashThreshold', 'Patlama Eşiği', 0.02, 0.98, 0.01, true), [WDL, ORGB])); nodes.push(wrap(rangeRow('flashStrength', 'Patlama Gücü', 0, 1.5, 0.01), [WDL, ORGB])); nodes.push(wrap(rangeRow('flashDecay', 'Patlama Sönümleme', 0.45, 0.995, 0.005), [WDL, ORGB])); diff --git a/src/admin/modulation-panel.js b/src/admin/modulation-panel.js index 68d773e1..ee005e6b 100644 --- a/src/admin/modulation-panel.js +++ b/src/admin/modulation-panel.js @@ -125,6 +125,7 @@ 'lighting.rainbowBaseBrightness': ['Rainbow Taban Parlaklığı', 0.02, 1], 'lighting.rainbowSpeed': ['Rainbow Akış Hızı', 0.05, 3], 'lighting.rainbowSpread': ['Rainbow Renk Yayılımı', 0.1, 4], + 'lighting.responseCurve': ['Işık Eğrisi', 1, 2.6], 'lighting.rippleSpeed': ['Dalga Hızı', 0.05, 3], 'lighting.rippleWidth': ['Dalga Genişliği', 0.03, 0.6], 'lighting.saturation': ['Renk Doygunluğu', 0, 1.5], diff --git a/src/shared/i18n.js b/src/shared/i18n.js index 7e6707bb..23302c47 100644 --- a/src/shared/i18n.js +++ b/src/shared/i18n.js @@ -373,6 +373,11 @@ 'Sessizlikte Işık': 'Idle Light Level', 'Seviye Dengeleme': 'Level Balance', 'Gürültü Kapısı': 'Noise Gate', + 'Işık Eğrisi': 'Light Curve', + 'Işık eğrisi 1 iken parlaklık sesle doğru orantılıdır (eski yanıt). Yükseldikçe orta seviyeler kararır.': + 'At 1 the light curve is proportional to the sound (the previous response). Higher values darken the middle levels.', + 'Seçilen bant ışığı o frekanstan sürer. Otomatik seçim bas, orta ve tizi eşit tartıp en güçlüsünü izler.': + 'The selected band drives the light from that frequency. Auto weighs bass, mid and treble equally and follows the strongest.', 'Renk Doygunluğu': 'Color Saturation', 'Renk Yayılımı': 'Color Spread', 'Görselleştirici Bar Renkleri': 'Visualizer Bar Colors', diff --git a/src/shared/lighting-render.js b/src/shared/lighting-render.js index 2f042e3a..3fe49efa 100644 --- a/src/shared/lighting-render.js +++ b/src/shared/lighting-render.js @@ -19,7 +19,8 @@ * Renk hesabı kasıtlı olarak yenilendi. Anlık görüntü artık bu hesabın * sözleşmesidir; sessiz kaymayı test yakalar. Davranış testleri vuruşun * sürekli basta da sürmesini, bantların şerit boyunca ayrılmasını, seviye - * dengelemesini ve algısal parlaklığı ayrıca kilitler. + * dengelemesini ve ışık eğrisini ayrıca kilitler. Eğri, dengeleme ve + * gürültü kapısı varsayılanı eski doğrusal yanıttır; karartma isteğe bağlıdır. */ (function () { const STATIC_MODES = new Set(['single-color', 'per-device', 'per-led']); @@ -56,6 +57,9 @@ agcGain: 1, agcApplied: 1, }; + /* scaleHex bunu okur. renderPixel kare başında ayardaki eğriye çeker. + Doğrudan çağrı (test, ana parlaklık) varsayılan 1'de doğrusal kalır. */ + let lightCurve = 1; function clamp(value, min = 0, max = 1) { return Math.max(min, Math.min(max, Number(value) || 0)); @@ -65,7 +69,26 @@ return ((value % divisor) + divisor) % divisor; } + function curveOf(value) { + const n = Number(value); + if (!Number.isFinite(n) || n <= 1) return 1; + return Math.min(2.6, n); + } + function normalizeLighting(config) { + const src = config && typeof config === 'object' ? Object.assign({}, config) : {}; + /* Eğri anahtarı yokken 0.75 / 0.04 motorun kendi kısma varsayılanıydı + ve kayda geçmiş olabilir. Eğri elle seçilmediyse o çift eski doğrusal + yanıta döner. Başka bir dengeleme veya kapı değeri korunur. */ + if (src.responseCurve == null) { + const norm = Number(src.normalize); + const gate = Number(src.squelch); + if (Number.isFinite(norm) && Number.isFinite(gate) + && Math.abs(norm - 0.75) < 0.001 && Math.abs(gate - 0.04) < 0.001) { + src.normalize = 0; + src.squelch = 0; + } + } return { enabled: false, mode: 'visualizer-sync', @@ -100,8 +123,9 @@ flowSpeed: 0.45, audioAcceleration: 0.8, bandResponse: 'instant', - normalize: 0.75, - squelch: 0.04, + normalize: 0, + squelch: 0, + responseCurve: 1, bandAttack: 0.92, bandRelease: 0.38, bandThreshold: 0.08, @@ -124,7 +148,7 @@ thresholdBurstColorPosition: 'source', deviceColors: {}, deviceLedColors: {}, - ...(config || {}), + ...src, }; } @@ -190,31 +214,36 @@ return rgbHex(left.map((value, index) => value * (1 - t) + right[index] * t)); } - /* Algısal parlaklık. İstenen 0..1 değer PWM'e 2,2 kuvvetiyle iner; böylece - kaydırıcının ortası göze de orta gelir. 1'in üstü kanalları ayrı ayrı - tavana yapıştırmaz: taşan pay üç kanalı birlikte beyaza yaklaştırır, - ton kaymaz. */ - function scaleHex(color, factor) { + /* Işık eğrisi. 1 eski doğrusal çarpımdır: sesin yarısı ışığın yarısıdır. + 1'in üstü orta seviyeleri karartır. O zaman 1'i aşan pay kanalları ayrı + ayrı tavana yapıştırmaz; üç kanal birlikte beyaza yaklaşır, ton kaymaz. + Sıfır kanal sıfır kalır. */ + function scaleHex(color, factor, curve) { + const c = curve == null ? lightCurve : curveOf(curve); const rgb = parseHex(color); let x = Math.max(0, Number(factor) || 0); + if (c <= 1) return rgbHex(rgb.map((value) => (value <= 0 ? 0 : value * x))); let over = 0; if (x > 1) { over = 1 - Math.exp(-(x - 1) * 1.6); x = 1; } - const linear = Math.pow(x, 2.2); + const shaped = Math.pow(x, c); const lift = over * 0.42; - return rgbHex(rgb.map((value) => (value <= 0 ? 0 : value + (255 - value) * lift) * linear)); + return rgbHex(rgb.map((value) => (value <= 0 ? 0 : value + (255 - value) * lift) * shaped)); } - /* Ana parlaklık, gama uygulanmış rengin ÜSTÜNE biner. Baytı bir kez daha - kuvvetlemek ortayı karartırdı; önce algıya dönülür, çarpılır, yeniden kodlanır. */ - function scaleMaster(color, master) { + /* Ana parlaklık, eğri uygulanmış rengin ÜSTÜNE biner. Eğri 1 iken düz + çarpımdır. Eğri yükselince baytı ikinci kez kuvvetlememek için önce + doğrusal ışığa dönülür, çarpılır, aynı eğriyle yeniden kodlanır. */ + function scaleMaster(color, master, curve) { const m = clamp(master, 0, 1); if (m >= 0.999) return color; + const c = curve == null ? lightCurve : curveOf(curve); + if (c <= 1) return scaleHex(color, m, 1); const rgb = parseHex(color); - const inv = 1 / 2.2; - return rgbHex(rgb.map((value) => Math.pow(Math.pow(Math.max(0, value) / 255, inv) * m, 2.2) * 255)); + const inv = 1 / c; + return rgbHex(rgb.map((value) => (value <= 0 ? 0 : Math.pow(Math.pow(value / 255, inv) * m, c) * 255))); } function saturateHex(color, saturation) { @@ -320,11 +349,14 @@ } function triggerValue(triggerBand, bands) { - if (triggerBand === 'mid') return bands.mid; - if (triggerBand === 'treble') return bands.treble; - if (triggerBand === 'level') return bands.level; - if (triggerBand === 'auto') return Math.max(bands.bass, bands.mid * 0.95, bands.treble * 0.9); - return bands.bass; + const bass = bands.bass || 0; + const mid = bands.mid || 0; + const treble = bands.treble || 0; + if (triggerBand === 'mid') return mid; + if (triggerBand === 'treble') return treble; + if (triggerBand === 'level') return bands.level || 0; + if (triggerBand === 'auto') return Math.max(bass, mid, treble); + return bass; } function shapeBand(value, threshold, hardness) { @@ -393,12 +425,36 @@ }; } + /* Kazanç uygulanmış, eşik ve ayrıştırmadan önceki bant. Tetik ve + parlaklık bunu izler; ayrıştırma yalnız bölge renklerini ayırır. + Aksi halde yüksek bas, seçilen orta ve tizi yarıya indirip eşiğin + altında bırakıyor ve lamba yalnız basa bakıyor gibi kalıyordu. */ + function listenBands(raw, lighting) { + const bassGain = clamp(lighting.bassGain, 0, 3); + const midGain = clamp(lighting.midGain, 0, 3); + const trebleGain = clamp(lighting.trebleGain, 0, 3); + return { + level: clamp(raw.level), + bass: clamp((raw.bass || 0) * bassGain), + mid: clamp((raw.mid || 0) * midGain), + treble: clamp((raw.treble || 0) * trebleGain), + }; + } + function dominantPosition(bands) { - const weighted = [bands.bass * 1.08, bands.mid, bands.treble * 0.96]; + const weighted = [bands.bass || 0, bands.mid || 0, bands.treble || 0]; const index = weighted.indexOf(Math.max(...weighted)); return [0.08, 0.5, 0.9][index]; } + function triggerPosition(triggerBand, bands) { + if (triggerBand === 'bass') return 0.08; + if (triggerBand === 'mid') return 0.5; + if (triggerBand === 'treble') return 0.9; + if (triggerBand === 'level') return 0.5; + return dominantPosition(bands); + } + function gateValue(value, floor) { const x = clamp(value); if (!(floor > 0)) return x; @@ -456,6 +512,7 @@ const profile = lighting.bandResponse || 'instant'; const bandInput = profile === 'smooth' ? animation.smooth : rawBands; const separated = separatedBands(bandInput, lighting, dt); + const heard = listenBands(bandInput, lighting); const bands = { level: profile === 'instant' ? rawBands.level : animation.smooth.level, bass: separated.bass, @@ -512,15 +569,15 @@ animation.phase = mod(animation.phase + dt * speed, 1); animation.flash *= Math.pow(clamp(lighting.flashDecay, 0.45, 0.995), dt * 30); - const trigger = triggerValue(lighting.triggerBand, bands); + const trigger = triggerValue(lighting.triggerBand, heard); const threshold = clamp(lighting.flashThreshold, 0.02, 0.98); if (lighting.mode !== 'threshold-background-burst') { const bandName = lighting.triggerBand || 'bass'; if (bandName === 'auto') { onsetStrength = Math.max( - readOnset('bass', bands.bass, dt, 0.09), - readOnset('mid', bands.mid, dt, 0.09), - readOnset('treble', bands.treble, dt, 0.048) + readOnset('bass', heard.bass, dt, 0.09), + readOnset('mid', heard.mid, dt, 0.09), + readOnset('treble', heard.treble, dt, 0.048) ); } else { const key = onsets[bandName] ? bandName : 'bass'; @@ -541,7 +598,7 @@ position: direction === 'reverse' ? 1 : 0, direction: direction === 'reverse' ? -1 : 1, strength: Math.max(0.45, onsetStrength), - colorPosition: dominantPosition(bands), + colorPosition: triggerPosition(lighting.triggerBand, heard), }); if (animation.ripples.length > 6) animation.ripples.shift(); } @@ -561,6 +618,7 @@ return { dt, bands, + listen: heard, rawBands, bars: balanced.bars, hit, @@ -591,9 +649,11 @@ function renderPixel(mode, position, bars, lighting, visualConfig, state) { const { bands, time } = state; + lightCurve = curveOf(lighting && lighting.responseCurve); + const heard = (state && state.listen) || bands; + const drive = triggerValue(lighting.triggerBand, heard); const columns = state && Array.isArray(state.bars) && state.bars.length ? state.bars : bars; const baseLevel = clamp(lighting.baseLevel, 0, 0.75); - const energy = clamp(bands.level * 0.45 + bands.bass * 0.3 + bands.mid * 0.15 + bands.treble * 0.1); const spreadPosition = position * clamp(lighting.spread, 0.1, 4); const response = clamp(lighting.intensity); @@ -632,7 +692,7 @@ } if (mode === 'rainbow') { - const audio = triggerValue(lighting.rainbowAudioBand || 'level', bands); + const audio = triggerValue(lighting.rainbowAudioBand || 'level', heard); const ordered = lighting.rainbowStyle !== 'single'; const huePosition = ordered ? position * clamp(lighting.rainbowSpread, 0.1, 4) : 0; const hue = animation.phase * 360 + huePosition * 360; @@ -673,22 +733,23 @@ const sampled = Array.isArray(visualConfig?.__lightingBackgroundColors) && visualConfig.__lightingBackgroundColors.length > 0; const samplePosition = sampled ? clamp(position) : spreadPosition + animation.phase; - const color = sourceColor('background', samplePosition, energy, time, lighting, visualConfig); - const reactive = baseLevel + energy * clamp(lighting.intensity) * (1 - baseLevel); + const color = sourceColor('background', samplePosition, drive, time, lighting, visualConfig); + const reactive = baseLevel + clamp(drive) * clamp(lighting.intensity) * (1 - baseLevel); return scaleHex(color, reactive * (1 + animation.flash * clamp(lighting.flashStrength, 0, 1.5))); } if (mode === 'beat-pulse') { - const trigger = triggerValue(lighting.triggerBand, bands); - const tonePosition = dominantPosition(bands); - const ambient = sourceColor(lighting.paletteSource, spreadPosition + animation.phase * 0.2, trigger, time, lighting, visualConfig); - const tone = sourceColor(lighting.paletteSource, tonePosition + animation.phase * 0.08, trigger, time, lighting, visualConfig); + const tonePosition = triggerPosition(lighting.triggerBand, heard); + const ambient = sourceColor(lighting.paletteSource, spreadPosition + animation.phase * 0.2, drive, time, lighting, visualConfig); + const tone = sourceColor(lighting.paletteSource, tonePosition + animation.phase * 0.08, drive, time, lighting, visualConfig); const color = mixHex(ambient, tone, clamp(animation.flash * 1.4)); - return scaleHex(color, baseLevel + clamp(animation.flash * response + trigger * 0.22 * response) * (1 - baseLevel)); + const follow = clamp(drive * response); + const punch = clamp(animation.flash * response); + return scaleHex(color, baseLevel + clamp(Math.max(follow, punch)) * (1 - baseLevel)); } if (mode === 'ripple') { - let color = scaleHex(sourceColor(lighting.paletteSource, spreadPosition + animation.phase * 0.25, energy, time, lighting, visualConfig), baseLevel); + let color = scaleHex(sourceColor(lighting.paletteSource, spreadPosition + animation.phase * 0.25, drive, time, lighting, visualConfig), baseLevel); let peak = baseLevel; const width = clamp(lighting.rippleWidth, 0.03, 0.6); for (const ripple of animation.ripples) { @@ -699,8 +760,9 @@ color = mixHex(color, rippleColor, clamp(strength)); peak = Math.max(peak, strength); } + const body = baseLevel + clamp(drive) * response * (1 - baseLevel); const lit = baseLevel + Math.max(0, peak - baseLevel) * response; - return scaleHex(color, Math.max(baseLevel, lit)); + return scaleHex(color, Math.max(body, lit)); } if (mode === 'ambient-fusion') { @@ -708,15 +770,15 @@ const sampled = Array.isArray(visualConfig?.__lightingBackgroundColors) && visualConfig.__lightingBackgroundColors.length > 0; const visualizerColor = sourceColor('visualizer', spreadPosition + animation.phase * 0.08, bar, time, lighting, visualConfig); - const backgroundColor = sourceColor('background', sampled ? clamp(position) : spreadPosition + animation.phase, energy, time, lighting, visualConfig); + const backgroundColor = sourceColor('background', sampled ? clamp(position) : spreadPosition + animation.phase, drive, time, lighting, visualConfig); const color = mixHex(visualizerColor, backgroundColor, clamp(lighting.fusionMix)); - const factor = baseLevel + clamp(bar * 0.72 + energy * 0.28) * clamp(lighting.intensity) * (1 - baseLevel); + const factor = baseLevel + clamp(bar * 0.35 + drive * 0.65) * clamp(lighting.intensity) * (1 - baseLevel); return scaleHex(color, factor * (1 + animation.flash * clamp(lighting.flashStrength, 0, 1.5) * 0.7)); } if (mode === 'device-flow') { - const color = sourceColor(lighting.paletteSource, spreadPosition + animation.phase, energy, time, lighting, visualConfig); - const factor = baseLevel + energy * response * (1 - baseLevel); + const color = sourceColor(lighting.paletteSource, spreadPosition + animation.phase, drive, time, lighting, visualConfig); + const factor = baseLevel + clamp(drive) * response * (1 - baseLevel); return scaleHex(color, factor * (1 + animation.flash * clamp(lighting.flashStrength, 0, 1.5) * 0.55)); } diff --git a/tests/fixtures-lighting.json b/tests/fixtures-lighting.json index 3526c722..bd01d699 100644 --- a/tests/fixtures-lighting.json +++ b/tests/fixtures-lighting.json @@ -1,142 +1,142 @@ { "visualizer-sync": [ - "#020b07 #0d1d1f #373363 #12051c #020404", - "#020b07 #0d1d1f #373262 #12051c #020404", - "#020b07 #0d1c1e #363161 #12051b #020404", - "#020b07 #0d1c1e #35315f #12051b #020404", - "#020a07 #0d1b1e #352f5e #12051b #020404", - "#020a07 #0d1b1d #342e5c #11051a #020404", - "#020a07 #0d1a1d #332d5a #11041a #020404", - "#020a07 #0c1a1c #322c59 #11041a #020404", - "#020a07 #0c191c #322b58 #110419 #020404", - "#020a07 #0c191c #312a56 #041911 #020404", - "#020a07 #0c191b #302955 #041910 #020404", - "#020a07 #0c181b #2f2853 #041810 #020404" + "#0a3a27 #21494d #4d4789 #391055 #0e2122", + "#0a3a27 #21494d #4d478a #391056 #0e2122", + "#0a3a27 #21484e #4d468a #391056 #0e2122", + "#0a3a27 #21484e #4d468a #391056 #0e2122", + "#0a3a27 #21484e #4e458a #390f56 #0e2122", + "#0a3927 #22484e #4e458a #390f56 #0e2122", + "#0a3927 #22484e #4e458a #390f56 #0e2122", + "#0a3927 #22474e #4e458b #390f56 #0f2022", + "#0a3927 #22474e #4e458b #390e56 #0f2022", + "#0b3927 #22474e #4e448b #0e5639 #0f2022", + "#0b3927 #22474e #4e448b #0e5639 #0f2022", + "#0b3927 #22464e #4f438b #0f5639 #0f2023" ], "spectrum-bars": [ - "#041a11 #173437 #3b376a #200930 #040909", - "#041a11 #173337 #3b3669 #1f0930 #040909", - "#041a11 #173336 #3a3669 #1f092f #040809", - "#041911 #173236 #3a3568 #1f092f #040809", - "#041911 #173136 #393467 #1f082e #040809", - "#041911 #173135 #393466 #1e082e #040809", - "#041911 #163134 #393365 #1e082e #040809", - "#041811 #163034 #383263 #1e082d #040809", - "#041810 #162f33 #373162 #1e082d #040808", - "#041810 #162f33 #373161 #1d082c #040808", - "#041810 #162e32 #363060 #1d082c #040808", - "#041710 #162d32 #362f60 #1d072c #040808" + "#0e5639 #2a5d64 #4f498e #47146c #143031", + "#0e5639 #2a5d64 #4f498e #47146c #142f31", + "#0f5639 #2b5d64 #4f498e #47146c #142f31", + "#0f5639 #2b5d64 #4f488e #47146c #142f31", + "#0f563a #2b5d64 #4f488e #47146c #142f31", + "#0f553a #2b5d64 #4f488e #48136c #152f31", + "#0f553a #2b5d64 #50488e #48136c #152f31", + "#0f553a #2c5c64 #50488e #48136c #152f31", + "#0f553a #2c5c64 #50488e #48136c #152f31", + "#0f553a #2c5c64 #50488e #48136c #152f31", + "#0f553a #2c5c64 #50478f #48136d #152f31", + "#0f543a #2c5c65 #50478f #49136d #152e31" ], "band-zones": [ - "#0c2609 #0b2215 #0b0a15 #111612 #0b2108", - "#11340d #0e2e1d #151327 #0d110e #081906", - "#0d280a #0b2416 #191730 #171d18 #0e2b0b", - "#0c2409 #0a2014 #19172f #141915 #0c2509", - "#12370e #0f311f #141226 #171e18 #0e2b0b", - "#174712 #143f28 #100f20 #161c16 #0d280a", - "#143d0f #113622 #121022 #161d17 #0d2a0a", - "#0e2c0b #0c2719 #17152c #19201a #0f2e0b", - "#0e2a0a #0c2618 #1a1832 #161c17 #0d290a", - "#143d0f #113622 #18162e #181f19 #0f2e0b", - "#154010 #123924 #141226 #131914 #0c2409", - "#0f2e0b #0d291a #100f1f #1c241d #11350d" + "#236c1b #1e603c #2b2853 #354538 #206419", + "#287d1f #226f46 #39356e #303e32 #1d5a16", + "#24701c #1f633e #3f3a79 #3d4f40 #25731c", + "#236b1b #1d5f3c #3f3a78 #3a4a3c #236c1b", + "#2a8220 #247449 #39346d #3e5041 #26751d", + "#2f9324 #288252 #353165 #3c4e3f #24711c", + "#2c8a22 #267a4d #37336a #3e5041 #25741d", + "#26781e #216a43 #3e3978 #415444 #277a1e", + "#26761d #206942 #423d7f #3e5041 #25741d", + "#2d8c23 #267c4e #403b7b #415444 #277b1e", + "#2e9024 #278050 #3b3671 #3b4c3e #246f1b", + "#287d1f #226f46 #363268 #475b4a #2b8421" ], "background-sync": [ - "#070712 #041011 #0c0d0d #070611 #041011", - "#232760 #175957 #43414c #25225e #17565a", - "#232d65 #185f58 #4a3c55 #252863 #185c5b", - "#151e3f #103c35 #302138 #161b3e #0f3b37", - "#26407d #227562 #643876 #293a7c #1e7567", - "#213f73 #226a55 #5f2b72 #233a71 #1f6a59", - "#152e50 #1a4938 #441853 #172b4f #17493b", - "#17385c #20523c #481b5c #18345a #1d523f", - "#12314d #1d442f #38174b #132e4c #1a4432", - "#19496c #2c603f #492069 #1a466d #286043", - "#1a5170 #32673f #48226e #1b4e73 #2f6743", - "#12394b #254628 #2d174a #12374d #22462b" + "#323082 #20777b #586261 #362b81 #20737f", + "#5660ea #39dad5 #a69fba #5a53e6 #39d3dc", + "#36469d #259589 #745e85 #393e9b #268f8d", + "#354ea4 #289b87 #7d5692 #3846a1 #26978d", + "#4f86ff #48f3cc #cf74f6 #5379ff #3ef3d5", + "#4d94ff #51f8c6 #de63ff #5287ff #48f8d1", + "#387bd2 #45bf92 #b340d9 #3c70cf #3dbf99", + "#255b95 #358560 #742c95 #275592 #2f8566", + "#348fde #54c486 #a041d9 #3786da #4dc48e", + "#3badfc #69e292 #ac4cf7 #3ca4ff #60e29c", + "#34a3df #66cd7d #8f45dd #359de6 #5ecd86", + "#226d8d #47854c #552c8d #226991 #418551" ], "beat-pulse": [ - "#010704 #020505 #030306 #040107 #020505", - "#0b3728 #0e322a #112e2c #14292d #0e332a", - "#0d1f1f #101a21 #121523 #151025 #0f1a21", - "#091816 #0b1418 #0e0f1a #110a1c #0b1418", - "#0b3426 #0e2f28 #112a2a #14252c #0e2f28", - "#092a1e #0c2420 #0f1e22 #082a1e #0c2420", - "#061f16 #091a18 #0c151a #061f16 #091a18", - "#051710 #071212 #0a0e14 #041710 #071212", - "#05100e #070d0f #090911 #04110e #070d0f", - "#0a2e22 #0d2924 #102426 #0a2f22 #0d2924", - "#08241a #0b1e1c #0e191e #07241a #0b1f1c", - "#051a13 #081515 #0b1017 #051a13 #081515" + "#13744e #27555a #3a3567 #4d1674 #25575a", + "#1b7c5c #1d7a5d #1e775e #20755f #1d7a5d", + "#156247 #195a4a #1e524d #224b50 #195b4a", + "#146348 #1c574c #234c51 #2a3f56 #1b584c", + "#1e8362 #1f8063 #207e64 #227c65 #1f8063", + "#1f926c #268770 #2d7c74 #1f936b #25896f", + "#197958 #226b5e #2b5c64 #197a57 #216c5e", + "#135941 #1b4c46 #233e4c #125b40 #1a4d46", + "#1a7457 #206b5a #25615e #197556 #1f6b5a", + "#1f906a #2a7e72 #356c79 #1e9169 #297f71", + "#1e8b66 #2b746e #385e77 #1d8c65 #2a766e", + "#145e45 #1f4c4c #293b53 #135f44 #1e4e4b" ], "ripple": [ - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000" + "#03110b #060d0e #09080f #0b0311 #060d0e", + "#03140e #070e10 #0a0912 #0d0414 #070f10", + "#020e0a #050a0b #07070d #09020e #050b0b", + "#030f0b #050b0c #08070e #0a0310 #050b0c", + "#04150f #080f11 #0a0913 #03150e #070f11", + "#051710 #081012 #0c0a15 #04170f #081112", + "#04130d #070d0f #0a0811 #03130d #060e0f", + "#030e0a #050a0b #07060d #020e0a #050a0b", + "#04120d #070d0f #0a0811 #03120d #070d0f", + "#051610 #081012 #0c0a15 #051710 #081112", + "#04150f #080f11 #0c0914 #04160f #080f11", + "#030e0a #050a0c #08060e #030f0a #050a0c" ], "ambient-fusion": [ - "#04080b #0a1c1e #303240 #0d071a #020707", - "#09151b #153f40 #656089 #1d113a #061213", - "#08151b #143c3b #615283 #1b1137 #061212", - "#061115 #11322f #544073 #150f2d #040e0e", - "#09191e #17423d #714b9a #1c163d #071514", - "#08171c #163c36 #683d8f #191538 #071312", - "#061417 #14322c #5c2f7f #15132f #060f0e", - "#061518 #15312a #552d79 #14132f #06100e", - "#051315 #142c25 #49296d #12132b #060e0c", - "#07191b #1b3a2e #5a358b #171938 #08130f", - "#06191a #1b372b #503181 #161935 #08130f", - "#051515 #172e23 #412a6e #12162c #070f0c" + "#1e4158 #216267 #52576f #3a1e70 #1b5057", + "#2d6889 #33999a #827baf #5731ac #2a7f84", + "#204f64 #267572 #69598e #3f2881 #1e5c5c", + "#1f5367 #287770 #6c5294 #3f2c84 #1f605d", + "#2b7b95 #3aa498 #9764ce #5641b9 #2d8d83", + "#2a8199 #3ea695 #9c5bd6 #5546bd #319084", + "#216c7e #368978 #8845bb #453e9c #2a7467", + "#185460 #2d6b5b #683895 #34337a #21564a", + "#207582 #3e8c73 #7f47bc #4347a2 #307662", + "#238791 #489b7c #824dca #4953b6 #39866d", + "#207f85 #468f6f #7348bb #4451a9 #387c62", + "#175c5d #376a50 #54378f #323c79 #295642" ], "device-flow": [ - "#03100b #050b0c #08070e #0a0310 #050c0c", - "#0c3c2a #152b31 #1f1a37 #0b3d29 #152c30", - "#0d402e #192e36 #231c3d #0d422e #182f35", - "#09291f #101d23 #171128 #092a1e #101e23", - "#114737 #1e323f #2b1d48 #104936 #1d343f", - "#114335 #1d2f3d #291a45 #104434 #1d303c", - "#0d2f27 #16202c #1f1232 #0c3026 #15222c", - "#10362e #1a2534 #24143b #0f372d #192634", - "#0e2d27 #171f2d #201033 #0d2e27 #16202d", - "#123631 #1d2438 #27123f #113830 #1c2637", - "#153b37 #21273f #2d1347 #143d36 #20293f", - "#102928 #181b2d #210d33 #0f2a27 #181c2d" + "#15734e #27535b #3a3468 #4d1475 #26565a", + "#20a877 #3d7989 #594a9c #1fab75 #3b7d88", + "#177051 #2b505e #3e306b #167251 #29525d", + "#1a7457 #2e5264 #433071 #187655 #2d5563", + "#29a982 #477796 #6544aa #26ac81 #447a95", + "#2dad8a #4c799f #6b44b4 #2bb188 #4a7d9d", + "#25866e #3e5c7e #57338f #238a6d #3c5f7e", + "#1c5d4f #2d405b #3f2267 #1a604e #2c425a", + "#298170 #425781 #5b2d92 #268470 #405b80", + "#329587 #50649b #6e32ae #309985 #4e6899", + "#31877e #4c5990 #682ca3 #2e8a7d #4a5d8f", + "#215754 #333960 #451b6c #205a53 #323b5f" ], "rainbow": [ - "#100402 #071002 #020e10 #0a0210 #100402", - "#5c200d #215c0d #0d495c #480d5c #5c200d", - "#843d13 #208413 #135984 #761384 #843d13", - "#47290a #0a470a #0a2847 #470a46 #47290a", - "#895e14 #148924 #143e89 #891479 #895e14", - "#876c13 #138732 #132d87 #871368 #876c13", - "#564e0c #0c5629 #0c1356 #560c38 #564e0c", - "#8e9215 #159257 #191592 #92154f #8e9215", - "#667711 #117755 #211177 #771133 #667711", - "#465e0d #0d5e4d #250d5e #5e0d1e #465e0d", - "#5d9315 #15938a #4b1593 #93151e #5d9315", - "#35650e #0e6065 #3e0e65 #65130e #35650e" + "#4a120b #234a0b #0b434a #320b4a #4a120b", + "#a03917 #39a017 #177ea0 #7d17a0 #a03917", + "#bd581b #2ebd1b #1b80bd #a91bbd #bd581b", + "#915315 #159115 #155291 #911591 #915315", + "#c3871c #1cc333 #1c57c3 #c31cab #c3871c", + "#c39d1c #1cc34a #1c41c3 #c31c95 #c39d1c", + "#a19417 #17a14e #1724a1 #a11769 #a19417", + "#c5cd1d #1dcd7c #241dcd #cd1d6d #c5cd1d", + "#a0bc1b #1bbc87 #371bbc #bc1b4f #a0bc1b", + "#7dab18 #18ab8e #4518ab #ab1835 #7dab18", + "#82d21e #1ed2c7 #6d1ed2 #d21e28 #82d21e", + "#5ab319 #19a7b3 #7119b3 #b32519 #5ab319" ], "threshold-background-burst": [ - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000", - "#000000 #000000 #000000 #000000 #000000" + "#03060a #03060a #03060a #03060a #03060a", + "#03060a #03060a #03060a #03060a #03060a", + "#02060a #02060a #02060a #02060a #02060a", + "#02070a #02070a #02070a #02070a #02070a", + "#02070a #02070a #02070a #02070a #02070a", + "#02070a #02070a #02070a #02070a #02070a", + "#020709 #020709 #020709 #020709 #020709", + "#020809 #020809 #020809 #020809 #020809", + "#020809 #020809 #020809 #020809 #020809", + "#020809 #020809 #020809 #020809 #020809", + "#020908 #020908 #020908 #020908 #020908", + "#020908 #020908 #020908 #020908 #020908" ] } diff --git a/tests/lighting-render.test.js b/tests/lighting-render.test.js index 9f0155d5..e47abf9a 100644 --- a/tests/lighting-render.test.js +++ b/tests/lighting-render.test.js @@ -183,19 +183,31 @@ test('seviye dengeleme kısık parçayı hedefe çekiyor', () => { assert.ok(level > 0.45, 'kısık seviye dengelenmedi: ' + level); }); -test('algısal parlaklık ortayı doğrusalın altına indiriyor ve taşırmıyor', () => { +test('ışık eğrisi 1 doğrusal, yükseldikçe ortayı kararır', () => { const r = R.createRenderer(); - const mid = r.scaleHex('#ffffff', 0.5); - const channel = parseInt(mid.slice(1, 3), 16); - assert.ok(channel > 40 && channel < 80, 'orta parlaklık: ' + mid); + const fresh = r.normalizeLighting({}); + assert.strictEqual(fresh.responseCurve, 1); + assert.strictEqual(fresh.normalize, 0); + assert.strictEqual(fresh.squelch, 0); + assert.strictEqual(r.scaleHex('#ffffff', 0.5), '#808080'); assert.strictEqual(r.scaleHex('#ffffff', 1), '#ffffff'); assert.strictEqual(r.scaleHex('#000000', 2), '#000000'); - const hot = r.scaleHex('#ff8844', 1.35); + const curved = r.scaleHex('#ffffff', 0.5, 2.2); + const channel = parseInt(curved.slice(1, 3), 16); + assert.ok(channel > 40 && channel < 80, 'eğri 2.2 ortayı karartmalı: ' + curved); + const hot = r.scaleHex('#ff8844', 1.35, 2.2); const red = parseInt(hot.slice(1, 3), 16); const green = parseInt(hot.slice(3, 5), 16); const blue = parseInt(hot.slice(5, 7), 16); assert.ok(green > 136 && blue > 68, 'taşma diğer kanalları da açmalı: ' + hot); assert.ok(red >= green && green >= blue, 'ton sırası bozuldu: ' + hot); + const migrated = r.normalizeLighting({ normalize: 0.75, squelch: 0.04 }); + assert.strictEqual(migrated.normalize, 0); + assert.strictEqual(migrated.squelch, 0); + const kept = r.normalizeLighting({ normalize: 0.75, squelch: 0.04, responseCurve: 2.2 }); + assert.strictEqual(kept.normalize, 0.75); + assert.strictEqual(kept.squelch, 0.04); + assert.strictEqual(kept.responseCurve, 2.2); }); test('ana parlaklık gamayı ikinci kez uygulamıyor', () => { @@ -205,6 +217,7 @@ test('ana parlaklık gamayı ikinci kez uygulamıyor', () => { const half = r.scaleMaster('#ffffff', 0.5); const direct = r.scaleHex('#ffffff', 0.5); assert.strictEqual(half, direct); + assert.strictEqual(r.scaleMaster('#ffffff', 0.5, 2.2), r.scaleHex('#ffffff', 0.5, 2.2)); }); test('32 sütun şerit boyunca ayrılıyor', () => { @@ -328,6 +341,66 @@ test('bar spektrumu üç banda düşmeden konuma göre değişiyor', () => { assert.ok(parseInt(left.slice(1, 3), 16) > parseInt(right.slice(1, 3), 16), left + ' / ' + right); }); +function channelOf(hex) { + return parseInt(String(hex).slice(1, 3), 16); +} + +function showLighting(r, extra) { + return r.normalizeLighting(Object.assign({ + mode: 'beat-pulse', + normalize: 0, + squelch: 0, + responseCurve: 1, + smoothing: 0, + bandResponse: 'instant', + bandThreshold: 0.6, + bandHardness: 0.63, + bandSeparation: 0.78, + bassGain: 1.9, + midGain: 1.6, + trebleGain: 1.05, + intensity: 1, + baseLevel: 0.02, + flashThreshold: 0.52, + flashStrength: 1.5, + flashDecay: 0.87, + paletteSource: 'custom', + color: '#ffffff', + color2: '#ffffff', + }, extra || {})); +} + +function pulseChannel(r, lighting, frame) { + r.resetAnimation('beat-pulse'); + const state = r.updateAnimation(frame, lighting, {}, 2000); + return channelOf(r.renderPixel('beat-pulse', 0.5, null, lighting, {}, state)); +} + +test('mid, tiz ve otomatik seçim seçilen bandı izler', () => { + const r = R.createRenderer(); + const midHeavy = { level: 0.7, bass: 0.22, mid: 0.82, treble: 0.08 }; + const bassHeavy = { level: 0.7, bass: 0.9, mid: 0.08, treble: 0.05 }; + const trebleHeavy = { level: 0.55, bass: 0.16, mid: 0.1, treble: 0.88 }; + const midOn = showLighting(r, { triggerBand: 'mid' }); + const midLit = pulseChannel(r, midOn, midHeavy); + const midDark = pulseChannel(r, midOn, bassHeavy); + assert.ok(midLit > 180, 'orta seçiliyken orta zayıf: ' + midLit); + assert.ok(midDark < 90, 'orta seçiliyken bas hâlâ sürüyor: ' + midDark); + const trebleOn = showLighting(r, { triggerBand: 'treble' }); + const trebleLit = pulseChannel(r, trebleOn, trebleHeavy); + const trebleDark = pulseChannel(r, trebleOn, bassHeavy); + assert.ok(trebleLit > 180, 'tiz seçiliyken tiz zayıf: ' + trebleLit); + assert.ok(trebleDark < 80, 'tiz seçiliyken bas hâlâ sürüyor: ' + trebleDark); + const auto = showLighting(r, { triggerBand: 'auto' }); + const bassOnly = showLighting(r, { triggerBand: 'bass' }); + const autoMid = pulseChannel(r, auto, midHeavy); + const bassOnMid = pulseChannel(r, bassOnly, midHeavy); + assert.ok(autoMid > bassOnMid + 40, 'otomatik seçim basa kilitli: ' + autoMid + ' / ' + bassOnMid); + const autoTreble = pulseChannel(r, auto, trebleHeavy); + const bassOnTreble = pulseChannel(r, bassOnly, trebleHeavy); + assert.ok(autoTreble > bassOnTreble + 40, 'otomatik seçim tizi kaçırdı: ' + autoTreble + ' / ' + bassOnTreble); +}); + test('dynamic-lighting artık kendi kopyasını taşımıyor', () => { /* İki kopya kalırsa biri düzeltilip diğeri unutulur. */ const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'main', 'dynamic-lighting.js'), 'utf-8');