Skip to content

Commit

Permalink
Fix #1351
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Jul 27, 2024
1 parent 2f5849c commit 76c4dac
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/midi/fluid_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ new_fluid_midi_file(const char *buffer, size_t length)
FLUID_MEMSET(mf, 0, sizeof(fluid_midi_file));

mf->c = -1;
mf->running_status = -1;
mf->running_status = 0;

mf->buffer = buffer;
mf->buf_len = (int)length;
Expand Down Expand Up @@ -632,6 +632,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
/* read the delta-time of the event */
if(fluid_midi_file_read_varlen(mf) != FLUID_OK)
{
FLUID_LOG(FLUID_DBG, "Reading delta-time failed unexpectedly (track=%d)", track->num);
return FLUID_FAILED;
}

Expand All @@ -651,7 +652,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
{
if((mf->running_status & 0x80) == 0)
{
FLUID_LOG(FLUID_ERR, "Undefined status and invalid running status");
FLUID_LOG(FLUID_ERR, "Undefined status and invalid running status (0x%X, 0x%X)", status, mf->running_status);
return FLUID_FAILED;
}

Expand All @@ -660,14 +661,12 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
}

/* check what message we have */

mf->running_status = status;

if(status == MIDI_SYSEX) /* system exclusif */
if(status == MIDI_SYSEX) /* system exclusive */
{
/* read the length of the message */
if(fluid_midi_file_read_varlen(mf) != FLUID_OK)
{
FLUID_LOG(FLUID_DBG, "Failed to read length of SYSEX msg (track=%d)", track->num);
return FLUID_FAILED;
}

Expand All @@ -686,6 +685,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
/* read the data of the message */
if(fluid_midi_file_read(mf, metadata, mf->varlen) != FLUID_OK)
{
FLUID_LOG(FLUID_DBG, "Failed to read data of SYSEX msg (track=%d)", track->num);
FLUID_FREE(metadata);
return FLUID_FAILED;
}
Expand Down Expand Up @@ -733,6 +733,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
/* get the length of the data part */
if(fluid_midi_file_read_varlen(mf) != FLUID_OK)
{
FLUID_LOG(FLUID_DBG, "Failed to read length of META msg (track=%d)", track->num);
return FLUID_FAILED;
}

Expand Down Expand Up @@ -765,6 +766,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
FLUID_FREE(dyn_buf);
}

FLUID_LOG(FLUID_DBG, "Failed to read meta msg (track=%d)", track->num);
return FLUID_FAILED;
}
}
Expand Down Expand Up @@ -947,7 +949,8 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
}
else /* channel messages */
{

// remember current status (not applicable to SYSEX and META events!)
mf->running_status = status;
type = status & 0xf0;
channel = status & 0x0f;

Expand Down Expand Up @@ -1016,7 +1019,7 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)

default:
/* Can't possibly happen !? */
FLUID_LOG(FLUID_ERR, "Unrecognized MIDI event");
FLUID_LOG(FLUID_ERR, "Unrecognized MIDI event 0x%X", status);
return FLUID_FAILED;
}

Expand Down

0 comments on commit 76c4dac

Please sign in to comment.