Commit 8ebe9c5fefcebca02b75398f93b5064e738002fd

Authored by aarnaude
1 parent b8018ff4

analyse midi

Showing 1 changed file with 57 additions and 44 deletions   Show diff stats
analyse_midi_keyboard.c
... ... @@ -12,18 +12,23 @@
12 12  
13 13  
14 14  
15   -#define NUM_PORT 24
16   -
17   -static snd_seq_t *seq;
  15 +//#define NUM_PORT 20
18 16  
19 17  
  18 +static snd_seq_t *seq;
  19 +int NUM_PORT;
  20 +typedef struct {
  21 + int type;
  22 + int note;
  23 + int velocity;
  24 +} Evenement;
20 25  
21 26 void recup_num(){
22 27 FILE* fd;
23   - int num_port;
  28 + //int NUM_PORT;
24 29 fd=fopen("num_count2.txt","r");
25   - fscanf(fd, "%d", &num_port);
26   - printf("num = %d \n", num_port);
  30 + fscanf(fd, "%d", &NUM_PORT);
  31 + printf("num = %d \n", NUM_PORT);
27 32 fclose(fd);
28 33  
29 34 }
... ... @@ -46,12 +51,12 @@ static void create_port(void)
46 51 int err;
47 52  
48 53 err = snd_seq_create_simple_port(seq, "analyseurmidi",
49   - SND_SEQ_PORT_CAP_WRITE |
50   - SND_SEQ_PORT_CAP_SUBS_WRITE,
51   - SND_SEQ_PORT_TYPE_MIDI_GENERIC |
52   - SND_SEQ_PORT_TYPE_APPLICATION);
  54 + SND_SEQ_PORT_CAP_WRITE |
  55 + SND_SEQ_PORT_CAP_SUBS_WRITE,
  56 + SND_SEQ_PORT_TYPE_MIDI_GENERIC |
  57 + SND_SEQ_PORT_TYPE_APPLICATION);
53 58 if (err<0)
54   - printf("Port non créé \n");
  59 + printf("Port non créé \n");
55 60 }
56 61  
57 62 static void connect_port(void)
... ... @@ -59,34 +64,39 @@ static void connect_port(void)
59 64 int err;
60 65 err = snd_seq_connect_from(seq, 0, NUM_PORT, 0);
61 66 if (err < 0)
62   - printf("Impossible de se connecter au port \n");
63   -
64   -}
65   -
66   -void action(snd_seq_event_t *event){
67   -
68   - if (event->type == SND_SEQ_EVENT_NOTEON)
69   - {
70   - printf("note : %d , velocite : %d\n",event->data.note.note, event->data.note.velocity);
71   - }
72   - if (event->type == SND_SEQ_EVENT_NOTEOFF)
73   - {
74   - printf("noteOFF : %2d , %d velocite : %d\n", event->data.note.channel, event->data.note.note, event->data.note.velocity);
75   - }
76   - if (event->type == SND_SEQ_EVENT_CONTROLLER)
77   - {
78   - printf("programme : %2d, %d %d\n", event->data.control.channel, event->data.control.param, event->data.control.value);
79   - }
  67 + printf("Impossible de se connecter au port \n");
80 68  
81 69 }
82 70  
83   -int main(){
84   - init_seq();
85   - struct pollfd *pfds;
86   - int npfds, err;
87   - create_port();
88   - connect_port();
  71 +Evenement action(snd_seq_event_t *event){
  72 + Evenement k;
  73 + if (event->type == SND_SEQ_EVENT_NOTEON)
  74 + {
  75 + k.type=0;
  76 + k.note=event->data.note.note;
  77 + k.velocity=event->data.note.velocity;
  78 + //printf("note : %d , velocite : %d\n",event->data.note.note, event->data.note.velocity);
  79 + return k;
  80 + }
  81 + if (event->type == SND_SEQ_EVENT_NOTEOFF)
  82 + {
  83 + k.type=1;
  84 + k.note=event->data.note.note;
  85 + k.velocity=event->data.note.velocity;
  86 + //printf("noteOFF : %2d , %d velocite : %d\n", event->data.note.channel, event->data.note.note, event->data.note.velocity);
  87 + return k;
  88 + }
  89 +/* if (event->type == SND_SEQ_EVENT_CONTROLLER)
  90 + {
  91 + printf("programme : %2d, %d %d\n", event->data.control.channel, event->data.control.param, event->data.control.value);
  92 + }*/
  93 + return k;
  94 +}
89 95  
  96 +void boucle(){
  97 + Evenement k;
  98 + struct pollfd *pfds;
  99 + int npfds, err;
90 100 npfds = snd_seq_poll_descriptors_count(seq, POLLIN);
91 101 pfds = alloca(sizeof(*pfds) * npfds);
92 102 for (;;) {
... ... @@ -99,19 +109,22 @@ int main(){
99 109 if (err < 0)
100 110 break;
101 111 if (event)
102   - {
  112 + {
103 113 action(event);
104   - }
  114 + }
105 115 } while (err > 0);
106 116 fflush(stdout);
107   - }
  117 + }
108 118  
109   -
110   -
111   - snd_seq_close(seq);
  119 +}
112 120  
113 121  
114   - recup_num();
115   -
116   - return 0;
  122 +int lancer(){
  123 + recup_num();
  124 + init_seq();
  125 + create_port();
  126 + connect_port();
  127 + boucle();
  128 + snd_seq_close(seq);
  129 + return 0;
117 130 }
... ...