Old 01-18-2019, 05:48 AM   #1
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 600
Default Read and write from file on disk

Hi

Is it possible (I presume it must be?) to allow a Reaper script to create, write to, read from and delete a small file on the hard disk?

I can think of some uses for this, such as storing the state of an array or variable in a file (somehow! not sure of what form the data would need to take) so that a script can run multiple times, but always make decisions based on the state of events when it was run the first time.

There may be another way to do this, but any pointers/resources would be welcome.

Thanks
Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 05:58 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,467
Default

Yes, all ReaScripts (Lua, Python and ELL) can read and write files (except if run with restricted permissions).

https://www.lua.org/manual/5.3/manual.html#6.8
https://www.lua.org/manual/5.3/manua...#pdf-os.remove

There's also REAPER's temporary, permanent and project extstates.

Last edited by cfillion; 01-18-2019 at 06:06 AM.
cfillion is offline   Reply With Quote
Old 01-18-2019, 06:29 AM   #3
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 600
Default

Ok, ExtState sounds like it might be the way to go, as this is only for temporary use within an edit, and would never need to be recalled after the project was closed etc.

Is there a resource to learn about this please?

Thanks
andyp24 is offline   Reply With Quote
Old 01-18-2019, 06:39 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,467
Default

Search for "ExtState" in the ReaScript documentation (Help menu in REAPER). The functions are SetExtState, HasExtState, GetExtState and DeleteExtState. An extstate is identified by a section and key of your choice. The section is usually chosen to be unique to the script and the key to identify the data being stored. Set the "persist" argument to false in order to have the extstate stored only until REAPER is closed.
cfillion is offline   Reply With Quote
Old 01-18-2019, 06:46 AM   #5
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 600
Default

Yeah, I see them in the API documentation, but as someone very new to scripting of any kind, I was hoping for an idiot's guide :-)

I guess I'll just experiment and see what I can make it do.

Thanks
Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 07:54 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,416
Default

You should consider inspecting already made script, you have tons of exemple of file reading and exporting there :P

Also check sitepoint tutorial about Lua I/O, very well done doc.
X-Raym is offline   Reply With Quote
Old 01-18-2019, 08:02 AM   #7
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 600
Default

I will, thanks - not at my Reaper setup right now though.

But how do I know which scripts to look at? :-)

Thanks for the other suggestion too.

Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 09:34 AM   #8
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 725
Default

Toy around with them.

Type in the function and put into the parameters, what they expect. If they fail, they will tell you that and you can learn from that.

In your case: try to set(reaper.SetExtState) an extstate and successfully get it(reaper.GetExtState).

like:

my_new_extstate_section = "sectionname"
my_new_extstate_key = "keyname"
my_new_extstate_value = "I am the value. Try to get or I will feel abondaned in here."

reaper.SetExtState(my_new_extstate_section, my_new_extstate_key, my_new_extstate_value, false)

extstate_value = reaper.GetExtState("sectionname", "keyname")


Toy around with it, until it does, what you want and move on to the next step. And don't be afraid of mistakes. This is the fastest way of learning the basics of ReaScript and Lua.


A great resource is also X-Raym's tutorial on ReaScript:

https://www.extremraym.com/en/reascript-basics-part1/
__________________
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-18-2019, 09:52 AM   #9
andyp24
Human being with feelings
 
Join Date: Mar 2016
Posts: 600
Default

Thanks mespotine

I will do just that - try some very simple scripts that do nothing but read and write various things to and from ExtState until I figure it out...

And thanks for the other recommendation, but already 99% of everything I know about ReaScript comes from X-Raym's video series :-)

That's what got me started and convinced me I might actually be able to understand enough to do something useful with it!

Andy
andyp24 is offline   Reply With Quote
Old 01-18-2019, 09:55 AM   #10
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 725
Default

So then, browse through the scripts, that you can download via ReaPack. There are many of them and they are good
__________________
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
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 02:11 PM.


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