diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-16 21:47:09 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-16 21:47:09 +0100 |
| commit | 9f4923385f06a5d6f8e86b5004398a0c335cd6db (patch) | |
| tree | 817fc2d7a390823e69edbfb57395cf7c888a04ed | |
| parent | bb4f36f9c32a1484b62e80630825cbcec3976cad (diff) | |
refactor: remove END_DEMO directive, auto-calculate from sequences
Remove END_DEMO keyword from timeline format. Demo duration now
calculated from max effect end time across all sequences. Sort
sequences by start time at compile time for deterministic ordering.
Changes:
- seq_compiler.py: Auto-calculate duration, sort sequences
- seq_compiler.cc: Remove END_DEMO parsing, sort by start time
- workspaces/test/timeline.seq: Remove END_DEMO directive
- Generated timeline.cc: Duration now 40.0f (was hardcoded)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| -rw-r--r-- | tools/seq_compiler.cc | 28 | ||||
| -rwxr-xr-x | tools/seq_compiler.py | 12 | ||||
| -rw-r--r-- | workspaces/test/timeline.seq | 2 |
3 files changed, 27 insertions, 15 deletions
diff --git a/tools/seq_compiler.cc b/tools/seq_compiler.cc index 5804031..462bdba 100644 --- a/tools/seq_compiler.cc +++ b/tools/seq_compiler.cc @@ -703,17 +703,7 @@ int main(int argc, char* argv[]) { std::string command; ss >> command; - if (command == "END_DEMO") { - std::string end_time; - if (!(ss >> end_time)) { - std::cerr << "Error line " << line_num - << ": END_DEMO requires <time>\n"; - return 1; - } - // Convert beat notation to time - demo_end_time = convert_to_time(end_time, bpm); - std::cout << "Demo end time: " << demo_end_time << "s\n"; - } else if (command == "SEQUENCE") { + if (command == "SEQUENCE") { std::string start, priority; if (!(ss >> start >> priority)) { std::cerr << "Error line " << line_num @@ -855,9 +845,23 @@ int main(int argc, char* argv[]) { } } - // Sort sequences by priority + // Calculate demo end time from maximum effect end time + float max_end_time = 0.0f; + for (const auto& seq : sequences) { + float seq_start = std::stof(seq.start_time); + for (const auto& eff : seq.effects) { + max_end_time = std::max(max_end_time, seq_start + std::stof(eff.end)); + } + } + demo_end_time = std::to_string(max_end_time); + std::cout << "Demo end time (calculated): " << demo_end_time << "s\n"; + + // Sort sequences by start time (primary) then priority (secondary) std::sort(sequences.begin(), sequences.end(), [](const SequenceEntry& a, const SequenceEntry& b) { + float a_start = std::stof(a.start_time); + float b_start = std::stof(b.start_time); + if (a_start != b_start) return a_start < b_start; return std::stoi(a.priority) < std::stoi(b.priority); }); diff --git a/tools/seq_compiler.py b/tools/seq_compiler.py index 3b8d126..70faf5b 100755 --- a/tools/seq_compiler.py +++ b/tools/seq_compiler.py @@ -446,6 +446,16 @@ def main(): print("Error: No sequences found in input file", file=sys.stderr) sys.exit(1) + # Sort sequences by start time + sequences.sort(key=lambda s: s.start_time) + + # Calculate demo duration from max effect end time (absolute time) + demo_duration = 0.0 + for seq in sequences: + for effect in seq.effects: + # Effect times are relative to sequence start + demo_duration = max(demo_duration, seq.start_time + effect.end) + # Process each sequence all_cpp = '''// Generated by seq_compiler.py // DO NOT EDIT @@ -523,7 +533,7 @@ void RenderTimeline(WGPUCommandEncoder encoder, float time, int width, int heigh } float GetDemoDuration() { - return 40.0f; // TODO: Calculate from sequences + return ''' + f'{demo_duration:.1f}f' + '''; } // Surface-based rendering with framebuffers diff --git a/workspaces/test/timeline.seq b/workspaces/test/timeline.seq index c4aba02..d4b0004 100644 --- a/workspaces/test/timeline.seq +++ b/workspaces/test/timeline.seq @@ -5,5 +5,3 @@ SEQUENCE 0.0 0 "MainLoop" EFFECT + Flash source -> flash_out 0.0 16.0 EFFECT + PeakMeter flash_out -> sink 0.0 16.0 - -END_DEMO 32.0 |
