summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStepan Moskovchenko <stevenm@rockbox.org>2005-04-15 20:27:04 +0000
committerStepan Moskovchenko <stevenm@rockbox.org>2005-04-15 20:27:04 +0000
commit5811214b0c6fc7b060b46a3eee3d919ffe850e89 (patch)
tree648a1cd469188107ced6231ac6d504955598426e
parent19631f455226f5f02c577c732072ba3f04ccb9bb (diff)
downloadrockbox-5811214b0c6fc7b060b46a3eee3d919ffe850e89.tar.gz
rockbox-5811214b0c6fc7b060b46a3eee3d919ffe850e89.zip
Code cleanup, fix warnings, error checking, add midi2wav to viewers.config
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6304 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/midi/guspat.c8
-rw-r--r--apps/plugins/midi/guspat.h2
-rw-r--r--apps/plugins/midi/midifile.c7
-rw-r--r--apps/plugins/midi/midiutil.c42
-rw-r--r--apps/plugins/midi/sequencer.c2
-rw-r--r--apps/plugins/midi/synth.c38
-rw-r--r--apps/plugins/midi2wav.c71
-rw-r--r--apps/plugins/viewers.config1
8 files changed, 114 insertions, 57 deletions
diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c
index f0f1effd2a..675d6ffe3d 100644
--- a/apps/plugins/midi/guspat.c
+++ b/apps/plugins/midi/guspat.c
@@ -94,6 +94,14 @@ struct GPatch * gusload(char * filename)
94 94
95 int file = rb->open(filename, O_RDONLY); 95 int file = rb->open(filename, O_RDONLY);
96 96
97 if(file == -1)
98 {
99 char message[50];
100 snprintf(message, 50, "Error opening %s", filename);
101 rb->splash(HZ*2, true, message);
102 return NULL;
103 }
104
97 gp->header=readData(file, 12); 105 gp->header=readData(file, 12);
98 gp->gravisid=readData(file, 10); 106 gp->gravisid=readData(file, 10);
99 gp->desc=readData(file, 60); 107 gp->desc=readData(file, 60);
diff --git a/apps/plugins/midi/guspat.h b/apps/plugins/midi/guspat.h
index 5007c4d2ca..75bdb2ca01 100644
--- a/apps/plugins/midi/guspat.h
+++ b/apps/plugins/midi/guspat.h
@@ -17,7 +17,7 @@
17 ****************************************************************************/ 17 ****************************************************************************/
18 18
19//This came from one of the Gravis documents 19//This came from one of the Gravis documents
20const static unsigned int gustable[]= 20static const unsigned int gustable[]=
21{ 21{
22 8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433, 22 8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433,
23 16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867, 23 16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c
index 08efb73529..c786b8e5a6 100644
--- a/apps/plugins/midi/midifile.c
+++ b/apps/plugins/midi/midifile.c
@@ -185,7 +185,6 @@ struct Track * readTrack(int file)
185 trk->pos = 0; 185 trk->pos = 0;
186 trk->delta = 0; 186 trk->delta = 0;
187 187
188 int len=0;
189 int numEvents=0; 188 int numEvents=0;
190 189
191 int pos = rb->lseek(file, 0, SEEK_CUR); 190 int pos = rb->lseek(file, 0, SEEK_CUR);
@@ -269,6 +268,8 @@ int readVarData(int file)
269 return(value); 268 return(value);
270} 269}
271 270
271
272/*
272//This function should not be needed because we 273//This function should not be needed because we
273//can just release the whole memory buffer at once 274//can just release the whole memory buffer at once
274void unloadFile(struct MIDIfile * mf) 275void unloadFile(struct MIDIfile * mf)
@@ -296,10 +297,10 @@ void unloadFile(struct MIDIfile * mf)
296 } 297 }
297 free(mf); //Unload the main struct 298 free(mf); //Unload the main struct
298} 299}
299 300*/
300void bail(const char * err) 301void bail(const char * err)
301{ 302{
302 printf("\nERROR: %s\n", err); 303 rb->splash(HZ*3, true, err);
303 exit(0); 304 exit(0);
304} 305}
305 306
diff --git a/apps/plugins/midi/midiutil.c b/apps/plugins/midi/midiutil.c
index 0ab5a35a78..41a02ae682 100644
--- a/apps/plugins/midi/midiutil.c
+++ b/apps/plugins/midi/midiutil.c
@@ -40,16 +40,18 @@
40#define CTRL_PANNING 10 40#define CTRL_PANNING 10
41#define CHANNEL 1 41#define CHANNEL 1
42 42
43 43//Most of these are deprecated.. rampdown is used, maybe one other one too
44#define STATE_ATTACK 1 44#define STATE_ATTACK 1
45#define STATE_DECAY 2 45#define STATE_DECAY 2
46#define STATE_SUSTAIN 3 46#define STATE_SUSTAIN 3
47#define STATE_RELEASE 4 47#define STATE_RELEASE 4
48#define STATE_RAMPDOWN 5 48#define STATE_RAMPDOWN 5
49 49
50//Loop states
50#define STATE_LOOPING 7 51#define STATE_LOOPING 7
51#define STATE_NONLOOPING 8 52#define STATE_NONLOOPING 8
52 53
54//Various bits in the GUS mode byte
53#define LOOP_ENABLED 4 55#define LOOP_ENABLED 4
54#define LOOP_PINGPONG 8 56#define LOOP_PINGPONG 8
55#define LOOP_REVERSE 16 57#define LOOP_REVERSE 16
@@ -65,7 +67,8 @@ unsigned char chVol[16]; //Channel volume
65unsigned char chPanLeft[16]; //Channel panning 67unsigned char chPanLeft[16]; //Channel panning
66unsigned char chPanRight[16]; 68unsigned char chPanRight[16];
67unsigned char chPat[16]; //Channel patch 69unsigned char chPat[16]; //Channel patch
68unsigned char chPW[16]; //Channel pitch wheel, MSB 70unsigned char chPW[16]; //Channel pitch wheel, MSB only
71
69 72
70struct GPatch * gusload(char *); 73struct GPatch * gusload(char *);
71struct GPatch * patchSet[128]; 74struct GPatch * patchSet[128];
@@ -118,8 +121,19 @@ struct MIDIfile
118 int numPatches; 121 int numPatches;
119}; 122};
120 123
121void *my_malloc(int size);
122 124
125
126void sendEvent(struct Event * ev);
127int tick(struct MIDIfile * mf);
128inline void setPoint(struct SynthObject * so, int pt);
129struct Event * getEvent(struct Track * tr, int evNum);
130int readTwoBytes(int file);
131int readFourBytes(int file);
132int readVarData(int file);
133int midimain(void * filename);
134
135
136//Rick's code
123void *alloc(int size) 137void *alloc(int size)
124{ 138{
125 static char *offset = NULL; 139 static char *offset = NULL;
@@ -143,7 +157,7 @@ void *alloc(int size)
143 totalSize -= size + 4; 157 totalSize -= size + 4;
144 return ret; 158 return ret;
145} 159}
146 160/*
147void *ralloc(char *offset, int len) 161void *ralloc(char *offset, int len)
148{ 162{
149 int size; 163 int size;
@@ -175,18 +189,13 @@ void *ralloc(char *offset, int len)
175 189
176 return ret; 190 return ret;
177} 191}
178 192*/
179 193
180void * allocate(int size) 194void * allocate(int size)
181{ 195{
182 return alloc(size); 196 return alloc(size);
183} 197}
184 198
185void sendEvent(struct Event * ev);
186int tick(struct MIDIfile * mf);
187inline void setPoint(struct SynthObject * so, int pt);
188struct Event * getEvent(struct Track * tr, int evNum);
189
190unsigned char readChar(int file) 199unsigned char readChar(int file)
191{ 200{
192 char buf[2]; 201 char buf[2];
@@ -211,11 +220,9 @@ int eof(int fd)
211 return size+1 == rb->lseek(fd, 0, SEEK_CUR); 220 return size+1 == rb->lseek(fd, 0, SEEK_CUR);
212} 221}
213 222
214void printf(char *fmt, ...) {} 223void printf(char *fmt, ...) {fmt=fmt; }
215
216//#define my_malloc(a) malloc(a)
217
218 224
225/*
219void *audio_bufferbase; 226void *audio_bufferbase;
220void *audio_bufferpointer; 227void *audio_bufferpointer;
221unsigned int audio_buffer_free; 228unsigned int audio_buffer_free;
@@ -252,11 +259,8 @@ void setmallocpos(void *pointer)
252 audio_bufferpointer = pointer; 259 audio_bufferpointer = pointer;
253 audio_buffer_free = audio_bufferpointer - audio_bufferbase; 260 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
254} 261}
255 262*/
256void exit(int code) 263void exit(int code)
257{ 264{
265 code = code; //Stub function, kill warning for now
258} 266}
259
260void free(void * ptr)
261{
262} \ No newline at end of file
diff --git a/apps/plugins/midi/sequencer.c b/apps/plugins/midi/sequencer.c
index fb98fdaf51..f7c6f30376 100644
--- a/apps/plugins/midi/sequencer.c
+++ b/apps/plugins/midi/sequencer.c
@@ -242,7 +242,7 @@ void sendEvent(struct Event * ev)
242int tick(struct MIDIfile * mf) 242int tick(struct MIDIfile * mf)
243{ 243{
244 if(mf==NULL) 244 if(mf==NULL)
245 return; 245 return 0;
246 246
247 int a=0; 247 int a=0;
248 int tracksAdv=0; 248 int tracksAdv=0;
diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c
index 0d07ed91d0..86cb43483a 100644
--- a/apps/plugins/midi/synth.c
+++ b/apps/plugins/midi/synth.c
@@ -49,7 +49,7 @@ void readTextBlock(int file, char * buf)
49 49
50//Filename is the name of the config file 50//Filename is the name of the config file
51//The MIDI file should have been loaded at this point 51//The MIDI file should have been loaded at this point
52void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig) 52int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
53{ 53{
54 char patchUsed[128]; 54 char patchUsed[128];
55 char drumUsed[128]; 55 char drumUsed[128];
@@ -92,8 +92,8 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
92 if(mf->tracks[a] == NULL) 92 if(mf->tracks[a] == NULL)
93 { 93 {
94 printf("\nNULL TRACK !!!"); 94 printf("\nNULL TRACK !!!");
95 exit(1); 95 rb->splash(HZ*2, true, "Null Track in loader.");
96 return; 96 return -1;
97 } 97 }
98 98
99 for(ts=0; ts<mf->tracks[a]->numEvents; ts++) 99 for(ts=0; ts<mf->tracks[a]->numEvents; ts++)
@@ -112,29 +112,43 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
112 } 112 }
113 113
114 int file = rb->open(filename, O_RDONLY); 114 int file = rb->open(filename, O_RDONLY);
115 if(file == -1)
116 {
117 rb->splash(HZ*2, true, "Bad patch config.\nDid you install the patchset?");
118 return -1;
119 }
115 120
116 char name[30]; 121 char name[40];
117 char fn[30]; 122 char fn[40];
118 123
119 //Scan our config file and load the right patches as needed 124 //Scan our config file and load the right patches as needed
120 int c = 0; 125 int c = 0;
121 rb->snprintf(name, 30, ""); 126 rb->snprintf(name, 40, "");
122 for(a=0; a<128; a++) 127 for(a=0; a<128; a++)
123 { 128 {
124 while(readChar(file)!=' ' && !eof(file)); 129 while(readChar(file)!=' ' && !eof(file));
125 readTextBlock(file, name); 130 readTextBlock(file, name);
126 131
127 rb->snprintf(fn, 30, "/patchset/%s.pat", name); 132 rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
128 printf("\nLOADING: <%s> ", fn); 133 printf("\nLOADING: <%s> ", fn);
134
129 if(patchUsed[a]==1) 135 if(patchUsed[a]==1)
130 patchSet[a]=gusload(fn); 136 patchSet[a]=gusload(fn);
131 137
138// if(patchSet[a] == NULL)
139// return -1;
140
132 while((c != '\n')) 141 while((c != '\n'))
133 c = readChar(file); 142 c = readChar(file);
134 } 143 }
135 rb->close(file); 144 rb->close(file);
136 145
137 file = rb->open(drumConfig, O_RDONLY); 146 file = rb->open(drumConfig, O_RDONLY);
147 if(file == -1)
148 {
149 rb->splash(HZ*2, true, "Bad drum config.\nDid you install the patchset?");
150 return -1;
151 }
138 152
139 //Scan our config file and load the drum data 153 //Scan our config file and load the drum data
140 int idx=0; 154 int idx=0;
@@ -143,7 +157,7 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
143 { 157 {
144 readTextBlock(file, number); 158 readTextBlock(file, number);
145 readTextBlock(file, name); 159 readTextBlock(file, name);
146 rb->snprintf(fn, 30, "/patchset/%s.pat", name); 160 rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
147 161
148 idx = rb->atoi(number); 162 idx = rb->atoi(number);
149 if(idx == 0) 163 if(idx == 0)
@@ -151,13 +165,15 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
151 165
152 if(drumUsed[idx]==1) 166 if(drumUsed[idx]==1)
153 drumSet[idx]=gusload(fn); 167 drumSet[idx]=gusload(fn);
168
169// if(drumSet[idx] == NULL)
170// return -1;
171
154 while((c != '\n') && (c != 255) && (!eof(file))) 172 while((c != '\n') && (c != 255) && (!eof(file)))
155 {
156 printf("loop");
157 c = readChar(file); 173 c = readChar(file);
158 }
159 } 174 }
160 rb->close(file); 175 rb->close(file);
176 return 0;
161} 177}
162 178
163 179
diff --git a/apps/plugins/midi2wav.c b/apps/plugins/midi2wav.c
index f8368535d1..0b1659b1dd 100644
--- a/apps/plugins/midi2wav.c
+++ b/apps/plugins/midi2wav.c
@@ -19,13 +19,17 @@
19#define SAMPLE_RATE 48000 19#define SAMPLE_RATE 48000
20#define MAX_VOICES 100 20#define MAX_VOICES 100
21 21
22/* This is for writing to the DSP directly from the Simulator 22/*
23#if defined(SIMULATOR)
24// This is for writing to the DSP directly from the Simulator
23#include <stdio.h> 25#include <stdio.h>
24#include <stdlib.h> 26#include <stdlib.h>
25#include <linux/soundcard.h> 27#include <linux/soundcard.h>
26#include <sys/ioctl.h> 28#include <sys/ioctl.h>
29#endif
27*/ 30*/
28 31
32
29#include "../../plugin.h" 33#include "../../plugin.h"
30#include "midi/midiutil.c" 34#include "midi/midiutil.c"
31#include "midi/guspat.h" 35#include "midi/guspat.h"
@@ -47,23 +51,56 @@ struct plugin_api * rb;
47 51
48 52
49 53
54
50enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 55enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
51{ 56{
52 TEST_PLUGIN_API(api); 57 TEST_PLUGIN_API(api);
53 (void)parameter; 58 rb = api;
54 rb = api; 59 TEST_PLUGIN_API(api);
55 rb->splash(HZ*2, true, "MIDI"); 60 (void)parameter;
56 midimain(); 61 rb = api;
57 rb->splash(HZ*2, true, "FINISHED PLAYING"); 62
58 return PLUGIN_OK; 63 if(parameter == NULL)
64 {
65 rb->splash(HZ*2, true, " Play .MID file ");
66 return PLUGIN_OK;
67 }
68 rb->splash(HZ, true, parameter);
69 if(midimain(parameter) == -1)
70 {
71 return PLUGIN_ERROR;
72 }
73 rb->splash(HZ*3, true, "FINISHED PLAYING");
74 return PLUGIN_OK;
59} 75}
60 76
61 77
62int midimain() 78int midimain(void * filename)
63{ 79{
64 rb->splash(HZ*2, true, "OPENED DSP"); 80
81 printf("\nHello.\n");
82
83 rb->splash(HZ/5, true, "LOADING MIDI");
84
85 struct MIDIfile * mf = loadFile(filename);
86 long bpm, nsmp, l;
87
88 int bp=0;
89
90 rb->splash(HZ/5, true, "LOADING PATCHES");
91 if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
92 {
93 return -1;
94 }
95
65 fd=rb->open("/dsp.raw", O_WRONLY|O_CREAT); 96 fd=rb->open("/dsp.raw", O_WRONLY|O_CREAT);
97
66/* 98/*
99//This lets you hear the music through the sound card if you are on Simulator
100//Make a symlink, archos/dsp.raw and make it point to /dev/dsp or whatever
101//your sound device is.
102
103#if defined(SIMULATOR)
67 int arg, status; 104 int arg, status;
68 int bit, samp, ch; 105 int bit, samp, ch;
69 106
@@ -82,24 +119,14 @@ int midimain()
82 status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg); 119 status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
83 status = ioctl(fd, SOUND_PCM_READ_RATE, &arg); 120 status = ioctl(fd, SOUND_PCM_READ_RATE, &arg);
84 samp=arg; 121 samp=arg;
122#endif
85*/ 123*/
86 124
87 printf("\nHello.\n");
88// initSound(); //Open the computer's sound card
89 int a=0;
90 125
91 rb->splash(HZ*2, true, "LOADING MIDI"); 126 rb->splash(HZ/5, true, " START PLAYING ");
92 127
93 struct MIDIfile * mf = loadFile("/test.mid");
94 128
95 rb->splash(HZ*2, true, "LOADED MIDI");
96 long bpm, nsmp, l;
97
98 int bp=0;
99 129
100 rb->splash(HZ*2, true, "LOADING PATCHES");
101 initSynth(mf, "/iriver2.cfg", "/drums.cfg"); //Initialize the MIDI syntehsizer
102 rb->splash(HZ*2, true, "START PLAYING");
103 130
104 signed char buf[3000]; 131 signed char buf[3000];
105 132
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index dcb7ca126f..9b30e20f7b 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -17,3 +17,4 @@ ogg,vorbis2wav.rock, 00 00 00 00 00 00
17wv,wv2wav.rock, 00 00 00 00 00 00 17wv,wv2wav.rock, 00 00 00 00 00 00
18m3u,iriverify.rock,00 00 00 00 00 00 18m3u,iriverify.rock,00 00 00 00 00 00
19mpc,mpc2wav.rock, 00 00 00 00 00 00 19mpc,mpc2wav.rock, 00 00 00 00 00 00
20mid,midi2wav.rock, 01 20 30 40 50 60