32 |
} |
} |
33 |
|
|
34 |
int MidiIn::open_alsa_midi_seq(void) { |
int MidiIn::open_alsa_midi_seq(void) { |
|
|
|
35 |
int portid; |
int portid; |
|
|
|
36 |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { |
37 |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
38 |
exit(1); |
exit(1); |
51 |
} |
} |
52 |
|
|
53 |
int MidiIn::Main() { |
int MidiIn::Main() { |
|
|
|
54 |
int res = open_alsa_midi_seq(); |
int res = open_alsa_midi_seq(); |
55 |
if (res < 0) { |
if (res < 0) { |
56 |
fprintf(stderr,"opening of MIDI in device failed, exiting.\n"); |
fprintf(stderr,"opening of MIDI in device failed, exiting.\n"); |
66 |
snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); |
snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); |
67 |
while (true) { |
while (true) { |
68 |
if (poll(pfd, npfd, 100000) > 0) { |
if (poll(pfd, npfd, 100000) > 0) { |
|
|
|
69 |
do { |
do { |
70 |
snd_seq_event_input(seq_handle, &ev); |
snd_seq_event_input(seq_handle, &ev); |
|
|
|
71 |
switch (ev->type) { |
switch (ev->type) { |
72 |
case SND_SEQ_EVENT_CONTROLLER: |
case SND_SEQ_EVENT_CONTROLLER: |
73 |
// fprintf(stderr, "Control event on Channel %2d: num=%5d val=%5d \n", |
pAudioThread->SendControlChange(ev->data.control.channel, ev->data.control.param, ev->data.control.value); |
|
// ev->data.control.channel, ev->data.control.param, ev->data.control.value); |
|
|
|
|
|
pAudioThread->ProcessContinuousController(ev->data.control.channel, ev->data.control.param, ev->data.control.value); |
|
|
|
|
74 |
break; |
break; |
75 |
|
|
76 |
case SND_SEQ_EVENT_PITCHBEND: |
case SND_SEQ_EVENT_PITCHBEND: |
79 |
break; |
break; |
80 |
|
|
81 |
case SND_SEQ_EVENT_NOTEON: |
case SND_SEQ_EVENT_NOTEON: |
|
//fprintf(stderr, "Note On event on Channel %2d: note=%5d velocity=%d \n", |
|
|
// ev->data.control.channel, ev->data.note.note, ev->data.note.velocity); |
|
82 |
if (ev->data.note.velocity != 0) { |
if (ev->data.note.velocity != 0) { |
83 |
pAudioThread->ProcessNoteOn(ev->data.note.note, ev->data.note.velocity); |
pAudioThread->SendNoteOn(ev->data.note.note, ev->data.note.velocity); |
84 |
} |
} |
85 |
else { |
else { |
86 |
pAudioThread->ProcessNoteOff(ev->data.note.note, 0); |
pAudioThread->SendNoteOff(ev->data.note.note, 0); |
87 |
} |
} |
88 |
break; |
break; |
89 |
|
|
90 |
case SND_SEQ_EVENT_NOTEOFF: |
case SND_SEQ_EVENT_NOTEOFF: |
91 |
//fprintf(stderr, "Note Off event on Channel %2d: note=%5d velocity=%d \n", |
pAudioThread->SendNoteOff(ev->data.note.note, ev->data.note.velocity); |
|
// ev->data.control.channel, ev->data.note.note, ev->data.note.velocity); |
|
|
pAudioThread->ProcessNoteOff(ev->data.note.note, ev->data.note.velocity); |
|
92 |
break; |
break; |
93 |
} |
} |
94 |
snd_seq_free_event(ev); |
snd_seq_free_event(ev); |
95 |
} while (snd_seq_event_input_pending(seq_handle, 0) > 0); |
} while (snd_seq_event_input_pending(seq_handle, 0) > 0); |
96 |
} // end of if(poll...) |
} |
97 |
} // end of while |
} |
98 |
} |
} |
99 |
|
|