Class Session Notes

Index > Small Basic music composition


We continued our Small Basic lesson, focusing on composition of music. The sub-language for writing music in SB is simple in its construction, asking that you supply an octave, CDEFGAB notes, and the length of each individual note.


Small Basic offers a simple syntax for programming music. This syntax includes an octave (optional; if one is not supplied, octave 4 will be assumed), followed by a series of CDEFGAB notes with a number signifying the length of the note, such as the sequence in the example below, which is the sequence for a snippet of Twinkle Twinkle Little Star.

O5 C4 C4 G4 G4 A4 A4 G2 F4 F4 E4 E4 D4 D4 C2

In Small Basic, this sequence is interpreted in the format of a string, which would be enclosed in double-quotation marks.

Source sample

Copy and paste the following code into a Small Basic text editor and press F5 to run the program.

'The following line allows for the user to write a sequence, like the above example
'mySong = "O5 C4 C4 G4 G4 A4 A4 G2 F4 F4 E4 E4 D4 D4 C2"
mySong = TextWindow.Read()