Commit 876963c4e12d6953c2295f0d40de5795d7b2feb1
1 parent
8ebe9c5f
threading sur les FDs avec le clavier maitre MIDI
Showing
2 changed files
with
165 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +midi_note={} | ||
2 | + | ||
3 | +midi_note[0]=262 | ||
4 | +midi_note[1]=277 | ||
5 | +midi_note[2]=294 | ||
6 | +midi_note[3]=311 | ||
7 | +midi_note[4]=330 | ||
8 | +midi_note[5]=349 | ||
9 | +midi_note[6]=370 | ||
10 | +midi_note[7]=392 | ||
11 | +midi_note[8]=415 | ||
12 | +midi_note[9]=440 | ||
13 | +midi_note[10]=466 | ||
14 | +midi_note[11]=494 | ||
15 | +midi_note[12]=523 | ||
16 | +midi_note[13]=554 | ||
17 | +midi_note[14]=587 | ||
18 | +midi_note[15]=622 | ||
19 | +midi_note[16]=659 | ||
20 | +midi_note[17]=698 | ||
21 | +midi_note[18]=740 | ||
22 | +midi_note[19]=784 | ||
23 | +midi_note[20]=831 | ||
24 | +midi_note[21]=880 | ||
25 | +midi_note[22]=932 | ||
26 | +midi_note[23]=988 | ||
27 | +midi_note[24]=1046 | ||
28 | +midi_note[25]=1109 | ||
29 | +midi_note[26]=1175 | ||
30 | +midi_note[27]=1244 | ||
31 | +midi_note[28]=1318 | ||
32 | +midi_note[29]=1397 | ||
33 | +midi_note[30]=1480 | ||
34 | +midi_note[31]=1568 | ||
35 | +midi_note[32]=1661 | ||
36 | +midi_note[33]=1760 | ||
37 | +midi_note[34]=1865 | ||
38 | +midi_note[35]=1975 | ||
39 | +midi_note[36]=2093 | ||
40 | +midi_note[37]=2217 | ||
41 | +midi_note[38]=2349 | ||
42 | +midi_note[39]=2489 | ||
43 | +midi_note[40]=2637 | ||
44 | +midi_note[41]=2794 | ||
45 | +midi_note[42]=2960 | ||
46 | +midi_note[43]=3136 | ||
47 | +midi_note[44]=3322 | ||
48 | +midi_note[45]=3520 | ||
49 | +midi_note[46]=3729 | ||
50 | +midi_note[47]=3951 | ||
51 | +midi_note[48]=4186 | ||
52 | +midi_note[49]=4435 | ||
53 | +midi_note[50]=4698 | ||
54 | +midi_note[51]=4978 | ||
55 | +midi_note[52]=5274 | ||
56 | +midi_note[53]=5588 | ||
57 | +midi_note[54]=5920 | ||
58 | +midi_note[55]=6272 | ||
59 | +midi_note[56]=6645 | ||
60 | +midi_note[57]=7040 | ||
61 | +midi_note[58]=7458 | ||
62 | +midi_note[59]=7902 | ||
63 | +midi_note[60]=8372 | ||
64 | +midi_note[61]=8870 | ||
65 | +midi_note[62]=9396 | ||
66 | +midi_note[63]=9956 | ||
67 | +midi_note[64]=10548 | ||
68 | +midi_note[65]=11176 | ||
69 | +midi_note[66]=11840 | ||
70 | +midi_note[67]=12544 | ||
71 | +midi_note[68]=13290 | ||
72 | +midi_note[69]=14080 | ||
73 | +midi_note[70]=14918 | ||
74 | +midi_note[71]=15804 | ||
75 | +midi_note[72]=16744 | ||
76 | +midi_note[73]=17740 | ||
77 | +midi_note[74]=18792 | ||
78 | +midi_note[75]=19912 | ||
79 | +midi_note[76]=21098 |
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
1 | +from ctypes import * | ||
2 | +from RPi import GPIO | ||
3 | +from threading import Thread | ||
4 | +from threading import Event | ||
5 | +import dico_akai | ||
6 | +import ctypes as ct | ||
7 | +import signal | ||
8 | +import sys | ||
9 | + | ||
10 | +_lib = ct.cdll.LoadLibrary("./libanalysemidi.so") | ||
11 | + | ||
12 | +class Evenement(Structure): | ||
13 | + _fields_ = [("type", ct.c_int),("note", ct.c_int), ("velocity",ct.c_int)] | ||
14 | + | ||
15 | +_lib.wait_event.restype = Evenement | ||
16 | + | ||
17 | +class FD(Thread): | ||
18 | + | ||
19 | + def __init__(self, pin): | ||
20 | + Thread.__init__(self); | ||
21 | + self.pin = pin | ||
22 | + self.running = False | ||
23 | + | ||
24 | + def run(self): | ||
25 | + p = GPIO.PWM(self.pin,1) | ||
26 | + p.start(50) | ||
27 | + self.running = True | ||
28 | + while self.running: | ||
29 | + e.wait() | ||
30 | + if r.type == 0: | ||
31 | + p.ChangeFrequency(dico_akai.midi_note[r.note]) | ||
32 | + if r.type == 1: | ||
33 | + p.ChangeFrequency(1) | ||
34 | + e.clear() | ||
35 | + | ||
36 | + def stop(self): | ||
37 | + self.running = False | ||
38 | + | ||
39 | +def fin_du_live(signal, frame): | ||
40 | + print("fin du live") | ||
41 | + e.set() | ||
42 | + fd1.stop() | ||
43 | + fd2.stop() | ||
44 | + fd1.join() | ||
45 | + fd2.join() | ||
46 | + GPIO.cleanup() | ||
47 | + _lib.close() | ||
48 | + sys.exit(0) | ||
49 | + | ||
50 | +signal.signal(signal.SIGINT, fin_du_live) | ||
51 | +_lib.recup_num() | ||
52 | +_lib.init_seq() | ||
53 | +_lib.create_port() | ||
54 | +_lib.connect_port() | ||
55 | +#Initialisation des FDs | ||
56 | +GPIO.setmode(GPIO.BCM) | ||
57 | +#FD1 | ||
58 | +GPIO.setup(23,GPIO.OUT) | ||
59 | +GPIO.setup(24,GPIO.OUT) | ||
60 | +GPIO.setup(25,GPIO.OUT) | ||
61 | +#FD2 | ||
62 | +GPIO.setup(16,GPIO.OUT) | ||
63 | +GPIO.setup(20,GPIO.OUT) | ||
64 | +GPIO.setup(21,GPIO.OUT) | ||
65 | +#PWM | ||
66 | +GPIO.setup(18,GPIO.OUT) | ||
67 | +GPIO.setup(13,GPIO.OUT) | ||
68 | +#Act FD1 | ||
69 | +GPIO.output(23,GPIO.LOW) | ||
70 | +GPIO.output(24,GPIO.LOW) | ||
71 | +GPIO.output(25,GPIO.LOW) | ||
72 | +#Act FD2 | ||
73 | +GPIO.output(16,GPIO.LOW) | ||
74 | +GPIO.output(20,GPIO.LOW) | ||
75 | +GPIO.output(21,GPIO.LOW) | ||
76 | + | ||
77 | +r = _lib.wait_event() | ||
78 | +e = Event() | ||
79 | + | ||
80 | +fd1 = FD(13) | ||
81 | +fd2 = FD(18) | ||
82 | +fd1.start() | ||
83 | +fd2.start() | ||
84 | +while(True): | ||
85 | + r = _lib.wait_event() | ||
86 | + e.set() |