Difference between revisions of "PLAY"
|Line 73:||Line 73:|
* [[PLAY(n)]], [[ON PLAY (n)]]
* [[PLAY(n)]], [[ON PLAY(n)]]
* [[SOUND]], [[DRAW]]
* [[SOUND]], [[DRAW]]
Revision as of 02:48, 6 November 2010
PLAY is a statement that plays music through the sound card in QB64 using a command STRING.
- Syntax: PLAY commandstring$
- The commandstring can be any literal or variable STRING consisting of the following uppercase or lowercase commands:
- On - Sets the current octave (from 0 to 6). Example "O3"
- < - Down one octave (cannot be below zero).
- > - Up one octave (cannot be above 6).
- A, B, C, D, E, F or G are the notes in the current octave. Can use the following suffixes:
- + or # for a sharp note. Example: "C#"
- - for a flat note. Example: "C-"
- Nn - Plays a note n by number(n can be between 0 to 84 in the 7 octaves, where 0 is a rest). Example: "N42".
- Ln - Sets length of a note (n can be 1 to 64 where 1 is a whole note and 4 is a quarter of a note etc.). Example: "L4"
- MS - Each note plays 3/4 of length set by L (staccato)
- MN - Each note plays 7/8 of length set by L (normal)
- ML - Each note plays full length set by L (legato)
- Pn - Pause in the duration of n quarternotes (n can be 1 to 64) corresponding to L, example "P32"
- Tn - Tempo sets number of L4 quarter notes per minute (n can be 32 to 255 where 120 is the default). Example: "T180"
- . - period after a note plays 1½ times the note length determined by L * T.
- .. - two periods plays 1-3/4 times the note length determined by L * T.
- MF - Play music in the foreground (each note must be completed before another can start).
- MB - Play music in the background (the background buffer can only hold 32 notes in QuickBASIC, QB64 has no limits).
- X + VARPTR$(string-expression) - executes a command string variable. MUST be used with variables!.
Example: Plays "Frosty the snowman". Printing is not delayed in QB64.
CLS : PRINT "Frosty the Snow Man" FOR X = 1 TO 2 PRINT IF X = 1 THEN PRINT "Fros-ty the Snow man was a jolly happy soul," IF X = 2 THEN PRINT "Fros-ty the Snow man knew the sun was hot that day" PLAY "mb t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2." IF X = 1 THEN PRINT "with a corn cob pipe and a button nose and two eyes made out of coal." IF X = 2 THEN PRINT "so he said Let's run and we'll have some fun now before I melt away." PLAY "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2." IF X = 1 THEN PRINT "Fros-ty the Snow Man is a fair-y tale, they say," IF X = 2 THEN PRINT "Down to the vil-lage, with a broom-stick in his hand," PLAY "g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2." IF X = 1 THEN PRINT "He was made of snow but the chil-dren knew how he come to life one day." IF X = 2 THEN PRINT "run-ning here and there all a-round the square, say-in' catch me if you can." PLAY "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2." IF X = 1 THEN PRINT "There must have been some magic in that old silk hat they found." IF X = 2 THEN PRINT "He led them down the streets of town right to the traffic cop." PLAY "c4a4a4o3c4c4o2b4a4g4e4f4a4g4f4e2." IF X = 1 THEN PRINT "For when they placed it on his head he be-gan to dance a round." IF X = 2 THEN PRINT "And he on-ly paused a moment when he heard him hol-ler Stop!" PLAY "e8e8d4d4g4g4b4b4o3d4d8o2b8o3d4c4o2b4a4g4p4" IF X = 1 THEN PRINT "Oh, Fros-ty the Snow Man was a-live as he could be," IF X = 2 THEN PRINT "For, Fros-ty the Snow Man had to hur-ry on his way" PLAY "g2g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g8g2." IF X = 1 THEN PRINT "and the chil-dren say he could laugh and play just the same as you and me." IF X = 2 THEN PRINT "but he waved good-bye say-in' Don't you cry, I'll be back a-gain some day." PLAY "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4" _DELAY 55 'PLAY in QB64 does not delay program NEXT X PRINT : PRINT "Thump-et-y thump thump, thump-et-y thump thump, look at Fros-ty go." PLAY "t180g8g8g4g4g4a8g8g4g4g4a4g4e4g4d1" PRINT "Thump-et-y thump thump, thump-et-y thump thump, ov-er the hills of snow." PLAY "t180g8g8g4g4g4a8g8g4g4g4g8g8g4a4b4o3c2c4p1" END