Browse Source

Set MIDI error to 0 if no error occured

In the ALSA backend, do not set midi->error to the count of bytes
written or read if the write or read operation was successful. Set
it instead to zero.
develop
Damien Goutte-Gattat 8 years ago
parent
commit
6109ef5ac9
  1. 26
      src/midi.c

26
src/midi.c

@ -97,24 +97,40 @@ alsa_midi_close(midi_io_t *midi)
static ssize_t
alsa_midi_write(midi_io_t *midi, unsigned char *buffer, size_t len)
{
ssize_t n;
/* Flush reading buffer. */
midi->pos = midi->len = 0;
midi->error = snd_rawmidi_write(midi->alsa.out, buffer, len);
return midi->error == len ? midi->error : -1;
if ( (n = snd_rawmidi_write(midi->alsa.out, buffer, len)) != len ) {
midi->error = n;
n = -1;
}
else
midi->error = 0;
return n;
}
static ssize_t
alsa_midi_read(midi_io_t *midi, unsigned char *buffer, size_t len)
{
midi->error = snd_rawmidi_read(midi->alsa.in, buffer, len);
return midi->error >= 0 ? midi->error : -1;
ssize_t n;
if ( (n = snd_rawmidi_read(midi->alsa.in, buffer, len)) < 0 ) {
midi->error = n;
n = -1;
}
else
midi->error = 0;
return n;
}
static const char *
alsa_midi_error(midi_io_t *midi)
{
if ( midi->error > 0 )
if ( midi->error == 0 )
return NULL;
else
return snd_strerror(midi->error);

Loading…
Cancel
Save