Old 11-24-2020, 09:22 AM   #1
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 451
Default EEL floats inaccuracy?

Hello again. :-)


I've found that the EEL variables can be off on their math. For example, I was testing a script that aligned split items to the grid, by calculating what time position it would be and moving them there.


But I noticed close up that the items were off the grid. Being pedantic about these kind of things I was quite annoyed the items were not lining up. And thought my math was slightly off but couldn't see where.


I decided to test with a simple tempo of 120, where each measure is exactly 2 seconds and each beat 0.5 seconds. By calculating a time position as it went along and moved the items to that place. 0.5 is a nice easy number to work with, 0.5 + 0.5 = 1.0 and 2.0 plus 2.0 is 4.0.



Or so I thought! Even with a simple 120 BPM I found the numbers didn't add up to exactly where they should be. I had to snap my time positions with SnapToGrid. Huh.


Is this normal? I realise there is a limited amount of precision, especially with time values of even integer BPM, but expected a simple addition of 0.5 to be perfect. I didn't expect the need to do it the "old fashioned" way using upscaled integers then downscaling them to floats. I tend to methodically halve a value by dividing it into 2 over multiplying it by 0.5, both for accuracy and because floats weren't a luxury I grew up with. But with EEL even simple math is not working for me as it should.


Did I miss something? Carrying the one. Setting that decimal point. :-D
Hypex is offline   Reply With Quote
Old 11-24-2020, 03:51 PM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Could you post an example of code, that shows this behavior?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 11-25-2020, 09:02 AM   #3
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 451
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Could you post an example of code, that shows this behavior?

I knew this would happen. Well this is embarrassing. I did some more tests and this time all the items aligned to the grid. It surely can't be random. But as an example this code would be replicating what I was doing. It takes a set of items, selected in this case, and aligns each to the grid. This uses a pre set tempo of 120, starts at time 0 and assumes each item is one measure each in length. I've also tested with BPM of 115, 130, and going down to the beat. Now it all matches up. I don't know what is going on.



Code:
       
function main() 
(
    Time = 0;
    BPM = 120;
    BeatsPerBar = 4;
    Seconds = BeatsPerBar * 60;
    BPMTime = Seconds / BPM;
  
    i = 0;  
    while(i < CountSelectedMediaItems(0)) 
    (
        Item = GetSelectedMediaItem(0, i);
        SetMediaItemPosition(Item, Time, 0); 
        
        Time += BPMTime;
        
        i += 1;
    );

);

main();
Hypex is offline   Reply With Quote
Old 11-25-2020, 03:22 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

Quote:
Originally Posted by Hypex View Post
I knew this would happen. Well this is embarrassing. I did some more tests and this time all the items aligned to the grid.
In Germany, this is called the "Vorführeffekt" (literally translated to "presentation-effect".

__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 11-25-2020, 07:46 PM   #5
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 451
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
In Germany, this is called the "Vorführeffekt"

Then I think I have been "Vorführeffekted".
Hypex 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 08:37 AM.


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