-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.py
More file actions
50 lines (42 loc) · 974 Bytes
/
test1.py
File metadata and controls
50 lines (42 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#encoding=utf-8
import synth, midi
synth.init()
synth.create_reverb(8192, 0)
def handler( cmd ):
if isinstance(cmd, midi.Command.Note_ON):
cmd.note+=-24+3
# print cmd
if cmd.vel:
cmd.vel*=0.2/127.0
if cmd.chan==2:
cmd.chan=1
elif cmd.chan==9:
if cmd.note == 15:
cmd.chan=6
cmd.note=15
cmd.vel*=2.5
elif cmd.note in (48, 21, 25):
cmd.chan=4
elif cmd.chan==11:
cmd.chan=2
cmd.note+=12
elif cmd.chan==10:
cmd.chan=7
cmd.note+=24+12
cmd.vel*=.33
elif cmd.chan==12:
cmd.chan=2
cmd.note+=12+12+12
cmd.vel*=0.25
synth.play_note(cmd.chan, cmd.note, cmd.vel )
#midi.capture_midi_in( handler )
#capture = midi.Capture(handler)
#capture.start()
import struct
EV_KEY = 0x1
f=open("/dev/input/event0")
while 1:
ev_sec, ev_usec, ev_type, ev_code, ev_val = struct.unpack('qqHHi', f.read(24))
if ev_type == EV_KEY:
if ev_val == 1:
handler(midi.Command.Note_ON( 11, ev_code+30, 100))