midi repeat improvements

This commit is contained in:
zicodxx 2006-05-05 14:18:42 +00:00
parent 249088e477
commit a43384d92a
4 changed files with 44 additions and 24 deletions

View file

@ -107,7 +107,7 @@ void hmp_stop(hmp_file *hmp) {
hmp->evbuf = mhdr->lpNext; hmp->evbuf = mhdr->lpNext;
free(mhdr); free(mhdr);
} }
if (hmp->hmidi) { if (hmp->hmidi) {
midiStreamClose(hmp->hmidi); midiStreamClose(hmp->hmidi);
hmp->hmidi = NULL; hmp->hmidi = NULL;
@ -214,7 +214,7 @@ static int get_event(hmp_file *hmp, event *ev) {
} else if (ev_num == 0xff) { } else if (ev_num == 0xff) {
ev->msg[1] = *(trk->cur++); ev->msg[1] = *(trk->cur++);
trk->left--; trk->left--;
if (!(got = get_var_num(ev->data = trk->cur, if (!(got = get_var_num(ev->data = trk->cur,
trk->left, (unsigned long *)&ev->datalen))) trk->left, (unsigned long *)&ev->datalen)))
return HMP_INVALID_FILE; return HMP_INVALID_FILE;
trk->cur += ev->datalen; trk->cur += ev->datalen;
@ -285,15 +285,20 @@ static int setup_buffers(hmp_file *hmp) {
return 0; return 0;
} }
static void reset_tracks(struct hmp_file *hmp) { static void reset_tracks(struct hmp_file *hmp)
{
int i; int i;
for (i = 0; i < hmp->num_trks; i++) { for (i = 0; i < hmp->num_trks; i++) {
hmp->trks[i].cur = hmp->trks[i].data; hmp->trks [i].cur = hmp->trks [i].data;
hmp->trks[i].left = hmp->trks[i].len; hmp->trks [i].left = hmp->trks [i].len;
hmp->trks [i].cur_time = 0;
} }
hmp->cur_time=0;
} }
extern int loop;
static void _stdcall midi_callback(HMIDISTRM hms, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { static void _stdcall midi_callback(HMIDISTRM hms, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) {
MIDIHDR *mhdr; MIDIHDR *mhdr;
hmp_file *hmp; hmp_file *hmp;
@ -301,7 +306,7 @@ static void _stdcall midi_callback(HMIDISTRM hms, UINT uMsg, DWORD dwUser, DWORD
if (uMsg != MOM_DONE) if (uMsg != MOM_DONE)
return; return;
mhdr = ((MIDIHDR *)dw1); mhdr = ((MIDIHDR *)dw1);
mhdr->dwBytesRecorded = 0; mhdr->dwBytesRecorded = 0;
hmp = (hmp_file *)(mhdr->dwUser); hmp = (hmp_file *)(mhdr->dwUser);
@ -310,9 +315,15 @@ static void _stdcall midi_callback(HMIDISTRM hms, UINT uMsg, DWORD dwUser, DWORD
hmp->bufs_in_mm--; hmp->bufs_in_mm--;
if (!hmp->stop) { if (!hmp->stop) {
while (fill_buffer(hmp) == HMP_EOF) while (fill_buffer(hmp) == HMP_EOF) {
if (loop)
hmp->stop = 0;
else
hmp->stop = 1;
reset_tracks(hmp); reset_tracks(hmp);
if ((rc = midiStreamOut(hmp->hmidi, hmp->evbuf, }
if ((rc = midiStreamOut(hmp->hmidi, hmp->evbuf,
sizeof(MIDIHDR))) != MMSYSERR_NOERROR) { sizeof(MIDIHDR))) != MMSYSERR_NOERROR) {
/* ??? */ /* ??? */
} else { } else {
@ -320,7 +331,6 @@ static void _stdcall midi_callback(HMIDISTRM hms, UINT uMsg, DWORD dwUser, DWORD
hmp->bufs_in_mm++; hmp->bufs_in_mm++;
} }
} }
} }
static void setup_tempo(hmp_file *hmp, unsigned long tempo) { static void setup_tempo(hmp_file *hmp, unsigned long tempo) {
@ -332,12 +342,14 @@ static void setup_tempo(hmp_file *hmp, unsigned long tempo) {
mhdr->dwBytesRecorded += 12; mhdr->dwBytesRecorded += 12;
} }
int hmp_play(hmp_file *hmp) {
int hmp_play(hmp_file *hmp, int bLoop)
{
int rc; int rc;
MIDIPROPTIMEDIV mptd; MIDIPROPTIMEDIV mptd;
#if 0 #if 1
unsigned int numdevs; unsigned int numdevs;
int i=0; int i=0; // ZICO - LOOP HERE
numdevs=midiOutGetNumDevs(); numdevs=midiOutGetNumDevs();
hmp->devid=-1; hmp->devid=-1;
@ -346,17 +358,19 @@ int hmp_play(hmp_file *hmp) {
MIDIOUTCAPS devcaps; MIDIOUTCAPS devcaps;
midiOutGetDevCaps(i,&devcaps,sizeof(MIDIOUTCAPS)); midiOutGetDevCaps(i,&devcaps,sizeof(MIDIOUTCAPS));
if ((devcaps.wTechnology==MOD_FMSYNTH) || (devcaps.wTechnology==MOD_SYNTH)) if ((devcaps.wTechnology==MOD_FMSYNTH) || (devcaps.wTechnology==MOD_SYNTH))
// if ((devcaps.dwSupport & (MIDICAPS_VOLUME | MIDICAPS_STREAM)) == (MIDICAPS_VOLUME | MIDICAPS_STREAM))
hmp->devid=i; hmp->devid=i;
i++; i++;
} while ((i<(int)numdevs) && (hmp->devid==-1)); } while ((i<(int)numdevs) && (hmp->devid==-1));
#else if (hmp->devid == -1)
hmp->devid = MIDI_MAPPER;
#endif #endif
hmp->bLoop = bLoop;
hmp->devid = MIDI_MAPPER;
if ((rc = setup_buffers(hmp))) if ((rc = setup_buffers(hmp)))
return rc; return rc;
if ((midiStreamOpen(&hmp->hmidi, &hmp->devid,1,(DWORD)midi_callback, if ((midiStreamOpen(&hmp->hmidi, &hmp->devid,1, (DWORD) (size_t) midi_callback,
0, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR) { 0, CALLBACK_FUNCTION)) != MMSYSERR_NOERROR) {
hmp->hmidi = NULL; hmp->hmidi = NULL;
return HMP_MM_ERR; return HMP_MM_ERR;
} }
@ -382,15 +396,15 @@ int hmp_play(hmp_file *hmp) {
return rc; return rc;
} }
#if 0 #if 0
{ FILE *f = fopen("dump","wb"); fwrite(hmp->evbuf->lpData, { FILE *f = fopen("dump","wb"); fwrite(hmp->evbuf->lpData,
hmp->evbuf->dwBytesRecorded,1,f); fclose(f); exit(1);} hmp->evbuf->dwBytesRecorded,1,f); fclose(f); exit(1);}
#endif #endif
if ((rc = midiOutPrepareHeader((HMIDIOUT)hmp->hmidi, hmp->evbuf, if ((rc = midiOutPrepareHeader((HMIDIOUT)hmp->hmidi, hmp->evbuf,
sizeof(MIDIHDR))) != MMSYSERR_NOERROR) { sizeof(MIDIHDR))) != MMSYSERR_NOERROR) {
/* FIXME: cleanup... */ /* FIXME: cleanup... */
return HMP_MM_ERR; return HMP_MM_ERR;
} }
if ((rc = midiStreamOut(hmp->hmidi, hmp->evbuf, if ((rc = midiStreamOut(hmp->hmidi, hmp->evbuf,
sizeof(MIDIHDR))) != MMSYSERR_NOERROR) { sizeof(MIDIHDR))) != MMSYSERR_NOERROR) {
/* FIXME: cleanup... */ /* FIXME: cleanup... */
return HMP_MM_ERR; return HMP_MM_ERR;
@ -401,4 +415,3 @@ int hmp_play(hmp_file *hmp) {
midiStreamRestart(hmp->hmidi); midiStreamRestart(hmp->hmidi);
return 0; return 0;
} }

View file

@ -6,6 +6,8 @@
#define HMP_TRACKS 32 #define HMP_TRACKS 32
#define HMP_BUFFERS 4 #define HMP_BUFFERS 4
#define HMP_BUFSIZE 1024 #define HMP_BUFSIZE 1024
#define BE_INT(x) (x)
#define BE_SHORT(x) (x)
typedef struct event { typedef struct event {
unsigned int delta; unsigned int delta;
@ -33,8 +35,10 @@ typedef struct hmp_file {
unsigned char *pending; unsigned char *pending;
unsigned int pending_size; unsigned int pending_size;
unsigned int pending_event; unsigned int pending_event;
int stop; /* 1 -> don't send more data */ int stop;
int bufs_in_mm; /* number of queued buffers */ int bufs_in_mm;
int bLoop;
unsigned int midi_division;
} hmp_file; } hmp_file;
@ -44,7 +48,7 @@ typedef struct hmp_file {
#define HMP_EOF 1 #define HMP_EOF 1
hmp_file *hmp_open(const char *filename); hmp_file *hmp_open(const char *filename);
int hmp_play(hmp_file *hmp); int hmp_play(hmp_file *hmp, int bLoop);
void hmp_close(hmp_file *hmp); void hmp_close(hmp_file *hmp);
#endif #endif

View file

@ -60,7 +60,7 @@ void digi_play_midi_song(char *filename, char *melodic_bank, char *drum_bank, in
if ((hmp = hmp_open(filename))) if ((hmp = hmp_open(filename)))
{ {
hmp_play(hmp); hmp_play(hmp,loop);
digi_midi_song_playing = 1; digi_midi_song_playing = 1;
digi_set_midi_volume(midi_volume); digi_set_midi_volume(midi_volume);
} }

View file

@ -304,6 +304,7 @@ int songs_haved2_cd()
} }
#endif #endif
int loop;
void songs_play_song( int songnum, int repeat ) void songs_play_song( int songnum, int repeat )
{ {
@ -338,6 +339,8 @@ void songs_play_song( int songnum, int repeat )
digi_play_midi_song(songnum, repeat); digi_play_midi_song(songnum, repeat);
#endif #endif
} }
loop = repeat;
} }
int current_song_level; int current_song_level;