Skip to content

fix: correct fractional_beat calculation to use finest level#33

Merged
jon-myers merged 3 commits intomainfrom
fix-fractional-beat
Sep 9, 2025
Merged

fix: correct fractional_beat calculation to use finest level#33
jon-myers merged 3 commits intomainfrom
fix-fractional-beat

Conversation

@jon-myers
Copy link
Contributor

Summary

Fixed the fractional_beat calculation to always represent position within the finest hierarchical level unit (between pulses), regardless of the reference_level parameter.

Problem

The previous implementation incorrectly calculated fractional_beat relative to different hierarchical levels depending on the reference_level parameter. This caused confusing results where:

  • meter.get_musical_time(0.125) returned C0:0.2+0.500 instead of C0:0.2+0.000
  • meter.get_musical_time(0.0625) returned C0:0.1+0.250 instead of C0:0.1+0.000
  • meter.get_musical_time(0.03125) returned C0:0.0+0.125 instead of C0:0.0+0.500

Solution

  • fractional_beat is now always calculated as position between pulses (finest level)
  • reference_level only affects hierarchical_position truncation, not fractional calculation
  • This provides consistent, predictable behavior across all reference levels

Changes

  • Simplified get_musical_time() to use unified fractional_beat calculation
  • Added test case with Jon's specific examples to prevent regression
  • Updated existing tests to match corrected behavior
  • All 30 tests now pass ✅

Test Results

30 passed, 4 warnings in 0.08s

🤖 Generated with Claude Code

The fractional_beat should always represent the position within the finest
hierarchical level unit (between pulses), regardless of the reference_level
parameter. The reference_level only affects hierarchical_position truncation.

Fixed examples:
- meter.get_musical_time(0.125) now returns C0:0.2+0.000 (was C0:0.2+0.500)
- meter.get_musical_time(0.0625) now returns C0:0.1+0.000 (was C0:0.1+0.250)
- meter.get_musical_time(0.03125) now returns C0:0.0+0.500 (was C0:0.0+0.125)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…havior

- Fix test timing values to land between pulses when expecting fractional values
- Update expected fractional_beat values to match pulse-based calculation
- Update test comments to reflect corrected behavior where fractional_beat
  is always between pulses regardless of reference_level

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

📦 Test Package Built Successfully!

This PR has been automatically built and uploaded to TestPyPI for testing.

🔗 TestPyPI Link: https://test.pypi.org/project/idtap/

To test this version:

pip install --index-url https://test.pypi.org/simple/ idtap

✅ All tests passed and package builds successfully.

…implementation

- Clarify that fractional_beat is ALWAYS calculated between pulses (finest level)
- Remove reference level recalculation from Step 5
- Simplify algorithm to remove complex helper functions
- Update test case comments to reflect pulse-based calculation
- Fix test case expected values to match corrected behavior
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2025

📦 Test Package Built Successfully!

This PR has been automatically built and uploaded to TestPyPI for testing.

🔗 TestPyPI Link: https://test.pypi.org/project/idtap/

To test this version:

pip install --index-url https://test.pypi.org/simple/ idtap

✅ All tests passed and package builds successfully.

@jon-myers jon-myers merged commit 74b1303 into main Sep 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant