forked from len0rd/rockbox
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
This commit is contained in:
parent
19631f4552
commit
5811214b0c
8 changed files with 114 additions and 57 deletions
|
@ -94,6 +94,14 @@ struct GPatch * gusload(char * filename)
|
|||
|
||||
int file = rb->open(filename, O_RDONLY);
|
||||
|
||||
if(file == -1)
|
||||
{
|
||||
char message[50];
|
||||
snprintf(message, 50, "Error opening %s", filename);
|
||||
rb->splash(HZ*2, true, message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gp->header=readData(file, 12);
|
||||
gp->gravisid=readData(file, 10);
|
||||
gp->desc=readData(file, 60);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
//This came from one of the Gravis documents
|
||||
const static unsigned int gustable[]=
|
||||
static const unsigned int gustable[]=
|
||||
{
|
||||
8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433,
|
||||
16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
|
||||
|
|
|
@ -185,7 +185,6 @@ struct Track * readTrack(int file)
|
|||
trk->pos = 0;
|
||||
trk->delta = 0;
|
||||
|
||||
int len=0;
|
||||
int numEvents=0;
|
||||
|
||||
int pos = rb->lseek(file, 0, SEEK_CUR);
|
||||
|
@ -269,6 +268,8 @@ int readVarData(int file)
|
|||
return(value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//This function should not be needed because we
|
||||
//can just release the whole memory buffer at once
|
||||
void unloadFile(struct MIDIfile * mf)
|
||||
|
@ -296,10 +297,10 @@ void unloadFile(struct MIDIfile * mf)
|
|||
}
|
||||
free(mf); //Unload the main struct
|
||||
}
|
||||
|
||||
*/
|
||||
void bail(const char * err)
|
||||
{
|
||||
printf("\nERROR: %s\n", err);
|
||||
rb->splash(HZ*3, true, err);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,16 +40,18 @@
|
|||
#define CTRL_PANNING 10
|
||||
#define CHANNEL 1
|
||||
|
||||
|
||||
//Most of these are deprecated.. rampdown is used, maybe one other one too
|
||||
#define STATE_ATTACK 1
|
||||
#define STATE_DECAY 2
|
||||
#define STATE_SUSTAIN 3
|
||||
#define STATE_RELEASE 4
|
||||
#define STATE_RAMPDOWN 5
|
||||
|
||||
//Loop states
|
||||
#define STATE_LOOPING 7
|
||||
#define STATE_NONLOOPING 8
|
||||
|
||||
//Various bits in the GUS mode byte
|
||||
#define LOOP_ENABLED 4
|
||||
#define LOOP_PINGPONG 8
|
||||
#define LOOP_REVERSE 16
|
||||
|
@ -65,7 +67,8 @@ unsigned char chVol[16]; //Channel volume
|
|||
unsigned char chPanLeft[16]; //Channel panning
|
||||
unsigned char chPanRight[16];
|
||||
unsigned char chPat[16]; //Channel patch
|
||||
unsigned char chPW[16]; //Channel pitch wheel, MSB
|
||||
unsigned char chPW[16]; //Channel pitch wheel, MSB only
|
||||
|
||||
|
||||
struct GPatch * gusload(char *);
|
||||
struct GPatch * patchSet[128];
|
||||
|
@ -118,8 +121,19 @@ struct MIDIfile
|
|||
int numPatches;
|
||||
};
|
||||
|
||||
void *my_malloc(int size);
|
||||
|
||||
|
||||
void sendEvent(struct Event * ev);
|
||||
int tick(struct MIDIfile * mf);
|
||||
inline void setPoint(struct SynthObject * so, int pt);
|
||||
struct Event * getEvent(struct Track * tr, int evNum);
|
||||
int readTwoBytes(int file);
|
||||
int readFourBytes(int file);
|
||||
int readVarData(int file);
|
||||
int midimain(void * filename);
|
||||
|
||||
|
||||
//Rick's code
|
||||
void *alloc(int size)
|
||||
{
|
||||
static char *offset = NULL;
|
||||
|
@ -143,7 +157,7 @@ void *alloc(int size)
|
|||
totalSize -= size + 4;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
void *ralloc(char *offset, int len)
|
||||
{
|
||||
int size;
|
||||
|
@ -175,18 +189,13 @@ void *ralloc(char *offset, int len)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void * allocate(int size)
|
||||
{
|
||||
return alloc(size);
|
||||
}
|
||||
|
||||
void sendEvent(struct Event * ev);
|
||||
int tick(struct MIDIfile * mf);
|
||||
inline void setPoint(struct SynthObject * so, int pt);
|
||||
struct Event * getEvent(struct Track * tr, int evNum);
|
||||
|
||||
unsigned char readChar(int file)
|
||||
{
|
||||
char buf[2];
|
||||
|
@ -211,11 +220,9 @@ int eof(int fd)
|
|||
return size+1 == rb->lseek(fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
void printf(char *fmt, ...) {}
|
||||
|
||||
//#define my_malloc(a) malloc(a)
|
||||
|
||||
void printf(char *fmt, ...) {fmt=fmt; }
|
||||
|
||||
/*
|
||||
void *audio_bufferbase;
|
||||
void *audio_bufferpointer;
|
||||
unsigned int audio_buffer_free;
|
||||
|
@ -252,11 +259,8 @@ void setmallocpos(void *pointer)
|
|||
audio_bufferpointer = pointer;
|
||||
audio_buffer_free = audio_bufferpointer - audio_bufferbase;
|
||||
}
|
||||
|
||||
*/
|
||||
void exit(int code)
|
||||
{
|
||||
code = code; //Stub function, kill warning for now
|
||||
}
|
||||
|
||||
void free(void * ptr)
|
||||
{
|
||||
}
|
|
@ -242,7 +242,7 @@ void sendEvent(struct Event * ev)
|
|||
int tick(struct MIDIfile * mf)
|
||||
{
|
||||
if(mf==NULL)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
int a=0;
|
||||
int tracksAdv=0;
|
||||
|
|
|
@ -49,7 +49,7 @@ void readTextBlock(int file, char * buf)
|
|||
|
||||
//Filename is the name of the config file
|
||||
//The MIDI file should have been loaded at this point
|
||||
void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||
int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||
{
|
||||
char patchUsed[128];
|
||||
char drumUsed[128];
|
||||
|
@ -92,8 +92,8 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
|||
if(mf->tracks[a] == NULL)
|
||||
{
|
||||
printf("\nNULL TRACK !!!");
|
||||
exit(1);
|
||||
return;
|
||||
rb->splash(HZ*2, true, "Null Track in loader.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(ts=0; ts<mf->tracks[a]->numEvents; ts++)
|
||||
|
@ -112,29 +112,43 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
|||
}
|
||||
|
||||
int file = rb->open(filename, O_RDONLY);
|
||||
if(file == -1)
|
||||
{
|
||||
rb->splash(HZ*2, true, "Bad patch config.\nDid you install the patchset?");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char name[30];
|
||||
char fn[30];
|
||||
char name[40];
|
||||
char fn[40];
|
||||
|
||||
//Scan our config file and load the right patches as needed
|
||||
int c = 0;
|
||||
rb->snprintf(name, 30, "");
|
||||
rb->snprintf(name, 40, "");
|
||||
for(a=0; a<128; a++)
|
||||
{
|
||||
while(readChar(file)!=' ' && !eof(file));
|
||||
readTextBlock(file, name);
|
||||
|
||||
rb->snprintf(fn, 30, "/patchset/%s.pat", name);
|
||||
rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
|
||||
printf("\nLOADING: <%s> ", fn);
|
||||
|
||||
if(patchUsed[a]==1)
|
||||
patchSet[a]=gusload(fn);
|
||||
|
||||
// if(patchSet[a] == NULL)
|
||||
// return -1;
|
||||
|
||||
while((c != '\n'))
|
||||
c = readChar(file);
|
||||
}
|
||||
rb->close(file);
|
||||
|
||||
file = rb->open(drumConfig, O_RDONLY);
|
||||
if(file == -1)
|
||||
{
|
||||
rb->splash(HZ*2, true, "Bad drum config.\nDid you install the patchset?");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Scan our config file and load the drum data
|
||||
int idx=0;
|
||||
|
@ -143,7 +157,7 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
|||
{
|
||||
readTextBlock(file, number);
|
||||
readTextBlock(file, name);
|
||||
rb->snprintf(fn, 30, "/patchset/%s.pat", name);
|
||||
rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
|
||||
|
||||
idx = rb->atoi(number);
|
||||
if(idx == 0)
|
||||
|
@ -151,13 +165,15 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
|||
|
||||
if(drumUsed[idx]==1)
|
||||
drumSet[idx]=gusload(fn);
|
||||
|
||||
// if(drumSet[idx] == NULL)
|
||||
// return -1;
|
||||
|
||||
while((c != '\n') && (c != 255) && (!eof(file)))
|
||||
{
|
||||
printf("loop");
|
||||
c = readChar(file);
|
||||
}
|
||||
}
|
||||
rb->close(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue