Q(uick)BASIC Function: PLAY
Quick View
PLAY
An event-trapping function that returns the number of notes currently in the background-music queue
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- PLAY(n)
Description/Parameter(s)
n | Any numeric expression. |
Example
Music$ = "MBT180o2P2P8L8GGGL2E-P24P8L8FFFL2D"
PLAY Music$
WHILE PLAY(0) > 5: WEND
PRINT "Just about done!"
Syntax
- PLAY(n)
Description/Parameter(s)
The argument n is a dummy argument and may be any numeric value. |
PLAY(n) will return 0 when the user is in music-foreground mode. |
Syntax
- PLAY (n)
Description/Parameter(s)
n | A dummy argument that may be any numeric value. It is not used by the PLAY function. |
The PLAY function is not available for OS/2 protected mode. |
Example
This example uses the PLAY statements and the PLAY and VARPTR$ functions to play continuous music by calling an event-handling subroutine when the background music buffer goes from three to two notes.
CLS
'Call subroutine Replay when the music buffer goes from 3 to 2 notes.
ON PLAY(3) GOSUB Replay
'Turn on event trapping for PLAY.
PLAY ON
'Define a string containing the melody.
FElise$ = "o3 L8 E D+ E D+ E o2 B o3 D C L2 o2 A"
PLAY "MB X" + VARPTR$(FElise$)
'Suspend event trapping until next PLAY ON but remember events that occur
'while event trapping is disabled.
PLAY STOP
'Introduce a variable-length delay.
LOCATE 23, 1: PRINT "Press any key to continue."
DO
LOOP WHILE INKEY$ = ""
'Re-enable play event trapping remembering that a PLAY event has occurred.
PLAY ON
LOCATE 23, 1: PRINT "Press any key to stop. "
'Loop until a key is pressed.
DO
GOSUB BackGround
LOOP WHILE INKEY$ = ""
'Disable PLAY event processing.
PLAY OFF
'Count down to 0 notes in the queue.
DO
GOSUB BackGround
LOOP UNTIL NoteCount = 0
END
'PLAY event-handling subroutine.
Replay:
'Increment and print a counter each time.
Count% = Count% + 1
LOCATE 3, 1: PRINT "Replay routine called"; Count%; "time(s)";
'PLAY it again to fill the buffer.
PLAY "MB X" + VARPTR$(FElise$)
RETURN
'Background music queue reporting subroutine.
BackGround:
'Get a notecount.
NoteCount = PLAY(0)
LOCATE 1, 1
PRINT "Background queue notes remaining --> "; NoteCount
'Loop until Notecount changes or equals 0.
DO
LOOP UNTIL NoteCount <> PLAY(0) OR NoteCount = 0
RETURN