From 400d698a605288b05abde5024ca50d9a289cb0e1 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Fri, 20 Sep 2013 23:12:50 +0200 Subject: midikeyboard --- midi-keyboard/midikeyboard.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 midi-keyboard/midikeyboard.py (limited to 'midi-keyboard') 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() -- cgit v1.2.1