View Single Post
Old 04-17-2013, 10:22 AM   #87
Argitoth
Human being with feelings
 
Argitoth's Avatar
 
Join Date: Feb 2008
Location: Mesa, AZ
Posts: 2,057
Default

nooooonoonnoononoo, this script will create tracks every time it is run. I need the tracks to be added only if the track is not already there. In other words, don't create new tracks just because there's media items already in the track. This script acts exactly like the Xenakios one at the moment. I'm trying to edit the script myself so it works this way, but any copy and pasting of code just isn't working, still trying to figure it out.

edit: ok got it. I simply removed the block of code that says "check if next tracks are empty". Thank you spk77!

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 - add tracks if needed"):

    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, create more tracks if needed
    needed = int(RPR_CountTracks(0) - trackIndex + 1 - len(selItemIdL))
    if needed < 0:
        for tr in range(abs(needed)):
            # insert new track(s) at the end
            RPR_InsertTrackAtIndex(RPR_CountTracks(0), 1)

    # move each item to its own track
    for j, id in enumerate(selItemIdL):
        destTrack = RPR_CSurf_TrackFromID(trackIndex + j, 0)
        RPR_MoveMediaItemToTrack(id, destTrack)

    # update view
    RPR_TrackList_AdjustWindows(False)
    RPR_UpdateArrange()
edit: added the below change (blue text) to the above script
__________________
Soundemote - Home of the chaosfly and pretty oscilloscope.
MyReaperPlugin - Easy-to-use cross-platform C++ REAPER extension template

Last edited by Argitoth; 04-18-2013 at 12:01 PM.
Argitoth is offline   Reply With Quote