Difference between revisions of "PLAY"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 28: Line 28:
  
  
''Example:'' PLAY "'''c3''' l16 '''a+''' '''b-''' cdl8efl4gl16 '''p32''' deggdel4gp1614c-p16l8cecdel4dl10c"
+
''Example:'' Plays "Frosty the snowman".
  
 
+
{{CodeStart}} '' ''
 
+
CLS : PRINT "Frosty the Snow Man"
''Explanation:'' (explained parts are shown in bold and separated from the rest)
+
{{Cl|FOR...NEXT|FOR}} X = 1 {{Cl|TO}} 2
 
+
  PRINT
 
+
  IF X = 1 THEN PRINT "Fros-ty the Snow man was a jolly happy soul,"
"c3" means the same as "l3 c", setting the length to one third of a whole note.
+
  IF X = 2 THEN PRINT "Fros-ty the Snow man knew the sun was hot that day"
 
+
  {{Cl|PLAY}} "mb t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
a+ means A sharp (or a# which you can also use).
+
  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."
b- means B flat.
+
  {{Cl|PLAY}} "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2."
 
+
  IF X = 1 THEN PRINT "Fros-ty the Snow Man is a fair-y tale, they say,"
p32 means to pause 32 quarternotes.
+
  IF X = 2 THEN PRINT "Down to the vil-lage, with a broom-stick in his hand,"
 
+
  {{Cl|PLAY}} "g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
You can use spaces in the string for clarity without affecting anything.
+
  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."
 +
  {{Cl|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."
 +
  {{Cl|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!"
 +
  {{Cl|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"
 +
  {{Cl|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."
 +
  {{Cl|PLAY}} "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4"
 +
NEXT X
 +
PRINT : PRINT "Thump-et-y thump thump, thump-et-y thump thump, look at Fros-ty go."
 +
{{Cl|PLAY}} "t180g8g8g4g4g4a8g8g4g4g4a4g4e4g4d1"
 +
PRINT "Thump-et-y thump thump, thump-et-y thump thump, ov-er the hills of snow."
 +
{{Cl|PLAY}} "t180g8g8g4g4g4a8g8g4g4g4g8g8g4a4b4o3c2c4p1" '' ''
 +
{{CodeEnd}}
  
  

Revision as of 22:16, 4 November 2010

PLAY is a statement that plays music using a command STRING.


Syntax: PLAY commandstring


The commandstring can consist of the following commands:
  • On - Sets the current octave (n can be between 0 to 6), example "O3"
  • Nn - Plays the note n (n can be between 0 to 84, where 0 is a rest), example "N42"
  • < - Down one octave (cannot get below zero).
  • > - Up one octave (cannot get above 6).
  • 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#"
  • 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"
  • Tn - 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)
  • Pn - 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.



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" 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"


See also:'



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