Sure. This is one way of doing it:
on gist (with sintax highlighting to make it more readable)
https://gist.github.com/Claudiohbsan...efcb6b95dab8da
Code:
-- 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(io.open(projFile,"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
table.insert(projectChunks,projectChunk)
end
f:close()
return projectChunks
end
-- 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
end
end
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+)")
To find out which parameter to search for, open an RPP file in a text editor and find the name of the line you want to extract.
I'm not entirely sure this is the most efficient way of parsing the strings as I'm myself pretty new to it, but it work and I don't notice any performance hit for a single parameter like this.