summaryrefslogtreecommitdiff
path: root/apps/plugins/midi
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2006-05-08 02:43:29 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2006-05-08 02:43:29 +0000
commitb9b2bcd9b9706abe5898813ac26c33d02ba1a996 (patch)
tree372ffcd7b2db5ac39000c8fd2ebf597ebb7e26f4 /apps/plugins/midi
parent1d085333775768f3f6a45c67187b9cae514e1e32 (diff)
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
Diffstat (limited to 'apps/plugins/midi')
-rw-r--r--apps/plugins/midi/midifile.c45
-rw-r--r--apps/plugins/midi/midiutil.c2
2 files changed, 34 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