Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Last active Oct 1, 2021
Embed
What would you like to do?
Custom ReaScripts Preset Files

ReaScript Preset File

Documentation

Concept

Preset script files allow you to modify main variables and functions from a script file without modifying its source, so that your modifications will be preserved even if the parent script is updated by its developer. It only works with scripts written with this concept in mind.

For User

  1. Create a new Preset script file next to the Parent script file of your choice. You can name it whatever you want. You can do it via REAPER Actions windowNew Action button → New ReaScript menu.
  2. Copy the Preset script.lua content. For that, you can click here, and do CTRL/CMD+A to select all text, and then do CTRL/CMD+C to copy the code.
  3. Paste the code into the Preset script file via the opened IDE (code editor) window.
  4. Copy parent script file name and paste it to the User Config Area 1/2 section of the preset script.
  5. Open the Parent script file into a code editor. It can be REAPER IDE, via Actions windowEdit Action button → ReaScript IDE menu.
  6. Copy parent script User Config Area variables and paste to the User Config Area 2/2 section of the preset script over the template variables.
  7. Alter the User Config Area 2/2 variables in the preset script as you want.
  8. Save your Preset script file (CTRL/CMD+S if done via REAPER IDE).

The preset script is now ready to use.

For Devs

  1. Wrap main code in a Init() function as in Parent script.lua.
  2. Add boolean to prevent running Init() directly if the script is called by preset script.
  3. Have a User Config Area at top of the script.
  4. Prevent saving last input if necessary (for script with GUI) so that this feature stay for main script (not the preset, which usually will not have any popup).
--[[
* ReaScript Name: Parent script
* About: For devs
* Author: X-Raym
* Author URI: https://www.extremraym.com
* Repository: X-Raym/REAPER-ReaScripts
* Licence: GPL v3
* REAPER: 5.0
* Version: 1.0
--]]
-- USER CONFIG AREA ------------------------------------------------------
-- Typical global variables names. This will be out global variables which could be altered in the preset file.
popup = false
console = false
-------------------------------------------------- END OF USER CONFIG AREA
function Init() -- The Init function of the script.
end
if not preset_file_init then -- If the file is run directly, it will execute Init(), else it will wait for Init() to be called explicitely from the preset scripts (usually after having modified some global variable states).
Init()
end
--[[
* ReaScript Name: Name of the Original Script - Preset 1 (or any any you want)
* About: Edit the User Config Areas to make it work.
* Author: X-Raym
* Author URI: https://www.extremraym.com
* Licence: GPL v3
* REAPER: 5.0
* Version: 1.0
--]]
-- USER CONFIG AREA 1/2 ------------------------------------------------------
-- Dependency Name
local script = "X-Raym_Set selected items position and order.lua" -- 1. The target script path relative to this file. If no folder, then it means preset file is right to the target script.
-------------------------------------------------- END OF USER CONFIG AREA 1/2
-- PARENT SCRIPT CALL --------------------------------------------------------
-- Get Script Path
local script_folder = debug.getinfo(1).source:match("@?(.*[\\|/])")
local script_path = script_folder .. script -- This can be erased if you prefer enter absolute path value above.
-- Prevent Init() Execution
preset_file_init = true
-- Run the Script
if reaper.file_exists( script_path ) then
dofile( script_path )
else
reaper.MB("Missing parent script.\n" .. script_path, "Error", 0)
return
end
---------------------------------------------------- END OF PARENT SCRIPT CALL
-- USER CONFIG AREA 2/2 ------------------------------------------------------
-- 2. Put your variables there, so that it overrides the default ones.
-- You can usually copy the User Config Area variable of the target script. Examples below.
-- Typical global variables names
popup = false
console = false
-------------------------------------------------- END OF USER CONFIG AREA 2/2
-- RUN -------------------------------------------------------------------
Init() -- run the init function of the target script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment