Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 08-31-2012, 05:42 PM   #1
Viente
Human being with feelings
 
Viente's Avatar
 
Join Date: Feb 2012
Posts: 1,972
Default Selecting only item with specific name (looking for mistake)

I have a part of the code which should select only item with name "Pitch Up" among selected items. But it doesn't work, Only when i have such item (named "Pitch Up") among selected items Reaper freezes...what i'm doing wrong?
Thanks!

Code:
     num_items = RPR_CountSelectedMediaItems(0)

     i = 0
     while i < num_items:
       Item_Index = 0
       Item_ID = RPR_GetSelectedMediaItem(0, Item_Index)
       Current_Take = RPR_GetMediaItemInfo_Value(Item_ID, "I_CURTAKE") # Get active take index for current item
       Take_ID = RPR_GetMediaItemTake(Item_ID, int(Current_Take)); 
       Take_Name = RPR_GetSetMediaItemTakeInfo_String(Take_ID, "P_NAME", "", 0)[3] # Get active take name
    
       if Take_Name == "Pitch Up" :
                RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 1)
       else:
                RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 0)
                i += 1

Last edited by Viente; 08-31-2012 at 06:06 PM.
Viente is offline   Reply With Quote
Old 09-01-2012, 01:00 AM   #2
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Not sure, but it looks like
i += 1
should be executed also when the take name fits. I think now when the take name fits it will go into an infinite loop, because it doesn't change i in that case.

try
Code:
    if Take_Name == "Pitch Up" :
            RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 1)
    else:
            RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 0)
    i += 1
gofer is offline   Reply With Quote
Old 09-01-2012, 02:14 AM   #3
Viente
Human being with feelings
 
Viente's Avatar
 
Join Date: Feb 2012
Posts: 1,972
Default

Thanks for reply gofer!

Its not freezes now but still doesnt work (not selecting any item at all)
Viente is offline   Reply With Quote
Old 09-01-2012, 02:53 AM   #4
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Maybe it's just missing the

RPR_UpdateTimeline()

at the end?

with that line a quick check seemed to work (deselects all items where the active take isn't called "Pitch Up").
gofer is offline   Reply With Quote
Old 09-01-2012, 03:04 AM   #5
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

Firstly, you don't need 'Item_Index'. The first line of the loop should be:

Item_ID = RPR_GetSelectedMediaItem(0, i)

... otherwise you're not incrementing through items.

But even with that change, it won't work properly in all scenarios; it will miss items sometimes.

Try this:

Code:
num_items = RPR_CountSelectedMediaItems(0)

i = 0
while i < num_items:
    item = RPR_GetSelectedMediaItem(0, i)
    cur_take = RPR_GetMediaItemInfo_Value(item, "I_CURTAKE")
    take = RPR_GetMediaItemTake(item, int(cur_take))
    take_name = RPR_GetSetMediaItemTakeInfo_String(take, "P_NAME", "", 0)[3]
    
    if take_name == "Pitch Up":  # unselect wanted items
        RPR_SetMediaItemInfo_Value(item, "B_UISEL", 0)
    else:
        i += 1

RPR_Main_OnCommand(41115, 0)  # invert item selection
Calling the invert item sel action negates the need to update the arrange again.

- edit - oops - actually no don't use invert item selection - it will mess everything up .... off to lunch now, will reply again at some point

Last edited by timlloyd; 09-01-2012 at 03:10 AM.
timlloyd is offline   Reply With Quote
Old 09-01-2012, 03:28 AM   #6
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Quote:
Originally Posted by timlloyd View Post
Firstly, you don't need 'Item_Index'. The first line of the loop should be:

Item_ID = RPR_GetSelectedMediaItem(0, i)

... otherwise you're not incrementing through items.
That's a thing I thought about as well... you're partly right.
He is actually incrementing through items, because items get deselected during the loop and the next item will be Item_Index 0.

But (and this I didn't think about earlier):
That's true only until the take is called "Pitch Up". It stays selected, so the next loop iteration will use the same item again. and again until i = num_items.

Probably it will work to accumulate a list of "to be deselected" items in the loop (not doing Item_Index =0) and deselect them afterwards in a separate step.



EDIT: or - in the original script - increment Item_Index by 1 if Take_Name == "Pitch Up". (That would afford the line Item_Index = 0 to be before the loop, not inside, to not reset it to zero again)

Last edited by gofer; 09-01-2012 at 03:35 AM.
gofer is offline   Reply With Quote
Old 09-01-2012, 03:42 AM   #7
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

Quote:
Originally Posted by gofer View Post
But (and this I didn't think about earlier):
That's true only until the take is called "Pitch Up". It stays selected, so the next loop iteration will use the same item again. and again until i = num_items.
True - I'm now remembering I had the same problem a while ago.

Quote:
Probably it will work to accumulate a list of "to be deselected" items in the loop (not doing Item_Index =0) and deselect them afterwards in a separate step.
yep

Quote:
EDIT: or - in the original script - increment Item_Index by 1 if Take_Name == "Pitch Up". (That would afford the line Item_Index = 0 to be before the loop, not inside, to not reset it to zero again)
yeah that's what you want:

Code:
num_items = RPR_CountSelectedMediaItems(0)

i = 0
for j in range(0, num_items):
    item = RPR_GetSelectedMediaItem(0, i)
    cur_take = RPR_GetMediaItemInfo_Value(item, "I_CURTAKE")
    take = RPR_GetMediaItemTake(item, int(cur_take))
    take_name = RPR_GetSetMediaItemTakeInfo_String(take, "P_NAME", "", 0)[3]
    
    if take_name == "TEST":
        RPR_SetMediaItemInfo_Value(item, "B_UISEL", 1)
        i += 1
    else:
        RPR_SetMediaItemInfo_Value(item, "B_UISEL", 0)

RPR_UpdateArrange()
timlloyd is offline   Reply With Quote
Old 09-01-2012, 06:46 AM   #8
Viente
Human being with feelings
 
Viente's Avatar
 
Join Date: Feb 2012
Posts: 1,972
Default

I luv you guys
Viente 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 03:32 AM.


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