|
|
|
08-20-2018, 12:50 PM
|
#1
|
Human being with feelings
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
|
REQ: Select only last Item of all selected Items.
Dear Reaper Scripters !
Is this maybe possible to script:
Situation:
- Having some Items selected. (can be on same track, can be on different tracks).
When executing the Script, only the last Item (so the Item on the far right of all the selected Items) will be selected.
Many thanks in advance !
Warm Regards.
|
|
|
08-20-2018, 01:09 PM
|
#2
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Try this:
Code:
-- Select last item of selected items by spk77 (20 August 2018)
-- https://forum.cockos.com/showthread.php?t=210311
function main()
local item_count = reaper.CountSelectedMediaItems(0)
if item_count == 0 then
return
end
local max_item_end = -1
local last_item
for i = 1, item_count do
local item = reaper.GetSelectedMediaItem(0, i-1)
if item ~= nil then
local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local item_end = item_pos + item_len
if item_end > max_item_end then
max_item_end = item_end
last_item = item
end
end
end
reaper.Main_OnCommand(40289, 0) -- Unselect items
if last_item ~= nil then
reaper.SetMediaItemSelected(last_item, true)
end
reaper.UpdateArrange()
reaper.Undo_OnStateChangeEx("Select last of selected items)", -1, -1)
end
reaper.defer(main)
|
|
|
08-20-2018, 01:29 PM
|
#3
|
Human being with feelings
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
|
My God, are you some kind of Reaper Scripting Robot ?!
Beautiful, just Beautiful, thanks so much !
|
|
|
08-20-2018, 03:36 PM
|
#4
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
|
Quote:
Originally Posted by spk77
Try this:
|
Is there something wrong by doing it this way? Just trying to learn better.
Code:
count_sel_items = reaper.CountSelectedMediaItems(0)
if count_sel_items < 2 then return end
lastitem = reaper.GetSelectedMediaItem(0, count_sel_items-1)
reaper.Main_OnCommand(40289, 0) -- Item: Unselect all items
reaper.SetMediaItemSelected(lastitem, true) -- Select last item
reaper.UpdateArrange()
THANKS!
Last edited by Edgemeal; 08-20-2018 at 04:05 PM.
|
|
|
08-21-2018, 11:49 AM
|
#5
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by vanhaze
My God, are you some kind of Reaper Scripting Robot ?!
Beautiful, just Beautiful, thanks so much !
|
Glad it worked
Quote:
Originally Posted by Edgemeal
Is there something wrong by doing it this way? Just trying to learn better.
Code:
count_sel_items = reaper.CountSelectedMediaItems(0)
if count_sel_items < 2 then return end
lastitem = reaper.GetSelectedMediaItem(0, count_sel_items-1)
reaper.Main_OnCommand(40289, 0) -- Item: Unselect all items
reaper.SetMediaItemSelected(lastitem, true) -- Select last item
reaper.UpdateArrange()
THANKS!
|
That would work if selected items are on a single track, but count_sel_items-1 isn't necessarily the last item in timeline order:
In this case, count_sel_items-1 would be the first item in timeline. (reaper.GetSelectedMediaItem doesn't return items in chronological order)
|
|
|
05-11-2022, 09:32 AM
|
#6
|
Human being with feelings
Join Date: Feb 2016
Location: Hollyweird
Posts: 2,637
|
Hey I'm doing research for my script project and was wondering, what exactly is Undo_OnStateChangeEx() doing here? I can't find an explanation in any docs.
|
|
|
05-11-2022, 11:33 AM
|
#7
|
Human being with feelings
Join Date: Feb 2016
Location: Hollyweird
Posts: 2,637
|
Amalgama explained to me that this command creates an additional undo point within an existing undo block
|
|
|
07-15-2023, 05:12 PM
|
#8
|
Human being with feelings
Join Date: Jul 2019
Posts: 24
|
Get Latest/Newest
Quote:
Originally Posted by spk77
Try this:
Code:
-- Select last item of selected items by spk77 (20 August 2018)
-- https://forum.cockos.com/showthread.php?t=210311
function main()
local item_count = reaper.CountSelectedMediaItems(0)
if item_count == 0 then
return
end
local max_item_end = -1
local last_item
for i = 1, item_count do
local item = reaper.GetSelectedMediaItem(0, i-1)
if item ~= nil then
local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local item_end = item_pos + item_len
if item_end > max_item_end then
max_item_end = item_end
last_item = item
end
end
end
reaper.Main_OnCommand(40289, 0) -- Unselect items
if last_item ~= nil then
reaper.SetMediaItemSelected(last_item, true)
end
reaper.UpdateArrange()
reaper.Undo_OnStateChangeEx("Select last of selected items)", -1, -1)
end
reaper.defer(main)
|
This is great. I am just learning the most basic elements of scripting in reaper, but i was wondering if there is a way to tweak this to select the most recently added item. Ideally, MIDI item. My hope would be to have the MIDI editor always focus to the MIDI item that was most recently recorded.
|
|
|
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 05:11 PM.
|