diff --git a/analyse_midi_keyboard.c b/analyse_midi_keyboard.c index 8aaa8f5..b829395 100644 --- a/analyse_midi_keyboard.c +++ b/analyse_midi_keyboard.c @@ -28,12 +28,12 @@ void recup_num(){ //int NUM_PORT; fd=fopen("num_count2.txt","r"); fscanf(fd, "%d", &NUM_PORT); - printf("num = %d \n", NUM_PORT); + //printf("num = %d \n", NUM_PORT); fclose(fd); } -static void init_seq(void) +void init_seq(void) { int err; @@ -46,7 +46,7 @@ static void init_seq(void) if (err<0) printf("set client name"); } -static void create_port(void) +void create_port(void) { int err; @@ -59,7 +59,7 @@ static void create_port(void) printf("Port non créé \n"); } -static void connect_port(void) +void connect_port(void) { int err; err = snd_seq_connect_from(seq, 0, NUM_PORT, 0); @@ -93,8 +93,7 @@ Evenement action(snd_seq_event_t *event){ return k; } -void boucle(){ - Evenement k; +Evenement wait_event(){ struct pollfd *pfds; int npfds, err; npfds = snd_seq_poll_descriptors_count(seq, POLLIN); @@ -110,21 +109,16 @@ void boucle(){ break; if (event) { - action(event); + return action(event); } } while (err > 0); fflush(stdout); } + } -int lancer(){ - recup_num(); - init_seq(); - create_port(); - connect_port(); - boucle(); +void close_sequencer(){ snd_seq_close(seq); - return 0; } diff --git a/test.py b/test.py index e017ac9..77d9a55 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,86 @@ +from ctypes import * +from RPi import GPIO +from threading import Thread +from threading import Event +import dico_akai import ctypes as ct -_lib = ct.cdll.LoadLibrary("./analyse.so") +import signal +import sys -_lib.lancer() +_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: + if b == 1: + if r.type == 0: + p.ChangeFrequency(dico_akai.midi_note[r.note]) + if r.type == 1: + p.ChangeFrequency(1) + + def stop(self): + self.running = False + +def fin_du_live(signal, frame): + print("fin du live") + 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() +b = 1 +fd1 = FD(13) +fd2 = FD(18) +fd1.start() +fd2.start() +while(True): + prev = r.type + r = _lib.wait_event() + if r.type != prev: + b=1 + else: + b=0 diff --git a/test2.py b/test2.py old mode 100644 new mode 100755 index 807d62c..3626d06 --- a/test2.py +++ b/test2.py @@ -1,3 +1,5 @@ +#! /usr/bin/python + from ctypes import * from RPi import GPIO from threading import Thread -- libgit2 0.21.2