test: update midifile library to ANSI C

The midifile library used by the playmidi1 program dates from 1989, and
used pre-ANSI function definitions and prototypes. GCC 15 now defaults
to C23 where () means the same as (void) in prototypes, which causes
type mismatch errors.

Update the code to use ANSI function definitions and prototypes, so
it'll compile happily as anything from ANSI C to C23. This revealed that
playmidi1's do_tempo had the wrong argument type, so correct that as
well.

Closes: https://github.com/alsa-project/alsa-lib/pull/463
Signed-off-by: Adam Sampson <ats@offog.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Adam Sampson 2025-07-06 05:07:45 +01:00 committed by Jaroslav Kysela
parent 782b0597c2
commit 3a97718124
3 changed files with 140 additions and 181 deletions

View file

@ -79,34 +79,34 @@
/* public stuff */ /* public stuff */
/* Functions to be called while processing the MIDI file. */ /* Functions to be called while processing the MIDI file. */
int (*Mf_getc) () = NULLFUNC; int (*Mf_getc) (void) = NULLFUNC;
void (*Mf_error) () = NULLFUNC; void (*Mf_error) (char *s) = NULLFUNC;
void (*Mf_header) () = NULLFUNC; void (*Mf_header) (int format, int ntrks, int division) = NULLFUNC;
void (*Mf_trackstart) () = NULLFUNC; void (*Mf_trackstart) (void) = NULLFUNC;
void (*Mf_trackend) () = NULLFUNC; void (*Mf_trackend) (void) = NULLFUNC;
void (*Mf_noteon) () = NULLFUNC; void (*Mf_noteon) (int chan, int c1, int c2) = NULLFUNC;
void (*Mf_noteoff) () = NULLFUNC; void (*Mf_noteoff) (int chan, int c1, int c2) = NULLFUNC;
void (*Mf_pressure) () = NULLFUNC; void (*Mf_pressure) (int chan, int c1, int c2) = NULLFUNC;
void (*Mf_parameter) () = NULLFUNC; void (*Mf_parameter) (int chan, int c1, int c2) = NULLFUNC;
void (*Mf_pitchbend) () = NULLFUNC; void (*Mf_pitchbend) (int chan, int c1, int c2) = NULLFUNC;
void (*Mf_program) () = NULLFUNC; void (*Mf_program) (int chan, int c1) = NULLFUNC;
void (*Mf_chanpressure) () = NULLFUNC; void (*Mf_chanpressure) (int chan, int c1) = NULLFUNC;
void (*Mf_sysex) () = NULLFUNC; void (*Mf_sysex) (int len, char *msg) = NULLFUNC;
void (*Mf_arbitrary) () = NULLFUNC; void (*Mf_arbitrary) (int len, char *msg) = NULLFUNC;
void (*Mf_metamisc) () = NULLFUNC; void (*Mf_metamisc) (int type, int len, char *msg) = NULLFUNC;
void (*Mf_seqnum) () = NULLFUNC; void (*Mf_seqnum) (int num) = NULLFUNC;
void (*Mf_eot) () = NULLFUNC; void (*Mf_eot) (void) = NULLFUNC;
void (*Mf_smpte) () = NULLFUNC; void (*Mf_smpte) (char m0, char m1, char m2, char m3, char m4) = NULLFUNC;
void (*Mf_tempo) () = NULLFUNC; void (*Mf_tempo) (long tempo) = NULLFUNC;
void (*Mf_timesig) () = NULLFUNC; void (*Mf_timesig) (char m0, char m1, char m2, char m3) = NULLFUNC;
void (*Mf_keysig) () = NULLFUNC; void (*Mf_keysig) (char m0, char m1) = NULLFUNC;
void (*Mf_seqspecific) () = NULLFUNC; void (*Mf_seqspecific) (int len, char *msg) = NULLFUNC;
void (*Mf_text) () = NULLFUNC; void (*Mf_text) (int type, int len, char *msg) = NULLFUNC;
/* Functions to implement in order to write a MIDI file */ /* Functions to implement in order to write a MIDI file */
int (*Mf_putc) () = NULLFUNC; int (*Mf_putc) (unsigned char c) = NULLFUNC;
int (*Mf_writetrack) () = NULLFUNC; int (*Mf_writetrack) (int track) = NULLFUNC;
int (*Mf_writetempotrack) () = NULLFUNC; int (*Mf_writetempotrack) (void) = NULLFUNC;
int Mf_nomerge = 0; /* 1 => continue'ed system exclusives are */ int Mf_nomerge = 0; /* 1 => continue'ed system exclusives are */
/* not collapsed. */ /* not collapsed. */
@ -132,29 +132,34 @@ static int tempo_history_count = 0;
static long Mf_toberead = 0L; static long Mf_toberead = 0L;
static long Mf_numbyteswritten = 0L; static long Mf_numbyteswritten = 0L;
static long readvarinum (); static long readvarinum (void);
static long read32bit (); static long read32bit (void);
static long to32bit (); static long to32bit (int, int, int, int);
static int read16bit (); static int read16bit (void);
static int to16bit (); static int to16bit (int, int);
static char *msg (); static char *msg (void);
static void readheader (); static void readheader (void);
static int readtrack (); static int readtrack (void);
static void badbyte (); static void badbyte (int);
static void metaevent (); static void metaevent (int);
static void sysex (); static void sysex (void);
static void chanmessage (); static void chanmessage (int, int, int);
static void msginit (); static void msginit (void);
static int msgleng (); static int msgleng (void);
static void msgadd (); static void msgadd (int);
static void biggermsg (); static void biggermsg (void);
static int eputc (); static int eputc (unsigned char);
double mf_ticks2sec (unsigned long ticks, int division, unsigned long tempo); double mf_ticks2sec (unsigned long ticks, int division, unsigned long tempo);
int mf_write_meta_event (); void write32bit (unsigned long data);
void mf_write_tempo (); void write16bit (int data);
void mf_write_seqnum (); void mf_write_track_chunk (int which_track, FILE *fp);
void WriteVarLen (); void mf_write_header_chunk (int format, int ntracks, int division);
int mf_write_meta_event (unsigned long delta_time, unsigned char type,
unsigned char *data, unsigned long size);
void mf_write_tempo (unsigned long delta_time, unsigned long tempo);
void mf_write_seqnum (unsigned long delta_time, unsigned int seqnum);
void WriteVarLen (unsigned long value);
#ifdef READ_MODS #ifdef READ_MODS
#include "mp_mod.c" #include "mp_mod.c"
@ -163,7 +168,7 @@ static int mod_file_flag = 0;
static int force_exit; static int force_exit;
void void
mfread () mfread (void)
{ {
force_exit = 0; force_exit = 0;
if (Mf_getc == NULLFUNC) if (Mf_getc == NULLFUNC)
@ -181,15 +186,13 @@ mfread ()
/* for backward compatibility with the original lib */ /* for backward compatibility with the original lib */
void void
midifile () midifile (void)
{ {
mfread (); mfread ();
} }
static static int
int readmt (char *s) /* read through the "MThd" or "MTrk" header string */
readmt (s) /* read through the "MThd" or "MTrk" header string */
char *s;
{ {
int n = 0; int n = 0;
char *p = s; char *p = s;
@ -211,9 +214,8 @@ readmt (s) /* read through the "MThd" or "MTrk" header string */
return (c); return (c);
} }
static static int
int egetc (void) /* read a single character and abort on EOF */
egetc () /* read a single character and abort on EOF */
{ {
int c = (*Mf_getc) (); int c = (*Mf_getc) ();
@ -225,9 +227,8 @@ egetc () /* read a single character and abort on EOF */
return (c); return (c);
} }
static static void
void readheader (void) /* read a header chunk */
readheader () /* read a header chunk */
{ {
int format, ntrks, division; int format, ntrks, division;
@ -280,9 +281,8 @@ readheader () /* read a header chunk */
/*#define DEBUG_TIMES*/ /*#define DEBUG_TIMES*/
static static unsigned long
unsigned long find_tempo(void)
find_tempo()
{ {
int i; int i;
unsigned long old_tempo = Mf_currtempo; unsigned long old_tempo = Mf_currtempo;
@ -307,9 +307,8 @@ printf("[revised_time %lu, new_tempo %lu]\n", revised_time, new_tempo);
return(new_tempo); return(new_tempo);
} }
static static int
int readtrack (void) /* read a track chunk */
readtrack () /* read a track chunk */
{ {
/* This array is indexed by the high half of a status byte. It's */ /* This array is indexed by the high half of a status byte. It's */
/* value is either the number of bytes needed (1 or 2) for a channel */ /* value is either the number of bytes needed (1 or 2) for a channel */
@ -499,10 +498,8 @@ old_f_realtime, delta_secs * 1600.0);
return (1); return (1);
} }
static static void
void badbyte (int c)
badbyte (c)
int c;
{ {
char buff[32]; char buff[32];
@ -510,8 +507,7 @@ badbyte (c)
mferror (buff); mferror (buff);
} }
static static void
void
metaevent (int type) metaevent (int type)
{ {
int leng = msgleng (); int leng = msgleng ();
@ -577,19 +573,15 @@ metaevent (int type)
} }
} }
static static void
void sysex (void)
sysex ()
{ {
if (Mf_sysex) if (Mf_sysex)
(*Mf_sysex) (msgleng (), msg ()); (*Mf_sysex) (msgleng (), msg ());
} }
static static void
void chanmessage (int status, int c1, int c2)
chanmessage (status, c1, c2)
int status;
int c1, c2;
{ {
int chan = status & 0xf; int chan = status & 0xf;
@ -635,7 +627,7 @@ chanmessage (status, c1, c2)
/* number of characters it took. */ /* number of characters it took. */
static long static long
readvarinum () readvarinum (void)
{ {
long value; long value;
int c; int c;
@ -668,14 +660,13 @@ to32bit (int c1, int c2, int c3, int c4)
} }
static int static int
to16bit (c1, c2) to16bit (int c1, int c2)
int c1, c2;
{ {
return ((c1 & 0xff) << 8) + (c2 & 0xff); return ((c1 & 0xff) << 8) + (c2 & 0xff);
} }
static long static long
read32bit () read32bit (void)
{ {
int c1, c2, c3, c4; int c1, c2, c3, c4;
@ -687,7 +678,7 @@ read32bit ()
} }
static int static int
read16bit () read16bit (void)
{ {
int c1, c2; int c1, c2;
c1 = egetc (); c1 = egetc ();
@ -697,8 +688,7 @@ read16bit ()
/* static */ /* static */
void void
mferror (s) mferror (char *s)
char *s;
{ {
if (Mf_error) if (Mf_error)
(*Mf_error) (s); (*Mf_error) (s);
@ -714,30 +704,26 @@ static char *Msgbuff = NULL; /* message buffer */
static int Msgsize = 0; /* Size of currently allocated Msg */ static int Msgsize = 0; /* Size of currently allocated Msg */
static int Msgindex = 0; /* index of next available location in Msg */ static int Msgindex = 0; /* index of next available location in Msg */
static static void
void msginit (void)
msginit ()
{ {
Msgindex = 0; Msgindex = 0;
} }
static char * static char *
msg () msg (void)
{ {
return (Msgbuff); return (Msgbuff);
} }
static static int
int msgleng (void)
msgleng ()
{ {
return (Msgindex); return (Msgindex);
} }
static static void
void msgadd (int c)
msgadd (c)
int c;
{ {
/* If necessary, allocate larger message buffer. */ /* If necessary, allocate larger message buffer. */
if (Msgindex >= Msgsize) if (Msgindex >= Msgsize)
@ -745,11 +731,9 @@ msgadd (c)
Msgbuff[Msgindex++] = c; Msgbuff[Msgindex++] = c;
} }
static static void
void biggermsg (void)
biggermsg ()
{ {
/* char *malloc(); */
char *newmess; char *newmess;
char *oldmess = Msgbuff; char *oldmess = Msgbuff;
int oldleng = Msgsize; int oldleng = Msgsize;
@ -805,12 +789,9 @@ static int laststatus = 0;
* to work with Mf_putc. * to work with Mf_putc.
*/ */
void void
mfwrite (format, ntracks, division, fp) mfwrite (int format, int ntracks, int division, FILE *fp)
int format, ntracks, division;
FILE *fp;
{ {
int i; int i;
void mf_write_track_chunk (), mf_write_header_chunk ();
if (Mf_putc == NULLFUNC) if (Mf_putc == NULLFUNC)
mferror ("mfmf_write() called without setting Mf_putc"); mferror ("mfmf_write() called without setting Mf_putc");
@ -837,14 +818,10 @@ mfwrite (format, ntracks, division, fp)
} }
void void
mf_write_track_chunk (which_track, fp) mf_write_track_chunk (int which_track, FILE *fp)
int which_track;
FILE *fp;
{ {
unsigned long trkhdr, trklength; unsigned long trkhdr, trklength;
long offset, place_marker; long offset, place_marker;
void write16bit (), write32bit ();
laststatus = 0; laststatus = 0;
@ -910,11 +887,9 @@ mf_write_track_chunk (which_track, fp)
void void
mf_write_header_chunk (format, ntracks, division) mf_write_header_chunk (int format, int ntracks, int division)
int format, ntracks, division;
{ {
unsigned long ident, length; unsigned long ident, length;
void write16bit (), write32bit ();
ident = MThd; /* Head chunk identifier */ ident = MThd; /* Head chunk identifier */
length = 6; /* Chunk length */ length = 6; /* Chunk length */
@ -948,11 +923,8 @@ mf_write_header_chunk (format, ntracks, division)
* size - The length of the meta-event data. * size - The length of the meta-event data.
*/ */
int int
mf_write_midi_event (delta_time, type, chan, data, size) mf_write_midi_event (unsigned long delta_time, int type, int chan,
unsigned long delta_time; char *data, unsigned long size)
int chan, type;
unsigned long size;
char *data;
{ {
int i; int i;
unsigned char c; unsigned char c;
@ -999,11 +971,9 @@ mf_write_midi_event (delta_time, type, chan, data, size)
* data. * data.
* size - The length of the meta-event data. * size - The length of the meta-event data.
*/ */
int int
mf_write_meta_event (delta_time, type, data, size) mf_write_meta_event (unsigned long delta_time, unsigned char type,
unsigned long delta_time; unsigned char *data, unsigned long size)
unsigned char *data, type;
unsigned long size;
{ {
int i; int i;
@ -1027,9 +997,7 @@ mf_write_meta_event (delta_time, type, data, size)
} /* end mf_write_meta_event */ } /* end mf_write_meta_event */
void void
mf_write_tempo (delta_time, tempo) mf_write_tempo (unsigned long delta_time, unsigned long tempo)
unsigned long delta_time;
unsigned long tempo;
{ {
/* Write tempo */ /* Write tempo */
/* all tempos are written as 120 beats/minute, */ /* all tempos are written as 120 beats/minute, */
@ -1046,9 +1014,7 @@ mf_write_tempo (delta_time, tempo)
} }
void void
mf_write_seqnum (delta_time, seqnum) mf_write_seqnum (unsigned long delta_time, unsigned int seqnum)
unsigned long delta_time;
unsigned seqnum;
{ {
WriteVarLen (delta_time); WriteVarLen (delta_time);
@ -1060,10 +1026,7 @@ mf_write_seqnum (delta_time, seqnum)
} }
unsigned long unsigned long
mf_sec2ticks (secs, division, tempo) mf_sec2ticks (double secs, int division, unsigned long tempo)
int division;
unsigned long tempo;
double secs;
{ {
return (unsigned long) (((secs * 1000.0) / 4.0 * division) / tempo); return (unsigned long) (((secs * 1000.0) / 4.0 * division) / tempo);
} }
@ -1072,8 +1035,7 @@ mf_sec2ticks (secs, division, tempo)
* Write multi-length bytes to MIDI format files * Write multi-length bytes to MIDI format files
*/ */
void void
WriteVarLen (value) WriteVarLen (unsigned long value)
unsigned long value;
{ {
unsigned long buffer; unsigned long buffer;
@ -1102,10 +1064,7 @@ WriteVarLen (value)
* *
*/ */
double double
mf_ticks2sec (ticks, division, tempo) mf_ticks2sec (unsigned long ticks, int division, unsigned long tempo)
int division;
unsigned long tempo;
unsigned long ticks;
{ {
double smpte_format, smpte_resolution; double smpte_format, smpte_resolution;
@ -1133,8 +1092,7 @@ mf_ticks2sec (ticks, division, tempo)
* *
*/ */
void void
write32bit (data) write32bit (unsigned long data)
unsigned long data;
{ {
eputc ((unsigned) ((data >> 24) & 0xff)); eputc ((unsigned) ((data >> 24) & 0xff));
eputc ((unsigned) ((data >> 16) & 0xff)); eputc ((unsigned) ((data >> 16) & 0xff));
@ -1143,8 +1101,7 @@ write32bit (data)
} }
void void
write16bit (data) write16bit (int data)
int data;
{ {
eputc ((unsigned) ((data & 0xff00) >> 8)); eputc ((unsigned) ((data & 0xff00) >> 8));
eputc ((unsigned) (data & 0xff)); eputc ((unsigned) (data & 0xff));
@ -1152,8 +1109,7 @@ write16bit (data)
/* write a single character and abort on error */ /* write a single character and abort on error */
static int static int
eputc (c) eputc (unsigned char c)
unsigned char c;
{ {
int return_val; int return_val;

View file

@ -1,27 +1,27 @@
/* definitions for MIDI file parsing code */ /* definitions for MIDI file parsing code */
extern int (*Mf_getc)(); extern int (*Mf_getc)(void);
extern void (*Mf_header)(); extern void (*Mf_error)(char *s);
extern void (*Mf_trackstart)(); extern void (*Mf_header)(int format, int ntrks, int division);
extern void (*Mf_trackend)(); extern void (*Mf_trackstart)(void);
extern void (*Mf_noteon)(); extern void (*Mf_trackend)(void);
extern void (*Mf_noteoff)(); extern void (*Mf_noteon)(int chan, int c1, int c2);
extern void (*Mf_pressure)(); extern void (*Mf_noteoff)(int chan, int c1, int c2);
extern void (*Mf_parameter)(); extern void (*Mf_pressure)(int chan, int c1, int c2);
extern void (*Mf_pitchbend)(); extern void (*Mf_parameter)(int chan, int c1, int c2);
extern void (*Mf_program)(); extern void (*Mf_pitchbend)(int chan, int c1, int c2);
extern void (*Mf_chanpressure)(); extern void (*Mf_program)(int chan, int c1);
extern void (*Mf_sysex)(); extern void (*Mf_chanpressure)(int chan, int c1);
extern void (*Mf_metamisc)(); extern void (*Mf_sysex)(int len, char *msg);
extern void (*Mf_seqspecific)(); extern void (*Mf_arbitrary)(int len, char *msg);
extern void (*Mf_seqnum)(); extern void (*Mf_metamisc)(int type, int len, char *msg);
extern void (*Mf_text)(); extern void (*Mf_seqnum)(int num);
extern void (*Mf_eot)(); extern void (*Mf_eot)(void);
extern void (*Mf_timesig)(); extern void (*Mf_smpte)(char m0, char m1, char m2, char m3, char m4);
extern void (*Mf_smpte)(); extern void (*Mf_tempo)(long tempo);
extern void (*Mf_tempo)(); extern void (*Mf_timesig)(char m0, char m1, char m2, char m3);
extern void (*Mf_keysig)(); extern void (*Mf_keysig)(char m0, char m1);
extern void (*Mf_arbitrary)(); extern void (*Mf_seqspecific)(int len, char *msg);
extern void (*Mf_error)(); extern void (*Mf_text)(int type, int len, char *msg);
extern unsigned long Mf_currtime; extern unsigned long Mf_currtime;
extern unsigned long Mf_realtime; extern unsigned long Mf_realtime;
extern unsigned long Mf_currtempo; extern unsigned long Mf_currtempo;
@ -33,20 +33,23 @@ extern int Mf_file_size;
#endif #endif
/* definitions for MIDI file writing code */ /* definitions for MIDI file writing code */
extern int (*Mf_putc)(); extern int (*Mf_putc)(unsigned char c);
extern int (*Mf_writetrack)(); extern int (*Mf_writetrack)(int track);
extern int (*Mf_writetempotrack)(); extern int (*Mf_writetempotrack)(void);
extern void midifile(); extern void midifile(void);
extern unsigned long mf_sec2ticks(); extern unsigned long mf_sec2ticks(double secs, int division,
extern void mfwrite(); unsigned long tempo);
extern int mf_write_meta_event(); extern void mfwrite(int format, int ntracks, int division, FILE *fp);
extern int mf_write_meta_event(unsigned long delta_time, unsigned char type,
unsigned char *data, unsigned long size);
extern int mf_write_midi_event(unsigned long delta_time, int type, extern int mf_write_midi_event(unsigned long delta_time, int type,
int chan, char *data, unsigned long size); int chan, char *data, unsigned long size);
extern double mf_ticks2sec(unsigned long ticks,int division,unsigned long tempo); extern double mf_ticks2sec(unsigned long ticks, int division,
extern void mf_write_tempo(); unsigned long tempo);
extern void mf_write_seqnum(); extern void mf_write_tempo(unsigned long delta_time, unsigned long tempo);
extern void mfread(); extern void mf_write_seqnum(unsigned long delta_time, unsigned int seqnum);
extern void mfread(void);
extern void mferror(char *s); extern void mferror(char *s);
#ifndef NO_LC_DEFINES #ifndef NO_LC_DEFINES

View file

@ -243,14 +243,14 @@ static void alsa_stop_timer(void)
} }
/* change the tempo */ /* change the tempo */
static void do_tempo(int us) static void do_tempo(long us)
{ {
snd_seq_event_t ev; snd_seq_event_t ev;
if (verbose >= VERB_MUCH) { if (verbose >= VERB_MUCH) {
double bpm; double bpm;
bpm = 60.0E6 / (double) us; bpm = 60.0E6 / (double) us;
printf("Tempo %d us/beat, %.2f bpm\n", us, bpm); printf("Tempo %ld us/beat, %.2f bpm\n", us, bpm);
} }
/* store the new tempo and timestamp of the tempo change */ /* store the new tempo and timestamp of the tempo change */