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)
downloadrockbox-b9b2bcd9b9706abe5898813ac26c33d02ba1a996.tar.gz
rockbox-b9b2bcd9b9706abe5898813ac26c33d02ba1a996.zip
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;
22 22
23struct Track * readTrack(int file); 23struct Track * readTrack(int file);
24int readID(int file); 24int readID(int file);
25void bail(const char *);
26 25
27struct MIDIfile * loadFile(char * filename) 26struct MIDIfile * loadFile(char * filename)
28{ 27{
@@ -31,7 +30,8 @@ struct MIDIfile * loadFile(char * filename)
31 30
32 if(file==-1) 31 if(file==-1)
33 { 32 {
34 bail("Could not open file\n"); 33 printf("Could not open file\n");
34 return NULL;
35 } 35 }
36 36
37 mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile)); 37 mfload = (struct MIDIfile*)malloc(sizeof(struct MIDIfile));
@@ -39,27 +39,48 @@ struct MIDIfile * loadFile(char * filename)
39 if(mfload==NULL) 39 if(mfload==NULL)
40 { 40 {
41 rb->close(file); 41 rb->close(file);
42 bail("Could not allocate memory for MIDIfile struct\n"); 42 printf("Could not allocate memory for MIDIfile struct\n");
43 return NULL;
43 } 44 }
44 45
45 rb->memset(mfload, 0, sizeof(struct MIDIfile)); 46 rb->memset(mfload, 0, sizeof(struct MIDIfile));
46 47
47 if(readID(file) != ID_MTHD) 48 int fileID = readID(file);
49 if(fileID != ID_MTHD)
48 { 50 {
49 rb->close(file); 51 if(fileID == ID_RIFF)
50 bail("Invalid file header chunk."); 52 {
53 printf("\nDetected RMID file");
54 printf("\nLooking for MThd header");
55 char dummy[17];
56 rb->read(file, &dummy, 16);
57 if(readID(file) != ID_MTHD)
58 {
59 rb->close(file);
60 printf("Invalid MIDI header within RIFF.");
61 return NULL;
62 }
63
64 } else
65 {
66 rb->close(file);
67 printf("Invalid file header chunk.");
68 return NULL;
69 }
51 } 70 }
52 71
53 if(readFourBytes(file)!=6) 72 if(readFourBytes(file)!=6)
54 { 73 {
55 rb->close(file); 74 rb->close(file);
56 bail("Header chunk size invalid."); 75 printf("Header chunk size invalid.");
76 return NULL;
57 } 77 }
58 78
59 if(readTwoBytes(file)==2) 79 if(readTwoBytes(file)==2)
60 { 80 {
61 rb->close(file); 81 rb->close(file);
62 bail("MIDI file type not supported"); 82 printf("MIDI file type 2 not supported");
83 return NULL;
63 } 84 }
64 85
65 mfload->numTracks = readTwoBytes(file); 86 mfload->numTracks = readTwoBytes(file);
@@ -231,6 +252,8 @@ int readID(int file)
231 return ID_MTHD; 252 return ID_MTHD;
232 if(rb->strcmp(id, "MTrk")==0) 253 if(rb->strcmp(id, "MTrk")==0)
233 return ID_MTRK; 254 return ID_MTRK;
255 if(rb->strcmp(id, "RIFF")==0)
256 return ID_RIFF;
234 return ID_UNKNOWN; 257 return ID_UNKNOWN;
235} 258}
236 259
@@ -294,9 +317,5 @@ void unloadFile(struct MIDIfile * mf)
294 free(mf); //Unload the main struct 317 free(mf); //Unload the main struct
295} 318}
296*/ 319*/
297void bail(const char * err) 320
298{
299 rb->splash(HZ*3, true, err);
300 exit(0);
301}
302 321
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 @@
24#define ID_MTHD 1 24#define ID_MTHD 1
25#define ID_MTRK 2 25#define ID_MTRK 2
26#define ID_EOF 3 26#define ID_EOF 3
27#define ID_RIFF 4
28
27 29
28//MIDI Commands 30//MIDI Commands
29#define MIDI_NOTE_OFF 128 31#define MIDI_NOTE_OFF 128