Fixed freezing after loader error messages.

Added RMID (Windows MIDI) header support. Added .RMI extension to
viewers.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9888 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Stepan Moskovchenko 2006-05-08 02:43:29 +00:00
parent 1d08533377
commit b9b2bcd9b9
4 changed files with 40 additions and 13 deletions

View file

@ -22,7 +22,6 @@ extern struct plugin_api * rb;
struct Track * readTrack(int file); struct Track * readTrack(int file);
int readID(int file); int readID(int file);
void bail(const char *);
struct MIDIfile * loadFile(char * filename) struct MIDIfile * loadFile(char * filename)
{ {
@ -31,7 +30,8 @@ struct MIDIfile * loadFile(char * filename)
if(file==-1) if(file==-1)
{ {
bail("Could not open file\n"); printf("Could not open file\n");
return NULL;
} }
mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile)); mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile));
@ -39,27 +39,48 @@ struct MIDIfile * loadFile(char * filename)
if(mfload==NULL) if(mfload==NULL)
{ {
rb->close(file); rb->close(file);
bail("Could not allocate memory for MIDIfile struct\n"); printf("Could not allocate memory for MIDIfile struct\n");
return NULL;
} }
rb->memset(mfload, 0, sizeof(struct MIDIfile)); rb->memset(mfload, 0, sizeof(struct MIDIfile));
if(readID(file) != ID_MTHD) int fileID = readID(file);
if(fileID != ID_MTHD)
{ {
rb->close(file); if(fileID == ID_RIFF)
bail("Invalid file header chunk."); {
printf("\nDetected RMID file");
printf("\nLooking for MThd header");
char dummy[17];
rb->read(file, &dummy, 16);
if(readID(file) != ID_MTHD)
{
rb->close(file);
printf("Invalid MIDI header within RIFF.");
return NULL;
}
} else
{
rb->close(file);
printf("Invalid file header chunk.");
return NULL;
}
} }
if(readFourBytes(file)!=6) if(readFourBytes(file)!=6)
{ {
rb->close(file); rb->close(file);
bail("Header chunk size invalid."); printf("Header chunk size invalid.");
return NULL;
} }
if(readTwoBytes(file)==2) if(readTwoBytes(file)==2)
{ {
rb->close(file); rb->close(file);
bail("MIDI file type not supported"); printf("MIDI file type 2 not supported");
return NULL;
} }
mfload->numTracks = readTwoBytes(file); mfload->numTracks = readTwoBytes(file);
@ -231,6 +252,8 @@ int readID(int file)
return ID_MTHD; return ID_MTHD;
if(rb->strcmp(id, "MTrk")==0) if(rb->strcmp(id, "MTrk")==0)
return ID_MTRK; return ID_MTRK;
if(rb->strcmp(id, "RIFF")==0)
return ID_RIFF;
return ID_UNKNOWN; return ID_UNKNOWN;
} }
@ -294,9 +317,5 @@ void unloadFile(struct MIDIfile * mf)
free(mf); //Unload the main struct free(mf); //Unload the main struct
} }
*/ */
void bail(const char * err)
{
rb->splash(HZ*3, true, err);
exit(0);
}

View file

@ -24,6 +24,8 @@
#define ID_MTHD 1 #define ID_MTHD 1
#define ID_MTRK 2 #define ID_MTRK 2
#define ID_EOF 3 #define ID_EOF 3
#define ID_RIFF 4
//MIDI Commands //MIDI Commands
#define MIDI_NOTE_OFF 128 #define MIDI_NOTE_OFF 128

View file

@ -208,6 +208,11 @@ int midimain(void * filename)
printf("\nLoading file"); printf("\nLoading file");
mf= loadFile(filename); mf= loadFile(filename);
if(mf == NULL)
{
printf("\nError loading file.");
return -1;
}
if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
return -1; return -1;

View file

@ -12,6 +12,7 @@ gb,viewers/rockboy, 0C 2A 59 7A 2E 0C
gbc,viewers/rockboy, 0C 2A 59 7A 2E 0C gbc,viewers/rockboy, 0C 2A 59 7A 2E 0C
m3u,viewers/iriverify,00 00 00 00 00 00 m3u,viewers/iriverify,00 00 00 00 00 00
mid,viewers/midiplay, 20 70 70 3F 00 00 mid,viewers/midiplay, 20 70 70 3F 00 00
rmi,viewers/midiplay, 20 70 70 3F 00 00
rsp,viewers/searchengine, 0e 11 11 31 7e 60 rsp,viewers/searchengine, 0e 11 11 31 7e 60
ss,rocks/sudoku, 55 55 55 55 55 55 ss,rocks/sudoku, 55 55 55 55 55 55
wav,viewers/wav2wv, 00 00 00 00 00 00 wav,viewers/wav2wv, 00 00 00 00 00 00