Difference between revisions of "PLAY"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 2: Line 2:
  
  
:::::::''Syntax:'' PLAY commandstring
+
:::::::''Syntax:'' PLAY ''commandstring$''
  
  
  
:::'''The commandstring can consist of the following commands:'''
+
* The ''commandstring'' can be any literal or variable [[STRING]] consisting of the following uppercase or lowercase commands:
*'''O'''n - Sets the current octave (n can be between 0 to 6), example "O3"
+
:*'''O'''n - Sets the current octave (from 0 to 6). Example "O3"
*'''N'''n - Plays the note n (n can be between 0 to 84, where 0 is a rest), example "N42"
+
:*'''<''' - Down one octave (cannot be below zero).
*'''<''' - Down one octave (cannot get below zero).
+
:*'''>''' - Up one octave (cannot be above 6).
*'''>''' - Up one octave (cannot get above 6).
+
:*'''A''', '''B''', '''C''', '''D''', '''E''', '''F''' or '''G''' are the notes in the current octave. Can use the following suffixes:
*'''A''', '''B''', '''C''', '''D''', '''E''', '''F''' or '''G''' - Play A-G in the current octave, you can use '''+''' or '''#''' for sharp and '''-''' for flat, example "C#"
+
::*'''+''' or '''#''' for sharp. Example: "C#"
 +
::*'''-''' for flat  
 +
:*'''N'''n - Plays the note n (n can be between 0 to 84 in the 7 octaves, where 0 is a rest), example "N42".
 +
:*'''L'''n - 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)
 +
::*'''P'''n - Pause in the duration of n quarternotes (n can be 1 to 64) corresponding to L, example "P32"
 +
::*'''T'''n - Tempo sets number 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 the other can start).
 +
:*'''MB''' - Play music in the background (the background buffer can only hold 32 notes in QuickBASIC, QB64 has no limits).
  
*'''L'''n - 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"
+
:*'''X''' '''+''' [[VARPTR$]](string-expression) - execute another command string.
*'''T'''n - Sets quarter of notes per minute (n can be 32 to 255 where 120 is the default), example "T180"
 
*'''MS''' - Each note plays 3/4 of length (staccato)
 
*'''MN''' - Each note plays full length (normal)
 
*'''ML''' - Each note plays 7/8 of length (legato)
 
*'''P'''n - Pause in the duration of n quarternotes (n can be 1 to 64), example "P32"
 
 
 
*'''MF''' - Play music in the foreground (each note must be completed before the other can start).
 
*'''MB''' - Play music in the background (the background buffer can only hold 32 notes in QuickBASIC, QB64 have no limits)
 
 
 
*'''X''' '''+''' [[VARPTR$]](string-expression) - execute another command string.
 
 
*'''NOTE: PLAY does NOT delay program progress in QB64! Use [[_DELAY]] and [[END]] to allow music completion.'''
 
*'''NOTE: PLAY does NOT delay program progress in QB64! Use [[_DELAY]] and [[END]] to allow music completion.'''
  

Revision as of 03:09, 5 November 2010

PLAY is a statement that plays music 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 sharp. Example: "C#"
  • - for flat
  • Nn - Plays the note n (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 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 the other 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) - execute another command string.
  • NOTE: PLAY does NOT delay program progress in QB64! Use _DELAY and END to allow music completion.


Example: Plays "Frosty the snowman".

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


See also:'



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page