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

Reply
 
Thread Tools Display Modes
Old 03-17-2024, 02:05 PM   #1
daniellumertz
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
Code:
 
---@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])
end
  
---@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)
    end))
end

---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 )
end

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
Old 03-17-2024, 06:54 PM   #2
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,801
Default

Fixing, thanks!
Justin is offline   Reply With Quote
Old 04-03-2024, 11:15 AM   #3
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,024
Default

Thanks for fixing this Justin!

Changing the sample rate via scripts seems to suffer from the same thing !
It just actually apply if the user opens/closes the project config window. Start recording wont change the samplerate

Code:
 
        local rate_val = 96000
        reaper.GetSetProjectInfo( proj, 'PROJECT_SRATE_USE', 1, true )
        reaper.GetSetProjectInfo( proj, 'PROJECT_SRATE', rate_val, true )
daniellumertz 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 11:39 PM.


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