Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 03-17-2024, 02:05 PM   #1
Human being with feelings
daniellumertz's Avatar
Join Date: Dec 2017
Location: Brazil
Posts: 2,024
Default GetSetProjectInfo_String Bit Depth and REAPER UI

Updating the bit depth using reaper.GetSetProjectInfo_String(proj, 'RECORD_FORMAT', bit) or reaper.GetSetProjectInfo_String(proj, 'RENDER_FORMAT', bit). Dont change the REAPER UI on the top right

Code to test
---@param data string
---@return string
function EncoderBase64(data)
    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    return ((data:gsub('.', function(x) 
        local r,b='',x:byte()
        for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
        return r;
    end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
        if (#x < 6) then return '' end
        local c=0
        for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
        return b:sub(c+1,c+1)
    end)..({ '', '==', '=' })[#data%3+1])
---@param data string
---@return string
function DecoderBase64(data)
    local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    data = string.gsub(data, '[^'..b..'=]', '')
    return (data:gsub('.', function(x)
        if (x == '=') then return '' end
        local r,f='',(b:find(x)-1)
        for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
        return r;
    end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
        if (#x ~= 8) then return '' end
        local c=0
        for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
        return string.char(c)

---Set the bitdepth of a project
---@param proj project|number|nil 
---@param key string 'RECORD_FORMAT' or 'RENDER_FORMAT'
---@param bitdepth number 8,16,24,32,666 ...
function SetBitDepth(proj, key, bitdepth)
    local _, current = reaper.GetSetProjectInfo_String( proj, key, '', false ) -- about https://mespotin.uber.space/Ultraschall/misc_docs/RENDER_How_RenderCFG-Base64-strings_are_encoded.txt
    local decoded = DecoderBase64(current)
    local d1 = decoded:sub(1,4)
    local d2 = decoded:sub(6)
    local bit = string.char(bitdepth)
    local new_d = d1..bit..d2
    new_d = EncoderBase64(new_d)
    reaper.GetSetProjectInfo_String(proj, key, new_d, true )

local proj = 0
SetBitDepth(proj, 'RECORD_FORMAT', 16)
SetBitDepth(proj, 'RENDER_FORMAT', 16)
Before running :

After running :

But if open / close the project settings / Reaper settings OR start recording it will update:

So I wonder, is this just an UI bug or does REAPER need to Update something. Am I missing some update in the code?
daniellumertz is offline   Reply With Quote

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 10:31 PM.

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