Guest User

Autorename Macro for FL Studio

a guest
Sep 21st, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. """macros > autorename.py
  2.  
  3. This script renames all content using some specified parameters.
  4.  
  5. Author: Miguel Guthridge
  6. """
  7.  
  8. # How many leading characters to remove
  9. TRIM_FIRST = 0
  10.  
  11. # Leading characters to remove if present
  12. TRIM_FIRST_CHARS = "Lullaby Stems_"
  13.  
  14. # How many ending characters to remove
  15. TRIM_END = 0
  16.  
  17. # Ending characters to remove if present
  18. TRIM_END_CHARS = ""
  19.  
  20. # List of characters to replace. Each element should be a tuple containing the character to find and the character to replace it with
  21. CHARACTER_REPLACEMENTS = [("_", " ")]
  22.  
  23. # Whether to capitalise first letters of words
  24. CAPITALISE_FIRST_LETTERS = False
  25.  
  26. CHANGE_PATTERNS = True
  27. CHANGE_PLAYLIST_TRACKS = True
  28. CHANGE_CHANNELS = True
  29. CHANGE_MIXER_TRACKS = True
  30.  
  31. import channels
  32. import mixer
  33. import playlist
  34. import patterns
  35. import general
  36.  
  37. def getNewName(name):
  38.     # Trim starts and ends
  39.     if len(name) > (TRIM_FIRST + TRIM_END):
  40.         if TRIM_END:
  41.             name = name[ TRIM_FIRST : -TRIM_END ]
  42.         else:
  43.             name = name[ TRIM_FIRST : ]
  44.     else:
  45.         name = ""
  46.    
  47.     # Trim first and ending chars
  48.     if name[ : len(TRIM_FIRST_CHARS) ] == TRIM_FIRST_CHARS and len(TRIM_FIRST_CHARS):
  49.         name = name[ len(TRIM_FIRST_CHARS) : ]
  50.    
  51.     if name[ -len(TRIM_END_CHARS) : ] == TRIM_END_CHARS and len(TRIM_END_CHARS):
  52.         name = name[ : -len(TRIM_END_CHARS) ]
  53.    
  54.     # Make character replacements
  55.     for replacement in CHARACTER_REPLACEMENTS:
  56.         for i in range(len(name)):
  57.             if name[i] == replacement[0]:
  58.                 if i != len(name):
  59.                     name = name[ : i] + replacement[1] + name[i + 1 : ]
  60.                 else:
  61.                     name = name[ : i] + replacement[1]
  62.    
  63.     # Set to Title Case
  64.     if CAPITALISE_FIRST_LETTERS:
  65.         name = name.title()
  66.    
  67.     return name
  68.  
  69. def run():
  70.     if CHANGE_PATTERNS:
  71.         for i in range(1, patterns.patternCount() + 1):
  72.             patterns.setPatternName(i, getNewName(patterns.getPatternName(i)))
  73.    
  74.     if CHANGE_PLAYLIST_TRACKS:
  75.         for i in range(playlist.trackCount()):
  76.             playlist.setTrackName(i, getNewName(playlist.getTrackName(i)))
  77.    
  78.     if CHANGE_CHANNELS:
  79.         for i in range(channels.channelCount(1)):
  80.             try:
  81.                 channels.setChannelName(i, getNewName(channels.getChannelName(i)))
  82.             except:
  83.                 print("An index out of range error occurred. Change the Channel Rack's display filter to 'All'.")
  84.    
  85.     if CHANGE_MIXER_TRACKS:
  86.         for i in range(mixer.trackCount()):
  87.             mixer.setTrackName(i, getNewName(mixer.getTrackName(i)))
  88.    
  89.     # This doesn't do anything for some reason
  90.     general.saveUndo("Run autorename Script", 0)
  91.    
  92.    
Advertisement
Add Comment
Please, Sign In to add comment