Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- if difference between item current and new edge coordinates is greater than the fade length
- -- the original fade length is preserved
- local r = reaper
- function no_undo()
- do return end
- end
- function Error_Tooltip(text, caps, spaced, x2, y2, want_color, want_blink)
- local x, y = r.GetMousePosition()
- local text = caps and text:upper() or text
- local utf8 = '[\0-\127\194-\244][\128-\191]*'
- local text = spaced and text:gsub(utf8,'%0 ') or text
- local x2, y2 = x2 and math.floor(x2) or 0, y2 and math.floor(y2) or 0
- r.TrackCtl_SetToolTip(text, x+x2, y+y2, true)
- if want_color then
- local color_init = r.GetThemeColor('col_tl_bg', 0)
- local color = color_init ~= 255 and 255 or 65535
- if want_blink then
- for i = 1, 100 do
- if i == 1 or i == 40 or i == 80 then
- r.SetThemeColor('col_tl_bg', color, 0)
- elseif i == 20 or i == 60 or i == 100 then
- r.SetThemeColor('col_tl_bg', color_init, 0)
- end
- r.UpdateTimeline()
- end
- else
- r.SetThemeColor('col_tl_bg', color, 0)
- for i = 1, 200 do
- r.UpdateTimeline()
- end
- r.SetThemeColor('col_tl_bg', color_init, 0)
- r.UpdateTimeline()
- end
- end
- r.UpdateTimeline()
- end
- local is_new_value, scr_name, sect_ID, cmd_ID, mode, resol, val, contextstr = r.get_action_context()
- scr_name = scr_name:match('([^\\/]+)%.%w+$')
- local cmd_ID = scr_name:match('left edge') and 41305 or scr_name:match('right edge') and 41311
- local sel_itms_cnt = r.CountSelectedMediaItems(0)
- local err = not cmd_ID and 'wrong script name' or sel_itms_cnt == 0 and 'no selected items'
- if err then
- Error_Tooltip('\n\n '..err..' \n\n', 1,1)
- return r.defer(no_undo) end
- local sel_items = {}
- for i=0, r.CountMediaItems(0)-1 do
- local item = r.GetMediaItem(0,i)
- if r.IsMediaItemSelected(item) then
- sel_items[#sel_items+1] = item
- end
- end
- r.Undo_BeginBlock()
- r.SelectAllMediaItems(0, false) -- selected false
- local FADE_PARM = cmd_ID == 41305 and 'D_FADEINLEN' or 'D_FADEOUTLEN'
- local fade_in = cmd_ID == 41305
- for k, item in ipairs(sel_items) do
- r.SetMediaItemSelected(item, true) -- selected true
- local pos = r.GetMediaItemInfo_Value(item, 'D_POSITION')
- local edge = fade_in and pos or pos+r.GetMediaItemInfo_Value(item, 'D_LENGTH')
- local fade_len = r.GetMediaItemInfo_Value(item, FADE_PARM)
- r.Main_OnCommand(cmd_ID,0) -- Item edit: Trim left/right edge of item to edit cursor
- if fade_len > 0 then
- local pos_new = r.GetMediaItemInfo_Value(item, 'D_POSITION')
- local edge_new = fade_in and pos_new or pos_new+r.GetMediaItemInfo_Value(item, 'D_LENGTH')
- local diff = edge_new-edge
- diff = math.abs(diff) > fade_len and 0 or diff*(fade_in and 1 or -1)
- r.SetMediaItemInfo_Value(item, FADE_PARM, math.abs(fade_len-diff))
- end
- end
- for k, item in ipairs(sel_items) do
- r.SetMediaItemSelected(item, true) -- selected true
- end
- r.Undo_EndBlock(scr_name,-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement