mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-03 01:25:45 -04:00
genmidi: Update to support Python 3 build.
Tweak the code used to build the GENMIDI Lump so that it properly supports Python 3 for build. Tested use cases were: * Normal build * a2i-to-sbi script to convert AdTrack2 instruments to SBI format * dumpgenmidi script to dump the instruments from a GENMIDI lump. * Running genmidi.py, sbi_file.py, a2i_file.py standalone to print the contents of files in their respective formats.
This commit is contained in:
parent
8422d38ce4
commit
e47b69a064
5 changed files with 37 additions and 39 deletions
|
@ -53,17 +53,17 @@ FIELDS = [
|
|||
]
|
||||
|
||||
def read(filename):
|
||||
f = open(filename)
|
||||
data = f.read()
|
||||
f.close()
|
||||
with open(filename, "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
header, name = struct.unpack("4s32s", data[0:36])
|
||||
header = header.decode("ascii")
|
||||
|
||||
if header != HEADER_VALUE:
|
||||
raise Exception("Invalid header for SBI file!")
|
||||
|
||||
instr_data = data[36:]
|
||||
result = { "name": name.rstrip("\0") }
|
||||
result = { "name": name.decode("ascii").rstrip("\0") }
|
||||
|
||||
for i in range(len(FIELDS)):
|
||||
result[FIELDS[i]], = struct.unpack("B", instr_data[i:i+1])
|
||||
|
@ -71,16 +71,14 @@ def read(filename):
|
|||
return result
|
||||
|
||||
def write(filename, data):
|
||||
f = open(filename, 'w')
|
||||
with open(filename, "wb") as f:
|
||||
f.write(struct.pack("4s", HEADER_VALUE.encode("ascii")))
|
||||
f.write(struct.pack("32s", data["name"].encode("ascii")))
|
||||
|
||||
f.write(struct.pack("4s32s", HEADER_VALUE, data["name"]))
|
||||
|
||||
for field in FIELDS:
|
||||
f.write(struct.pack("B", data[field]))
|
||||
for x in range(16 - len(FIELDS)):
|
||||
f.write(struct.pack("B", 0))
|
||||
|
||||
f.close()
|
||||
for field in FIELDS:
|
||||
f.write(struct.pack("B", data[field]))
|
||||
for x in range(16 - len(FIELDS)):
|
||||
f.write(struct.pack("B", 0))
|
||||
|
||||
if __name__ == "__main__":
|
||||
for filename in sys.argv[1:]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue