diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-12 00:30:56 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-12 00:30:56 +0100 |
| commit | 89c46872127aaede53362f64cdc3fe9b3164650b (patch) | |
| tree | 844882239088b35f2b1b555029780d26c6b4cfe8 /src/gpu/effect.cc | |
| parent | 4e0b7c040c3e45c66767b936a8058f76bcc31bf1 (diff) | |
feat: implement beat-based timing system
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 <noreply@anthropic.com>
Diffstat (limited to 'src/gpu/effect.cc')
| -rw-r--r-- | src/gpu/effect.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 58e011c..e0a9c24 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -226,7 +226,8 @@ void MainSequence::resize(int width, int height) { } } -void MainSequence::render_frame(float global_time, float beat, float peak, +void MainSequence::render_frame(float global_time, float beat_time, + float beat_phase, float peak, float aspect_ratio, WGPUSurface surface) { WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr); @@ -260,11 +261,12 @@ void MainSequence::render_frame(float global_time, float beat, float peak, // Construct common uniforms once (reused for all effects) CommonPostProcessUniforms base_uniforms = { .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, - ._pad = {0.0f, 0.0f}, .aspect_ratio = aspect_ratio, .time = 0.0f, // Will be set per-effect - .beat = beat, + .beat_time = beat_time, + .beat_phase = beat_phase, .audio_intensity = peak, + ._pad = 0.0f, }; for (const SequenceItem* item : scene_effects) { @@ -564,7 +566,8 @@ void MainSequence::simulate_until(float target_time, float step_rate, for (float t = 0.0f; t < target_time; t += step_rate) { WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr); - float beat = fmodf(t * bpm / 60.0f, 1.0f); + float absolute_beat_time = t * bpm / 60.0f; + float beat_phase = fmodf(absolute_beat_time, 1.0f); std::vector<SequenceItem*> scene_effects, post_effects; for (ActiveSequence& entry : sequences_) { if (t >= entry.start_time) { @@ -575,11 +578,12 @@ void MainSequence::simulate_until(float target_time, float step_rate, for (const SequenceItem* item : scene_effects) { CommonPostProcessUniforms test_uniforms = { .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, - ._pad = {0.0f, 0.0f}, .aspect_ratio = aspect_ratio, .time = t - item->start_time, - .beat = beat, + .beat_time = absolute_beat_time, + .beat_phase = beat_phase, .audio_intensity = 0.0f, + ._pad = 0.0f, }; item->effect->compute(encoder, test_uniforms); } |
