delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/26/02:46:56

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro MIDI
Date: Thu, 23 Oct 1997 21:27:41 +0100
Organization: Oxford University
Message-ID: <Pine.OSF.3.95.971023210115.4177A-100000@sable.ox.ac.uk>
NNTP-Posting-Host: sable.ox.ac.uk
Mime-Version: 1.0
cc: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
In-Reply-To: <344FABEE.152B@teleport.com>
Lines: 56
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 23 Oct 1997, Mark Contra wrote:

> Have you checked out WinJammer, a shareware MIDI sequencer for Windows,
> it is extremely powerful, and would probably let you insert events in
> any way you want, try http://www.winjammer.com

Thanks, I'll try that.

> I don't like the idea of having my main code check to see weather the
> MIDI has stopped playing and restart it again, it would slow things
> down and I would have to insert the checker all over my code. It would
> be very nice if the driver did it all for you behind the scenes, what's
> so hard, basically right now the driver goes (seeks) to position 0 
> (the beginning) when it ends, so just tell it to seek to an arbitrary
> position rather than 0. I would be extremly thankful if you could 
> implement this, because I know you've done a lot of work on the MIDI
> code for Allegro, so you would be the prime candidate.

Heh, I haven't actually done much work on it... just the three functions I
mentioned before.

The difficulty is that when the player loops the file, all it has to do is
restart playback. This only involves a call to the prepare_to_play
function. However, seeking to any other position in the file is
non-trivial; Allegro keeps internal data, relating to which notes are
currently being played, what hardware voice they're playing on, the midi
position, controller values, etc. The only real way to do a seek (I
concluded) is to scan through the file from the current position to the
target (or restart the file, then do the scan, for a reverse seek). To do
this I made it call back the midi_player function repeatedly until the
target position is reached; this ensures that Allegro's data is 100%
correct, but makes it impractical to do from within the midi_player
function (which is not reentrant).

As I said before, I think frequent polling is the best solution. Doing the
polling shouldn't slow anything down really; you'd just be checking
whether or not midi_pos was negative. If the program doesn't have a nice,
reasonably frequently-executed loop, a timer routine ought to be fine
(bearing in mind the caveats I mentioned before). I might try implementing
this tonight.

Alternatively, it may be possible to detect when the desired start point
is reached, and save a copy of the status of the MIDI driver. Then when
the loop should occur this copy could be restored. This technique sounds
extremely prone to error to me, though.

Yet another alternative would be, when the midi_player reaches EOF, to
leave the non-reentrant portion (i.e. tidy everything up as if we were
stopping), and then call midi_seek just before exiting. I may try this,
too.

-- 
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