forked from sskalnik/stable-audio-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkickbass_val_paths_md.py
More file actions
70 lines (54 loc) · 2.46 KB
/
kickbass_val_paths_md.py
File metadata and controls
70 lines (54 loc) · 2.46 KB
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
62
63
64
65
66
67
68
69
70
import os
import re
def get_custom_metadata(info, audio):
# Get filename without extension
file_name = os.path.basename(info["relpath"])
file_name_without_extension = os.path.splitext(file_name)[0]
# Replace non-alphanumeric characters with spaces, and remove leading/trailing spaces
#cleaned_file_name = re.sub('[^0-9a-zA-Z]+', ' ', file_name_without_extension).strip()
#cleaned_file_name = re.match('', cleaned_file_name).groups()[0]
# Get parent directory name (without the full path)
dir_name = os.path.dirname(info["relpath"])
prompt = os.path.split(dir_name)[1]
# Use the filename instead of parent directory if the filename has relevant info
if 'BPM' in file_name_without_extension:
prompt = file_name_without_extension
# Translate X beats of Y notes per bar from XbYn to "normal" time signature notation
# 4b4n = 4/4
# 3b16n = 3/16
# 69b420n = 69/420
prompt = re.sub(r'(\d+)b(\d+)n', r'\1/\2', prompt)
# Instrument123 => Instrument
# Acid1 => Acid
prompt = re.sub(r'^([a-zA-Z]+)\d+ ', r'\1 ', prompt, count=1)
# Acid6DistSplinterFat D# minor 120BPM 4/4 4bars
# Acid DistSplinterFat D# minor 120BPM 4/4 4bars
prompt = re.sub(r'^([a-zA-Z]+)\d+([a-zA-Z]+) ', r'\1 \2 ', prompt, count=1)
# Acid DistSplinterFat 120BPM 4/4 4bars
# Acid Distorted 120BPM 4/4 4bars
prompt = re.sub(r'Dist\w+ ', r' Distorted ', prompt, count=1)
# Acid Distorted 120BPM 4/4 4bars
# Acid Distorted 120 BPM 4/4 4bars
# KickBass F#0 120BPM 4b4n 1bar => KickBass F#0 120 BPM 4b4n 1bar
prompt = re.sub(r'(\d+)BPM', r'\1 BPM', prompt, count=1)
# Am = A minor
# G#m = G# minor
prompt = re.sub(r'( [ABCDEFG][#♭♮♯]?)m ', r'\1 minor ', prompt)
# AMajor = A Major
# F#Phrygian = F# Phrygian
prompt = re.sub(r'(^\w+ [ABCDEFG][#♭♮♯]?)([a-zA-Z]+)', r'\1 \2', prompt, count=1)
# TODO: obviate this hack
prompt = re.sub(r' D istorted ', r' Distorted ', prompt, count=1)
# 4bars = 4 bars
if 'bars' in prompt:
prompt = re.sub(r'(\d+)bars', r'\1 bars', prompt)
# KickBass F#0 120 BPM 4/4 1bar => KickBass F#0 120 BPM 4/4 1 bar
if '1bar' in prompt:
prompt = re.sub(r'1bar', r'1 bar', prompt)
# Remove (1), (2), etc.
prompt = re.sub(r'\(\d+\)$', r'', prompt)
# Reduce all whitespace to a single space
prompt = re.sub(r'\s+', ' ', prompt)
# Sanity check
print(f'{info["relpath"]} => {prompt}')
return {"prompt": prompt}