Old 10-08-2020, 08:28 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,680
Default Q: How to calculate the next quantize position?

In a JS FX, I wish to position a note at the next quantized position for that note length. For example a 16th note will be moved to the next 16th beat position (x.00, x.25, x.50, x.75). An 8th triplet will be moved to the next 8T position (x.00. x.333. x.666).

I have come up with this:

Quote:
note_sync = 1/4; // note length
note_pos = floor(beat_position) + (note_sync * ceil((beat_position - floor(beat_position)) / note_sync));


/* explanation of the calculation
beat_position - floor(beat_position) gives the decimal part of the beat position
(beat_position - floor(beat_position)) / note_sync gives the number of note_sync lengths in that decimal part
ceil( ... ) rounds up to the next integer number of note_sync lengths
(note_sync * ceil( ... )) gives the new decimal part of the beat position
floor(beat_position) gives the integer part of ther beat position
floor(beat_position) + (note_sync * ceil( ... )) gives the beat position for the next multiple of the note_sync

Examples:
-- beat position of 24.52 and note_sync of 1/3 (8th triplets) ==> 24.6666
-- beat position of 25 and note_sync of 1/3 (8th triplets) ==> 25
-- beat position of 25.1 and note_sync of 1/4 (16ths) ==> 25.25
-- beat position of 24.52 and note_sync of 3/8 (8ths dotted) ==> 24.75
/**/
Can you improve on this?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...

Last edited by DarkStar; 10-08-2020 at 09:10 AM.
DarkStar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.