"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/timidity.c" between
libtimidity-0.2.6.tar.gz and libtimidity-0.2.7.tar.gz

About: libTiMidity is a MIDI to WAVE converter library that uses Gravis Ultrasound-compatible patch files to generate digital audio data from General MIDI files.

timidity.c  (libtimidity-0.2.6):timidity.c  (libtimidity-0.2.7)
skipping to change at line 60 skipping to change at line 60
#include "ospaths.h" #include "ospaths.h"
static MidToneBank *master_tonebank[128], *master_drumset[128]; static MidToneBank *master_tonebank[128], *master_drumset[128];
static char def_instr_name[256] = ""; static char def_instr_name[256] = "";
#define MAXWORDS 10 #define MAXWORDS 10
#define MAX_RCFCOUNT 50 #define MAX_RCFCOUNT 50
/* Quick-and-dirty fgets() replacement. */ /* Quick-and-dirty fgets() replacement.
*/
static char *timi_fgets(char *s, int size, FILE *fp) static char *timi_fgets(char *s, int size, FILE *fp)
{ {
int num_read = 0; int num_read = 0;
char *p = s; char *p = s;
--size;/* so that we nul terminate properly */ --size;/* to nul terminate properly */
for (; num_read < size; ++p) for (; num_read < size; ++p)
{ {
if (fread(p, 1, 1, fp) != 1) if (fread(p, 1, 1, fp) != 1)
break; break;
num_read++; num_read++;
/* Unlike fgets(), don't store newline. Under Windows/DOS we'll /* Unlike fgets(), don't store newline. Under Windows/DOS we'll
* probably get an extra blank line for every line that's being * probably get an extra blank line for every line that's being
skipping to change at line 92 skipping to change at line 92
*p = '\0'; *p = '\0';
return s; return s;
} }
} }
*p = '\0'; *p = '\0';
return (num_read != 0)? s : NULL; return (num_read != 0)? s : NULL;
} }
static FILE **rcf_fp;
static int read_config_file(const char *name, int rcf_count) static int read_config_file(const char *name, int rcf_count)
{ {
FILE *fp;
char tmp[TIM_MAXPATH]; char tmp[TIM_MAXPATH];
char *w[MAXWORDS], *cp; char *w[MAXWORDS], *cp;
MidToneBank *bank; MidToneBank *bank;
int i, j, k, line, r, words; int i, j, k, line, r, words;
if (rcf_count >= MAX_RCFCOUNT) if (rcf_count >= MAX_RCFCOUNT) {
{
DEBUG_MSG("Probable source loop in configuration files\n"); DEBUG_MSG("Probable source loop in configuration files\n");
return -1; return -1;
} }
if (!(rcf_fp[rcf_count]=timi_openfile(name))) if (!(fp=timi_openfile(name)))
return -1; return -1;
bank = NULL; bank = NULL;
line = 0; line = 0;
r = -1; /* start by assuming failure, */ r = -1; /* start by assuming failure, */
while (timi_fgets(tmp, sizeof(tmp), rcf_fp[rcf_count])) while (timi_fgets(tmp, sizeof(tmp), fp))
{ {
line++; line++;
words=0; words=0;
w[0]=strtok(tmp, " \t\240"); w[0]=strtok(tmp, " \t\240");
if (!w[0]) continue; if (!w[0]) continue;
/* Originally the TiMidity++ extensions were prefixed like this */ /* Originally the TiMidity++ extensions were prefixed like this */
if (strcmp(w[0], "#extension") == 0) if (strcmp(w[0], "#extension") == 0)
{ {
w[0]=strtok(NULL, " \t\240"); w[0]=strtok(NULL, " \t\240");
skipping to change at line 300 skipping to change at line 298
{ {
master_tonebank[i] = (MidToneBank *) timi_calloc(sizeof(MidToneBank)); master_tonebank[i] = (MidToneBank *) timi_calloc(sizeof(MidToneBank));
if (!master_tonebank[i]) goto fail; if (!master_tonebank[i]) goto fail;
master_tonebank[i]->tone = (MidToneBankElement *) timi_calloc(128 * sizeo f(MidToneBankElement)); master_tonebank[i]->tone = (MidToneBankElement *) timi_calloc(128 * sizeo f(MidToneBankElement));
if (!master_tonebank[i]->tone) goto fail; if (!master_tonebank[i]->tone) goto fail;
} }
bank=master_tonebank[i]; bank=master_tonebank[i];
} }
else else
{ {
size_t sz;
if ((words < 2) || (*w[0] < '0' || *w[0] > '9')) if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
{ {
DEBUG_MSG("%s: line %d: syntax error\n", name, line); DEBUG_MSG("%s: line %d: syntax error\n", name, line);
goto fail; goto fail;
} }
i=atoi(w[0]); i=atoi(w[0]);
if (i<0 || i>127) if (i<0 || i>127)
{ {
DEBUG_MSG("%s: line %d: Program must be between 0 and 127\n", DEBUG_MSG("%s: line %d: Program must be between 0 and 127\n",
name, line); name, line);
goto fail; goto fail;
} }
if (!bank) if (!bank)
{ {
DEBUG_MSG("%s: line %d: Must specify tone bank or drum set before assignm ent\n", DEBUG_MSG("%s: line %d: Must specify tone bank or drum set before assignm ent\n",
name, line); name, line);
goto fail; goto fail;
} }
timi_free(bank->tone[i].name); timi_free(bank->tone[i].name);
bank->tone[i].name=(char *) timi_calloc(strlen(w[1])+1); sz = strlen(w[1])+1;
bank->tone[i].name = (char *) timi_calloc(sz);
if (!bank->tone[i].name) goto fail; if (!bank->tone[i].name) goto fail;
strcpy(bank->tone[i].name,w[1]); memcpy(bank->tone[i].name,w[1],sz);
bank->tone[i].note=bank->tone[i].amp=bank->tone[i].pan= bank->tone[i].note=bank->tone[i].amp=bank->tone[i].pan=
bank->tone[i].strip_loop=bank->tone[i].strip_envelope= bank->tone[i].strip_loop=bank->tone[i].strip_envelope=
bank->tone[i].strip_tail=-1; bank->tone[i].strip_tail=-1;
for (j=2; j<words; j++) for (j=2; j<words; j++)
{ {
if (!(cp=strchr(w[j], '='))) if (!(cp=strchr(w[j], '=')))
{ {
DEBUG_MSG("%s: line %d: bad patch option %s\n", name, line, w[j]); DEBUG_MSG("%s: line %d: bad patch option %s\n", name, line, w[j]);
goto fail; goto fail;
skipping to change at line 412 skipping to change at line 412
{ {
DEBUG_MSG("%s: line %d: bad patch option %s\n", name, line, w[j]); DEBUG_MSG("%s: line %d: bad patch option %s\n", name, line, w[j]);
goto fail; goto fail;
} }
} }
} }
} }
r = 0; /* we're good. */ r = 0; /* we're good. */
fail: fail:
fclose(rcf_fp[rcf_count]); fclose(fp);
rcf_fp[rcf_count] = NULL;
return r; return r;
} }
static int init_alloc_banks (void) static int init_alloc_banks (void)
{ {
/* Allocate memory for the standard tonebank and drumset */ /* Allocate memory for the standard tonebank and drumset */
master_tonebank[0] = (MidToneBank *) timi_calloc(sizeof(MidToneBank)); master_tonebank[0] = (MidToneBank *) timi_calloc(sizeof(MidToneBank));
if (!master_tonebank[0]) goto _nomem; if (!master_tonebank[0]) goto _nomem;
master_tonebank[0]->tone = (MidToneBankElement *) timi_calloc(128 * sizeof(Mid ToneBankElement)); master_tonebank[0]->tone = (MidToneBankElement *) timi_calloc(128 * sizeof(Mid ToneBankElement));
if (!master_tonebank[0]->tone) goto _nomem; if (!master_tonebank[0]->tone) goto _nomem;
skipping to change at line 439 skipping to change at line 438
return 0; return 0;
_nomem: _nomem:
DEBUG_MSG("Out of memory\n"); DEBUG_MSG("Out of memory\n");
mid_exit (); mid_exit ();
return -2; return -2;
} }
static int init_begin_config(const char *cf) static int init_begin_config(const char *cf)
{ {
const char *p; const char *p = get_last_dirsep(cf);
rcf_fp = (FILE **) timi_calloc(MAX_RCFCOUNT * sizeof(FILE*));
if (!rcf_fp)
return -2;
p = get_last_dirsep(cf);
if (p != NULL) if (p != NULL)
return timi_add_pathlist(cf, p - cf + 1); /* including DIRSEP */ return timi_add_pathlist(cf, p - cf + 1); /* including DIRSEP */
return 0; return 0;
} }
static int init_with_config(const char *cf) static int init_with_config(const char *cf)
{ {
int rc; int rc = init_begin_config(cf);
rc = init_begin_config(cf);
if (rc != 0) { if (rc != 0) {
mid_exit (); mid_exit ();
return rc; return rc;
} }
rc = read_config_file(cf, 0); rc = read_config_file(cf, 0);
if (rc != 0) if (rc != 0) {
mid_exit (); mid_exit ();
else {
timi_free(rcf_fp);
rcf_fp = NULL;
} }
return rc; return rc;
} }
int mid_init_no_config(void) int mid_init_no_config(void)
{ {
master_tonebank[0] = NULL; master_tonebank[0] = NULL;
master_drumset[0] = NULL; master_drumset[0] = NULL;
rcf_fp = NULL;
return init_alloc_banks(); return init_alloc_banks();
} }
int mid_init(const char *config_file) int mid_init(const char *config_file)
{ {
int rc = mid_init_no_config(); int rc = mid_init_no_config();
if (rc != 0) if (rc != 0) {
return rc; return rc;
}
if (config_file == NULL || *config_file == '\0') if (config_file == NULL || *config_file == '\0') {
return init_with_config(TIMIDITY_CFG); return init_with_config(TIMIDITY_CFG);
}
return init_with_config(config_file); return init_with_config(config_file);
} }
static void do_song_load(MidIStream *stream, MidSongOptions *options, MidSong ** out) static void do_song_load(MidIStream *stream, MidSongOptions *options, MidSong ** out)
{ {
MidSong *song; MidSong *song;
int i; int i;
*out = NULL; *out = NULL;
if (!stream) return; if (!stream) return;
skipping to change at line 647 skipping to change at line 633
timi_free(song->meta_data[i]); timi_free(song->meta_data[i]);
} }
timi_free(song); timi_free(song);
} }
void mid_exit(void) void mid_exit(void)
{ {
int i, j; int i, j;
if (rcf_fp) {
for (i = 0; i < MAX_RCFCOUNT; i++) {
if (rcf_fp[i])
fclose(rcf_fp[i]);
}
timi_free(rcf_fp);
rcf_fp = NULL;
}
for (i = 0; i < 128; i++) { for (i = 0; i < 128; i++) {
if (master_tonebank[i]) { if (master_tonebank[i]) {
MidToneBankElement *e = master_tonebank[i]->tone; MidToneBankElement *e = master_tonebank[i]->tone;
if (e != NULL) { if (e != NULL) {
for (j = 0; j < 128; j++) { for (j = 0; j < 128; j++) {
timi_free(e[j].name); timi_free(e[j].name);
} }
timi_free(e); timi_free(e);
} }
timi_free(master_tonebank[i]); timi_free(master_tonebank[i]);
skipping to change at line 693 skipping to change at line 670
long mid_get_version (void) long mid_get_version (void)
{ {
return LIBTIMIDITY_VERSION; return LIBTIMIDITY_VERSION;
} }
/* ===== for libtimidity <= 0.2.x compatibility ===== /* ===== for libtimidity <= 0.2.x compatibility =====
*/ */
MidDLSPatches *mid_dlspatches_load (MidIStream *stream) MidDLSPatches *mid_dlspatches_load (MidIStream *stream)
{ {
TIMI_UNUSED(stream);
return NULL; return NULL;
} }
void mid_dlspatches_free (MidDLSPatches *data) void mid_dlspatches_free (MidDLSPatches *data)
{ {
TIMI_UNUSED(data);
} }
MidSong *mid_song_load_dls(MidIStream *stream, MidDLSPatches *dlspatches, MidSon gOptions *options) MidSong *mid_song_load_dls(MidIStream *stream, MidDLSPatches *dlspatches, MidSon gOptions *options)
{ {
TIMI_UNUSED(stream);
TIMI_UNUSED(dlspatches);
TIMI_UNUSED(options);
return NULL; return NULL;
} }
 End of changes. 24 change blocks. 
42 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)