View Single Post
Old 04-16-2013, 11:09 AM   #84
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Argitoth View Post
[~~~~] = media item

I just need this:
[~~~~][~~~~][~~~~][~~~~][~~~~]

to this:
[~~~~]
_______[~~~~]
______________[~~~~]
_____________________[~~~~]
____________________________[~~~~]

but do not create new tracks like Xenakios "explode items"

Edit: Xenakios "spread items over tracks tracks..." works except that you have to type in a number... I'll use that for now, but would much rather have a hotkey without a menu popping up.
Maybe this works. It doesn't create new tracks:

Code:
from reaper_python import *
from contextlib import contextmanager

@contextmanager
def undoable(message):
    RPR_Undo_BeginBlock2(0)
    try:
        yield
    finally:
        RPR_Undo_EndBlock2(0, message, -1)

with undoable("Spread selected items over tracks"):

    def msg(m):
        RPR_ShowConsoleMsg(m)

    selItemIdL = []

    # get first selected item and track index
    firstSelItem =  RPR_GetSelectedMediaItem(0, 0)
    track = RPR_GetMediaItem_Track(firstSelItem)
    trackIndex = int(RPR_GetMediaTrackInfo_Value(track, "IP_TRACKNUMBER"))
    trackItemCount = RPR_CountTrackMediaItems(track)

    # make list from selected items in track
    for i in range(trackItemCount):
        itemId = RPR_GetTrackMediaItem(track, i)
        if int(RPR_GetMediaItemInfo_Value(itemId, "B_UISEL")):
            selItemIdL.append(itemId)

    # check if there are enough tracks for items
    needed = int(RPR_CountTracks(0) - trackIndex + 1 - len(selItemIdL))
    if needed < 0:
        msg("Not enough tracks for items. Add " + str(abs(needed)) + " track(s)")
    else:
        # move each item to its own track
        for j, id in enumerate(selItemIdL):
            destTrack = RPR_CSurf_TrackFromID(trackIndex + j, 0)
            RPR_MoveMediaItemToTrack(id, destTrack)
        RPR_UpdateArrange()
spk77 is offline   Reply With Quote