|
|
|
12-26-2023, 02:57 PM
|
#441
|
Human being with feelings
Join Date: Aug 2020
Posts: 281
|
Quote:
Originally Posted by Sexan
Adjusting fades on right click drag, edge limiting and etc
|
That's something.
|
|
|
02-14-2024, 10:16 AM
|
#442
|
Human being with feelings
Join Date: May 2013
Location: New York
Posts: 781
|
I'm running into some problems using BirdBird's SetRazorTrackRazorEdit and GetRazorEdit functions from the first post in this thread. It seems like the areaStart and areaEnd values from these two functions do not have the same amount of precision as the time values returned by built in api functions.
Here's a quick test script you can use to see what I'm talking about
Code:
--------------------Functions-------------------------
local function Msg(param)
reaper.ShowConsoleMsg(tostring(param).."\n")
end
function GetItemsInRange(track, areaStart, areaEnd)
local items = {}
local itemCount = reaper.CountTrackMediaItems(track)
for k = 0, itemCount - 1 do
local item = reaper.GetTrackMediaItem(track, k)
local pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local length = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local itemEndPos = pos+length
--check if item is in area bounds
if (itemEndPos > areaStart and itemEndPos <= areaEnd) or
(pos >= areaStart and pos < areaEnd) or
(pos <= areaStart and itemEndPos >= areaEnd) then
table.insert(items,item)
end
end
return items
end
function GetEnvelopePointsInRange(envelopeTrack, areaStart, areaEnd)
local envelopePoints = {}
for i = 1, reaper.CountEnvelopePoints(envelopeTrack) do
local retval, time, value, shape, tension, selected = reaper.GetEnvelopePoint(envelopeTrack, i - 1)
if time >= areaStart and time <= areaEnd then --point is in range
envelopePoints[#envelopePoints + 1] = {
id = i-1 ,
time = time,
value = value,
shape = shape,
tension = tension,
selected = selected
}
end
end
return envelopePoints
end
function SetTrackRazorEdit(track, areaStart, areaEnd, clearSelection)
if clearSelection == nil then clearSelection = false end
if clearSelection then
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
--parse string, all this string stuff could probably be written better
local str = {}
for j in string.gmatch(area, "%S+") do
table.insert(str, j)
end
--strip existing selections across the track
local j = 1
while j <= #str do
local GUID = str[j+2]
if GUID == '""' then
str[j] = ''
str[j+1] = ''
str[j+2] = ''
end
j = j + 3
end
--insert razor edit
local REstr = tostring(areaStart) .. ' ' .. tostring(areaEnd) .. ' ""'
table.insert(str, REstr)
local finalStr = ''
for i = 1, #str do
local space = i == 1 and '' or ' '
finalStr = finalStr .. space .. str[i]
end
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', finalStr, true)
return ret
else
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
local str = area ~= nil and area .. ' ' or ''
str = str .. tostring(areaStart) .. ' ' .. tostring(areaEnd) .. ' ""'
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', str, true)
return ret
end
end
function SetEnvelopeRazorEdit(envelope, areaStart, areaEnd, clearSelection, GUID)
local GUID = GUID == nil and GetGUIDFromEnvelope(envelope) or GUID
local track = reaper.Envelope_GetParentTrack(envelope)
if clearSelection then
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
--parse string
local str = {}
for j in string.gmatch(area, "%S+") do
table.insert(str, j)
end
--strip existing selections across the envelope
local j = 1
while j <= #str do
local envGUID = str[j+2]
if GUID ~= '""' and envGUID:sub(2,-2) == GUID then
str[j] = ''
str[j+1] = ''
str[j+2] = ''
end
j = j + 3
end
--insert razor edit
local REstr = tostring(areaStart) .. ' ' .. tostring(areaEnd) .. ' ' .. GUID
table.insert(str, REstr)
local finalStr = ''
for i = 1, #str do
local space = i == 1 and '' or ' '
finalStr = finalStr .. space .. str[i]
end
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', finalStr, true)
return ret
else
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
local str = area ~= nil and area .. ' ' or ''
str = str .. tostring(areaStart) .. ' ' .. tostring(areaEnd) .. ' ' .. GUID
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', str, true)
return ret
end
end
function GetRazorEdits()
local trackCount = reaper.CountTracks(0)
local areaMap = {}
for i = 0, trackCount - 1 do
local track = reaper.GetTrack(0, i)
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
if area ~= '' then
--PARSE STRING
local str = {}
for j in string.gmatch(area, "%S+") do
table.insert(str, j)
end
--FILL AREA DATA
local j = 1
while j <= #str do
--area data
local areaStart = tonumber(str[j])
local areaEnd = tonumber(str[j+1])
local GUID = str[j+2]
local isEnvelope = GUID ~= '""'
--get item/envelope data
local items = {}
local envelopeName, envelope
local envelopePoints
if not isEnvelope then
items = GetItemsInRange(track, areaStart, areaEnd)
else
envelope = reaper.GetTrackEnvelopeByChunkName(track, GUID:sub(2, -2))
local ret, envName = reaper.GetEnvelopeName(envelope)
envelopeName = envName
envelopePoints = GetEnvelopePointsInRange(envelope, areaStart, areaEnd)
end
local areaData = {
areaStart = areaStart,
areaEnd = areaEnd,
track = track,
items = items,
--envelope data
isEnvelope = isEnvelope,
envelope = envelope,
envelopeName = envelopeName,
envelopePoints = envelopePoints,
GUID = GUID:sub(2, -2)
}
table.insert(areaMap, areaData)
j = j + 3
end
end
end
return areaMap
end
--------Run---------------------------
cur_pos = reaper.GetCursorPosition()
track = reaper.GetTrack(0, 0)
SetTrackRazorEdit(track, cur_pos, cur_pos+1)
razor_areas = GetRazorEdits()
razor_start = razor_areas[1].areaStart
razor_end = razor_areas[1].areaEnd
Msg("Cursor Position = "..cur_pos)
Msg("Razor Area Start = "..razor_start)
if cur_pos == razor_start then Msg("The cursor position is the same as the start of the razor area") end
if cur_pos < razor_start then Msg("The cursor position is less than the start of the razor area") end
if cur_pos > razor_start then Msg("The cursor position is greater than the start of the razor area") end
Make sure your grid and/or snapping is turned off, move your edit cursor to a random position with the mouse then run this script. It will create a one second long razor edit starting at the cursor and show the values of both the cursor position and the razor area start in the console, and will report whether or not the two values are equal. In theory the two values should always be equal, and sometimes, if you're lucky with where you placed the cursor they are. More often then not though, the script reports that the two values are different despite the numerical readouts on the console appearing exactly the same.
Can anyone explain why this is happening? Is there a fix for this or is this just a bug with the way the api handles razor edits?
|
|
|
02-14-2024, 11:17 AM
|
#443
|
Human being with feelings
Join Date: Mar 2019
Posts: 428
|
Quote:
Originally Posted by RobinGShore
Can anyone explain why this is happening? Is there a fix for this or is this just a bug with the way the api handles razor edits?
|
What is your REAPER version? While the code there is old (and probably should be rewritten), the precision issue was adressed by the devs in v6.57:
Code:
+ ReaScript: increase precision of razor edit start/end position as returned by GetSetMediaTrackInfo("P_RAZOREDITS")
In general, when comparing floating values directly, checking if the absolute difference is smaller than a set threshold value would be enough for most tasks where you need to just check for equality. (math.abs(a - b) < very_small_value)
Last edited by BirdBird; 02-14-2024 at 11:25 AM.
|
|
|
02-14-2024, 03:04 PM
|
#444
|
Human being with feelings
Join Date: May 2013
Location: New York
Posts: 781
|
Quote:
Originally Posted by BirdBird
What is your REAPER version? While the code there is old (and probably should be rewritten), the precision issue was adressed by the devs in v6.57:
|
I'm on the latest version, 7.11. Seems like perhaps it wasn't completely fixed? I'd love to know though if anyone else can confirm what I'm seeing. I'm very much a novice when it comes any sort of programming, so it could be that I'm just doing something dumb.
Quote:
In general, when comparing floating values directly, checking if the absolute difference is smaller than a set threshold value would be enough for most tasks where you need to just check for equality. (math.abs(a - b) < very_small_value)
|
This is definitely helpful for some stuff, but I also need to be able to do greater than and less than comparisons between razor edits and item edges. I think this might be enough of hint though for me to get something that works, so thank you!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:28 PM.
|