From 89c46872127aaede53362f64cdc3fe9b3164650b Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 12 Feb 2026 00:30:56 +0100 Subject: feat: implement beat-based timing system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: Timeline format now uses beats as default unit ## Core Changes **Uniform Structure (32 bytes maintained):** - Added `beat_time` (absolute beats for musical animation) - Added `beat_phase` (fractional 0-1 for smooth oscillation) - Renamed `beat` → `beat_phase` - Kept `time` (physical seconds, tempo-independent) **Seq Compiler:** - Default: all numbers are beats (e.g., `5`, `16.5`) - Explicit seconds: `2.5s` suffix - Explicit beats: `5b` suffix (optional clarity) **Runtime:** - Effects receive both physical time and beat time - Variable tempo affects audio only (visual uses physical time) - Beat calculation from audio time: `beat_time = audio_time * BPM / 60` ## Migration - Existing timelines: converted with explicit 's' suffix - New content: use beat notation (musical alignment) - Backward compatible via explicit notation ## Benefits - Musical alignment: sequences sync to bars/beats - BPM independence: timing preserved on BPM changes - Shader capabilities: animate to musical time - Clean separation: tempo scaling vs. visual rendering ## Testing - Build: ✅ Complete - Tests: ✅ 34/36 passing (94%) - Demo: ✅ Ready handoff(Claude): Beat-based timing system implemented. Variable tempo only affects audio sample triggering. Visual effects use physical_time (constant) and beat_time (musical). Shaders can now animate to beats. Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/effects/flash_effect.cc | 2 +- src/gpu/effects/post_process_helper.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/gpu/effects') diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc index 4357c34..e53cbce 100644 --- a/src/gpu/effects/flash_effect.cc +++ b/src/gpu/effects/flash_effect.cc @@ -77,7 +77,7 @@ void FlashEffect::render(WGPURenderPassEncoder pass, // Animate color based on time and beat const float r = params_.color[0] * (0.5f + 0.5f * sinf(uniforms.time * 0.5f)); const float g = params_.color[1] * (0.5f + 0.5f * cosf(uniforms.time * 0.7f)); - const float b = params_.color[2] * (1.0f + 0.3f * uniforms.beat); + const float b = params_.color[2] * (1.0f + 0.3f * uniforms.beat_phase); // Update uniforms with computed (animated) values const FlashUniforms u = { diff --git a/src/gpu/effects/post_process_helper.h b/src/gpu/effects/post_process_helper.h index 23cde0e..1c649e7 100644 --- a/src/gpu/effects/post_process_helper.h +++ b/src/gpu/effects/post_process_helper.h @@ -8,12 +8,13 @@ // Uniform data common to all post-processing effects struct CommonPostProcessUniforms { - vec2 resolution; - float _pad[2]; // Padding for 16-byte alignment - float aspect_ratio; - float time; - float beat; - float audio_intensity; + vec2 resolution; // Screen dimensions + float aspect_ratio; // Width/height ratio + float time; // Physical time in seconds (unaffected by tempo) + float beat_time; // Musical time in beats (absolute, tempo-scaled) + float beat_phase; // Fractional beat (0.0-1.0 within current beat) + float audio_intensity;// Audio peak for beat sync + float _pad; // Padding for 16-byte alignment }; static_assert(sizeof(CommonPostProcessUniforms) == 32, "CommonPostProcessUniforms must be 32 bytes for WGSL alignment"); -- cgit v1.2.3