summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/midi/midifile.c45
-rw-r--r--apps/plugins/midi/midiutil.c2
-rw-r--r--apps/plugins/midiplay.c5
-rw-r--r--apps/plugins/viewers.config1
4 files changed, 40 insertions, 13 deletions
diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c
index 11f81b1fd6..1a778a7299 100644
--- a/apps/plugins/midi/midifile.c
+++ b/apps/plugins/midi/midifile.c
@@ -22,7 +22,6 @@ extern struct plugin_api * rb;
struct Track * readTrack(int file);
int readID(int file);
-void bail(const char *);
struct MIDIfile * loadFile(char * filename)
{
@@ -31,7 +30,8 @@ struct MIDIfile * loadFile(char * filename)
if(file==-1)
{
- bail("Could not open file\n");
+ printf("Could not open file\n");
+ return NULL;
}
mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile));
@@ -39,27 +39,48 @@ struct MIDIfile * loadFile(char * filename)
if(mfload==NULL)
{
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));
- if(readID(file) != ID_MTHD)
+ int fileID = readID(file);
+ if(fileID != ID_MTHD)
{
- rb->close(file);
- bail("Invalid file header chunk.");
+ if(fileID == ID_RIFF)
+ {
+ 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)
{
rb->close(file);
- bail("Header chunk size invalid.");
+ printf("Header chunk size invalid.");
+ return NULL;
}
if(readTwoBytes(file)==2)
{
rb->close(file);
- bail("MIDI file type not supported");
+ printf("MIDI file type 2 not supported");
+ return NULL;
}
mfload->numTracks = readTwoBytes(file);
@@ -231,6 +252,8 @@ int readID(int file)
return ID_MTHD;
if(rb->strcmp(id, "MTrk")==0)
return ID_MTRK;
+ if(rb->strcmp(id, "RIFF")==0)
+ return ID_RIFF;
return ID_UNKNOWN;
}
@@ -294,9 +317,5 @@ void unloadFile(struct MIDIfile * mf)
free(mf); //Unload the main struct
}
*/
-void bail(const char * err)
-{
- rb->splash(HZ*3, true, err);
- exit(0);
-}
+
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 08e6dbac65..4562089578 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -24,6 +24,8 @@
#define ID_MTHD 1
#define ID_MTRK 2
#define ID_EOF 3
+#define ID_RIFF 4
+
//MIDI Commands
#define MIDI_NOTE_OFF 128
diff --git a/apps/plugins/midiplay.c b/apps/plugins/midiplay.c
index 4814897906..51882212c7 100644
--- a/apps/plugins/midiplay.c
+++ b/apps/plugins/midiplay.c
@@ -208,6 +208,11 @@ int midimain(void * filename)
printf("\nLoading file");
mf= loadFile(filename);
+ if(mf == NULL)
+ {
+ printf("\nError loading file.");
+ return -1;
+ }
if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
return -1;
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index afab02278b..a731d64c25 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -12,6 +12,7 @@ gb,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
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
ss,rocks/sudoku, 55 55 55 55 55 55
wav,viewers/wav2wv, 00 00 00 00 00 00