Mail Archives: djgpp/1997/10/23/08:03:13
On Wed, 22 Oct 1997 16:02:45 -0700 in comp.os.msdos.djgpp Mark Contra
(markc AT teleport DOT com) wrote:
: Is there anybody willing to extend Allegro's MIDI functionality, to
: make it able to specify the loop point of a song rather then repeat
: from the begining? Such as:
: play_midi_file(MIDI *song, int loop_point);
: It would be useful if your songs had an intro piece before the looping
: chunk, like most RPG games do. Shawn says this would be kind of hard,
: but I don't see why. Anyway, volunteers would be appreciated.
A while ago I wrote some functions for the MIDI player, which allow you to
pause, continue, and seek through MIDI files. They're in the latest WIP.
Using these functions, it's possible to manually skip the intro to the
song; you'd tell the player not to loop it, and check frequently that
midi_pos != -1. If midi_pos == -1, the file has finished and you need to
restard it playing, then immediately skip to the loop start point.
Doing this automatically, behind the scenes, would require a great deal of
care, since the MIDI player is not reentrant; if, for example, you tried
to make it auto-seek on reaching the end of the song, there would be
problems since the seek function needs to call the midi_player function,
which would have called the seek function in the first place. A semaphore
flag is set by the player function on entry, and the subsequent calls
would be ignored.
Similar problems could occur if the test were done inside a timer
interrupt, but this technique is more feasible; suppose you have a timer
going of at regular intervals (e.g. 20ms), and the timer only has any
effect if the midi_semaphore flag is not set. Then it can check midi_pos,
and restart and seek the file before returning. I think it's safe to
assume that when midi_pos is -1 the midi_player won't already be installed
on a timer; certainly, calling midi_seek disengages it.
Ideally, you'd want some way of marking the point in the MIDI file where
the repeat should go; this could be done with a text-based event, for
instance, or a cue point. I was going to implement this once, until I
discovered that my MIDI sequencer doesn't let me insert arbitrary
events... :(
--
Regards,
george DOT foot AT merton DOT oxford DOT ac DOT uk
- Raw text -