Old 08-10-2020, 01:50 PM   #1
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Posts: 473
Default select only items with grid length

Something is wrong here.
can someone look at it
Thanks

Code:
--- select items with grid length ---
local function Msg(str)
  reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

 item_count = reaper.CountSelectedMediaItems(0)

 for i=0, item_count - 1 do

     item = reaper.GetSelectedMediaItem( 0, i )
   length = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )


  tempo = reaper.Master_GetTempo(0)   
  factor = 120 / tempo
   _,grid = reaper.GetSetProjectGrid(0, false)
  grid_length = (grid*2*factor)
  
  
    if length  == grid_length then
     reaper.SetMediaItemInfo_Value(item, "B_UISEL",1)
     else
     reaper.SetMediaItemInfo_Value(item, "B_UISEL",0)
  
end
end


reaper.UpdateArrange()
    
Msg(length)
__________________
Randomizer
Project Manager
Dragonetti is offline   Reply With Quote
Old 08-10-2020, 02:13 PM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,000
Default

Since your changing the selected state of the selected items in the loop, try looping backwards,

for i = item_count - 1, 0, -1 do
Edgemeal is offline   Reply With Quote
Old 08-10-2020, 02:49 PM   #3
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Posts: 473
Default

thanks
backwards, that's interesting.
It works
Code:
--- select items with grid length ---


 item_count = reaper.CountSelectedMediaItems(0)
        for i = item_count - 1, 0, -1 do
     --   for i=0, item_count - 1 do
     item = reaper.GetSelectedMediaItem( 0, i )
    length = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )


  tempo = reaper.Master_GetTempo(0)   
  factor = 120 / tempo
   _,grid = reaper.GetSetProjectGrid(0, false)
  grid_length = (grid*2*factor)
  
  
    if length  == grid_length then
     reaper.SetMediaItemInfo_Value(item, "B_UISEL",1)
     else
     reaper.SetMediaItemInfo_Value(item, "B_UISEL",0)
  
end
end


reaper.UpdateArrange()
__________________
Randomizer
Project Manager

Last edited by Dragonetti; 08-11-2020 at 10:41 AM.
Dragonetti 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 09:26 PM.


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