Old 01-26-2019, 05:16 PM   #1
Space Raiders
Human being with feelings
 
Join Date: Aug 2017
Posts: 69
Default Fade Item To Mouse Cursor Script

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
Space Raiders is offline   Reply With Quote
Old 01-28-2019, 01:00 AM   #2
Macc
Human being with feelings
 
Join Date: Feb 2017
Posts: 76
Default

There's smart fade by amalgama (I believe)... sorry
Macc is offline   Reply With Quote
Old 01-28-2019, 03:09 PM   #3
Space Raiders
Human being with feelings
 
Join Date: Aug 2017
Posts: 69
Default

Thanks for the reply. That one is to do with crossfades rather than normal fades though. This one is just for normal fades and is based on mouse position.
Space Raiders is offline   Reply With Quote
Old 02-19-2024, 05:09 AM   #4
citadela
Human being with feelings
 
citadela's Avatar
 
Join Date: Feb 2024
Location: Belgrade, Serbia
Posts: 1
Default

I literally registered only to thank you for this.
citadela is offline   Reply With Quote
Old Yesterday, 02:57 PM   #5
Space Raiders
Human being with feelings
 
Join Date: Aug 2017
Posts: 69
Default

Quote:
Originally Posted by citadela View Post
I literally registered only to thank you for this.
No problem.
Space Raiders 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 06:51 AM.


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