Skip to content

Commit

Permalink
timidity: recognize rmid files.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Jul 31, 2018
1 parent a3026d2 commit c9f8809
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions timidity/readmidi.c
Expand Up @@ -334,7 +334,7 @@ static void free_midi_list(MidiSong *song)
free(meep);
meep=next;
}
song->evlist=0;
song->evlist=NULL;
}

/* Allocate an array of MidiEvents and fill it from the linked list of
Expand Down Expand Up @@ -507,13 +507,24 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp)
if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1)
{
SNDDBG(("Not a MIDI file!\n"));
return 0;
return NULL;
}
if (memcmp(tmp, "RIFF", 4) == 0) { /* RMID ?? */
if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || memcmp(tmp, "RMID", 4) != 0 ||
SDL_RWread(song->rw, tmp, 1, 4) != 4 || memcmp(tmp, "data", 4) != 0 ||
SDL_RWread(song->rw, tmp, 1, 4) != 4 ||
/* SMF must begin from here onwards: */
SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1)
{
SNDDBG(("Not an RMID file!\n"));
return NULL;
}
}
len=SDL_SwapBE32(len);
if (memcmp(tmp, "MThd", 4) || len < 6)
{
SNDDBG(("Not a MIDI file!\n"));
return 0;
return NULL;
}

SDL_RWread(song->rw, &format, 2, 1);
Expand All @@ -539,17 +550,17 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp)
if (format<0 || format >2)
{
SNDDBG(("Unknown MIDI file format %d\n", format));
return 0;
return NULL;
}
if (tracks<1)
{
SNDDBG(("Bad number of tracks %d\n", tracks));
return 0;
return NULL;
}
if (format==0 && tracks!=1)
{
SNDDBG(("%d tracks with Type-0 MIDI (must be 1.)\n", tracks));
return 0;
return NULL;
}
SNDDBG(("Format: %d Tracks: %d Divisions: %d\n",
format, tracks, divisions));
Expand All @@ -565,7 +576,7 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp)
if (read_track(song, 0))
{
free_midi_list(song);
return 0;
return NULL;
}
break;

Expand All @@ -574,7 +585,7 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp)
if (read_track(song, 0))
{
free_midi_list(song);
return 0;
return NULL;
}
break;

Expand All @@ -583,7 +594,7 @@ MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp)
if (read_track(song, 1))
{
free_midi_list(song);
return 0;
return NULL;
}
break;
}
Expand Down

0 comments on commit c9f8809

Please sign in to comment.