midi repeat improvements
This commit is contained in:
parent
249088e477
commit
a43384d92a
|
@ -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;
|
||||||
|
@ -310,8 +315,14 @@ 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) {
|
||||||
/* ??? */
|
/* ??? */
|
||||||
|
@ -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,16 +358,18 @@ 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;
|
||||||
|
@ -401,4 +415,3 @@ int hmp_play(hmp_file *hmp) {
|
||||||
midiStreamRestart(hmp->hmidi);
|
midiStreamRestart(hmp->hmidi);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue