Old 01-19-2015, 09:18 AM   #1
jrp
Human being with feelings
 
Join Date: Nov 2014
Posts: 149
Default unselect an item

Hello,

I am writing on a script that needs items that are not under the edit cursor to be deselected

I could not find any clue on how to do that...
is it somehow possible with this:
RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", ???)
not sure what B_UISEL is supposed to be, writing in various numbers shows no reaction at all...
EDIT: It works, as soon as you move the mouse over an env-lane after running the script. Cracy!


I am using a while loop so far to identify if an item is not under the cursor.

Code:
Item_Count = RPR_CountMediaItems(0)
Item_Index = 0
cursor = RPR_GetCursorPosition()

while Item_Index < Item_Count: 
    Item_ID = RPR_GetMediaItem(0, Item_Index)
    start = RPR_GetMediaItemInfo_Value(Item_ID, "D_POSITION")   
    length = RPR_GetMediaItemInfo_Value(Item_ID, "D_LENGTH")
    end = start + length
   
    if (cursor > end) or (start > cursor):
          SOMEHOW MAKE IT UNSELECTED
    
    Item_Index = Item_Index + 1;

Last edited by jrp; 01-19-2015 at 10:05 AM.
jrp is offline   Reply With Quote
Old 01-19-2015, 09:39 AM   #2
jrp
Human being with feelings
 
Join Date: Nov 2014
Posts: 149
Default

i have seen the command

SetMediaItemInfo_Value(Item_ID, "B_UISEL", 1)

in other scripts, in fact i was using an eel script that used this command.

It is not working anymore... And i bet it did!

Tried some older versions, but it´s the same.


EDIT: It works, as soon as you move the mouse over an env-lane after running the script. Cracy!

What could have broken this?

Last edited by jrp; 01-19-2015 at 10:22 AM.
jrp is offline   Reply With Quote
Old 01-19-2015, 10:30 AM   #3
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,514
Default

Hello,

Usually when track/item selection is changed by a script, UpdateArrange -function is needed to refresh the screen:

Code:
EEL: UpdateArrange()
Python: RPR_UpdateArrange()
(Use it at the end of your script)



Here's another function to select/unselect an item:
Code:
EEL: SetMediaItemSelected(MediaItem item, bool selected)
Python: RPR_SetMediaItemSelected(MediaItem item, Boolean selected)
spk77 is offline   Reply With Quote
Old 01-19-2015, 10:37 AM   #4
jrp
Human being with feelings
 
Join Date: Nov 2014
Posts: 149
Default

marvelous!
Thanks!

Wonder why it used to work without that update command...
jrp is offline   Reply With Quote
Old 01-19-2015, 10:45 AM   #5
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,514
Default

EEL version:
Code:
i = 0;
loop(CountMediaItems(0),
  item_id = GetMediaItem(0, i);
  pos = GetMediaItemInfo_Value(item_id, "D_POSITION");
  length = GetMediaItemInfo_Value(item_id, "D_LENGTH");
  end_pos = pos + length;
  cursor_pos = GetCursorPosition();
  end_pos < cursor_pos || pos > cursor_pos ?
    SetMediaItemSelected(item_id, 0);
  i += 1;
);

Undo_OnStateChange("Unselect items outside edit cursor"); // add undo point
UpdateArrange();
spk77 is offline   Reply With Quote
Old 01-21-2015, 03:41 AM   #6
jrp
Human being with feelings
 
Join Date: Nov 2014
Posts: 149
Default

thanks for giving the example.

Where did you get the SetMediaItemSelected command?
Looks like there is useful stuff missing on the wiki page...
http://wiki.cockos.com/wiki/index.php/ReaScript_API

You seem to prefer to use eel for this kind of script, when trying to load older python scripts by other users i have already experienced that it can be problematic.
So i understand that eel is integrated into reaper and will always work?

For a script like this eel does not seem to be so much worse in terms of code writing compared to python... Just a bit more (); but otherwise much the same.
jrp is offline   Reply With Quote
Old 01-21-2015, 02:16 PM   #7
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,514
Default

Quote:
Originally Posted by jrp View Post
thanks for giving the example.

Where did you get the SetMediaItemSelected command?
Looks like there is useful stuff missing on the wiki page...
http://wiki.cockos.com/wiki/index.php/ReaScript_API

You seem to prefer to use eel for this kind of script, when trying to load older python scripts by other users i have already experienced that it can be problematic.
So i understand that eel is integrated into reaper and will always work?

For a script like this eel does not seem to be so much worse in terms of code writing compared to python... Just a bit more (); but otherwise much the same.

Go to: REAPER main menu -> Help -> ReaScript documentation.

Many people have had problems with Python installations/reascript. EEL seems to be noticeably faster than Python (at least on older computers the difference is quite huge, I think).
spk77 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 07:34 PM.


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