Blacken all Python files

Using the black code reformatter, pass it over all our Python files.
This allows for a consistent style across the code base.

Exception: lumps/dmxgus/stats.py, for readability.
This commit is contained in:
Mike Swanson 2019-09-04 19:36:23 -07:00
parent 6b486b6332
commit 4701d8f351
30 changed files with 2528 additions and 2102 deletions

View file

@ -23,16 +23,18 @@
from config import *
import midi
def instrument_num(instrument):
"""Given a GUS patch name, get the MIDI instrument number.
For percussion instruments, the instrument number is offset
by 128.
"""
for key, name in GUS_INSTR_PATCHES.items():
if name == instrument:
return key
raise Exception('Unknown instrument %s' % instrument)
def instrument_num(instrument):
"""Given a GUS patch name, get the MIDI instrument number.
For percussion instruments, the instrument number is offset
by 128.
"""
for key, name in GUS_INSTR_PATCHES.items():
if name == instrument:
return key
raise Exception("Unknown instrument %s" % instrument)
pattern = midi.Pattern(resolution=48)
track = midi.Track()
@ -40,62 +42,70 @@ track.append(midi.ControlChangeEvent(tick=0, channel=9, data=[7, 92]))
time = 500
for group in SIMILAR_GROUPS:
# Don't bother with special effects.
#if group[0] == 'blank':
# continue
# Don't bother with special effects.
# if group[0] == 'blank':
# continue
print "Group: "
empty = True
for instrument in group:
inum = instrument_num(instrument)
print("Group: ")
empty = True
for instrument in group:
inum = instrument_num(instrument)
# For normal instruments, play a couple of different notes.
# For percussion instruments, play a couple of note on
# the percussion channel.
if inum <= 128:
print "\t%s (%i)" % (instrument, inum)
track.extend([
midi.ProgramChangeEvent(tick=time, channel=0,
data=[inum]),
midi.NoteOnEvent(tick=0, channel=0,
velocity=92, pitch=midi.A_3),
midi.NoteOffEvent(tick=50, channel=0,
velocity=92, pitch=midi.A_3),
midi.NoteOnEvent(tick=0, channel=0,
velocity=92, pitch=midi.B_3),
midi.NoteOffEvent(tick=50, channel=0,
velocity=92, pitch=midi.B_3),
])
else:
print "\t%s (percussion %i)" % (instrument, inum-128)
track.extend([
midi.NoteOnEvent(tick=time, channel=9,
velocity=92, pitch=inum-128),
midi.NoteOffEvent(tick=50, channel=9,
pitch=inum-128),
midi.NoteOnEvent(tick=0, channel=9,
velocity=92, pitch=inum-128),
midi.NoteOffEvent(tick=50, channel=9,
pitch=inum-128),
])
# For normal instruments, play a couple of different notes.
# For percussion instruments, play a couple of note on
# the percussion channel.
if inum <= 128:
print("\t%s (%i)" % (instrument, inum))
track.extend(
[
midi.ProgramChangeEvent(tick=time, channel=0, data=[inum]),
midi.NoteOnEvent(
tick=0, channel=0, velocity=92, pitch=midi.A_3
),
midi.NoteOffEvent(
tick=50, channel=0, velocity=92, pitch=midi.A_3
),
midi.NoteOnEvent(
tick=0, channel=0, velocity=92, pitch=midi.B_3
),
midi.NoteOffEvent(
tick=50, channel=0, velocity=92, pitch=midi.B_3
),
]
)
else:
print("\t%s (percussion %i)" % (instrument, inum - 128))
track.extend(
[
midi.NoteOnEvent(
tick=time, channel=9, velocity=92, pitch=inum - 128
),
midi.NoteOffEvent(tick=50, channel=9, pitch=inum - 128),
midi.NoteOnEvent(
tick=0, channel=9, velocity=92, pitch=inum - 128
),
midi.NoteOffEvent(tick=50, channel=9, pitch=inum - 128),
]
)
empty = False
time = 100
empty = False
time = 100
if not empty:
time = 500
if not empty:
time = 500
# Four drumbeats indicate the end of the track and that the music is
# going to loop.
for i in range(4):
track.extend([
midi.NoteOnEvent(tick=20, channel=9, velocity=92, pitch=35),
midi.NoteOffEvent(tick=20, channel=9, pitch=35),
])
track.extend(
[
midi.NoteOnEvent(tick=20, channel=9, velocity=92, pitch=35),
midi.NoteOffEvent(tick=20, channel=9, pitch=35),
]
)
track.append(midi.EndOfTrackEvent(tick=1))
pattern.append(track)
# Save the pattern to disk
midi.write_midifile("comparison.mid", pattern)