Click Here To Go To The Your Computer Archive



Written By Andrew Bindon


Cover Art
Click Here To Enlarge Loading Screen

Loading Screen
Click Here To Enlarge Opening Screen

Opening Screen
Click Here To Enlarge Screenshot

Game Screenshot

Christmas Carols

While shepherds watched the box one night, Andrew Bindon plugged in his BBC Micro

The program listed plays 19 of my favourite Christmas carols in three-part harmony. At the same time it displays each note on to a normal musical score individually as the note is sounded. The clever part is that the program composes its own musical harmony to go together with the melody.

To understand how the auto-harmonisation works we must consider the way in which simplest musical harmony is composed. As an example let us use the key of G major. Using the common name-note notation together with pitch numbers this runs from octave to octave:

G A B C D E F# G
81 89 97 101 109 117 125 129

If we start at any note on this scale and take three alternative notes we form a triad. Basic musical harmony uses three of these triads beginning on the first, the fourth and the fifth note of the scale. These are called the primary triads. For the key of G major they are:

G 81; B 97; 0 109; C 101; E 117; G 129; D 109; F# 125; A 137.

We see that using these triads we have encompassed every note in the scale. The same chords will also map on to notes an octave away, or two octaves. These triads have a particularly pleasant musical sound. By selecting one of them to play with each note in the melody we can obtain an interesting and pleasant-sounding harmony backing.

The melody itself is read from data statements at the end of the program. These may be replaced in your preference. There is nothing new in reading data for music in this way but perhaps something which is new is the way in which the data is stored. Each of the single individual melodies are stored as three lines of data. The first line gives the number of rhythm units/bar, the position at which the bar is, the time signature, and the best way to display the music respectively.

The second line then gives the pitch of each note in the melody. The third line then give the length of each note in the melody. All three lines are read at the start of a piece. The procedure Procdata then picks out the character from the data string and converts them to pitch and duration numbers.

In this way a great saving on space is obtained and also this opens up the way for future enhancement of the program.

The code for this data storage is d for Do up to t for Te in the first octave and then the same for the next but in capitals. The range could be extended if needed. The rhythm is c for crotchet and so on. Dotted notes are then represented with capitals. Both of these codes can be understood clearly by examining the relevant lines in the Procdata routine.

The data conversion process may be fully understood by typing in the following lines.

DtDRDFFMltDisssDtDRDFFMltDlsssMRDMSFMltDFMRD (RETURN)

the computer will respond with Mistake but this does not matter:

REPEAT:char$=GET$:posit=INSTR("drmfsltDRMFSLTa",char$):
pit%=VAL(MID$("033041049053061069077081089097101109117125129",(posit-1)*3+1,3)):
SOUND1,-15,pit%,2:UNTIL FALSE (RETURN)

Now move the copy cursor up to the line of characters which you have typed above, think of the rhythm of the carol As With Gladness Men Of Old, and start tapping the copy key.

The process of transferring the notes to a musical score takes up a good part of the program. Each duration note is a character defined in PROCvdu. The score is displayed in Mode 4 with a yellow score background and a red foreground. At the beginning of each piece four lines of score with treble and base and key signature are constructed. Then as each note is played it appears on the score.

It is my experience that a program is never finished, merely developed. You start with an idea and develop it more and more until it becomes so huge that you scrap it and start again. It is thus that the listed program is open to enhancement. One thing you might like to try is changing the following lines thus:

 770 pit = VAL(MID$("033041045053061065077081089093101109113125129",
(posit-1)*3+1,3))
2340 DATA 33,45,61,53,65,81,61,77,89
1950 key = VAL(MID$("1432505234161",pitch/4+4+12*(pitch>=40),1))
1960 flat = VAL(MID$("00-100-100-1-100-100-10000",pitch/2+7+24*(pitch>=40),2))

This causes all the melodies to be played as if they were written in a minor key, although the score as shown does not allow for the raised 7th and the minor key is a rather crude version.

The program was developed on a 32K machine - Model B, OS 1.2. It will run on any 32K machine, but will not fit into 16K as memory for the Mode 4 screen. The program Saves in 20 blocks - that is 5K. 16K users could try leaving out all the graphics score routine, meaning variable names, the title list, or the input procedure. I have not included in the listing a profusion of untidy Rem statements. The meaningful variable and procedure names and the colon spacing between each procedure attempt to make the program readable.

To help your understanding of the program and debugging your typing errors the following may be useful:

PROCinput - inputs choice of melody, the key, speed and envelope selection.
PROCread - reads data into the arrays.
PROCfirst - sets up variables at the beginning of each melody.
PROCdata - converts data to pitch and duration numbers.
PROCplay - sounds melody together with harmoney syncronised, and checks for first beat of bar accent.
PROCchoosecord - selects harmony to accompany melody.
PROCenv - defines envelopes.
PROCtoscore - puts note onto screen.
PROCvdu - turns off cursor, defines colours and note characters.
PROCscore - sets up screen.
PROCclef - draws base and treble.
PROCbar - draws barline.
PROCsig - draws key signature.
PROCtotrep - selects random keys, speeds and envelope selections.