summaryrefslogtreecommitdiff
path: root/src/audio/tracker.h
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-07 19:22:43 +0100
committerskal <pascal.massimino@gmail.com>2026-02-07 19:22:43 +0100
commit726ae79dd3ba8f368d3a671f371e747c33195edd (patch)
tree9fbd250b47853a4b81312ff6baddd307341cb15c /src/audio/tracker.h
parent0eef80ccb12ced607b953bf680459028485b9c67 (diff)
refactor(audio): Convert tracker to unit-less timing system
Changes tracker timing from beat-based to unit-less system to separate musical structure from BPM-dependent playback speed. TIMING CONVENTION: - 1 unit = 4 beats (by convention) - Conversion: seconds = units * (4 / BPM) * 60 - At 120 BPM: 1 unit = 2 seconds BENEFITS: - Pattern structure independent of BPM - BPM changes only affect playback speed, not structure - Easier pattern composition (0.00-1.00 for typical 4-beat pattern) - Fixes issue where patterns played for 2s instead of expected duration DATA STRUCTURES (tracker.h): - TrackerEvent.beat → TrackerEvent.unit_time - TrackerPattern.num_beats → TrackerPattern.unit_length - TrackerPatternTrigger.time_sec → TrackerPatternTrigger.unit_time RUNTIME (tracker.cc): - Added BEATS_PER_UNIT constant (4.0) - Convert units to seconds at playback time using BPM - Pattern remains active for full unit_length duration - Fixed premature pattern deactivation bug COMPILER (tracker_compiler.cc): - Parse LENGTH parameter from PATTERN lines (defaults to 1.0) - Parse unit_time instead of beat values - Generate code with unit-less timing ASSETS: - test_demo.track: converted to unit-less (8 score triggers) - music.track: converted to unit-less (all patterns) - Events: beat/4 conversion (e.g., beat 2.0 → unit 0.50) - Score: seconds/unit_duration (e.g., 4s → 2.0 units at 120 BPM) VISUALIZER (track_visualizer/index.html): - Parse LENGTH parameter and BPM directive - Convert unit-less time to seconds for rendering - Update tick positioning to use unit_time - Display correct pattern durations DOCUMENTATION (doc/TRACKER.md): - Added complete .track format specification - Timing conversion reference table - Examples with unit-less timing - Pattern LENGTH parameter documentation FILES MODIFIED: - src/audio/tracker.{h,cc} (data structures + runtime conversion) - tools/tracker_compiler.cc (parser + code generation) - assets/{test_demo,music}.track (converted to unit-less) - tools/track_visualizer/index.html (BPM-aware rendering) - doc/TRACKER.md (format documentation) - convert_track.py (conversion utility script) TEST RESULTS: - test_demo builds and runs correctly - demo64k builds successfully - Generated code verified (unit-less values in music_data.cc) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/audio/tracker.h')
-rw-r--r--src/audio/tracker.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/audio/tracker.h b/src/audio/tracker.h
index 336f77f..4cd011b 100644
--- a/src/audio/tracker.h
+++ b/src/audio/tracker.h
@@ -8,7 +8,7 @@
#include <cstdint>
struct TrackerEvent {
- float beat;
+ float unit_time; // Unit-less time within pattern (0.0 to pattern.unit_length)
uint16_t sample_id;
float volume;
float pan;
@@ -17,11 +17,11 @@ struct TrackerEvent {
struct TrackerPattern {
const TrackerEvent* events;
uint32_t num_events;
- float num_beats;
+ float unit_length; // Pattern duration in units (typically 1.0 for 4-beat patterns)
};
struct TrackerPatternTrigger {
- float time_sec;
+ float unit_time; // Unit-less time when pattern triggers
uint16_t pattern_id;
// Modifiers could be added here
};
@@ -29,7 +29,7 @@ struct TrackerPatternTrigger {
struct TrackerScore {
const TrackerPatternTrigger* triggers;
uint32_t num_triggers;
- float bpm;
+ float bpm; // BPM is used only for playback scaling (1 unit = 4 beats)
};
// Global music data generated by tracker_compiler