Commit 9517040e20820ebb65f5a3250a0843fb091e99f8

Authored by aarnaude
1 parent 876963c4

live avec le clavier midi

Showing 3 changed files with 92 additions and 16 deletions   Show diff stats
analyse_midi_keyboard.c
... ... @@ -28,12 +28,12 @@ void recup_num(){
28 28 //int NUM_PORT;
29 29 fd=fopen("num_count2.txt","r");
30 30 fscanf(fd, "%d", &NUM_PORT);
31   - printf("num = %d \n", NUM_PORT);
  31 + //printf("num = %d \n", NUM_PORT);
32 32 fclose(fd);
33 33  
34 34 }
35 35  
36   -static void init_seq(void)
  36 +void init_seq(void)
37 37 {
38 38 int err;
39 39  
... ... @@ -46,7 +46,7 @@ static void init_seq(void)
46 46 if (err<0) printf("set client name");
47 47 }
48 48  
49   -static void create_port(void)
  49 +void create_port(void)
50 50 {
51 51 int err;
52 52  
... ... @@ -59,7 +59,7 @@ static void create_port(void)
59 59 printf("Port non créé \n");
60 60 }
61 61  
62   -static void connect_port(void)
  62 +void connect_port(void)
63 63 {
64 64 int err;
65 65 err = snd_seq_connect_from(seq, 0, NUM_PORT, 0);
... ... @@ -93,8 +93,7 @@ Evenement action(snd_seq_event_t *event){
93 93 return k;
94 94 }
95 95  
96   -void boucle(){
97   - Evenement k;
  96 +Evenement wait_event(){
98 97 struct pollfd *pfds;
99 98 int npfds, err;
100 99 npfds = snd_seq_poll_descriptors_count(seq, POLLIN);
... ... @@ -110,21 +109,16 @@ void boucle(){
110 109 break;
111 110 if (event)
112 111 {
113   - action(event);
  112 + return action(event);
114 113 }
115 114 } while (err > 0);
116 115 fflush(stdout);
117 116 }
  117 +
118 118  
119 119 }
120 120  
121 121  
122   -int lancer(){
123   - recup_num();
124   - init_seq();
125   - create_port();
126   - connect_port();
127   - boucle();
  122 +void close_sequencer(){
128 123 snd_seq_close(seq);
129   - return 0;
130 124 }
... ...
  1 +from ctypes import *
  2 +from RPi import GPIO
  3 +from threading import Thread
  4 +from threading import Event
  5 +import dico_akai
1 6 import ctypes as ct
2   -_lib = ct.cdll.LoadLibrary("./analyse.so")
  7 +import signal
  8 +import sys
3 9  
4   -_lib.lancer()
  10 +_lib = ct.cdll.LoadLibrary("./libanalysemidi.so")
5 11  
  12 +class Evenement(Structure):
  13 + _fields_ = [("type", ct.c_int),("note", ct.c_int), ("velocity",ct.c_int)]
6 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 + if b == 1:
  30 + if r.type == 0:
  31 + p.ChangeFrequency(dico_akai.midi_note[r.note])
  32 + if r.type == 1:
  33 + p.ChangeFrequency(1)
  34 +
  35 + def stop(self):
  36 + self.running = False
  37 +
  38 +def fin_du_live(signal, frame):
  39 + print("fin du live")
  40 + fd1.stop()
  41 + fd2.stop()
  42 + fd1.join()
  43 + fd2.join()
  44 + GPIO.cleanup()
  45 + _lib.close()
  46 + sys.exit(0)
  47 +
  48 +signal.signal(signal.SIGINT, fin_du_live)
  49 +_lib.recup_num()
  50 +_lib.init_seq()
  51 +_lib.create_port()
  52 +_lib.connect_port()
  53 +#Initialisation des FDs
  54 +GPIO.setmode(GPIO.BCM)
  55 +#FD1
  56 +GPIO.setup(23,GPIO.OUT)
  57 +GPIO.setup(24,GPIO.OUT)
  58 +GPIO.setup(25,GPIO.OUT)
  59 +#FD2
  60 +GPIO.setup(16,GPIO.OUT)
  61 +GPIO.setup(20,GPIO.OUT)
  62 +GPIO.setup(21,GPIO.OUT)
  63 +#PWM
  64 +GPIO.setup(18,GPIO.OUT)
  65 +GPIO.setup(13,GPIO.OUT)
  66 +#Act FD1
  67 +GPIO.output(23,GPIO.LOW)
  68 +GPIO.output(24,GPIO.LOW)
  69 +GPIO.output(25,GPIO.LOW)
  70 +#Act FD2
  71 +GPIO.output(16,GPIO.LOW)
  72 +GPIO.output(20,GPIO.LOW)
  73 +GPIO.output(21,GPIO.LOW)
  74 +r = _lib.wait_event()
  75 +b = 1
  76 +fd1 = FD(13)
  77 +fd2 = FD(18)
  78 +fd1.start()
  79 +fd2.start()
  80 +while(True):
  81 + prev = r.type
  82 + r = _lib.wait_event()
  83 + if r.type != prev:
  84 + b=1
  85 + else:
  86 + b=0
... ...
test2.py 100644 → 100755
  1 +#! /usr/bin/python
  2 +
1 3 from ctypes import *
2 4 from RPi import GPIO
3 5 from threading import Thread
... ...