Old 01-31-2017, 01:55 PM   #1
Reaktor:[Dave]
Human being with feelings
 
Reaktor:[Dave]'s Avatar
 
Join Date: Jun 2010
Location: Berlin
Posts: 563
Default Possible to get project samplerate?

I'm using LUA to write my first Reascripts. I've searched the net and the API for a way to get the project samplerate, but there was nothing that caught my eye. Is it possible or could that be added to the API?
Reaktor:[Dave] is offline   Reply With Quote
Old 08-04-2017, 08:44 PM   #2
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 834
Default

Quote:
Originally Posted by X-Raym View Post
For project sample rate you can use parse_timestr_length to see duration of one sample. Then divide one by the value and you should have samplerate !
Code:
ProjectSampleRate = 1 / reaper.parse_timestr_len( 1, 0, 4 )
__________________
Outboarder Scripts
Outboarder is offline   Reply With Quote
Old 08-04-2017, 09:42 PM   #3
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 135
Default

I believe you can get that from the .rpp file with some string parsing (not fun but not that bad as well).

The Project sample rate is defined by the line:

SAMPLERATE 48000 0 0

in which the first number is the sample rate, and the following 2 flags indicate both of the check boxes in the Project Settings Dialogue. First flag = check box to force project sample rate. Second flag = check box to "Force project tempo/time signature changes to occur on whole samples".

EDIT:just saw you mentioned it's your first reascripts. If the concept of how to parse the parameters from the rpp doesn't make that much sense yet just give a shout and I'll try to go into more detail over how I personally do it.
__________________
My Reapack Repo - Reapack Extension
Claudiohbsantos is offline   Reply With Quote
Old 08-05-2017, 04:16 AM   #4
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 834
Default

Quote:
Originally Posted by Claudiohbsantos View Post
I believe you can get that from the .rpp file with some string parsing (not fun but not that bad as well).

The Project sample rate is defined by the line:

SAMPLERATE 48000 0 0

in which the first number is the sample rate, and the following 2 flags indicate both of the check boxes in the Project Settings Dialogue. First flag = check box to force project sample rate. Second flag = check box to "Force project tempo/time signature changes to occur on whole samples".

EDIT:just saw you mentioned it's your first reascripts. If the concept of how to parse the parameters from the rpp doesn't make that much sense yet just give a shout and I'll try to go into more detail over how I personally do it.
That's exactly what I wanted to know (getting parameter from the .rpp file with some string parsing) , please go into more detail
I'll appreciate if you post code with comment.
__________________
Outboarder Scripts
Outboarder is offline   Reply With Quote
Old 08-07-2017, 08:39 PM   #5
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 135
Default

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.
__________________
My Reapack Repo - Reapack Extension
Claudiohbsantos is offline   Reply With Quote
Old 08-07-2017, 10:30 PM   #6
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 834
Default

That's exactly what I'm looking for
Heavy thanks.
__________________
Outboarder Scripts
Outboarder 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 01:59 AM.


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