Old 06-01-2020, 07:02 PM   #1
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default Philosophical question: Overtaking of Reaper's own PreventUIRefresh?

I'm currently working on some functions for Ultraschall-API, who allow making PreventUIRefresh more stable.

Reason is, that if you have a function, which does

reaper.PreventUIRefresh(-1)

and another function who makes

reaper.PreventUIRefresh(1)

after each other, they cancel each other out.
This can be a problem, if you have in your code reaper.PreventUIRefresh(-1) and a Ultraschall-API function reaper.PreventUIRefresh(1). Both want to prevent UI-refresh but in the end, everything in my Ultraschall-API-function will be visible, as it canceled out the PreventUIRefresh from your script.

Now here's the thing: I can overtake this function to manage it fully independent of what you pass to the function as parameter. That means, I overwrite the Reaper-function with my one, which counts fully on its own and tries to prevent this cancellation for better stability.

And here's my question from an ethical and philosophical point: assuming I can pull it off: shall I do it or do you prefer Reaper's own function to be untouched?
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-01-2020, 07:11 PM   #2
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 10,951
Default

This is why PreventUIRefresh() keeps an internal counter. You should always call PreventUIRefresh(1) to initiate and PreventUIRefresh(-1) to end, not the other way around. That will ensure that refresh remains in the prevent state until everyone who called to initiate it has called to end it.
schwa is offline   Reply With Quote
Old 06-01-2020, 07:16 PM   #3
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default

Ah, thanks.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-01-2020, 07:23 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default

@schwa

Would adding a function like:

reaper.GetCurrentUIRefreshCounter()

possible? So I can check in my functions if I need to use PreventUIRefresh in the first place.

That way, I can prevent possible cancellations, when people first subtract and then add by accident. I just like to make my stuff as rock solid as possible without interfering in the code of scripters.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-01-2020, 07:27 PM   #5
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 10,951
Default

If some caller initiates the call with -1, that should be considered a bug. It's like a reference count, designed to be used by multiple callers who don't need to know about the existence of the others.
schwa is offline   Reply With Quote
Old 06-01-2020, 07:32 PM   #6
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default

Quote:
Originally Posted by schwa View Post
If some caller initiates the call with -1, that should be considered a bug. It's like a reference count, designed to be used by multiple callers who don't need to know about the existence of the others.
Sure but I cannot check this happening at all currently so I can not give any feedback to the user of my functions for them to correct it. I can only take care of my own bugs.

Unless I overtake PreventUIRefresh and count an internal counter as well, and if it ever tries to go into negative areas, I throw a Lua-error.

BTW: does PreventUIRefresh check, whether someone tries to go into negative areas currently and prevents that? If not, maybe an error-message or at least no ui-refresh-prevention possible would be good.
So people can not use it wrong, as the first call to PreventUIRefresh(-1) wouldn't prevent UIRefresh at all. That could make coders think about, how to do it correctly rather than continuing the wrong way.

Could break some old scripts though but well...
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-01-2020, 07:38 PM   #7
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 10,951
Default

Our general approach the API is to only lightly check inputs and let bad extensions blow up REAPER. Unless you have a known case of somebody calling this function backwards (the documentation does say "add then remove"), I wouldn't bother changing the internals.
schwa is offline   Reply With Quote
Old 06-01-2020, 07:53 PM   #8
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default

Ok. But nevertheless, a way of getting the current counter would still be helpful for these edgecases. So I can deal with it properly in my functions, even if it's only a problem in a handful of cases.
I spend a lot of time to prevent possible misuses of my functions and I always feel a little brr brr brr, for not having a way to deal with UIRefresh that well.
If I could get the counter, I could deal with it properly.

In the end, it's all about not bothering unsuspecting endusers with unexpected flickerings of their UI just because of edge-cases.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   Reply With Quote
Old 06-01-2020, 07:58 PM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 647
Default

Oh, and are the counters reset after a script finishes? Or can a forgotten PreventUIRefresh(-1) still prevent UI refresh after script is finished?
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is online now   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 09:14 AM.


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