Old 12-30-2018, 05:08 PM   #1
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 2,790
Default SetProjExtState when quitting Reaper.

Hi,

I guess this is a bug - as it doesn't really make any sense to work this way.

When you have a deferred script running when you close Reaper - and choose the save option on the dialog that pops up (if the project is dirty) - the quit routine runs ok for the running script - but any changes made in the quit routine to the project ext state do not save with the project. I'm assuming the project is perhaps saved before the quit routine for the script is run.

I would guess this is not preferred behaviour? If a script is set to write data to the project external state when the script is quit - then I'd assume this should happen - and it gets saved with the project. This doesn't happen in the circumstance I described above.

It works fine if you manually close the script (not whilst quitting Reaper) - the project ext state data is written to the project file fine in this case.

The problem I have with this is that my script's data is saved in a separate datafile - but I use the project state to store the filename of the datafile. However - when Reaper is quit whilst the script is still running - the script writes the data to the datafile ok - but then tries to store the latest datafile name in project ext state - but it doesn't get saved with the project - so when reloading the script - it loads an old datafile instead.

I cannot find a work around for this problem.

I have tested this behaviour with a dedicated script - which simply writes a known random number into the project state and an external file when the script quits. The external file always shows the latest random number when I quit Reaper with the script running - but the project ext state always shows an older number - never the last one.

Any thoughts?

Thanks,
Leon.

Win10 64bit - Reaper 64bit - testing latest dev release - but as far as I know - it has been working this way since forever.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 01-06-2019, 04:39 AM   #2
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 331
Default

Following this with falcon eyes!
__________________
ToDoList MusicMath Donation Mark4celeste Frid i ditt hjärta Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 01-11-2019, 06:51 AM   #3
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 690
Default

Could this be solved with a Main_SaveProject in the atexit-function? Or would this lead to other unforseen behavior?
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-11-2019, 01:11 PM   #4
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 2,790
Default

Quote:
Originally Posted by mespotine View Post
Could this be solved with a Main_SaveProject in the atexit-function? Or would this lead to other unforseen behavior?
I don't think that would work unfortunately. There's no way of telling whether the save as dialog was answered yes or no. In the case of No (do not save project) - my script does not want to be saving it's data.

And when simply closing the script manually (using the X) - we don't want to be saving the project - as the user may decide to discard the changes.

This is where the main problem lies - I have a system which uses a 'temporary' save file, and a 'non-temporary' one. I can detect when the user has hit save in the project when the script is running - triggering my script to save a 'non-temporary' save file.

But when the script is simply closed - it will save a 'temporary' save file - as at this point - there is no way of telling whether the user is going to save the project file or not. If they do not - then the user should be able to load the script with the correct version of the save data.

There's a lot more to it than just this - but I've found (or know) solutions to every problem so far except that if my script is running and the user closes Reaper - and then selects Yes to the save data dialog - my script saves the data - but the project cannot get updated with the correct filename to load up as it seems to not save the project data once I've set the project state when the script is shut down. So my assumption is that the project saves before any running scripts have had the chance to terminate.

So I think the only solution is to request that the project saves on shutdown - but after all scripts have completed termination (and have been able to set any data in the project state).

EDIT: Your suggestion might work now I've thought harder about it - if I first do a check in the at-exit function to see if the project is dirty or not - it can try to resave the project if it is not dirty (assuming the project has been saved first - then it shouldn't be dirty). This might work and might not produce any unwanted side-effects - I'll try it out.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal

Last edited by lb0; 01-11-2019 at 04:33 PM.
lb0 is offline   Reply With Quote
Old 01-13-2019, 06:37 AM   #5
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 2,790
Default

Quote:
Originally Posted by mespotine View Post
Could this be solved with a Main_SaveProject in the atexit-function? Or would this lead to other unforseen behavior?
Hi Mespotine,

I had a chance to test this out - and unfortunately it just ends up wiping the project (rpp) file with a completely blank project (when quitting reaper and choosing Save from the dialog). I assume because Reaper has already cleared out all of the tracks etc before the scripts quit routine is run. Interestingly though - it still recognizes the current project name in order to save over it.

So my bug report still stands

I really hope it can be looked into sometime by the Reaper devs.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 01-13-2019, 04:40 PM   #6
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 690
Default

Could you successfully check, if the project was saved(clean) or unsaved(dirty) when the atexit-function is executed?

If you can find that out, it would be possible to write it into the rpp-file directly, even though it has been closed already.
If yes, I'll add that feature on my todo-list for the Ultraschall-API.
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-13-2019, 04:58 PM   #7
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 2,790
Default

Quote:
Originally Posted by mespotine View Post
Could you successfully check, if the project was saved(clean) or unsaved(dirty) when the atexit-function is executed?

If you can find that out, it would be possible to write it into the rpp-file directly, even though it has been closed already.
If yes, I'll add that feature on my todo-list for the Ultraschall-API.
This I'd have to do further testing on to confirm - but it seems so. It certainly picked up that the project was not dirty in order to trigger the resave. But whether this is the default return due to no project being open - I don't know.

What would happen if you were simply closing the script GUI (of a saved (clean) project) - because this would still trigger the attempt to write to the RPP file. It shouldn't matter whether it succeeds or not in this case - just avoid errors writing to a potentially open rpp file... I guess it only needs to write the value in should it be incorrect anyway - thus possibly avoiding any issue.

...a quick test suggests you can rename an open rpp file - so I guess there is no locking happening on the actual file normally.

Thanks for the suggestion - I'll give it a go. My only worry is that of additional time to find the key in a potentially large file - but a second or two hopefully will not be an issue.


Ideally - I still think Reaper should close any open scripts and run their quit routines before potentially saving the project (when Reaper is quitting). To me - this simply makes more sense.

But I think your way of thinking might just work - so thank you again. I'll report back when I've had a chance to try it out.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 01-13-2019, 05:47 PM   #8
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 690
Default

Quote:
Originally Posted by lb0 View Post
Ideally - I still think Reaper should close any open scripts and run their quit routines before potentially saving the project (when Reaper is quitting). To me - this simply makes more sense.
I'm with you on that. Or at least addition of a function onprojectexit(ReaProject proj) as sometimes, running the atexit-function should happen as the very last thing before Reaper is quitting, even after all projects are closed already.

An onprojectexit(ReaProject proj)-function should be run before the project "proj" is closed.
__________________
Ultraschall-API: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs for Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-14-2019, 02:10 AM   #9
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 2,790
Default

Quote:
Originally Posted by mespotine View Post
I'm with you on that. Or at least addition of a function onprojectexit(ReaProject proj) as sometimes, running the atexit-function should happen as the very last thing before Reaper is quitting, even after all projects are closed already.

An onprojectexit(ReaProject proj)-function should be run before the project "proj" is closed.
yep - that would be the neatest solution which would give greatest control over how a script handles a Reaper project closing. But I'm not aware of any other 'interrupt' style function calls in Lua Reascript - maybe there's a reason for this - I've no idea. Hopefully something like this can be implemented.
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 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 06:55 PM.


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