PLAY: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 3: Line 3:


{{PageSyntax}}
{{PageSyntax}}
::: '''PLAY ''commandstring$'''''
: [[PLAY]] {{Parameter|commandstring$}}




{{PageParameters}}
{{PageParameters}}
* The ''commandstring'' can be any literal or variable [[STRING]] consisting of the following uppercase or lowercase commands:
* The {{Parameter|commandstring$}} can be any literal or variable [[STRING]] consisting of the following commands:
** Command string values are not case sensitive and spacing is ignored. Use upper or lower case as desired.
:*'''O'''n - Sets the current octave (from 0 to 6). Example: '''{{Text|PLAY "O3"|green}}'''
:*'''O'''n - Sets the current octave (from 0 to 6). Example: '''{{Text|PLAY "O3"|green}}'''
:*'''<''' - Down one octave (cannot be below zero). Example: '''{{Text|PLAY "<<"|green}}''' 'goes down two octaves.
:*'''<''' - Down one octave (cannot be below zero). Example: '''{{Text|PLAY "<<"|green}}''' 'goes down two octaves.
Line 19: Line 20:
::*'''MN''' - Each note plays 7/8 of length set by L (normal)
::*'''MN''' - Each note plays 7/8 of length set by L (normal)
::*'''ML''' - Each note plays full length set by L (legato)
::*'''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: '''{{Text|PLAY "P32"|green}}'''
::*'''P'''n - Specifies a pause (1 - 64). P1 is a whole-note pause, P2 is a half-note pause, etc.  (The pause is 1/n notes in length.) Example: '''{{Text|PLAY "P32"|green}}'''
::*'''T'''n - Tempo sets number of L4 quarter notes per minute (n can be 32 to 255 where 120 is the default). Example: '''{{Text|PLAY "T180"|green}}'''
::*'''T'''n - Tempo sets number of L4 quarter notes per minute (n can be 32 to 255 where 120 is the default). Example: '''{{Text|PLAY "T180"|green}}'''
:::*''' .  '''  - period after a note plays 1½ times the note length determined by L * T.
:::*''' .  '''  - 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.
:::*'''.. '''  - two periods plays 1-3/4 times the note length determined by L * T.
:*''',  '''  - '''commas in QB64''' stop play advancement to allow more than one note to be played simultaneously. Example: '''{{Text|PLAY "C,E,G,"|green}}'''
:*''',  '''  - '''commas in QB64''' stop play advancement to allow more than one note to be played simultaneously. Example: '''{{Text|PLAY "C,E,G,"|green}}'''
:*'''V'''n - Volume in '''QB64 only''' can be any volume from 0(none) to 100(full).  The default level is 50 when '''n''' is not specified.
:*'''V'''n - Volume in '''QB64 only''' can be any volume from 0 (none) to 100 (full).  The default level is 50 when '''n''' is not specified.
:*'''MF''' - Play music in the foreground (each note must be completed before another can start).
:*'''MF''' - Play music in the foreground (each note must be completed before another can start).
:*'''MB''' - Play music in the background while program code execution continues (QB64 has no note buffer limits).
:*'''MB''' - Play music in the background while program code execution continues (QB64 has no note buffer limits).
:*'''X''' '''+''' [[VARPTR$]](string-expression) - executes a command string variable. '''MUST be used with variables!'''.
:*'''X''' '''+''' [[VARPTR$]](string-expression) - executes a command string variable. '''MUST be used with variables!'''.
:*'''@'''n - Select waveform in '''QB64-PE only''' can be ('''1''' for square waveform, '''2''' for sawtooth waveform, '''3''' for triangle waveform (default), '''4''' for sine waveform, '''5''' for white noise or '''10''' for a waveform defined by the [[_WAVE]] statement (since QB64-PE v4.0.0)).
:*'''Q'''n - Volume ramp in '''QB64-PE only''' can be any duration (ms) from 0 to 100.
:*Numeric values "n" listed above can also be fetched from numeric variables using '''"="''' + [[VARPTR$]](numeric_variable).




''Usage:''
{{PageAvailability}}
* MB will allow music to play while program code progresses. MF will wait for code to continue playing notes.
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
* Command string values are not case sensitive and spacing is ignored. Use upper or lower case as desired.
<gallery widths="48px" heights="48px" mode="nolines">
*'''NOTE: In QB64, PLAY may NOT delay program progress! Use [[_DELAY]] and [[END]] to allow music completion.'''
File:Qb64.png|'''v0.610'''
File:Qbpe.png|'''all'''
File:Apix.png
File:Win.png|'''yes'''
File:Lnx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
<!-- additional availability notes go below here -->
* Complete '''X''' '''+''' [[VARPTR$]](string-expression) support was added in '''QB64-PE v3.8.0'''. Earlier versions of QB64-PE and QB64 only had '''=''' + [[VARPTR$]](numeric_variable) support.
* Support for '''@'''n and '''Q'''n was added in '''QB64-PE v3.8.0'''.
* Support for user-defined [[_WAVE]] waveforms (ID#:10) was added in '''QB64-PE v4.0.0'''.




''Example 1:'' Plays a sound with the volume and note varying from 0 to 50. Maximum note can only be 84.
{{PageExamples}}
;Example 1:Plays a sound with the volume and note varying from 0 to 50. Maximum note can only be 84.
{{CodeStart}}
{{CodeStart}}
{{Cl|PLAY}} "mll64"
{{Cl|PLAY}} {{Text|<nowiki>"q0mll64"</nowiki>|#FFB100}}
{{Cl|DO}}
{{Cl|DO}}
     {{Cl|FOR...NEXT|FOR}} x = 1 {{Cl|TO}} 50
     {{Cl|FOR}} x = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|50|#F580B1}}
         a$ = a$ + "v" + {{Cl|LTRIM$}}({{Cl|STR$}}(x)) + "n" + {{Cl|LTRIM$}}({{Cl|STR$}}(x))
         a$ = a$ + {{Text|<nowiki>"v"</nowiki>|#FFB100}} + {{Cl|LTRIM$}}({{Cl|STR$}}(x)) + {{Text|<nowiki>"n"</nowiki>|#FFB100}} + {{Cl|LTRIM$}}({{Cl|STR$}}(x))
     {{Cl|NEXT}}
     {{Cl|NEXT}}
     {{Cl|FOR...NEXT|FOR}} x = 50 {{Cl|TO}} 1 {{Cl|STEP}} -1
     {{Cl|FOR}} x = {{Text|50|#F580B1}} {{Cl|TO}} {{Text|1|#F580B1}} {{Cl|STEP}} {{Text|-1|#F580B1}}
         a$ = a$ + "v" + {{Cl|LTRIM$}}({{Cl|STR$}}(x)) + "n" + {{Cl|LTRIM$}}({{Cl|STR$}}(x))
         a$ = a$ + {{Text|<nowiki>"v"</nowiki>|#FFB100}} + {{Cl|LTRIM$}}({{Cl|STR$}}(x)) + {{Text|<nowiki>"n"</nowiki>|#FFB100}} + {{Cl|LTRIM$}}({{Cl|STR$}}(x))
     {{Cl|NEXT}}
     {{Cl|NEXT}}
     {{Cl|PLAY}} a$
     {{Cl|PLAY}} a$
     a$ = ""
     a$ = {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} <> ""
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} <> {{Text|<nowiki>""</nowiki>|#FFB100}}
{{Cl|PLAY}} "v10l1c,l4egl2o5c,o4l4eg"
{{Cl|PLAY}} {{Text|<nowiki>"v10l1c,l4egl2o5c,o4l4eg"</nowiki>|#FFB100}}
{{CodeEnd}}
{{CodeEnd}}
{{Small|Code by Galleon}}
{{Small|Code by Galleon}}


----


''Example 2:'' Plays "Frosty the snowman". The lyric printing is not delayed by PLAY in QB64.
;Example 2:Plays "Frosty the snowman". The lyric printing is not delayed by PLAY in QB64.
{{CodeStart}}
{{CodeStart}}
CLS : PRINT "Frosty the Snow Man"
{{Cl|CLS}}: {{Cl|PRINT}} {{Text|<nowiki>"Frosty the Snow Man"</nowiki>|#FFB100}}
{{Cl|FOR...NEXT|FOR}} X = 1 {{Cl|TO}} 2
{{Cl|FOR}} X = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|2|#F580B1}}
  PRINT
    {{Cl|PRINT}}
  IF X = 1 THEN PRINT "Fros-ty the Snow man was a jolly happy soul,"
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Fros-ty the Snow man was a jolly happy soul,"</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "Fros-ty the Snow man knew the sun was hot that day"
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Fros-ty the Snow man knew the sun was hot that day"</nowiki>|#FFB100}}
  {{Cl|PLAY}} "t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."   'MB removed to print song one line at a time
    {{Cl|PLAY}} {{Text|<nowiki>"t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."</nowiki>|#FFB100}} {{Text|<nowiki>'MB removed to print song one line at a time</nowiki>|#919191}}
  IF X = 1 THEN PRINT "with a corn cob pipe and a button nose and two eyes made out of coal."
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"with a corn cob pipe and a button nose and two eyes made out of coal."</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "so he said Let's run and we'll have some fun now before I melt away."
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"so he said Let's run and we'll have some fun now before I melt away."</nowiki>|#FFB100}}
  {{Cl|PLAY}} "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2."
    {{Cl|PLAY}} {{Text|<nowiki>"o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2."</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "Fros-ty the Snow Man is a fair-y tale, they say,"
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Fros-ty the Snow Man is a fair-y tale, they say,"</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "Down to the vil-lage, with a broom-stick in his hand,"
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Down to the vil-lage, with a broom-stick in his hand,"</nowiki>|#FFB100}}
  {{Cl|PLAY}} "g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
    {{Cl|PLAY}} {{Text|<nowiki>"g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "He was made of snow but the chil-dren knew how he come to life one day."
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"He was made of snow but the chil-dren knew how he come to life one day."</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "run-ning here and there all a-round the square, say-in' catch me if you can."
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"run-ning here and there all a-round the square, say-in' catch me if you can."</nowiki>|#FFB100}}
  {{Cl|PLAY}} "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2."
    {{Cl|PLAY}} {{Text|<nowiki>"o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2."</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "There must have been some magic in that old silk hat they found."
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"There must have been some magic in that old silk hat they found."</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "He led them down the streets of town right to the traffic cop."
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"He led them down the streets of town right to the traffic cop."</nowiki>|#FFB100}}
  {{Cl|PLAY}} "c4a4a4o3c4c4o2b4a4g4e4f4a4g4f4e2."
    {{Cl|PLAY}} {{Text|<nowiki>"c4a4a4o3c4c4o2b4a4g4e4f4a4g4f4e2."</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "For when they placed it on his head he be-gan to dance a round."
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"For when they placed it on his head he be-gan to dance a round."</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "And he on-ly paused a moment when he heard him hol-ler Stop!"
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"And he on-ly paused a moment when he heard him hol-ler Stop!"</nowiki>|#FFB100}}
  {{Cl|PLAY}} "e8e8d4d4g4g4b4b4o3d4d8o2b8o3d4c4o2b4a4g4p4"
    {{Cl|PLAY}} {{Text|<nowiki>"e8e8d4d4g4g4b4b4o3d4d8o2b8o3d4c4o2b4a4g4p4"</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "Oh, Fros-ty the Snow Man was a-live as he could be,"
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Oh, Fros-ty the Snow Man was a-live as he could be,"</nowiki>|#FFB100}}
  IF X = 2 THEN PRINT "For, Fros-ty the Snow Man had to hur-ry on his way"
    {{Cl|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"For, Fros-ty the Snow Man had to hur-ry on his way"</nowiki>|#FFB100}}
  {{Cl|PLAY}} "g2g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g8g2."
    {{Cl|PLAY}} {{Text|<nowiki>"g2g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g8g2."</nowiki>|#FFB100}}
  IF X = 1 THEN PRINT "and the chil-dren say he could laugh and play just the same as you and me."
    {{Cl|IF}} X = {{Text|1|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"and the chil-dren say he could laugh and play just the same as you and me."</nowiki>|#FFB100}}
  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|IF}} X = {{Text|2|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"but he waved good-bye say-in' Don't you cry, I'll be back a-gain some day."</nowiki>|#FFB100}}
  {{Cl|PLAY}} "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4"
    {{Cl|PLAY}} {{Text|<nowiki>"o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4"</nowiki>|#FFB100}}
NEXT X
{{Cl|NEXT}} X
PRINT : PRINT "Thump-et-y thump thump, thump-et-y thump thump, look at Fros-ty go."
{{Cl|PRINT}}: {{Cl|PRINT}} {{Text|<nowiki>"Thump-et-y thump thump, thump-et-y thump thump, look at Fros-ty go."</nowiki>|#FFB100}}
{{Cl|PLAY}} "t180g8g8g4g4g4a8g8g4g4g4a4g4e4g4d1"
{{Cl|PLAY}} {{Text|<nowiki>"t180g8g8g4g4g4a8g8g4g4g4a4g4e4g4d1"</nowiki>|#FFB100}}
PRINT "Thump-et-y thump thump, thump-et-y thump thump, ov-er the hills of snow."
{{Cl|PRINT}} {{Text|<nowiki>"Thump-et-y thump thump, thump-et-y thump thump, ov-er the hills of snow."</nowiki>|#FFB100}}
{{Cl|PLAY}} "t180g8g8g4g4g4a8g8g4g4g4g8g8g4a4b4o3c2c4p1"
{{Cl|PLAY}} {{Text|<nowiki>"t180g8g8g4g4g4a8g8g4g4g4g8g8g4a4b4o3c2c4p1"</nowiki>|#FFB100}}
{{Cl|END}}
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{Small|Greg Rismoen 12/09/84}}
{{Small|Code by Greg Rismoen}}


----


''Example 3:'' Clicking on the grid enables various notes to be played simultaneously.
;Example 3: Clicking on the grid enables various notes to be played simultaneously.
{{CodeStart}}
{{CodeStart}}
{{Cl|DIM}} {{Cl|SHARED}} grid(16, 16), grid2(16, 16), cur
{{Cl|DIM}} {{Cl|SHARED}} grid({{Text|16|#F580B1}}, {{Text|16|#F580B1}}), grid2({{Text|16|#F580B1}}, {{Text|16|#F580B1}}), cur
{{Cl|CONST}} maxx = 512
{{Cl|CONST}} maxx = {{Text|512|#F580B1}}
{{Cl|CONST}} maxy = 512
{{Cl|CONST}} maxy = {{Text|512|#F580B1}}
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(maxx, maxy, 32)
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(maxx, maxy, {{Text|32|#F580B1}})
{{Cl|_TITLE}} "MusicGrid"
{{Cl|_TITLE}} {{Text|<nowiki>"MusicGrid"</nowiki>|#FFB100}}
cleargrid
{{Text|cleargrid|#55FF55}}
{{Cl|DO}}
{{Cl|DO}}
     {{Cl|IF}} {{Cl|TIMER (function)|TIMER}} - t# > 1 / 8 {{Cl|THEN}} cur = (cur + 1) {{Cl|AND (boolean)|AND}} 15: t# = {{Cl|TIMER (function)|TIMER}}
     {{Cl|IF}} {{Cl|TIMER (function)|TIMER}} - t# > {{Text|1|#F580B1}} / {{Text|8|#F580B1}} {{Cl|THEN}} cur = (cur + {{Text|1|#F580B1}}) {{Cl|AND}} {{Text|15|#F580B1}}: t# = {{Cl|TIMER (function)|TIMER}}
     {{Cl|IF}} cur <> oldcur {{Cl|THEN}}
     {{Cl|IF}} cur <> oldcur {{Cl|THEN}}
         figuregrid
         {{Text|figuregrid|#55FF55}}
         drawgrid
         {{Text|drawgrid|#55FF55}}
         playgrid
         {{Text|playgrid|#55FF55}}
         oldcur = cur
         oldcur = cur
     {{Cl|END IF}}
     {{Cl|END IF}}
     domousestuff
     {{Text|domousestuff|#55FF55}}
     in$ = {{Cl|INKEY$}}
     in$ = {{Cl|INKEY$}}
     {{Cl|IF}} in$ = "C" {{Cl|OR (boolean)|OR}} in$ = "c" {{Cl|THEN}} cleargrid
     {{Cl|IF}} in$ = {{Text|<nowiki>"C"</nowiki>|#FFB100}} {{Cl|OR (boolean)|OR}} in$ = {{Text|<nowiki>"c"</nowiki>|#FFB100}} {{Cl|THEN}} {{Text|cleargrid|#55FF55}}
{{Cl|LOOP}} {{Cl|UNTIL}} in$ = {{Cl|CHR$}}(27)
{{Cl|DO...LOOP|LOOP UNTIL}} in$ = {{Cl|CHR$}}({{Text|27|#F580B1}})


{{Cl|SUB}} drawgrid
{{Cl|SUB}} {{Text|drawgrid|#55FF55}}
scale! = maxx / 16
    scale! = maxx / {{Text|16|#F580B1}}
scale2 = maxx \ 16 - 2
    scale2 = maxx \ {{Text|16|#F580B1}} - {{Text|2|#F580B1}}
{{Cl|FOR...NEXT|FOR}} y = 0 {{Cl|TO}} 15
    {{Cl|FOR}} y = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
    y1 = y * scale!
        y1 = y * scale!
    {{Cl|FOR...NEXT|FOR}} x = 0 {{Cl|TO}} 15
        {{Cl|FOR}} x = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
        x1 = x * scale!
            x1 = x * scale!
        c& = {{Cl|_RGB32}}(grid2(x, y) * 64 + 64, 0, 0)
            c& = {{Cl|_RGB32}}(grid2(x, y) * {{Text|64|#F580B1}} + {{Text|64|#F580B1}}, {{Text|0|#F580B1}}, {{Text|0|#F580B1}})
        {{Cl|LINE}} (x1, y1)-(x1 + scale2, y1 + scale2), c&, BF
            {{Cl|LINE}} (x1, y1)-(x1 + scale2, y1 + scale2), c&, BF
    {{Cl|NEXT}} x
        {{Cl|NEXT}} x
{{Cl|NEXT}} y
    {{Cl|NEXT}} y
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} figuregrid
{{Cl|SUB}} {{Text|figuregrid|#55FF55}}
{{Cl|FOR...NEXT|FOR}} y = 0 {{Cl|TO}} 15
    {{Cl|FOR}} y = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
    {{Cl|FOR...NEXT|FOR}} x = 0 {{Cl|TO}} 15
        {{Cl|FOR}} x = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
        grid2(x, y) = grid(x, y)
            grid2(x, y) = grid(x, y)
    {{Cl|NEXT}} x
        {{Cl|NEXT}} x
{{Cl|NEXT}} y
    {{Cl|NEXT}} y
{{Cl|FOR...NEXT|FOR}} y = 1 {{Cl|TO}} 14
    {{Cl|FOR}} y = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|14|#F580B1}}
    {{Cl|FOR...NEXT|FOR}} x = 1 {{Cl|TO}} 14
        {{Cl|FOR}} x = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|14|#F580B1}}
        {{Cl|IF}} grid(x, y) = 1 {{Cl|AND (boolean)|AND}} cur = x {{Cl|THEN}}
            {{Cl|IF}} grid(x, y) = {{Text|1|#F580B1}} {{Cl|AND (boolean)|AND}} cur = x {{Cl|THEN}}
            grid2(x, y) = 2
                grid2(x, y) = {{Text|2|#F580B1}}
            {{Cl|IF}} grid(x - 1, y) = 0 {{Cl|THEN}} grid2(x - 1, y) = 1
                {{Cl|IF}} grid(x - {{Text|1|#F580B1}}, y) = {{Text|0|#F580B1}} {{Cl|THEN}} grid2(x - {{Text|1|#F580B1}}, y) = {{Text|1|#F580B1}}
            {{Cl|IF}} grid(x + 1, y) = 0 {{Cl|THEN}} grid2(x + 1, y) = 1
                {{Cl|IF}} grid(x + {{Text|1|#F580B1}}, y) = {{Text|0|#F580B1}} {{Cl|THEN}} grid2(x + {{Text|1|#F580B1}}, y) = {{Text|1|#F580B1}}
            {{Cl|IF}} grid(x, y - 1) = 0 {{Cl|THEN}} grid2(x, y - 1) = 1
                {{Cl|IF}} grid(x, y - {{Text|1|#F580B1}}) = {{Text|0|#F580B1}} {{Cl|THEN}} grid2(x, y - {{Text|1|#F580B1}}) = {{Text|1|#F580B1}}
            {{Cl|IF}} grid(x, y + 1) = 0 {{Cl|THEN}} grid2(x, y + 1) = 1
                {{Cl|IF}} grid(x, y + {{Text|1|#F580B1}}) = {{Text|0|#F580B1}} {{Cl|THEN}} grid2(x, y + {{Text|1|#F580B1}}) = {{Text|1|#F580B1}}
        {{Cl|END IF}}
            {{Cl|END IF}}
    {{Cl|NEXT}} x
        {{Cl|NEXT}} x
{{Cl|NEXT}} y
    {{Cl|NEXT}} y
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} domousestuff
{{Cl|SUB}} {{Text|domousestuff|#55FF55}}
{{Cl|DO}} {{Cl|WHILE}} {{Cl|_MOUSEINPUT}}
    {{Cl|DO...LOOP|DO WHILE}} {{Cl|_MOUSEINPUT}}
    {{Cl|IF}} {{Cl|_MOUSEBUTTON}}(1) {{Cl|THEN}}
        {{Cl|IF}} {{Cl|_MOUSEBUTTON}}({{Text|1|#F580B1}}) {{Cl|THEN}}
        x = {{Cl|_MOUSEX}} \ (maxx \ 16)
            x = {{Cl|_MOUSEX}} \ (maxx \ {{Text|16|#F580B1}})
        y = {{Cl|_MOUSEY}} \ (maxy \ 16)
            y = {{Cl|_MOUSEY}} \ (maxy \ {{Text|16|#F580B1}})
        grid(x, y) = 1 - grid(x, y)
            grid(x, y) = {{Text|1|#F580B1}} - grid(x, y)
    {{Cl|END IF}}
        {{Cl|END IF}}
{{Cl|LOOP}}
    {{Cl|LOOP}}
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} playgrid
{{Cl|SUB}} {{Text|playgrid|#55FF55}}
n$ = "L16 "
    n$ = {{Text|<nowiki>"L16 "</nowiki>|#FFB100}}
'scale$ = "O1CO1DO1EO1FO1GO1AO1BO2CO2DO2EO2FO2GO2AO2BO3CO3D"
    {{Text|<nowiki>'scale$ = "O1CO1DO1EO1FO1GO1AO1BO2CO2DO2EO2FO2GO2AO2BO3CO3D"</nowiki>|#919191}}
scale$ = "o1fo1go1ao2co2do2fo2go2ao3co3do3fo3go3ao4co4do4fo"
    scale$ = {{Text|<nowiki>"o1fo1go1ao2co2do2fo2go2ao3co3do3fo3go3ao4co4do4fo"</nowiki>|#FFB100}}
{{Cl|FOR...NEXT|FOR}} y = 15 {{Cl|TO}} 0 {{Cl|STEP}} -1
    {{Cl|FOR}} y = {{Text|15|#F580B1}} {{Cl|TO}} {{Text|0|#F580B1}} {{Cl|STEP}} {{Text|-1|#F580B1}}
    {{Cl|IF}} grid(cur, y) = 1 {{Cl|THEN}}
        {{Cl|IF}} grid(cur, y) = {{Text|1|#F580B1}} {{Cl|THEN}}
        note$ = {{Cl|MID$}}(scale$, 1 + (15 - y) * 3, 3)
            note$ = {{Cl|MID$ (function)|MID$}}(scale$, {{Text|1|#F580B1}} + ({{Text|15|#F580B1}} - y) * {{Text|3|#F580B1}}, {{Text|3|#F580B1}})
        n$ = n$ + note$ + ","   'comma plays 2 or more column notes simultaneously
            n$ = n$ + note$ + {{Text|<nowiki>","</nowiki>|#FFB100}} {{Text|<nowiki>'comma plays 2 or more column notes simultaneously</nowiki>|#919191}}
    {{Cl|END IF}}
        {{Cl|END IF}}
{{Cl|NEXT}} y
    {{Cl|NEXT}} y
n$ = {{Cl|LEFT$}}(n$, {{Cl|LEN}}(n$) - 1)
    n$ = {{Cl|LEFT$}}(n$, {{Cl|LEN}}(n$) - {{Text|1|#F580B1}})
{{Cl|PLAY}} n$
    {{Cl|PLAY}} n$
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} cleargrid
{{Cl|SUB}} {{Text|cleargrid|#55FF55}}
{{Cl|FOR...NEXT|FOR}} y = 0 {{Cl|TO}} 15
    {{Cl|FOR}} y = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
    {{Cl|FOR...NEXT|FOR}} x = 0 {{Cl|TO}} 15
        {{Cl|FOR}} x = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}}
        grid(x, y) = 0
            grid(x, y) = {{Text|0|#F580B1}}
    {{Cl|NEXT}} x
        {{Cl|NEXT}} x
{{Cl|NEXT}} y
    {{Cl|NEXT}} y
{{Cl|END SUB}}
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}
{{Small|Code by JP}}
{{Small|Code by JP}}


----


''Example 4:'' Play strings starting with MB allow program code to run while music plays in background.
;Example 4:Play strings starting with MB allow program code to run while music plays in background.
{{CodeStart}}
{{CodeStart}}
' 2012, 2013 mennonite
{{Text|<nowiki>' 2012, 2013 mennonite</nowiki>|#919191}}
' license: creative commons cc0 1.0 universal
{{Text|<nowiki>' license: creative commons cc0 1.0 universal</nowiki>|#919191}}
' (public domain) http://creativecommons.org/publicdomain/zero/1.0/
{{Text|<nowiki>' (public domain) http://creativecommons.org/publicdomain/zero/1.0/</nowiki>|#919191}}


{{Cl|SCREEN}} 12 ' the following works in other screen modes, too
{{Cl|SCREEN}} {{Text|12|#F580B1}} {{Text|<nowiki>' the following works in other screen modes, too</nowiki>|#919191}}
{{Cl|RANDOMIZE}} {{Cl|TIMER (function)|TIMER}}
{{Cl|RANDOMIZE}} {{Cl|TIMER (function)|TIMER}}


{{Cl|PLAY}} "mb l4cf.l8el4fag.l8fl4gl8agl4f.l8fl4a>cl2dl4dl4c.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl2f>l4dc.<l8al4afg.l8fl4g>dc.<l8al4a>cl2dl4dc.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl1f"
{{Cl|PLAY}} {{Text|<nowiki>"mb l4cf.l8el4fag.l8fl4gl8agl4f.l8fl4a>cl2dl4dl4c.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl2f>l4dc.<l8al4afg.l8fl4g>dc.<l8al4a>cl2dl4dc.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl1f"</nowiki>|#FFB100}}


{{Cl|DIM}} ccs(1 {{Cl|TO}} 9, 1 {{Cl|TO}} 2)
{{Cl|DIM}} ccs({{Text|1|#F580B1}} {{Cl|TO}} {{Text|9|#F580B1}}, {{Text|1|#F580B1}} {{Cl|TO}} {{Text|2|#F580B1}})
ccs(1, 1) = 415: ccs(1, 2) = 289
ccs({{Text|1|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|415|#F580B1}}: ccs({{Text|1|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|289|#F580B1}}
ccs(2, 1) = 185: ccs(2, 2) = 128
ccs({{Text|2|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|185|#F580B1}}: ccs({{Text|2|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|128|#F580B1}}
ccs(3, 1) = 108: ccs(3, 2) = 75
ccs({{Text|3|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|108|#F580B1}}: ccs({{Text|3|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|75|#F580B1}}
ccs(4, 1) = 70: ccs(4, 2) = 48
ccs({{Text|4|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|70|#F580B1}}: ccs({{Text|4|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|48|#F580B1}}
ccs(5, 1) = 48: ccs(5, 2) = 32
ccs({{Text|5|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|48|#F580B1}}: ccs({{Text|5|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|32|#F580B1}}
ccs(6, 1) = 32: ccs(6, 2) = 20
ccs({{Text|6|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|32|#F580B1}}: ccs({{Text|6|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|20|#F580B1}}
ccs(7, 1) = 20: ccs(7, 2) = 12
ccs({{Text|7|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|20|#F580B1}}: ccs({{Text|7|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|12|#F580B1}}
ccs(8, 1) = 10: ccs(8, 2) = 6
ccs({{Text|8|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|10|#F580B1}}: ccs({{Text|8|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|6|#F580B1}}
ccs(9, 1) = 2: ccs(9, 2) = 2
ccs({{Text|9|#F580B1}}, {{Text|1|#F580B1}}) = {{Text|2|#F580B1}}: ccs({{Text|9|#F580B1}}, {{Text|2|#F580B1}}) = {{Text|2|#F580B1}}


{{Cl|FOR...NEXT|FOR}} extra = 1 {{Cl|TO}} 23
{{Cl|FOR}} extra = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|23|#F580B1}}
  {{Cl|FOR...NEXT|FOR}} p = 1 {{Cl|TO}} 9
    {{Cl|FOR}} p = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|9|#F580B1}}
    gcolor {{Cl|INT}}({{Cl|RND}} * 9 + 14 - 9)
        {{Text|gcolor|#55FF55}} {{Cl|INT}}({{Cl|RND}} * {{Text|9|#F580B1}} + {{Text|14|#F580B1}} - {{Text|9|#F580B1}})
    {{Cl|_DELAY}} .04
        {{Cl|_DELAY}} {{Text|.04|#F580B1}}
    {{Cl|CLS}}
        {{Cl|CLS}}
    gscale p
        {{Text|gscale|#55FF55}} p
    row = ccs(p, 1)
        row = ccs(p, {{Text|1|#F580B1}})
    cl = ccs(p, 2)
        cl = ccs(p, {{Text|2|#F580B1}})
    glocate row, cl
        {{Text|glocate|#55FF55}} row, cl
    gprint "000000000000000000000000000000000000000000000000000000000000000000000"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"000000000000000000000000000000000000000000000000000000000000000000000"</nowiki>|#FFB100}}
    glocate row + 1, cl
        {{Text|glocate|#55FF55}} row + {{Text|1|#F580B1}}, cl
    gprint "0x00x0xxxx0xxxx0xxxx0x0x000x00x0xxxx0x000x000x0x0xxxx0xxxx0xxxx000x00"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"0x00x0xxxx0xxxx0xxxx0x0x000x00x0xxxx0x000x000x0x0xxxx0xxxx0xxxx000x00"</nowiki>|#FFB100}}
    glocate row + 2, cl
        {{Text|glocate|#55FF55}} row + {{Text|2|#F580B1}}, cl
    gprint "0x00x0x00x0x00x0x00x0x0x000xx0x0x0000x000x000x0x0x0000x00x0x00x000x00"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"0x00x0x00x0x00x0x00x0x0x000xx0x0x0000x000x000x0x0x0000x00x0x00x000x00"</nowiki>|#FFB100}}
    glocate row + 3, cl
        {{Text|glocate|#55FF55}} row + {{Text|3|#F580B1}}, cl
    gprint "0xxxx0xxxx0xxxx0xxxx0x0x000x0xx0xxx00x0x0x000x0x0xxx00xxxx0xxxx000x00"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"0xxxx0xxxx0xxxx0xxxx0x0x000x0xx0xxx00x0x0x000x0x0xxx00xxxx0xxxx000x00"</nowiki>|#FFB100}}
    glocate row + 4, cl
        {{Text|glocate|#55FF55}} row + {{Text|4|#F580B1}}, cl
    gprint "0x00x0x00x0x0000x00000x0000x00x0x0000x0x0x0000x00x0000x00x0x0x0000000"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"0x00x0x00x0x0000x00000x0000x00x0x0000x0x0x0000x00x0000x00x0x0x0000000"</nowiki>|#FFB100}}
    glocate row + 5, cl
        {{Text|glocate|#55FF55}} row + {{Text|5|#F580B1}}, cl
    gprint "0x00x0x00x0x0000x00000x0000x00x0xxxx0xx0xx0000x00xxxx0x00x0x00x000x00"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"0x00x0x00x0x0000x00000x0000x00x0xxxx0xx0xx0000x00xxxx0x00x0x00x000x00"</nowiki>|#FFB100}}
    glocate row + 6, cl
        {{Text|glocate|#55FF55}} row + {{Text|6|#F580B1}}, cl
    gprint "000000000000000000000000000000000000000000000000000000000000000000000"
        {{Text|gprint|#55FF55}} {{Text|<nowiki>"000000000000000000000000000000000000000000000000000000000000000000000"</nowiki>|#FFB100}}
  {{Cl|NEXT}} p
    {{Cl|NEXT}} p
  {{Cl|SLEEP}} 1
    {{Cl|SLEEP}} {{Text|1|#F580B1}}
  {{Cl|IF...THEN|IF}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) {{Cl|THEN}} {{Cl|EXIT}} {{Cl|FOR...NEXT|FOR}}
    {{Cl|IF}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|27|#F580B1}}) {{Cl|THEN}} {{Cl|EXIT FOR}}
{{Cl|NEXT}} extra
{{Cl|NEXT}} extra


{{Cl|END}}
{{Cl|END}}


{{Cl|SUB}} gscale (s):
{{Cl|SUB}} {{Text|gscale|#55FF55}} (s):
{{Cl|SHARED}} gscalep
    {{Cl|SHARED}} gscalep
gscalep = {{Cl|INT}}(s)
    gscalep = {{Cl|INT}}(s)
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} gcolor (c):
{{Cl|SUB}} {{Text|gcolor|#55FF55}} (c):
{{Cl|SHARED}} gcolorp
    {{Cl|SHARED}} gcolorp
gcolorp = c
    gcolorp = c
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} gbackcolor (c):
{{Cl|SUB}} {{Text|gbackcolor|#55FF55}} (c):
{{Cl|SHARED}} gbackcolorp
    {{Cl|SHARED}} gbackcolorp
gbackcolorp = c
    gbackcolorp = c
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} glocate (row, column):
{{Cl|SUB}} {{Text|glocate|#55FF55}} (row, column):
{{Cl|SHARED}} gposxp
    {{Cl|SHARED}} gposxp
{{Cl|SHARED}} gposyp
    {{Cl|SHARED}} gposyp
gposyp = row
    gposyp = row
gposxp = column
    gposxp = column
{{Cl|END SUB}}
{{Cl|END SUB}}


{{Cl|SUB}} gprint (p$):
{{Cl|SUB}} {{Text|gprint|#55FF55}} (p$):
{{Cl|SHARED}} gscalep
    {{Cl|SHARED}} gscalep
{{Cl|SHARED}} gposxp, gposyp
    {{Cl|SHARED}} gposxp, gposyp
{{Cl|SHARED}} gcolorp, gbackcolorp
    {{Cl|SHARED}} gcolorp, gbackcolorp
' # means "use the foreground color here."
    {{Text|<nowiki>' # means "use the foreground color here."</nowiki>|#919191}}
' . means "use the background color here."
    {{Text|<nowiki>' . means "use the background color here."</nowiki>|#919191}}
' _ means "transparent - don't draw this block at all" (you can layer!)
    {{Text|<nowiki>' _ means "transparent - don't draw this block at all" (you can layer!)</nowiki>|#919191}}
' 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f means "do color attribute 0 to 15."
    {{Text|<nowiki>' 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f means "do color attribute 0 to 15."</nowiki>|#919191}}
' any letter after f: "use the foreground color here."
    {{Text|<nowiki>' any letter after f: "use the foreground color here."</nowiki>|#919191}}
{{Cl|IF...THEN|IF}} gscalep < 1 {{Cl|THEN}} gscalep = 1
    {{Cl|IF}} gscalep < {{Text|1|#F580B1}} {{Cl|THEN}} gscalep = {{Text|1|#F580B1}}
pcolorp = gcolorp
    pcolorp = gcolorp
{{Cl|FOR...NEXT|FOR}} p = 1 {{Cl|TO}} {{Cl|LEN}}(p$):
    {{Cl|FOR}} p = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|LEN}}(p$):
  {{Cl|SELECT CASE}} {{Cl|LCASE$}}({{Cl|MID$}}(p$, p, 1))
        {{Cl|SELECT CASE}} {{Cl|LCASE$}}({{Cl|MID$ (function)|MID$}}(p$, p, {{Text|1|#F580B1}}))
    {{Cl|CASE}} "#", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
            {{Cl|CASE}} {{Text|<nowiki>"#"</nowiki>|#FFB100}}, {{Text|<nowiki>"g"</nowiki>|#FFB100}}, {{Text|<nowiki>"h"</nowiki>|#FFB100}}, {{Text|<nowiki>"i"</nowiki>|#FFB100}}, {{Text|<nowiki>"j"</nowiki>|#FFB100}}, {{Text|<nowiki>"k"</nowiki>|#FFB100}}, {{Text|<nowiki>"l"</nowiki>|#FFB100}}, {{Text|<nowiki>"m"</nowiki>|#FFB100}}, {{Text|<nowiki>"n"</nowiki>|#FFB100}}, {{Text|<nowiki>"o"</nowiki>|#FFB100}}, {{Text|<nowiki>"p"</nowiki>|#FFB100}}, {{Text|<nowiki>"q"</nowiki>|#FFB100}}, {{Text|<nowiki>"r"</nowiki>|#FFB100}}, {{Text|<nowiki>"s"</nowiki>|#FFB100}}, {{Text|<nowiki>"t"</nowiki>|#FFB100}}, {{Text|<nowiki>"u"</nowiki>|#FFB100}}, {{Text|<nowiki>"v"</nowiki>|#FFB100}}, {{Text|<nowiki>"w"</nowiki>|#FFB100}}, {{Text|<nowiki>"x"</nowiki>|#FFB100}}, {{Text|<nowiki>"y"</nowiki>|#FFB100}}, {{Text|<nowiki>"z"</nowiki>|#FFB100}}
      pcolorp = gcolorp
                pcolorp = gcolorp
    {{Cl|CASE}} "."
            {{Cl|CASE}} {{Text|<nowiki>"."</nowiki>|#FFB100}}
      pcolorp = gbackcolorp
                pcolorp = gbackcolorp
    {{Cl|CASE}} "_"
            {{Cl|CASE}} {{Text|<nowiki>"_"</nowiki>|#FFB100}}
      pcolorp = -1
                pcolorp = {{Text|-1|#F580B1}}
    {{Cl|CASE}} "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
            {{Cl|CASE}} {{Text|<nowiki>"0"</nowiki>|#FFB100}}, {{Text|<nowiki>"1"</nowiki>|#FFB100}}, {{Text|<nowiki>"2"</nowiki>|#FFB100}}, {{Text|<nowiki>"3"</nowiki>|#FFB100}}, {{Text|<nowiki>"4"</nowiki>|#FFB100}}, {{Text|<nowiki>"5"</nowiki>|#FFB100}}, {{Text|<nowiki>"6"</nowiki>|#FFB100}}, {{Text|<nowiki>"7"</nowiki>|#FFB100}}, {{Text|<nowiki>"8"</nowiki>|#FFB100}}, {{Text|<nowiki>"9"</nowiki>|#FFB100}}, {{Text|<nowiki>"a"</nowiki>|#FFB100}}, {{Text|<nowiki>"b"</nowiki>|#FFB100}}, {{Text|<nowiki>"c"</nowiki>|#FFB100}}, {{Text|<nowiki>"d"</nowiki>|#FFB100}}, {{Text|<nowiki>"e"</nowiki>|#FFB100}}, {{Text|<nowiki>"f"</nowiki>|#FFB100}}
      pcolorp = {{Cl|INSTR}}("0123456789abcdef", {{Cl|LCASE$}}({{Cl|MID$}}(p$, p, 1))) - 1
                pcolorp = {{Cl|INSTR}}({{Text|<nowiki>"0123456789abcdef"</nowiki>|#FFB100}}, {{Cl|LCASE$}}({{Cl|MID$ (function)|MID$}}(p$, p, {{Text|1|#F580B1}}))) - {{Text|1|#F580B1}}
  {{Cl|END SELECT}}
        {{Cl|END SELECT}}
  {{Cl|IF...THEN|IF}} {{Cl|NOT}} pcolorp = -1 {{Cl|THEN}}
        {{Cl|IF}} {{Cl|NOT}} pcolorp = {{Text|-1|#F580B1}} {{Cl|THEN}}
    {{Cl|IF...THEN|IF}} gscalep > 1 {{Cl|THEN}}
            {{Cl|IF}} gscalep > {{Text|1|#F580B1}} {{Cl|THEN}}
      {{Cl|LINE}} ((gposxp - 1) * gscalep, (gposyp - 1) * gscalep)-{{Cl|STEP}}(gscalep - 1, gscalep - 1), pcolorp, BF
                {{Cl|LINE}} ((gposxp - {{Text|1|#F580B1}}) * gscalep, (gposyp - {{Text|1|#F580B1}}) * gscalep)-{{Cl|STEP}}(gscalep - {{Text|1|#F580B1}}, gscalep - {{Text|1|#F580B1}}), pcolorp, BF
    {{Cl|ELSE}}:
            {{Cl|ELSE}}:
      {{Cl|PSET}} (gposxp, gposyp), pcolorp
                {{Cl|PSET}} (gposxp, gposyp), pcolorp
    {{Cl|END IF}}
            {{Cl|END IF}}
  {{Cl|END IF}}
        {{Cl|END IF}}
  glocate gposyp, gposxp + 1
        {{Text|glocate|#55FF55}} gposyp, gposxp + {{Text|1|#F580B1}}
{{Cl|NEXT}} p
    {{Cl|NEXT}} p
gposxp = 1
    gposxp = {{Text|1|#F580B1}}
glocate gposyp + 1, 1 'gposyp = gposyp + 1
    {{Text|glocate|#55FF55}} gposyp + {{Text|1|#F580B1}}, {{Text|1|#F580B1}} {{Text|<nowiki>'gposyp = gposyp + 1</nowiki>|#919191}}
{{Cl|END SUB}}
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}
{{Small|Code by Mennonite}}
{{Small|Code by Mennonite}}


----


''Example 5:'' This example uses [[PRINT]] to good effect as string spacing is ignored by PLAY:
;Example 5:This example uses [[PRINT]] to good effect as string spacing is ignored by '''PLAY'''.
{{CodeStart}}
{{CodeStart}}
{{Cl|WIDTH}} 59, 28
{{Cl|WIDTH}} {{Text|59|#F580B1}}, {{Text|28|#F580B1}}
{{Cl|PRINT}} <nowiki>
{{Cl|PRINT}}
x$ = x$ + "  o3    l4        t        0120c    ml<f1  ,a      1,  "
x$ = x$ + {{Text|<nowiki>"  o3    l4        t        0120c    ml<f1  ,a      1,  "</nowiki>|#FFB100}}
x$ = x$ + "  >c    1,        mnf        .e  8f  am  l<  e1    ,g  "
x$ = x$ + {{Text|<nowiki>"  >c    1,        mnf        .e  8f  am  l<  e1    ,g  "</nowiki>|#FFB100}}
x$ = x$ + "  1,    >c      1, mn      g.  f8  ga  8g  8m  l<    "
x$ = x$ + {{Text|<nowiki>"  1,    >c      1, mn      g.  f8  ga  8g  8m  l<    "</nowiki>|#FFB100}}
x$ = x$ + "  f2.,a2.,      >c  2.      ,m  nf  .f  8a    ml<f    "
x$ = x$ + {{Text|<nowiki>"  f2.,a2.,      >c  2.      ,m  nf  .f  8a    ml<f    "</nowiki>|#FFB100}}
x$ = x$ + "  ,a,>c,mn    >cd2.,<f2    .,d2    .,<b        -2      "
x$ = x$ + {{Text|<nowiki>"  ,a,>c,mn    >cd2.,<f2    .,d2    .,<b        -2      "</nowiki>|#FFB100}}
x$ = x$ + "  .m    lb    -,>d,f,mn>d    ml      <c          1,      "
x$ = x$ + {{Text|<nowiki>"  .m    lb    -,>d,f,mn>d    ml      <c          1,      "</nowiki>|#FFB100}}
x$ = x$ + "  <a    1,  f1        ,m  n>      >c          .<      "
x$ = x$ + {{Text|<nowiki>"  <a    1,  f1        ,m  n>      >c          .<      "</nowiki>|#FFB100}}
x$ = x$ + "  a8    af  ml          c1  ,<      e1          ,g      "
x$ = x$ + {{Text|<nowiki>"  a8    af  ml          c1  ,<      e1          ,g      "</nowiki>|#FFB100}}
x$ = x$ + "                                                          "
x$ = x$ + {{Text|<nowiki>"                                                          "</nowiki>|#FFB100}}
x$ = x$ + "      1,m      n>  g.f8ga8g8m  l<                  f1    "
x$ = x$ + {{Text|<nowiki>"      1,m      n>  g.f8ga8g8m  l<                  f1    "</nowiki>|#FFB100}}
x$ = x$ + "      ,d1,    <b  -1          ,m                n>      "
x$ = x$ + {{Text|<nowiki>"      ,d1,    <b  -1          ,m                n>      "</nowiki>|#FFB100}}
x$ = x$ + "      >f .d    8d  c<            f2              .,      "
x$ = x$ + {{Text|<nowiki>"      >f .d    8d  c<            f2              .,      "</nowiki>|#FFB100}}
x$ = x$ + "      a2  .,  c2  .,>f2.        ml      <      b-        "
x$ = x$ + {{Text|<nowiki>"      a2  .,  c2  .,>f2.        ml      <      b-        "</nowiki>|#FFB100}}
x$ = x$ + "      ,>  d,  f,  mn>dml          <c    1,<    a1        "
x$ = x$ + {{Text|<nowiki>"      ,>  d,  f,  mn>dml          <c    1,<    a1        "</nowiki>|#FFB100}}
x$ = x$ + "      ,f    1, mn  >>              c.  <a 8a  fm          "
x$ = x$ + {{Text|<nowiki>"      ,f    1, mn  >>              c.  <a 8a  fm          "</nowiki>|#FFB100}}
x$ = x$ + "      lc    2.,<  e2                .,g2  .,mn          "
x$ = x$ + {{Text|<nowiki>"      lc    2.,<  e2                .,g2  .,mn          "</nowiki>|#FFB100}}
x$ = x$ + "      >g      .f8  gml<b-,>d,        f,    mn            "
x$ = x$ + {{Text|<nowiki>"      >g      .f8  gml<b-,>d,        f,    mn            "</nowiki>|#FFB100}}
x$ = x$ + "                                                          "
x$ = x$ + {{Text|<nowiki>"                                                          "</nowiki>|#FFB100}}
x$ = x$ + ">d      ml  <<f2.,a2.,        >        c2.,m      n>  c."
x$ = x$ + {{Text|<nowiki>">d      ml  <<f2.,a2.,        >        c2.,m      n>  c."</nowiki>|#FFB100}}
x$ = x$ + " <a    8a  ml                <e,        g,  >c      ,m  n>"
x$ = x$ + {{Text|<nowiki>" <a    8a  ml                <e,        g,  >c      ,m  n>"</nowiki>|#FFB100}}
x$ = x$ + "  cm  l<    <b              -2 .,      >d  2.    ,f  2."
x$ = x$ + {{Text|<nowiki>"  cm  l<    <b              -2 .,      >d  2.    ,f  2."</nowiki>|#FFB100}}
x$ = x$ + "  ,mn>    d2.ml<          <b  -,      >d  ,f      ,m  n>"
x$ = x$ + {{Text|<nowiki>"  ,mn>    d2.ml<          <b  -,      >d  ,f      ,m  n>"</nowiki>|#FFB100}}
x$ = x$ + "    dm      l<<f1,        a1,>c1,mn    >c.<a      8a  fm"
x$ = x$ + {{Text|<nowiki>"    dm      l<<f1,        a1,>c1,mn    >c.<a      8a  fm"</nowiki>|#FFB100}}
x$ = x$ + "    lc      1,            <e1,g1,mn>g    .f  8g      a8  g8"
x$ = x$ + {{Text|<nowiki>"    lc      1,            <e1,g1,mn>g    .f  8g      a8  g8"</nowiki>|#FFB100}}
x$ = x$ + "    ml      <<          b-        1,  >d  1,          "
x$ = x$ + {{Text|<nowiki>"    ml      <<          b-        1,  >d  1,          "</nowiki>|#FFB100}}
x$ = x$ + "    f1      ,mn>f.d8dc  l1          ml  f,    c,    <a  ,f"</nowiki>
x$ = x$ + {{Text|<nowiki>"    f1      ,mn>f.d8dc  l1          ml  f,    c,    <a  ,f"</nowiki>|#FFB100}}
{{Cl|PRINT}} x$;
{{Cl|PRINT}} x$;
{{Cl|PLAY}} x$
{{Cl|PLAY}} x$
{{CodeEnd}}
{{CodeEnd}}
{{Small|Code by Luke}}
{{Small|Code by Luke}}
----
;Example 6:Demonstrates usage of [[VARPTR$]] with '''PLAY'''.
{{CodeStart}}
{{Text|<nowiki>'Play scale in 7 different octaves</nowiki>|#919191}}
scale$ = {{Text|<nowiki>"CDEFGAB"</nowiki>|#FFB100}}
play$ = {{Text|<nowiki>"L16O="</nowiki>|#FFB100}} + {{Cl|VARPTR$}}(i%) + {{Text|<nowiki>"X"</nowiki>|#FFB100}} + {{Cl|VARPTR$}}(scale$)
{{Cl|FOR}} i% = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|6|#F580B1}}
    {{Cl|PLAY}} play$
{{Cl|NEXT}}
{{CodeEnd}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[PLAY (function)]]
* [[PLAY (function)]]
* [[SOUND]], [[DRAW]]
* [[SOUND]], [[BEEP]], [[_WAVE]]
* [[_SNDRAW]]
* [[_SNDOPEN]], [[_SNDRAW]]
* [[_SNDOPEN]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 14:49, 21 November 2024

PLAY is a statement that plays notes of sound through the sound card in QB64 using a command STRING.


Syntax

PLAY commandstring$


Parameters

  • The commandstring$ can be any literal or variable STRING consisting of the following commands:
    • Command string values are not case sensitive and spacing is ignored. Use upper or lower case as desired.
  • On - Sets the current octave (from 0 to 6). Example: PLAY "O3"
  • < - Down one octave (cannot be below zero). Example: PLAY "<<" 'goes down two octaves.
  • > - Up one octave (cannot be above 6). Example: PLAY ">>" ' goes up two octaves.
  • 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: PLAY "C#"
  • - for a flat note. Example: PLAY "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: PLAY "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: PLAY "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 - Specifies a pause (1 - 64). P1 is a whole-note pause, P2 is a half-note pause, etc. (The pause is 1/n notes in length.) Example: PLAY "P32"
  • Tn - Tempo sets number of L4 quarter notes per minute (n can be 32 to 255 where 120 is the default). Example: PLAY "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.
  • , - commas in QB64 stop play advancement to allow more than one note to be played simultaneously. Example: PLAY "C,E,G,"
  • Vn - Volume in QB64 only can be any volume from 0 (none) to 100 (full). The default level is 50 when n is not specified.
  • MF - Play music in the foreground (each note must be completed before another can start).
  • MB - Play music in the background while program code execution continues (QB64 has no note buffer limits).
  • X + VARPTR$(string-expression) - executes a command string variable. MUST be used with variables!.
  • @n - Select waveform in QB64-PE only can be (1 for square waveform, 2 for sawtooth waveform, 3 for triangle waveform (default), 4 for sine waveform, 5 for white noise or 10 for a waveform defined by the _WAVE statement (since QB64-PE v4.0.0)).
  • Qn - Volume ramp in QB64-PE only can be any duration (ms) from 0 to 100.
  • Numeric values "n" listed above can also be fetched from numeric variables using "=" + VARPTR$(numeric_variable).


Availability

  • Complete X + VARPTR$(string-expression) support was added in QB64-PE v3.8.0. Earlier versions of QB64-PE and QB64 only had = + VARPTR$(numeric_variable) support.
  • Support for @n and Qn was added in QB64-PE v3.8.0.
  • Support for user-defined _WAVE waveforms (ID#:10) was added in QB64-PE v4.0.0.


Examples

Example 1
Plays a sound with the volume and note varying from 0 to 50. Maximum note can only be 84.
PLAY "q0mll64"
DO
    FOR x = 1 TO 50
        a$ = a$ + "v" + LTRIM$(STR$(x)) + "n" + LTRIM$(STR$(x))
    NEXT
    FOR x = 50 TO 1 STEP -1
        a$ = a$ + "v" + LTRIM$(STR$(x)) + "n" + LTRIM$(STR$(x))
    NEXT
    PLAY a$
    a$ = ""
LOOP UNTIL INKEY$ <> ""
PLAY "v10l1c,l4egl2o5c,o4l4eg"
Code by Galleon

Example 2
Plays "Frosty the snowman". The lyric printing is not delayed by PLAY 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 "t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2." 'MB removed to print song one line at a time
    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"
END
Code by Greg Rismoen

Example 3
Clicking on the grid enables various notes to be played simultaneously.
DIM SHARED grid(16, 16), grid2(16, 16), cur
CONST maxx = 512
CONST maxy = 512
SCREEN _NEWIMAGE(maxx, maxy, 32)
_TITLE "MusicGrid"
cleargrid
DO
    IF TIMER - t# > 1 / 8 THEN cur = (cur + 1) AND 15: t# = TIMER
    IF cur <> oldcur THEN
        figuregrid
        drawgrid
        playgrid
        oldcur = cur
    END IF
    domousestuff
    in$ = INKEY$
    IF in$ = "C" OR in$ = "c" THEN cleargrid
LOOP UNTIL in$ = CHR$(27)

SUB drawgrid
    scale! = maxx / 16
    scale2 = maxx \ 16 - 2
    FOR y = 0 TO 15
        y1 = y * scale!
        FOR x = 0 TO 15
            x1 = x * scale!
            c& = _RGB32(grid2(x, y) * 64 + 64, 0, 0)
            LINE (x1, y1)-(x1 + scale2, y1 + scale2), c&, BF
        NEXT x
    NEXT y
END SUB

SUB figuregrid
    FOR y = 0 TO 15
        FOR x = 0 TO 15
            grid2(x, y) = grid(x, y)
        NEXT x
    NEXT y
    FOR y = 1 TO 14
        FOR x = 1 TO 14
            IF grid(x, y) = 1 AND cur = x THEN
                grid2(x, y) = 2
                IF grid(x - 1, y) = 0 THEN grid2(x - 1, y) = 1
                IF grid(x + 1, y) = 0 THEN grid2(x + 1, y) = 1
                IF grid(x, y - 1) = 0 THEN grid2(x, y - 1) = 1
                IF grid(x, y + 1) = 0 THEN grid2(x, y + 1) = 1
            END IF
        NEXT x
    NEXT y
END SUB

SUB domousestuff
    DO WHILE _MOUSEINPUT
        IF _MOUSEBUTTON(1) THEN
            x = _MOUSEX \ (maxx \ 16)
            y = _MOUSEY \ (maxy \ 16)
            grid(x, y) = 1 - grid(x, y)
        END IF
    LOOP
END SUB

SUB playgrid
    n$ = "L16 "
    'scale$ = "O1CO1DO1EO1FO1GO1AO1BO2CO2DO2EO2FO2GO2AO2BO3CO3D"
    scale$ = "o1fo1go1ao2co2do2fo2go2ao3co3do3fo3go3ao4co4do4fo"
    FOR y = 15 TO 0 STEP -1
        IF grid(cur, y) = 1 THEN
            note$ = MID$(scale$, 1 + (15 - y) * 3, 3)
            n$ = n$ + note$ + "," 'comma plays 2 or more column notes simultaneously
        END IF
    NEXT y
    n$ = LEFT$(n$, LEN(n$) - 1)
    PLAY n$
END SUB

SUB cleargrid
    FOR y = 0 TO 15
        FOR x = 0 TO 15
            grid(x, y) = 0
        NEXT x
    NEXT y
END SUB
Code by JP

Example 4
Play strings starting with MB allow program code to run while music plays in background.
' 2012, 2013 mennonite
' license: creative commons cc0 1.0 universal
' (public domain) http://creativecommons.org/publicdomain/zero/1.0/

SCREEN 12 ' the following works in other screen modes, too
RANDOMIZE TIMER

PLAY "mb l4cf.l8el4fag.l8fl4gl8agl4f.l8fl4a>cl2dl4dl4c.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl2f>l4dc.<l8al4afg.l8fl4g>dc.<l8al4a>cl2dl4dc.<l8al4afg.l8fl4gl8agl4f.l8dl4dcl1f"

DIM ccs(1 TO 9, 1 TO 2)
ccs(1, 1) = 415: ccs(1, 2) = 289
ccs(2, 1) = 185: ccs(2, 2) = 128
ccs(3, 1) = 108: ccs(3, 2) = 75
ccs(4, 1) = 70: ccs(4, 2) = 48
ccs(5, 1) = 48: ccs(5, 2) = 32
ccs(6, 1) = 32: ccs(6, 2) = 20
ccs(7, 1) = 20: ccs(7, 2) = 12
ccs(8, 1) = 10: ccs(8, 2) = 6
ccs(9, 1) = 2: ccs(9, 2) = 2

FOR extra = 1 TO 23
    FOR p = 1 TO 9
        gcolor INT(RND * 9 + 14 - 9)
        _DELAY .04
        CLS
        gscale p
        row = ccs(p, 1)
        cl = ccs(p, 2)
        glocate row, cl
        gprint "000000000000000000000000000000000000000000000000000000000000000000000"
        glocate row + 1, cl
        gprint "0x00x0xxxx0xxxx0xxxx0x0x000x00x0xxxx0x000x000x0x0xxxx0xxxx0xxxx000x00"
        glocate row + 2, cl
        gprint "0x00x0x00x0x00x0x00x0x0x000xx0x0x0000x000x000x0x0x0000x00x0x00x000x00"
        glocate row + 3, cl
        gprint "0xxxx0xxxx0xxxx0xxxx0x0x000x0xx0xxx00x0x0x000x0x0xxx00xxxx0xxxx000x00"
        glocate row + 4, cl
        gprint "0x00x0x00x0x0000x00000x0000x00x0x0000x0x0x0000x00x0000x00x0x0x0000000"
        glocate row + 5, cl
        gprint "0x00x0x00x0x0000x00000x0000x00x0xxxx0xx0xx0000x00xxxx0x00x0x00x000x00"
        glocate row + 6, cl
        gprint "000000000000000000000000000000000000000000000000000000000000000000000"
    NEXT p
    SLEEP 1
    IF INKEY$ = CHR$(27) THEN EXIT FOR
NEXT extra

END

SUB gscale (s):
    SHARED gscalep
    gscalep = INT(s)
END SUB

SUB gcolor (c):
    SHARED gcolorp
    gcolorp = c
END SUB

SUB gbackcolor (c):
    SHARED gbackcolorp
    gbackcolorp = c
END SUB

SUB glocate (row, column):
    SHARED gposxp
    SHARED gposyp
    gposyp = row
    gposxp = column
END SUB

SUB gprint (p$):
    SHARED gscalep
    SHARED gposxp, gposyp
    SHARED gcolorp, gbackcolorp
    ' # means "use the foreground color here."
    ' . means "use the background color here."
    ' _ means "transparent - don't draw this block at all" (you can layer!)
    ' 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f means "do color attribute 0 to 15."
    ' any letter after f: "use the foreground color here."
    IF gscalep < 1 THEN gscalep = 1
    pcolorp = gcolorp
    FOR p = 1 TO LEN(p$):
        SELECT CASE LCASE$(MID$(p$, p, 1))
            CASE "#", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
                pcolorp = gcolorp
            CASE "."
                pcolorp = gbackcolorp
            CASE "_"
                pcolorp = -1
            CASE "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
                pcolorp = INSTR("0123456789abcdef", LCASE$(MID$(p$, p, 1))) - 1
        END SELECT
        IF NOT pcolorp = -1 THEN
            IF gscalep > 1 THEN
                LINE ((gposxp - 1) * gscalep, (gposyp - 1) * gscalep)-STEP(gscalep - 1, gscalep - 1), pcolorp, BF
            ELSE:
                PSET (gposxp, gposyp), pcolorp
            END IF
        END IF
        glocate gposyp, gposxp + 1
    NEXT p
    gposxp = 1
    glocate gposyp + 1, 1 'gposyp = gposyp + 1
END SUB
Code by Mennonite

Example 5
This example uses PRINT to good effect as string spacing is ignored by PLAY.
WIDTH 59, 28
PRINT
x$ = x$ + "   o3    l4         t         0120c    ml<f1   ,a      1,  "
x$ = x$ + "   >c    1,        mnf        .e  8f   am  l<   e1    ,g   "
x$ = x$ + "   1,    >c       1, mn       g.   f8  ga   8g   8m  l<    "
x$ = x$ + "   f2.,a2.,      >c   2.      ,m  nf   .f  8a     ml<f     "
x$ = x$ + "   ,a,>c,mn     >cd2.,<f2     .,d2     .,<b        -2      "
x$ = x$ + "   .m    lb    -,>d,f,mn>d    ml       <c          1,      "
x$ = x$ + "   <a    1,   f1         ,m   n>       >c          .<      "
x$ = x$ + "   a8    af  ml           c1  ,<       e1          ,g      "
x$ = x$ + "                                                           "
x$ = x$ + "      1,m      n>  g.f8ga8g8m  l<                   f1     "
x$ = x$ + "      ,d1,     <b  -1           ,m                 n>      "
x$ = x$ + "      >f .d    8d  c<            f2               .,       "
x$ = x$ + "      a2  .,   c2  .,>f2.         ml      <      b-        "
x$ = x$ + "      ,>   d,  f,  mn>dml          <c    1,<    a1         "
x$ = x$ + "      ,f    1, mn  >>               c.  <a 8a  fm          "
x$ = x$ + "      lc     2.,<  e2                .,g2   .,mn           "
x$ = x$ + "      >g      .f8  gml<b-,>d,         f,     mn            "
x$ = x$ + "                                                           "
x$ = x$ + ">d      ml  <<f2.,a2.,         >         c2.,m       n>  c."
x$ = x$ + " <a    8a   ml                <e,        g,  >c      ,m  n>"
x$ = x$ + "  cm  l<    <b               -2 .,       >d   2.     ,f  2."
x$ = x$ + "   ,mn>     d2.ml<          <b   -,      >d  ,f      ,m  n>"
x$ = x$ + "    dm      l<<f1,         a1,>c1,mn     >c.<a       8a  fm"
x$ = x$ + "    lc      1,            <e1,g1,mn>g    .f  8g      a8  g8"
x$ = x$ + "    ml      <<           b-         1,   >d   1,           "
x$ = x$ + "    f1      ,mn>f.d8dc  l1           ml  f,    c,    <a  ,f"
PRINT x$;
PLAY x$
Code by Luke

Example 6
Demonstrates usage of VARPTR$ with PLAY.
'Play scale in 7 different octaves
scale$ = "CDEFGAB"

play$ = "L16O=" + VARPTR$(i%) + "X" + VARPTR$(scale$)

FOR i% = 0 TO 6
    PLAY play$
NEXT


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link