Blame view

test2.py 1.74 KB
9517040e   aarnaude   live avec le clav...
1
2
  #! /usr/bin/python
  
876963c4   aarnaude   threading sur les...
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  from ctypes import *
  from RPi import GPIO
  from threading import Thread
  from threading import Event
  import dico_akai
  import ctypes as ct
  import signal
  import sys
  
  _lib = ct.cdll.LoadLibrary("./libanalysemidi.so")
  
  class Evenement(Structure):
  	_fields_ = [("type", ct.c_int),("note", ct.c_int), ("velocity",ct.c_int)]
  
  _lib.wait_event.restype = Evenement
  
  class FD(Thread):
  
          def __init__(self, pin):
                  Thread.__init__(self);
                  self.pin = pin
  		self.running = False
  
          def run(self):
                  p = GPIO.PWM(self.pin,1)
                  p.start(50)
  		self.running = True
                  while self.running:
                          	e.wait()
  				if r.type == 0:
                                  	p.ChangeFrequency(dico_akai.midi_note[r.note])
                          	if r.type == 1:
                                  	p.ChangeFrequency(1)
  				e.clear()
  
  	def stop(self):
  		self.running = False
  
  def fin_du_live(signal, frame):
  	print("fin du live")
  	e.set()
  	fd1.stop()
  	fd2.stop()
  	fd1.join()
  	fd2.join()
  	GPIO.cleanup()
  	_lib.close()	
  	sys.exit(0)
  
  signal.signal(signal.SIGINT, fin_du_live)
  _lib.recup_num()
  _lib.init_seq()
  _lib.create_port()
  _lib.connect_port()
  #Initialisation des FDs
  GPIO.setmode(GPIO.BCM)
  #FD1
  GPIO.setup(23,GPIO.OUT)
  GPIO.setup(24,GPIO.OUT)
  GPIO.setup(25,GPIO.OUT)
  #FD2
  GPIO.setup(16,GPIO.OUT)
  GPIO.setup(20,GPIO.OUT)
  GPIO.setup(21,GPIO.OUT)
  #PWM
  GPIO.setup(18,GPIO.OUT)
  GPIO.setup(13,GPIO.OUT)
  #Act FD1
  GPIO.output(23,GPIO.LOW)
  GPIO.output(24,GPIO.LOW)
  GPIO.output(25,GPIO.LOW)
  #Act FD2
  GPIO.output(16,GPIO.LOW)
  GPIO.output(20,GPIO.LOW)
  GPIO.output(21,GPIO.LOW)
  
  r = _lib.wait_event()
  e = Event()
  
  fd1 = FD(13)
  fd2 = FD(18)
  fd1.start()
  fd2.start()
  while(True):
  	r = _lib.wait_event()
  	e.set()