mirror of
https://github.com/alda-lang/alda.git
synced 2026-02-27 18:24:13 +01:00
This commit fixes a bug where an accumulating delay would occur in the
REPL when using voices. The root cause was a faulty offset
synchronization mechanism that failed to account for the effective
offset of an instrument with active voices.
The fix involves several related changes:
1. **Correct Offset Calculation:**
- A new `CalculateEffectiveOffset` method on the `Part` struct now
correctly calculates the furthest point in time reached by an
instrument or any of its voices.
2. **Robust Synchronization via Stable IDs:**
- The synchronization mechanism between the REPL and the player,
which is responsible for adjusting note offsets, has been
refactored to be more robust.
- It now uses a stable, unique string ID for each part instead of
unstable memory pointers. This prevents synchronization failures.
- The `syncOffsets` map in the transmitter and related functions
have been updated from `map[*Part]float64` to `map[string]float64`.
3. **Voice Logic Correction:**
- A structural bug in `VoiceMarker.UpdateScore` that caused voices
to be nested incorrectly has been fixed.
- The logic in `VoiceGroupEndMarker.UpdateScore` has been corrected
to properly propagate the instruments state forward after a
voice group is collapsed.
4. **User-Friendly Part IDs:**
- As a follow-on improvement, the part IDs (which are exposed in
the REPL) have been changed from their previous pointer-based
representation to short, sequential, human-readable identifiers
(e.g., "part001", "part002").