home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BKPLAY10.ZIP / BACKPLAY.DOC next >
Encoding:
Text File  |  1988-09-27  |  5.6 KB  |  111 lines

  1. (* BackPlay  --  A unit for playing music in the background.
  2.  
  3.   Version 1.00 --  9/24/1988 -- First version
  4.  
  5.   Copyright 1988 Scott Bussinger
  6.   All rights reserved.
  7.  
  8.   Scott Bussinger
  9.   Professional Practice Systems
  10.   110 South 131st Street
  11.   Tacoma, WA  98444
  12.   (206)531-8944
  13.   Compuserve [72247,2671]
  14.  
  15.   This unit allows you to play music in the background of your Turbo Pascal 5.0
  16. programs. In the background means that once you start the music playing, you
  17. can continue on with the rest of your program and the music keeps playing
  18. without any additional effort on your part until the song is finished. You can
  19. use this to provide special sound effects in your programs or just to add a
  20. cute indication that your program is still working on something.
  21.   The unit accepts music files from Neil Rubenking's PianoMan program version
  22. 4.0 and the code in this file is based on information gained from his sample
  23. music playing routines.  You can either play the .MUZ files off of your disks,
  24. or imbed the the MUZ data directly into your program so the the file need not
  25. be available at run time.  Neil's PianoMan is an excellent shareware product
  26. and is available from many bulletin boards on in the IBM Software forum on
  27. Compuserve. It allows you to play your computer's keyboard like a piano
  28. keyboard and record and edit music entered in real time or from sheet music.
  29. There are also many files of songs already entered that you can use. One sample
  30. archive for instance contains over 50 sample songs.
  31.  
  32.      function PlayingInBackground: boolean;
  33.           This returns true if there is still music being played in the
  34.           background. You may use this to wait for a song to finish before
  35.           proceeding.
  36.  
  37.      procedure PlayingMode(Action: SongAction);
  38.           This routine lets you change the current way songs are being played.
  39.           The acceptable parameters are RepeatSong to cause the current music
  40.           buffer to be repeated endlessly when the song finishes. This mode
  41.           continues until EndRepeatSong or StopSong is used, the program ends
  42.           or you call PlayMuz or PlaySong again.  SuspendSong turns off the
  43.           music temporarily (perhaps to ask the user a question) and the music
  44.           will continue when ResumeSong is used. StopSong will end the current
  45.           song immediately.
  46.  
  47.      function PlayMuz(Filename: string): boolean;
  48.           This routine loads an MUZ file from disk and adds it to the current
  49.           music buffer. If a song is currently playing, it will start when the
  50.           current song ends otherwise the song will start immediately. This
  51.           routine automatically clears the RepeatSong mode. PlayMuz returns
  52.           true if the file was found or false if not found. It will look for
  53.           the .MUZ file first in the current directory and then in all of the
  54.           directories in the current PATH.
  55.  
  56.      procedure PlaySong(S: Song);
  57.           This routine is like PlayMuz, except it plays a song that is imbedded
  58.           into your program using the {$L} compiler directive. To load an
  59.           .MUZ file use the BINOBJ program that comes with Turbo Pascal to
  60.           convert the .MUZ file to an .OBJ file with a line like:
  61.                BINOBJ HITCHKOK.MUZ HITCHKOK Hitchkok
  62.           and include it in your program as an external routine like:
  63.                {$L HITCHKOK.OBJ}
  64.                procedure Hitchkok; external;
  65.           to play this song, you'll use PlaySong(Hitchkok). This lets you play
  66.           songs without including a lot of extra files with your program.
  67.  
  68.   Note that there is a size limit to the background music buffer. This is set
  69. by constant BackgroundBufferSize and is normally 256 note changes.  A staccato
  70. is treated as two notes (the 'on' part and the rest between notes) so this will
  71. handle up to about 128 notes in a typical song.  The buffer is only cleared
  72. when the entire buffer is emptied (and silence prevails), so if you keep
  73. calling PlayMuz or PlaySong and the previous song isn't over, the buffer just
  74. gets larger. The music is automatically turned off when the program ends.
  75.   There's one last limitation on the techniques used by BackPlay. Note changes
  76. can only take place 18.2 times a second (the standard system clock rate). All
  77. note durations and staccatos in the song are rounded to the nearest number of
  78. clock ticks. This means that the song may have a slightly different tempo when
  79. played using BackPlay than it does under PianoMan and that very short notes and
  80. staccatos may disappear altogether. Most of the multivoice songs done in
  81. PianoMan will sound terrible with BackPlay because of this limitation.
  82.   If you compile this file you'll see an example program this uses both
  83. PlaySong and PlayMuz.  The first part shows that the music continues while
  84. calculations take place.  The last part show how you can wait for a song to
  85. finish before continuing (or ending the program in this case). Before compiling
  86. the demo, you'll need to convert the PLAYDEM1.MUZ file into PLAYDEM1.OBJ using
  87. the BINOBJ utility that comes with Turbo Pascal using the following command
  88. line at a DOS prompt:
  89.      BINOBJ PLAYDEM1.MUZ PLAYDEM1 PlayDem1
  90. *)
  91.  
  92. program PlayDemo;
  93.  
  94. uses BackPlay;
  95.  
  96. var I: longint;
  97.  
  98. {$L PLAYDEM1.OBJ}
  99. {$F+}
  100. procedure PlayDem1; external;
  101. {$F-}
  102.  
  103. begin
  104. PlaySong(PlayDem1);               { Start playing the first song (already in memory) }
  105. for I := 1 to 250 do              { Look busy }
  106.   writeln(I:3,sqr(I):10);
  107. if not PlayMuz('PLAYDEM2') then   { Play second song (loaded from disk file PLAYDEM2.MUZ }
  108.   writeln('PLAYDEM2.MUZ not found.');
  109. while PlayingInBackground do ;    { Wait for song to finish }
  110. end.
  111.