From 1dd5235944e6dd940da50724b821f8160d699149 Mon Sep 17 00:00:00 2001 From: Zoredh Date: Fri, 1 Feb 2019 01:30:10 +0100 Subject: [PATCH] erste funktionierende version --- README.md | 4 +++- hero.py | 50 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 615f71e..ed63d78 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # herocontrol -Midi-Guitarhero-Controller \ No newline at end of file +Midi-Guitarhero-Controller + +kleine Spielerei, um aus einem Guitar-Hero-Controller oder ähnlichem mal n bisschen "Krach" rauszubekommen diff --git a/hero.py b/hero.py index 3ec2e4c..af98e6d 100644 --- a/hero.py +++ b/hero.py @@ -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))