<!-- PDF page 148 -->

can be), so each one is in channel **A** of *PSG1* and the command is simply **PLAY a$** – or (as seen in line 20) **PLAY "M56UX5000W1O3(((C)))"**.

In fact any of the *channels* can produce either a *musical tone* or *noise* or even nothing at all, so you can mix sound effects in with your music (see *Channel selection* later on).

### Constructing strings

Composing music and sound effects in *NextBASIC* is just a matter of creating strings containing the information you want. Try this – very simple – example, which plays just one note – an **A**.

```
a$="a": PLAY a$
```

Any music program using **PLAY** will generally use *string variables* rather than literals to tell it what to play, as you can see by looking at the earlier examples. The more complex, or longer, the piece and the more complicated sound, the more complex the strings become as obvious from the increased complexity of the examples above.

Any *musical sound* has a *pitch* and *duration*. It also has a *volume* and *timbre*. The strings in the earlier examples contain information about all of these. The summary below lists each possible command, and they are explained in detail opposite.

### PLAY command summary

This is a brief list of the commands which can be contained in a **PLAY** string. Note that all letters except note names must always be in capitals.

| String entry | Function |
|---|---|
| c-b or C-B | Gives pitch of note within current octave range |
| $ | Flattens note following it |
| # | Sharpens note following it |
| Ox | Sets octave range x (0 to 8) |
| 1-12 | Sets duration of note |
| & | Denotes a rest |
| N | Separates two numbers |
| Vx | Sets volume to x (0-15) |
| Wx | Sets volume effect to x (0-7) |
| U | Turns on volume effect in the current channel |
| Xx | Sets duration of volume effect to x (0-65535) |
| Tx | Sets tempo to x (60-240) bpm |
| ( ) | Enclose repeated phrase |
| ! ! | Enclose a comment |
| H | Halts a PLAY command |
| Mx | Selects channel and sets type to x (1-63) |
| Yx | Turns on MIDI channel x (1-16) |
| Zx | Sends x as a MIDI patch |
| L | Restricts output from current PSG to Left Speaker Only |
| R | Restricts output from current PSG to Right Speaker Only |
| S | Restores stereo mode to current PSG |

*Table 10 – **PLAY** commands*

### Setting the pitch

As you saw above, you set the pitch of any note by giving its musical name – eg. **C E G**. *Sharp* notes are prefixed by **#** (eg **#C**) and flat notes by **$**. A *two-octave range* in the *key of C*, which use the letters **c** to **b** for the notes in the lower *octave* and **C** to **B** in capitals for the

