-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoundFont samples rename v0.1.py
61 lines (51 loc) · 1.63 KB
/
SoundFont samples rename v0.1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 29 17:52:54 2018
@author: Luiz Guilherme de M. Ventura
"""
import os
import glob
import re
def atoi(text):
return int(text) if text.isdigit() else text
def natural_keys(text):
'''
alist.sort(key=natural_keys) sorts in human order
http://nedbatchelder.com/blog/200712/human_sorting.html
(See Toothy's implementation in the comments)
'''
return [ atoi(c) for c in re.split('(\d+)', text) ]
p = input("Enter the path to the directory with the files: ")
#if p[-1] == '\"' or p[-1] == '\'':
# p = p[:-1]
# p = p + '/' + p[0] # insert a / if it is missing
#else:
# p = p + '/'
p = p + '/'
p = p.replace('\'', '')
p = p.replace('\"','')
ext = input("Enter the file extension (like .wav) ")
listFiles = glob.glob(p + '*' + ext)
s = input("Enter the name prefix with a # where the numeration is: ")
l = input("How long is the number string? ")
n = input("How many files in total? ")
print("So, your files are in the form: {",)
for i in range(3):
print(s.replace('#','%.{}d'.format(l) % (i+1)) + ext + ', ',)
print("}")
cfrm = input("Confirm? [y/n]: ")
listFiles.sort(key=natural_keys)
if cfrm == 'y':
nt = input("first note [e.g. c#2]: ")
nv = int(input("number of velocities: "))
i = 1
for file in listFiles:
os.rename(file, p + str(nt) + s.replace('#', '') + str(i) + ext)
print(file + ' -> ' + p + str(nt) + s.replace('#', '') + str(i) + ext)
if i == nv:#int(nv):
nt = input("next note [e.g. c#2]: ")
nv = int(input("number of velocities: "))
i = 1
else:
i += 1