This script fades the item under the mouse cursor to the mouse. It fades in or out dependent upon if the mouse is nearer the start or the end of the item.
This took me longer than I thought. I hope it helps someone else and I hope there isn't already a way to do this.
Code:
--Save item selection
numberOfSelectedItemsAtStart = reaper.CountSelectedMediaItems(0);
local selectedItems = {};
for i=0, numberOfSelectedItemsAtStart-1 do
selectedItems[i] = reaper.GetSelectedMediaItem(0,i);
--take = reaper.GetMediaItemTake(selectedItems[i], 0)
--reaper.ShowConsoleMsg(reaper.GetTakeName(take))
--reaper.ShowConsoleMsg("\n")
end
--Save cursor pos
firstEditCursorPos = reaper.GetCursorPosition();
--Select item under mouse and move edit cursor:
reaper.Main_OnCommand(40528, 0); --Select item under mouse cursor
reaper.Main_OnCommand(40514, 0); --Move edit ccursor ro mouse cursor ! no snapping
theItem = reaper.GetSelectedMediaItem(0,0);
--Find if the cursor is nearer the start or finish:
if theItem then
start = reaper.GetMediaItemInfo_Value(theItem, "D_POSITION");
finish = start + reaper.GetMediaItemInfo_Value(theItem, "D_LENGTH");
editCursorPos = reaper.GetCursorPosition();
if editCursorPos > start and editCursorPos < finish then
cursorDistanceFromStart = editCursorPos - start;
cursorDistanceFromFinish = finish - editCursorPos;
if cursorDistanceFromStart < cursorDistanceFromFinish then
reaper.Main_OnCommand(40509, 0); --fadein
else
reaper.Main_OnCommand(40510, 0); --fadeour
end
end
reaper.SetMediaItemSelected(theItem, false)
end
--reset the selection and editcursor
reaper.SetEditCurPos(firstEditCursorPos, false, false);
if numberOfSelectedItemsAtStart > 0 then
for i=0, numberOfSelectedItemsAtStart-1 do
reaper.SetMediaItemSelected(selectedItems[i], true)
--take = reaper.GetMediaItemTake(selectedItems[i], 0)
--reaper.ShowConsoleMsg(reaper.GetTakeName(take))
--reaper.ShowConsoleMsg("\n")
end
reaper.UpdateArrange()
end