Qbasic Tutorial for beginners and children (Under Construction)


Playing Music & Sounds

  • The PLAY statement
  • The SOUND statement
The PLAY statement is used to play music. The command is used as follows:

PLAY CommandString

The commandstring expression contains the note or list of notes that will be played by the PLAY statement.

Octave and tone commands:
Ooctave Sets the current octave (0 - 6).
< or > Moves up or down one octave.
A - G Plays the specified note in the current octave.
Nnote Plays a specified note (0 - 84) in the seven-octave
range (0 is a rest).

Duration and tempo commands:
Llength Sets the length of each note (1 - 64). L1 is whole note,
L2 is a half note, etc.
ML Sets music legato.
MN Sets music normal.
MS Sets music staccato.
Ppause Specifies a pause (1 - 64). P1 is a whole-note pause,
P2 is a half-note pause, etc.
Ttempo Sets the tempo in quarter notes per minute (32 - 255).

Mode commands:
MF Plays music in foreground.
MB Plays music in background.

 

Example:

PLAY "CDEFG"

PLAY

 

The code below plays the Seven octaves.

PLAY "L8"
FOR X = 0 TO 6
     PLAY "O" + STR$(X)
     PLAY "c d e f g a b"
NEXT

Each time the FOR NEXT statement makes a revolution, variable X is incremented by 1. It thus moves from 0 to 6. The computer statement 

PLAY "O" + STR$(x)

sets BASIC to play one octave higher.

 

PLAY "l16"
FOR x = 0 TO 84
PLAY "N" + STR$(x)

NEXT
FOR x = 84 TO 0 STEP -1
PLAY "N" + STR$(x)

NEXT


pages viewed since January  19 2002