From 8ebe9c5fefcebca02b75398f93b5064e738002fd Mon Sep 17 00:00:00 2001 From: aarnaude Date: Fri, 28 Apr 2017 14:57:35 +0200 Subject: [PATCH] analyse midi --- analyse_midi_keyboard.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/analyse_midi_keyboard.c b/analyse_midi_keyboard.c index d42757c..8aaa8f5 100644 --- a/analyse_midi_keyboard.c +++ b/analyse_midi_keyboard.c @@ -12,18 +12,23 @@ -#define NUM_PORT 24 - -static snd_seq_t *seq; +//#define NUM_PORT 20 +static snd_seq_t *seq; +int NUM_PORT; +typedef struct { + int type; + int note; + int velocity; +} Evenement; void recup_num(){ FILE* fd; - int num_port; + //int NUM_PORT; fd=fopen("num_count2.txt","r"); - fscanf(fd, "%d", &num_port); - printf("num = %d \n", num_port); + fscanf(fd, "%d", &NUM_PORT); + printf("num = %d \n", NUM_PORT); fclose(fd); } @@ -46,12 +51,12 @@ static void create_port(void) int err; err = snd_seq_create_simple_port(seq, "analyseurmidi", - SND_SEQ_PORT_CAP_WRITE | - SND_SEQ_PORT_CAP_SUBS_WRITE, - SND_SEQ_PORT_TYPE_MIDI_GENERIC | - SND_SEQ_PORT_TYPE_APPLICATION); + SND_SEQ_PORT_CAP_WRITE | + SND_SEQ_PORT_CAP_SUBS_WRITE, + SND_SEQ_PORT_TYPE_MIDI_GENERIC | + SND_SEQ_PORT_TYPE_APPLICATION); if (err<0) - printf("Port non créé \n"); + printf("Port non créé \n"); } static void connect_port(void) @@ -59,34 +64,39 @@ static void connect_port(void) int err; err = snd_seq_connect_from(seq, 0, NUM_PORT, 0); if (err < 0) - printf("Impossible de se connecter au port \n"); - -} - -void action(snd_seq_event_t *event){ - - if (event->type == SND_SEQ_EVENT_NOTEON) - { - printf("note : %d , velocite : %d\n",event->data.note.note, event->data.note.velocity); - } - if (event->type == SND_SEQ_EVENT_NOTEOFF) - { - printf("noteOFF : %2d , %d velocite : %d\n", event->data.note.channel, event->data.note.note, event->data.note.velocity); - } - if (event->type == SND_SEQ_EVENT_CONTROLLER) - { - printf("programme : %2d, %d %d\n", event->data.control.channel, event->data.control.param, event->data.control.value); - } + printf("Impossible de se connecter au port \n"); } -int main(){ - init_seq(); - struct pollfd *pfds; - int npfds, err; - create_port(); - connect_port(); +Evenement action(snd_seq_event_t *event){ + Evenement k; + if (event->type == SND_SEQ_EVENT_NOTEON) + { + k.type=0; + k.note=event->data.note.note; + k.velocity=event->data.note.velocity; + //printf("note : %d , velocite : %d\n",event->data.note.note, event->data.note.velocity); + return k; + } + if (event->type == SND_SEQ_EVENT_NOTEOFF) + { + k.type=1; + k.note=event->data.note.note; + k.velocity=event->data.note.velocity; + //printf("noteOFF : %2d , %d velocite : %d\n", event->data.note.channel, event->data.note.note, event->data.note.velocity); + return k; + } +/* if (event->type == SND_SEQ_EVENT_CONTROLLER) + { + printf("programme : %2d, %d %d\n", event->data.control.channel, event->data.control.param, event->data.control.value); + }*/ + return k; +} +void boucle(){ + Evenement k; + struct pollfd *pfds; + int npfds, err; npfds = snd_seq_poll_descriptors_count(seq, POLLIN); pfds = alloca(sizeof(*pfds) * npfds); for (;;) { @@ -99,19 +109,22 @@ int main(){ if (err < 0) break; if (event) - { + { action(event); - } + } } while (err > 0); fflush(stdout); - } + } - - - snd_seq_close(seq); +} - recup_num(); - - return 0; +int lancer(){ + recup_num(); + init_seq(); + create_port(); + connect_port(); + boucle(); + snd_seq_close(seq); + return 0; } -- libgit2 0.21.2