delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/23/08:03:13

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro MIDI
Date: 23 Oct 1997 03:54:26 GMT
Organization: Oxford University, England
Message-ID: <62mhpi$enb$1@news.ox.ac.uk>
References: <344E8615 DOT 59F4 AT teleport DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
Lines: 46
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019