mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-01 13:25:46 -04:00
genmidi: Better dumpgenmidi output.
This adds dumping for the tune= field that was just added in commit
276118107
, but also:
* Instrument name gets put in a comment at the end of line - like the
current configuration in config.py.
* Instrument calls get split across two lines when there are many
parameters, to try to keep to 80 columns.
* off1= and off2= parameters now get outputted as +x or -x rather than
just x or -x.
This commit is contained in:
parent
ffb7348b8e
commit
a94ae50ffb
1 changed files with 29 additions and 7 deletions
|
@ -26,23 +26,41 @@ def instr_to_str_def(filename, filename2, instr):
|
|||
if is_null_voice(instr.voice1):
|
||||
return "NullInstrument"
|
||||
|
||||
args = ['"%s"' % filename]
|
||||
file_args = "%r" % filename
|
||||
|
||||
if instr.voice2 is not None:
|
||||
args.append('"%s"' % filename2)
|
||||
file_args += ", %r" % filename2
|
||||
|
||||
instr_name = instr.voice1["name"]
|
||||
|
||||
extra_args = []
|
||||
if instr.fixed_note is not None:
|
||||
args.append("note=%s" % midi.def_for_note(instr.fixed_note))
|
||||
extra_args.append("note=%s" % midi.def_for_note(instr.fixed_note))
|
||||
if instr.offset1 != 0:
|
||||
args.append("off1=%i" % instr.offset1)
|
||||
extra_args.append("off1=%+i" % instr.offset1)
|
||||
if instr.offset2 != 0:
|
||||
args.append("off2=%i" % instr.offset2)
|
||||
extra_args.append("off2=%+i" % instr.offset2)
|
||||
if instr.tune != 0:
|
||||
extra_args.append("tune=%+i" % instr.tune)
|
||||
|
||||
return "Instrument(%s)" % (", ".join(args))
|
||||
extra_args = ", ".join(extra_args)
|
||||
if extra_args:
|
||||
file_args += ", "
|
||||
|
||||
if len(file_args + extra_args) <= 32:
|
||||
return "\tInstrument(%s%s), %s# %s" % (
|
||||
file_args, extra_args,
|
||||
" " * (32 - len(file_args + extra_args)),
|
||||
instr_name)
|
||||
|
||||
return "\tInstrument(%s %s# %s\n\t %s)," % (
|
||||
file_args.strip(),
|
||||
" " * (35 - len(file_args)), instr_name,
|
||||
extra_args)
|
||||
|
||||
|
||||
def print_instr_def(filename, filename2, instr):
|
||||
print("\t%s," % instr_to_str_def(filename, filename2, instr))
|
||||
print(instr_to_str_def(filename, filename2, instr))
|
||||
|
||||
|
||||
def dump_instrument(filename, filename2, instr):
|
||||
|
@ -65,6 +83,9 @@ instruments = genmidi.read(sys.argv[1])
|
|||
main_instrs = instruments[0:128]
|
||||
percussion = instruments[128:]
|
||||
|
||||
print("# Note: all instruments must ALWAYS be defined, or use NullInstrument.")
|
||||
print("")
|
||||
print("# General MIDI instruments:")
|
||||
print("INSTRUMENTS = [")
|
||||
|
||||
for i in range(len(main_instrs)):
|
||||
|
@ -76,6 +97,7 @@ for i in range(len(main_instrs)):
|
|||
|
||||
print("]")
|
||||
print("")
|
||||
print("# Percussion instruments:")
|
||||
print("PERCUSSION = [")
|
||||
|
||||
for i in range(len(percussion)):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue