[PYTHON] Time sorted by REAPER and labeled

Introduction

I used to use a script that changes the names of items in a batch with REAPER because it was originally there.

image.png

When the tracks were separated, it felt like the name was poured into each track. It would have been nice if it was divided into one track ...

When I noticed, I had separated the tracks.

So I wrote a script that puts names in chronological order.

(Also, if there are too many characters, it seems that the characters are over, so it only worked halfway)

Overall flow

  1. Get the number of selected items
  2. Get the selected item
  3. Get the current take
  4. Get the start time and take of the current take
  5. Sort by time (sort)
  6. In the dialog, get the characters for renaming
  7. Rename when the button is pressed

Input dialog

I used Python tkinter. A screen like this appears.

image.png

Source

tatLable.py


RPR_ClearConsole()

#Get Selected Items
itemNum = RPR_CountSelectedMediaItems(0)

itemList = []

for itemidx in range(itemNum):
  mediaItem = RPR_GetSelectedMediaItem(0,itemidx)
  itemList.append(mediaItem)
  
# Sort Items
dict = {}  
 
for item in itemList:
  currentTakeId = RPR_GetMediaItemInfo_Value(item, "I_CURTAKE")
  startTime = RPR_GetMediaItemInfo_Value(item, "D_POSITION")
  currentTake = RPR_GetMediaItemTake(item,int(currentTakeId))
  
  retval, tk, parmname, stringNeedBig,setnewvalue = RPR_GetSetMediaItemTakeInfo_String(currentTake, "P_NAME", "", False)
 
  dict[startTime] = currentTake
  #RPR_ShowConsoleMsg(str(startTime) + ",")
#RPR_ShowConsoleMsg(str(startTime) + "\n")
  
# Sort Start Time    
sortedList = sorted(dict.items(), key=lambda x: x[0], reverse=False)

for item in sortedList:
  retval, tk, parmname, stringNeedBig,setnewvalue = RPR_GetSetMediaItemTakeInfo_String(item[1], "P_NAME", "", False)
  RPR_ShowConsoleMsg(stringNeedBig + ",")
  
# Dialog
import tkinter
root = tkinter.Tk()
root.title("Rename Item with CSV")
root.geometry("400x200")

label = tkinter.Label(root, text="Names(separated by \",\")")
label.grid()

txtbox = tkinter.Entry()
txtbox.grid()

def clicked():
  nameList = txtbox.get().split(',')
  
  index = 0
  length = len(nameList)
  for item in sortedList:
    
    if index <= length :
      newName = nameList[index]
      retval, tk, parmname, stringNeedBig,setnewvalue = RPR_GetSetMediaItemTakeInfo_String(item[1], "P_NAME", newName, True) 
      index += 1
     
  root.destroy()

button = tkinter.Button(root, text = "OK", command= clicked)
button.grid()

root.mainloop()

Summary

I found that I could manage the time sorting. I found out that a simple GUI can also be used, so it seems that various things will be done.

Recommended Posts

Time sorted by REAPER and labeled
Python> Sort by number and sort by alphabet> Use sorted ()
Date and time ⇔ character string
Python 3 sorted and comparison functions