Skip to content

Fix Sequential Note Playback in Simple Tuplet Block#4660

Closed
Ganasekhar-gif wants to merge 5 commits intosugarlabs:masterfrom
Ganasekhar-gif:fix-simple-tuplet-sequential-playback
Closed

Fix Sequential Note Playback in Simple Tuplet Block#4660
Ganasekhar-gif wants to merge 5 commits intosugarlabs:masterfrom
Ganasekhar-gif:fix-simple-tuplet-sequential-playback

Conversation

@Ganasekhar-gif
Copy link

@Ganasekhar-gif Ganasekhar-gif commented Apr 28, 2025

fix: #4633

Summary:
This PR addresses the issue with the playback behavior of the Simple Tuplet Block where notes would overlap instead of playing sequentially. The change ensures that notes in a tuplet are played in the correct order, one after another, preserving the intended timing and rhythm.

Changes:
Updated the playback logic for the Simple Tuplet Block to ensure notes are played sequentially rather than simultaneously.
Modified the line in the code where note playback timing is calculated, changing noteBeatValue * arg0 to noteBeatValue to ensure proper note separation.

Testing:
Before: The notes overlapped and sounded as if played together.
After: Notes are now played sequentially, with proper timing between each note.

Attached are the before and after video clips demonstrating the issue and the fix:
Before Changes(original):
https://github.com/user-attachments/assets/e2f8bfe7-6b9e-48e1-b0c1-b8d21bdad66c

After Changes:
https://github.com/user-attachments/assets/f08ac50b-54e2-4ec9-93f8-37a5bdff1e3d

This fix improves the behavior of the Simple Tuplet Block and ensures the correct sequential playback of notes.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ganasekhar-gif
Copy link
Author

Hi @therealharshit ,
Could you please take a look at this PR when you get a chance? I’ve made the necessary changes. Let me know if anything else is needed. Thanks!

@therealharshit
Copy link
Member

Well I still can't distinguish between the notes.
Video: tuplet.webm

You can see in the logs all the notes are sent to synth at the same time.
Logs: 7synthutils.js:1756 0 C2 0.19047619047619047 kick drum null null false 0

And I wouldn’t recommend changing any parameters without a clear understanding of the potential side effects, as it could have ramifications beyond this usage. If this change is necessary, it should be thoroughly tested to ensure it doesn't introduce regressions elsewhere.

BTW you are on the right track, keep going.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ganasekhar-gif
Copy link
Author

Ganasekhar-gif commented Apr 30, 2025

hi @therealharshit
Thank you for the feedback!

I've updated the code to ensure that each note in the tuplet is now played sequentially rather than simultaneously. Specifically, I modified the delay calculation logic so that each tuplet note's delay is based on its position within the group. This allows the notes to be sent to the synth with staggered timing, making them more distinguishable when played.

I understand your concern about changing parameters that might affect other parts of the system. The change I made currently applies only to the tuplet playback logic. However, I’d appreciate your input on whether this delay logic might be used elsewhere in other blocks or affect shared timing behavior across the app.

Could this potentially introduce conflicts or regressions in other features, or is the delay logic isolated enough to be safe for this case?

Happy to run further tests or adjust the implementation as needed—thanks again for your guidance!

@therealharshit
Copy link
Member

I made a code review, and rather than just changing the parameter I suggest you to find the reason behind this.
I can still hear it playing weirdly.

__callback = null;
}

const delay = i * beatValue * 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unused declaration.

TONEBPM / tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM;

const beatValue = bpmFactor / noteBeatValue / arg0;
const beatValue = noteBeatValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beatValue is used as a parameter and you have updated it.

}

const noteBeatValue = (1 / arg1) * activity.turtles.ithTurtle(turtle).singer.beatFactor;
const totalDuration = (1 / arg1) * activity.turtles.ithTurtle(turtle).singer.beatFactor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just changed the variable name.

@Ganasekhar-gif
Copy link
Author

Thank you for the detailed review!

You're right — I had only renamed the variable without addressing the root issue. I'll take a deeper look into how beatValue is used in the playback chain and try to identify why the tuplet notes are being triggered simultaneously.

I'll investigate whether the delay scheduling logic or beat factor application is contributing to this behavior and see how we can stagger the notes properly without unintended side effects.

Appreciate the guidance — I’ll follow up with a more thorough fix soon!

@Ganasekhar-gif
Copy link
Author

Ganasekhar-gif commented May 2, 2025

Hi @therealharshit ,

I’ve made the necessary changes to address the overlapping notes issue in the Simple Tuplet block. I’ve not introduced any new variables—just reused and properly applied the existing beatValue to ensure accurate timing and sequencing.

Here’s the updated behavior demonstration using 7 notes with a 1/4 note value:
https://github.com/user-attachments/assets/428fd351-6362-4f27-a89b-ea528d7608a7

Could you please review the video and confirm if this resolves the issue as expected ?
If not, I’d appreciate your guidance on what the expected output behavior should be, so I can align the behavior accordingly.

Thanks!

@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2025

✅ All Jest tests passed! This PR is ready to merge.

Copy link
Member

@therealharshit therealharshit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the notes are not in sequence. Please refer to console log and you can figure out what's the issue.

const bpmFactor = TONEBPM / tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM;

const beatValue = bpmFactor / noteBeatValue / arg0;
const beatValue = (noteBeatValue / arg0) * (TONEBPM / bpmFactor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the logic behind this change.

@Ganasekhar-gif
Copy link
Author

Hi @therealharshit ,

Following up on my previous commits to the STupletBlock, I've made further changes to address the issue where all notes were previously being sent to the synth simultaneously without any delay between them. The latest update properly introduces a delay between each note so they are now played sequentially.

📹 Video demo: https://github.com/user-attachments/assets/9c4208b4-6ee3-4536-aea9-331d7e2625d9

Could you please confirm if this behavior is now correct?
Specifically:
• For a 7 1/4 block, should the 7 notes be played sequentially over 4 seconds total?
• Is this now working as expected?
• If not, could you please clarify what the expected timing and sequencing should be for a 7 1/4 or similar tuplet?

Previously, all notes were sent simultaneously due to a lack of proper timing. I've now fixed that by introducing per-note delays based on the total beat duration. I'm not committing the change yet—just sharing this to validate the behavior and avoid regressions elsewhere.

Thanks for your time and guidance!

@Ganasekhar-gif
Copy link
Author

Still the notes are not in sequence. Please refer to console log and you can figure out what's the issue.

I’m currently testing the changes locally on my development server, and since I'm not connected to the production build or GitHub Pages deployment, I don't have access to the console logs you’re referring to.

If you could please share any relevant logs or point out the specific issue visible there, it would really help me debug further and ensure the block behaves correctly.

@Ganasekhar-gif
Copy link
Author

Hi @therealharshit,
Just a quick follow-up on the tuplet timing update I shared earlier. When you get a chance, could you please take a look and let me know if the current behavior aligns with what’s expected? I'd like to make sure everything looks good before finalizing the changes.

Appreciate your time — thanks again!

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

1 similar comment
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ganasekhar-gif Ganasekhar-gif closed this by deleting the head repository May 26, 2025
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.

Simple Tuplet block playing all the note simultaneously

2 participants