diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2013-09-20 23:12:50 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2013-09-20 23:12:50 +0200 |
commit | 400d698a605288b05abde5024ca50d9a289cb0e1 (patch) | |
tree | 1c157d645d7d14ecfae8463dba0713c431fa315f /midi-keyboard | |
parent | d636b27779a1bac6c55075086c170818346003b7 (diff) | |
download | scripts-400d698a605288b05abde5024ca50d9a289cb0e1.tar.gz scripts-400d698a605288b05abde5024ca50d9a289cb0e1.zip |
midikeyboard
Diffstat (limited to 'midi-keyboard')
-rw-r--r-- | midi-keyboard/midikeyboard.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/midi-keyboard/midikeyboard.py b/midi-keyboard/midikeyboard.py new file mode 100644 index 0000000..36765a6 --- /dev/null +++ b/midi-keyboard/midikeyboard.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +from evdev import uinput, ecodes as ec +import pygame +import pygame.midi +from pygame.locals import * +import time + +pygame.init() +pygame.fastevent.init() +event_get = pygame.fastevent.get +event_post = pygame.fastevent.post +pygame.midi.init() + +input_id = 2 +print ("using input_id :%s:" % input_id) +i = pygame.midi.Input( input_id ) + +keymap = { + 84:ec.KEY_ENTER, + 83:ec.KEY_F1, + 81:ec.KEY_F2, + 79:ec.KEY_F3, + 77:ec.KEY_F4, + 76:ec.KEY_F5, + 75:ec.KEY_ESCAPE, +} + +with uinput.UInput() as ui: + going = True + while going: + events = event_get() + for e in events: + if e.type in [QUIT]: + going = False + if e.type in [pygame.midi.MIDIIN]: + if e.data2>0: status = 1 + else: status = 0 + if keymap.has_key(e.data1): + ui.write(ec.EV_KEY, code, status) + ui.syn() + else: + print "unknown key",e + + if i.poll(): + midi_events = i.read(10) + midi_evs = pygame.midi.midis2events(midi_events, i.device_id) + for m_e in midi_evs: + event_post( m_e ) + del i + +pygame.midi.quit() |