Skip to content

Commit

Permalink
Release Trim left, right or both item edges via mouse and razor v1.4
Browse files Browse the repository at this point in the history
- fixed bug with take envelopes
  • Loading branch information
AZpercussion committed Aug 29, 2024
1 parent 474d943 commit 746cb6c
Showing 1 changed file with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-- @description Trim left, right or both item edges via mouse and razor
-- @author AZ
-- @version 1.3
-- @changelog
-- - fixed bug when stretch markers were blocking the left trim
-- - fixed potential bug with empty takes
-- @version 1.4
-- @changelog - fixed bug with take envelopes
-- @provides [main] az_Trim left, right or both item edges via mouse and razor/az_Open options for az_Trim left, right or both item edges via mouse and razor.lua
-- @link Forum thread https://forum.cockos.com/showthread.php?t=288069
-- @donation Donate via PayPal https://www.paypal.me/AZsound
Expand Down Expand Up @@ -394,13 +392,26 @@ function SetItemEdges(item, startTime, endTime)
if strmarksnum > 0 then
reaper.SetMediaItemTakeInfo_Value(take, 'D_STARTOFFS', offs)
for s = 0, strmarksnum -1 do
local retval, strpos, srcpos = reaper.GetTakeStretchMarker( take, s )
local retval, strpos, srcpos = reaper.GetTakeStretchMarker( take, s )
reaper.SetTakeStretchMarker( take, s, strpos - (startTime-pos)*rate, srcpos )
end
else
reaper.SetMediaItemTakeInfo_Value(take, 'D_STARTOFFS', offs)
end

local takeenvs = reaper.CountTakeEnvelopes(take)
for e = 0, takeenvs -1 do
local env = reaper.GetTakeEnvelope( take, e )
for p = 0, reaper.CountEnvelopePoints( env ) -1 do
local ret, time, value, shape, tens, sel = reaper.GetEnvelopePoint( env, p )
if ret then
time = time - (startTime-pos)*rate
reaper.SetEnvelopePoint( env, p, time, value, shape, tens, sel, true )
end
end
reaper.Envelope_SortPoints( env )
end

end
end
end
Expand Down Expand Up @@ -644,7 +655,7 @@ function GetRazorEdits()
i=i+1
end
end
else
else

---OLD WAY for backward compatibility-------

Expand Down Expand Up @@ -870,7 +881,7 @@ end
--------------------------------------------


function trim_sel_items(side, trimTime)
function trim_sel_items(side, trimTime) --side is 'left' or 'right'
local undoDesc
local iCount = reaper.CountSelectedMediaItems(0)

Expand All @@ -883,43 +894,51 @@ for i=0, iCount-1 do
local iEnd = iPos + reaper.GetMediaItemInfo_Value(item,'D_LENGTH')
local fIn = reaper.GetMediaItemInfo_Value(item,'D_FADEINLEN')
local fOut = reaper.GetMediaItemInfo_Value(item,'D_FADEOUTLEN')
local fInA = reaper.GetMediaItemInfo_Value(item,'D_FADEINLEN_AUTO')
local fOutA = reaper.GetMediaItemInfo_Value(item,'D_FADEOUTLEN_AUTO')

local fInShape = reaper.GetMediaItemInfo_Value(item,'C_FADEINSHAPE')
local fOutShape = reaper.GetMediaItemInfo_Value(item,'C_FADEOUTSHAPE')
local fInCurv = reaper.GetMediaItemInfo_Value(item,'D_FADEINDIR')
local fOutCurv = reaper.GetMediaItemInfo_Value(item,'D_FADEOUTDIR')

if fInA ~= 0 then fIn = fInA end
if fOutA~= 0 then fOut = fOutA end

if iPos < trimTime and trimTime < iEnd then

if side == 'left' then
SetItemEdges(item, trimTime, iEnd)
undoDesc = 'left'

if trimTime < iPos+fIn then
reaper.SetMediaItemInfo_Value(item,'D_FADEINLEN', fIn-(trimTime-iPos))
local param = 'D_FADEINLEN'
if fInA ~= 0 then param = 'D_FADEINLEN_AUTO' end
reaper.SetMediaItemInfo_Value(item, param, fIn-(trimTime-iPos))
reaper.SetMediaItemInfo_Value(item,'C_FADEINSHAPE', fInShape)
reaper.SetMediaItemInfo_Value(item,'D_FADEINDIR', fInCurv)
else
if reaper.GetToggleCommandState(41194) == 1 then fIn = defFlen else fIn = 0 end
--^^--Item: Toggle enable/disable default fadein/fadeout
reaper.SetMediaItemInfo_Value(item,'D_FADEINLEN', fIn)
reaper.SetMediaItemInfo_Value(item,'C_FADEINSHAPE', defFshape)
--reaper.SetMediaItemInfo_Value(item,'D_FADEINDIR', defFshape)
end

elseif side == 'right' then
SetItemEdges(item, iPos, trimTime)
undoDesc = 'right'

if trimTime > iEnd-fOut then
reaper.SetMediaItemInfo_Value(item,'D_FADEOUTLEN', fOut-(iEnd-trimTime))
local param = 'D_FADEOUTLEN'
if fOutA ~= 0 then param = 'D_FADEOUTLEN_AUTO' end
reaper.SetMediaItemInfo_Value(item, param, fOut-(iEnd-trimTime))
reaper.SetMediaItemInfo_Value(item,'C_FADEOUTSHAPE', fOutShape)
reaper.SetMediaItemInfo_Value(item,'D_FADEOUTDIR', fOutCurv)
else
if reaper.GetToggleCommandState(41194) == 1 then fOut = defFlen else fOut = 0 end
--^^--Item: Toggle enable/disable default fadein/fadeout
reaper.SetMediaItemInfo_Value(item,'D_FADEOUTLEN', fOut)
reaper.SetMediaItemInfo_Value(item,'C_FADEOUTSHAPE', defFshape)
--reaper.SetMediaItemInfo_Value(item,'D_FADEOUTDIR', defFshape)
end
end --left/right

Expand Down Expand Up @@ -979,7 +998,7 @@ end
--------------------------

-------START------
CurVers = 1.3
CurVers = 1.4
version = tonumber( reaper.GetExtState(ExtStateName, "version") )

if version ~= CurVers then
Expand Down

0 comments on commit 746cb6c

Please sign in to comment.