|
|
|
11-24-2014, 09:45 AM
|
#1
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Iterate function on each selected track
Hi there.
First attempts with Python ReaScript.
I wrote a script that performs some actions for each item on a track.
I actually do not consider the track at all in my function. But the "select and move to next item" (which I use to parse the items) works on the selected track by default (or the first of the selected tracks).
To my surprise I do not manage to expand my code to do the same thing for each selected track in a row.
Any advice please?
I suppose it is a simple thing, but I c'an't seem to figure it out.
thanks a lot,
C.
|
|
|
11-24-2014, 11:31 AM
|
#2
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Hi,
Looping example:
Code:
from reaper_python import *
def msg(m):
RPR_ShowConsoleMsg(m)
RPR_ShowConsoleMsg("\n")
def iterate():
# outer loop - for selected tracks
for i in range(RPR_CountSelectedTracks(0)): # loop through selected tracks
current_track = RPR_GetSelectedTrack(0, i) # get track pointer -> store to "current_track" var
msg(current_track) # show track pointer
# inner loop - for each items on current track (in outer loop)
for j in range(RPR_CountTrackMediaItems(current_track)): # loop through items on current track
current_item = RPR_GetTrackMediaItem(current_track, j) # get item pointer -> store to "current_item" var
msg(" " + current_item) # show item pointer
# call the "iterate" function:
iterate()
|
|
|
11-25-2014, 04:02 AM
|
#3
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Thanks for your answer spk77.
Your code is clearly cleaner than mine.
I'll rewrite the parsing according to your suggestion.
It should solve my problems.
Thanks again.
C
|
|
|
11-25-2014, 04:29 AM
|
#4
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
If you are using (native)actions from the action list - you may have to do something like this:
Code:
from reaper_python import *
def msg(m):
RPR_ShowConsoleMsg(m)
RPR_ShowConsoleMsg("\n")
def iterate():
RPR_Main_OnCommand(40289, 0) # Unselect all items
# outer loop - for selected tracks
for i in range(RPR_CountSelectedTracks(0)): # loop through selected track
current_track = RPR_GetSelectedTrack(0, i) # get track pointer -> store to "current_track" var
# inner loop - for each items on current track (in outer loop)
for j in range(RPR_CountTrackMediaItems(current_track)): # loop through items on current track
current_item = RPR_GetTrackMediaItem(current_track, j) # get item pointer -> store to "current_item" var
RPR_SetMediaItemSelected(current_item, True) # Set current item selected
# Add your actions here:
# RPR_Main_OnCommand(Action id here, 0);
# RPR_Main_OnCommand(Another action id here, 0);
RPR_SetMediaItemSelected(current_item, False) # Set current item UNselected
# call the "iterate" function:
iterate()
|
|
|
11-26-2014, 01:38 AM
|
#5
|
Human being with feelings
Join Date: Oct 2014
Posts: 77
|
Thanks again, spk77.
I managed to tidy my code, and have it working on many selected tracks.
I need to discover user input now... and maybe a basic GUI. I'll probably come back with some questions
Thanks,
Cheers
|
|
|
11-27-2014, 03:21 PM
|
#6
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Cedrik0s
Thanks again, spk77.
I managed to tidy my code, and have it working on many selected tracks.
I need to discover user input now... and maybe a basic GUI. I'll probably come back with some questions
Thanks,
Cheers
|
Glad you got it working
|
|
|
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 03:26 PM.
|