erste funktionierende version

This commit is contained in:
Zoredh 2019-02-01 01:30:10 +01:00
parent 9fe6a0e868
commit 1dd5235944
2 changed files with 44 additions and 10 deletions

View file

@ -1,3 +1,5 @@
# herocontrol
Midi-Guitarhero-Controller
Midi-Guitarhero-Controller
kleine Spielerei, um aus einem Guitar-Hero-Controller oder ähnlichem mal n bisschen "Krach" rauszubekommen

50
hero.py
View file

@ -6,6 +6,9 @@ from os import environ
from pygame.locals import QUIT, JOYBUTTONUP, JOYBUTTONDOWN, \
JOYAXISMOTION, JOYHATMOTION
# Braucht man fuer die Abfrage-Rate
clock = pygame.time.Clock()
# Bekannte Joysticks (ich verwende aber nur den ersten)
JOYSTICKS = []
@ -16,7 +19,8 @@ BUTTONS = {0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,11:8}
PRESSED = 0
# Midi-Offset (Leersaiten E2,A2,D3,G3,B3,E4)
MOF = {28,33,38,43,47,52}
MOF = {0:28,1:33,2:38,3:43,4:47,5:52}
CAPO = 12
# In welchem Bund sind die Saiten gedrueckt (-1 = nicht gespielt, 0 = Leersaite, 1 = 1. Bund usw.)
CHORDS = {
@ -36,7 +40,12 @@ CHORDS = {
"Gm":[3,5,5,3,3,3]
}
MAP = {
1:"C",
2:"D",
4:"Em",
8:"G"
}
# Hilfsfunktionen fuer die Bit-Manipulation (PRESSED)
def setbit(int_type, offset):
@ -49,22 +58,48 @@ def clearbit(int_type, offset):
def proc_event(event,midi_out):
global PRESSED
global CAPO
"Parse and act upon event"
if event.type == QUIT:
print("Received event 'Quit', exiting.")
exit(0)
elif event.type == JOYAXISMOTION:
print("axis %d value %0.3f" % (event.axis, event.value))
if event.value > 0.2 or event.value < -0.2:
if PRESSED > 0:
CHORD = MAP[PRESSED]
print CHORD
if event.value > 0:
i = 0
j = 1
PLAY = CHORDS[CHORD]
else:
i = 5
j = -1
PLAY = CHORDS[CHORD][::-1]
for NOTE in PLAY:
if NOTE > (-1):
print MOF[i]+NOTE
midi_out.note_on(MOF[i]+NOTE+CAPO,127)
clock.tick(50)
else:
#print "X"
pass
i += j
elif event.type == JOYBUTTONDOWN:
try:
print("button %d down." % event.button)
#print("button %d down." % event.button)
PRESSED = setbit(PRESSED,BUTTONS[event.button])
print("PRESSED = %s" % PRESSED)
#print("PRESSED = %s" % PRESSED)
except:
pass
elif event.type == JOYBUTTONUP:
try:
print("button %d up." % event.button)
#print("button %d up." % event.button)
PRESSED = clearbit(PRESSED,BUTTONS[event.button])
print("PRESSED = %s" % PRESSED)
#print("PRESSED = %s" % PRESSED)
except:
pass
'''
@ -99,9 +134,6 @@ def main():
environ["SDL_VIDEODRIVER"] = "dummy"
environ["SDL_AUDIODRIVER"] = "dummy"
# Braucht man fuer die Abfrage-Rate
clock = pygame.time.Clock()
# Alle Joysticks, die du findest
#for i in range(0, pygame.joystick.get_count()):
# JOYSTICKS.append(pygame.joystick.Joystick(i))