Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to get parameter from reaper RPP file. Reascript API
-- this function reads the RPP and stores it as chunks of 8 Kb in a table. This is more efficient than reading the file line by line (or at least I believe it is, please someone prove me wrong if you disagree =])
function readProjFileToTable(projFile)
local f = assert(,"r"))
local projectChunks = {}
local BUFSIZE = 2^13 -- 8K
while true do
local projectChunk, rest = f:read(BUFSIZE, "*line")
if not projectChunk then break end
if rest then projectChunk = projectChunk .. rest .. '\n' end
return projectChunks
-- given a table with the projectfile and the parameter you are looking for, returns the ful value of the parameter, which is the line of the parameter - parameter name (there are exceptions to this in the RPP file that would have to be addressed individually with this code)
function getParameterFromProjectChunks(param,projectChunks)
local projectChunks = readProjFileToTable(projFile)
for i,chunk in ipairs(projectChunks) do
for line in string.gmatch(chunk,"([^\r\n]*)[\r\n]") do
local value = string.match(line,param.." (.*)")
if value then return value end
------------- Main Execution:
local _,projFile = reaper.EnumProjects(0,"") -- gets path to .RPP
--[[ In the RPP, the SAMPLERATE line has 3 values:
(example from rpp:)
SAMPLERATE 48000 1 0
48000 is the samplerate
1 represents the checkbox "Project sample rate:" in the Project Settings.
0 represents the checkbox "Force project tempo/time signature...." in the Project Settings
The following call will get all three values as a string: ]]
local samplerateFromRPP = getParameterFromProjectChunks("SAMPLERATE",readProjFileToTable(projFile))
-- Extract first number from the SAMPLERATE value from the RPP, which is the samplerate.
local samplerate = string.match(samplerateFromRPP,"^(%d+)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.