Kommentare hinzugefügt und ausgemistet

This commit is contained in:
Zoredh 2019-02-06 21:12:25 +01:00
parent 5283b64651
commit e8f305939f

27
hero.py
View file

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
import json
import pygame import pygame
import pygame.midi import pygame.midi
from os import environ from os import environ
@ -72,25 +71,27 @@ def proc_event(event,midi_out):
print("axis %d value %0.3f" % (event.axis, event.value)) print("axis %d value %0.3f" % (event.axis, event.value))
print PRESSED print PRESSED
try: try:
# Bei analogen Joysticks erst ab einem Fuenftel reagieren
if event.value > 0.2 or event.value < -0.2: if event.value > 0.2 or event.value < -0.2:
if PRESSED > 0: if PRESSED > 0:
CHORD = MAP[PRESSED] CHORD = MAP[PRESSED]
print CHORD print CHORD
# Nach unten ist > 0 Chordarray wird von links nach rechts gespielt
if event.value > 0: if event.value > 0:
i = 0 i = 0
j = 1 j = 1
PLAY = CHORDS[CHORD] PLAY = CHORDS[CHORD]
# nach oben halt von rechts nach links
else: else:
i = 5 i = 5
j = -1 j = -1
PLAY = CHORDS[CHORD][::-1] PLAY = CHORDS[CHORD][::-1]
# Spiele jede Note fuer die angeschlagene Saite des Akkords
for NOTE in PLAY: for NOTE in PLAY:
if NOTE > (-1): if NOTE > (-1):
print MOF[i]+NOTE print MOF[i]+NOTE
midi_out.note_on(MOF[i]+NOTE+CAPO,127) midi_out.note_on(MOF[i]+NOTE+CAPO,127)
#clock.tick(50)
else: else:
#print "X"
pass pass
i += j i += j
except: except:
@ -111,20 +112,6 @@ def proc_event(event,midi_out):
#print("PRESSED = %s" % PRESSED) #print("PRESSED = %s" % PRESSED)
except: except:
pass pass
'''
elif event.type == JOYAXISMOTION:
print("axis %d value %0.3f" % (event.axis, event.value))
if event.value > 0.2 or event.value < -0.2:
midi_out.note_on(40,127)
elif event.type == JOYBUTTONDOWN:
print("button %d down." % event.button)
elif event.type == JOYBUTTONUP:
print("button %d up." % event.button)
elif event.type == JOYHATMOTION:
print("hat motion.")
else:
print("hat event %s." % event.type)
'''
def main(): def main():
@ -151,10 +138,12 @@ def main():
JOYSTICKS.append(pygame.joystick.Joystick(0)) JOYSTICKS.append(pygame.joystick.Joystick(0))
JOYSTICKS[-1].init() JOYSTICKS[-1].init()
print("Detected joystick '%s'" % JOYSTICKS[-1].get_name()) print("Detected joystick '%s'" % JOYSTICKS[-1].get_name())
# 5 Millisekunden warten, bevor das Dingens hier weiterlaeuft
clock.tick(50)
while 1: while 1:
try: try:
# 5 Millisekunden warten, bevor das Dingens hier weiterlaeuft
clock.tick(50)
for event in pygame.event.get(): for event in pygame.event.get():
proc_event(event,midi_out) proc_event(event,midi_out)
except KeyboardInterrupt: except KeyboardInterrupt: