The last issue of E&MM detailed the special dialect of BASIC used on the Sharp MZ-80K microcomputer which allows the user to program music. Ten different note and rest durations can be programmed and the computer will play music over a three octave range at any one of seven tempos. Users are soon able to write musical programs transcribing sheet music to a computer program — an early attempt will look something like the listing for the tune "Two Lovely Black Eyes" (program 1).
It will be seen that the Sharp BASIC is quite clever and that the notes can be sharpened by prefixing with a # symbol. Suffixes are also used and these are numbers which define the note and rest durations between a demi-semi quaver (0) and a semibreve (9). After a few hours' experimentation with the music lines it will become apparent that even this relatively short program can be simplified. When a series of notes have the same duration the numbered suffix need only be added to the first note. Each succeeding note will repeat the first duration until a new suffix is added. Thus the program for the tune "Two Lovely Black Eyes" becomes even easier (program 2).
With a little practice it soon becomes easy to remember the BASIC notation and programs like the Bach Musette (program 3) can be written quickly. Line 300 sets the tempo for the whole piece and the music in lines 310-340 is played only once. The music in lines 360-430 is played twice and this double play is defined in line 350. The ability of the computer to return and play the same music over again is a most useful facility and it is used in the next example tune — the Frank Mills composition "Music Box Dancer" (program 4). Here the music plays three times and increases in tempo each time. Line 44 defines the tempo as variable T which is set to vary between 4 and 6 in line 43. The net result of these two lines is that the program runs playing the music in lines 45-56 at a slow tempo then returns to the start and plays it again at a medium tempo before again returning to the beginning and playing the tune for the last time at a fast tempo. Without this return and tempo stepping facility the program would be three times as long and the tempo would have to be defined on three separate lines.
Last month I showed how to POKE machine code routines from BASIC to give a large variety of sound effects and it should be noted that the Sharp BASIC only covers three octaves. Using machine code it is possible to program notes from as high as 4kHz to as low as 40Hz. Spectacular cosmic sounds can be programmed in this way and POKEing machine code notes from BASIC will be detailed in next month's edition. It is fairly easy to see that a machine code program can be written which will allow some of the keys on the MZ-80K to be defined as certain notes. It is possible to write a routine to define the keys CDEFGA and B so that they respond by playing a scale. A keyboard scan routine checks if a key is pressed and the appropriate note is then played for as long as the note is depressed. However, the keyboard on the Sharp is laid out in QWERTY typewriter style and this is obviously not the best type of keyboard for a musician. Victor Kusin has taken one of our machine code routines and rewritten it to run from BASIC using data statements. The program defines the keys in two of the rows as per the conventional piano layout and the program illustrates this on the screen. As keys are depressed the appropriate notes are played and the Sharp BASIC notation is displayed. This enables musicians who play by ear to play on the Sharp keyboard and then see the tune in Sharp BASIC notation on the screen. It is then a simple matter to note the lines of program and to incorporate them in later programming.
This program is particularly popular with children and is used a great deal in various school music departments. With a little ingenuity and some programming experience it will soon become apparent that the Sharp music facilities are very important. The music greatly enhances the games — Space Invaders without sound would be unthinkable — and is very useful as an error indicator in business or computer assisted learning programs. It is very easy to program a friendly pip if you have made a correct entry and it is just as simple to program a low note to indicate the operator is trying to enter wrong information.
The "Computer Piano" program makes use of the special POKEs which are only used for music — the next issue of "Electronics and Music Maker" will examine memory locations 4514 and 4513 in greater detail and describe the use of strings in music programming.
mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.