-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_LM-4_disk1_fxp.py
98 lines (87 loc) · 3.19 KB
/
fix_LM-4_disk1_fxp.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: UTF-8 -*-
import re
import os
import sys
unknownBlock1 = b'\x00\x00\x05\x91\x00\x00\x10\x0C\x00\x00\x00\x00' #0x91 or 0x93 ?
unknownBlock2 = bytes.fromhex(
"000000003F80000000000001000000003F80000000000002000000003F8000000000000B0000000100000000000000000000000000000000"
)
def convertFxp(path):
newFxpContent = b""
fxpName = os.path.split(path)[1]
fPath = os.path.split(path)[0]
with open(path, 'rb') as fr:
fxpContent = fr.read()
pattern = re.compile(br'HaSm(.|\n)*?(\\[\w ]*\.aif)')
pos = 0
count = 0
while 1:
m = pattern.search(fxpContent[pos:])
if m is None:
newFxpContent += insertUnknownBlock2(fxpContent[pos:], b'Harp')
break
aName = m.group(2).replace(b"\\", b"\\\\")
repl = b'HaSm' + unknownBlock1 + bytes(doubleBackslash(fPath),
'utf-8') + aName
block = re.sub(pattern,
repl,
fxpContent[pos:pos + m.end()],
count=1)
if count > 0:
if "Reso" in fxpName: #Reso Kit preset has multiple samples in one pad
if findHaPa(block) is True:
block = insertUnknownBlock2(block, b'HaPa')
else:
block = insertUnknownBlock2(block, b'HaSm')
else:
block = insertUnknownBlock2(block, b'HaPa')
newFxpContent += block
pos += m.end()
count += 1
with open(fxpName, 'wb') as fw:
fw.write(newFxpContent)
print("success!")
def insertUnknownBlock2(chunk, reg):
pattern = re.compile(reg)
m = pattern.search(chunk)
if m is None:
print("can't find insert position")
return chunk
else:
return (chunk[:m.start()] + unknownBlock2 + chunk[m.start():])
def findHaPa(chunk):
pattern = re.compile(b'HaPa')
m = pattern.search(chunk)
if m is None:
return False
else:
return True
def doubleBackslash(str):
str = str.replace("\\", "\\\\")
str = str.replace("/", "\\\\")
return str
if __name__ == "__main__":
installPath = input(
"Input your preset & sample folder path: \nexample: C:\Program Files (x86)\Steinberg\Vstplugins\LM-4 MarkII\Wizoo Kits - Part1\Wizoo Presets & Samples\Latin Grooves Kits\n"
)
assert os.path.isdir(installPath), "illegal path"
if installPath.endswith("\\") or installPath.endswith("/"):
installPath = installPath[:-1]
try:
fileList = os.listdir(installPath)
except FileNotFoundError:
print("file not found")
sys.exit(0)
fxpList = []
for f in fileList:
if f.lower().endswith(".fxp"):
fxpList.append(f)
if len(fxpList) == 0:
print("can't find fxp files, please check directory")
sys.exit(0)
print(f"found {len(fxpList)} fxp files, processing...")
for f in fxpList:
print(f"converting {f} ...")
convertFxp(installPath + "\\" + f)
if f == fxpList[-1]:
print("all finished, converted preset files are in current folder")