diff options
Diffstat (limited to 'apps/plugins/midi/guspat.c')
-rw-r--r-- | apps/plugins/midi/guspat.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/apps/plugins/midi/guspat.c b/apps/plugins/midi/guspat.c index f650555520..d94fbce021 100644 --- a/apps/plugins/midi/guspat.c +++ b/apps/plugins/midi/guspat.c | |||
@@ -66,6 +66,8 @@ static struct GWaveform * loadWaveform(int file) | |||
66 | rb->memset(wav, 0, sizeof(struct GWaveform)); | 66 | rb->memset(wav, 0, sizeof(struct GWaveform)); |
67 | 67 | ||
68 | wav->name=readData(file, 7); | 68 | wav->name=readData(file, 7); |
69 | if (!wav->name) | ||
70 | return NULL; | ||
69 | /* printf("\nWAVE NAME = [%s]", wav->name); */ | 71 | /* printf("\nWAVE NAME = [%s]", wav->name); */ |
70 | wav->fractions=readChar(file); | 72 | wav->fractions=readChar(file); |
71 | wav->wavSize=readDWord(file); | 73 | wav->wavSize=readDWord(file); |
@@ -81,7 +83,11 @@ static struct GWaveform * loadWaveform(int file) | |||
81 | 83 | ||
82 | wav->balance=readChar(file); | 84 | wav->balance=readChar(file); |
83 | wav->envRate=readData(file, 6); | 85 | wav->envRate=readData(file, 6); |
86 | if (!wav->envRate) | ||
87 | return NULL; | ||
84 | wav->envOffset=readData(file, 6); | 88 | wav->envOffset=readData(file, 6); |
89 | if (!wav->envOffset) | ||
90 | return NULL; | ||
85 | 91 | ||
86 | wav->tremSweep=readChar(file); | 92 | wav->tremSweep=readChar(file); |
87 | wav->tremRate=readChar(file); | 93 | wav->tremRate=readChar(file); |
@@ -95,7 +101,11 @@ static struct GWaveform * loadWaveform(int file) | |||
95 | wav->scaleFactor=readWord(file); | 101 | wav->scaleFactor=readWord(file); |
96 | /* printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq); */ | 102 | /* printf("\nScaleFreq = %d ScaleFactor = %d RootFreq = %d", wav->scaleFreq, wav->scaleFactor, wav->rootFreq); */ |
97 | wav->res=readData(file, 36); | 103 | wav->res=readData(file, 36); |
104 | if (!wav->res) | ||
105 | return NULL; | ||
98 | wav->data=readData(file, wav->wavSize); | 106 | wav->data=readData(file, wav->wavSize); |
107 | if (!wav->data) | ||
108 | return NULL; | ||
99 | 109 | ||
100 | wav->numSamples = wav->wavSize / 2; | 110 | wav->numSamples = wav->wavSize / 2; |
101 | wav->startLoop = wav->startLoop >> 1; | 111 | wav->startLoop = wav->startLoop >> 1; |
@@ -166,7 +176,10 @@ static int selectWaveform(struct GPatch * pat, int midiNote) | |||
166 | struct GPatch * gusload(char * filename) | 176 | struct GPatch * gusload(char * filename) |
167 | { | 177 | { |
168 | struct GPatch * gp = (struct GPatch *)malloc(sizeof(struct GPatch)); | 178 | struct GPatch * gp = (struct GPatch *)malloc(sizeof(struct GPatch)); |
169 | rb->memset(gp, 0, sizeof(struct GPatch)); | 179 | |
180 | if (gp) | ||
181 | rb->memset(gp, 0, sizeof(struct GPatch)); | ||
182 | else return NULL; | ||
170 | 183 | ||
171 | int file = rb->open(filename, O_RDONLY); | 184 | int file = rb->open(filename, O_RDONLY); |
172 | 185 | ||
@@ -179,8 +192,23 @@ struct GPatch * gusload(char * filename) | |||
179 | } | 192 | } |
180 | 193 | ||
181 | gp->header=readData(file, 12); | 194 | gp->header=readData(file, 12); |
195 | if (!gp->header) | ||
196 | { | ||
197 | rb->close(file); | ||
198 | return NULL; | ||
199 | } | ||
182 | gp->gravisid=readData(file, 10); | 200 | gp->gravisid=readData(file, 10); |
201 | if (!gp->gravisid) | ||
202 | { | ||
203 | rb->close(file); | ||
204 | return NULL; | ||
205 | } | ||
183 | gp->desc=readData(file, 60); | 206 | gp->desc=readData(file, 60); |
207 | if (!gp->desc) | ||
208 | { | ||
209 | rb->close(file); | ||
210 | return NULL; | ||
211 | } | ||
184 | gp->inst=readChar(file); | 212 | gp->inst=readChar(file); |
185 | gp->voc=readChar(file); | 213 | gp->voc=readChar(file); |
186 | gp->chan=readChar(file); | 214 | gp->chan=readChar(file); |
@@ -188,28 +216,52 @@ struct GPatch * gusload(char * filename) | |||
188 | gp->vol=readWord(file); | 216 | gp->vol=readWord(file); |
189 | gp->datSize=readDWord(file); | 217 | gp->datSize=readDWord(file); |
190 | gp->res=readData(file, 36); | 218 | gp->res=readData(file, 36); |
219 | if (!gp->res) | ||
220 | { | ||
221 | rb->close(file); | ||
222 | return NULL; | ||
223 | } | ||
191 | 224 | ||
192 | gp->instrID=readWord(file); | 225 | gp->instrID=readWord(file); |
193 | gp->instrName=readData(file,16); | 226 | gp->instrName=readData(file,16); |
227 | if (!gp->instrName) | ||
228 | { | ||
229 | rb->close(file); | ||
230 | return NULL; | ||
231 | } | ||
194 | gp->instrSize=readDWord(file); | 232 | gp->instrSize=readDWord(file); |
195 | gp->layers=readChar(file); | 233 | gp->layers=readChar(file); |
196 | gp->instrRes=readData(file,40); | 234 | gp->instrRes=readData(file,40); |
197 | 235 | if (!gp->instrRes) | |
236 | { | ||
237 | rb->close(file); | ||
238 | return NULL; | ||
239 | } | ||
198 | 240 | ||
199 | gp->layerDup=readChar(file); | 241 | gp->layerDup=readChar(file); |
200 | gp->layerID=readChar(file); | 242 | gp->layerID=readChar(file); |
201 | gp->layerSize=readDWord(file); | 243 | gp->layerSize=readDWord(file); |
202 | gp->numWaves=readChar(file); | 244 | gp->numWaves=readChar(file); |
203 | gp->layerRes=readData(file,40); | 245 | gp->layerRes=readData(file,40); |
204 | 246 | if (!gp->layerRes) | |
247 | { | ||
248 | rb->close(file); | ||
249 | return NULL; | ||
250 | } | ||
205 | 251 | ||
206 | /* printf("\nFILE: %s", filename); */ | 252 | /* printf("\nFILE: %s", filename); */ |
207 | /* printf("\nlayerSamples=%d", gp->numWaves); */ | 253 | /* printf("\nlayerSamples=%d", gp->numWaves); */ |
208 | 254 | ||
209 | int a=0; | 255 | int a=0; |
210 | for(a=0; a<gp->numWaves; a++) | 256 | for(a=0; a<gp->numWaves; a++) |
257 | { | ||
211 | gp->waveforms[a] = loadWaveform(file); | 258 | gp->waveforms[a] = loadWaveform(file); |
212 | 259 | if (!gp->waveforms[a]) | |
260 | { | ||
261 | rb->close(file); | ||
262 | return NULL; | ||
263 | } | ||
264 | } | ||
213 | 265 | ||
214 | /* printf("\nPrecomputing note table"); */ | 266 | /* printf("\nPrecomputing note table"); */ |
215 | 267 | ||