Sound and Music in C128 Mode - continued
7.4 CODING A SONG FROM SHEET MUSICThis section provides a sample piece of sheet music and illustrates hoe to decode notes from a musical staff and translate them into a form the Commodore 128 can understand. This exercise is substantially faster and easier if you know how to read music. However, you don't have to be a musician to be able to play the tune on your Commodore 128. For those of you who cannot read music, Figure 7-11 shows how a typical musical staff is arranged and how the notes on the staff are related to the keys on a piano. Figure 7-11. Musical Staff.Figure 7-12 is an excerpt from a composition titled Invention 13 (Inventio 13 in Italian), by Johann Sebastian Bach. Although this composition was written a few hundred years ago, it can be played and enjoyed on most modern computer synthesizers, such as the SID chip, in the Commodore 128. Here are the opening measures of Invention 13. Figure 7-12. Part of Bach's Invention 13.
The best way to start coding a song into your Commodore 128 is by breaking down the notes down into intermediate code. Write down the upper staff notes on a piece of paper. Now write down the notes for the lower staff. Precede the note values with a duration code. For instance, precede an eighth note with an 8, precede a sixteenth note with a 16 and so on. Next, separate the notes so the notes on the upper staff for one measure are propertional in time with the notes for one measure on the lower staff. If the musical composition has a third staff, you would separate it so the duration is proportional to the two other upper staffs. Once the notes for all the staffs are separated into equal durations, a separate dedicated voice would play each note for a particular staff. For example, voice 1 would play the upper staff, voice 2 will play the second staff and voice 3 would play the lowest staff if it existed. Let's say the upper staff begins with a string of four eighth notes. In addition, say the lower staff begins with a string of eight sixteenth notes. Since a eighth note is proportional in time to two sixteenth notes, separate the notes as shown in Figure 7-13. Figure 7-13. Synchronizing Notes for Two Voices.
Since the synchronization and timing in a musical composition is critical, you must make sure the notes in the upper staff for voice 1, for example, are in time agreement with the notes in the lower staff for voice 2. The first note in the upper staff in Figure 7-12 is an A eighth note. The first two notes for voice 2 are D and E sixteenth notes. In this case, you must enter the voice 1 eighth note in the PLAY string first, then follow the voice 2 sixteenth notes immediately after it. To continue the example, the second note in Figure 7-12 for voice 1 (the upper staff) is a B eighth note. The B eighth note is equal in time to the two sixteenth notes, F and G, which appear in the bottom staff for voice 2. In order to coordinate the timing, enter the B eighth note in the string for voice 1 and follow it with the two sixteenth notes F and G for voice 2. As a rule, always start with the note with the longer duration. For example, if a bar starts with a series of two sixteenth notes on the lower staff for voice 2 and the upper staff starts with an eighth note for voice 1, enter the eighth note in the string first since it must play for the duration while the two sixteenth notes are being fetched by the Commodore 128. You must give the computer time to play the longer note first, the PLAY the notes of shorter duration, or else the composition will not be synchronized. Here's the program that plays Invention 13. Enter it into your C128, SAVE it for future use and then RUN it. 10 REM INVENTION 13 BY J.S. BACH 20 TEMPO 6 30 A$="V1O4T7U8X0 V2O4T7U8X0":REM V1=ORGAN, V2=PIANO 40 DO 50 PLAY A$ 60 READ A$ 70 LOOP UNTIL A$="END OF MUSIC" 80 END 90 REM **** FIRST MEASURE 100 DATA V2O1IA V1O3IE V2O2QA V1O3SAO4CO3BEM 110 DATA V2O2I#G V1O3SBO4DO4IC V2O2SAEM 120 DATA V1O4IE V2O2SAO3C V1O3I#G V2O2SBEM 130 DATA V1O4IE V2O2SBO3DM 140 REM **** SECOND MEASURE 150 DATA V2O3IC V1O3SAE V2O2IA V1O3SAO4CM 160 DATA V2O2I#G V1O3SBE V2O2IE V1O3SBO4DM 170 DATA V1O4IC V2O2SAE V1O3IA V2O2SAO3CM 180 DATA V1O4QR V2O2SBEBO3DM 190 REM **** THIRD MEASURE 200 DATA V2O3IC V1O4SRE V2O2IA V1O4SCEM 210 DATA V2O3IC V1O3SAO4C V2O2IA V1O2SEGM 220 DATA V1O3IF V2O3SDO2A V1O3IA V2O2SFAM 230 DATA V1O4ID V2O2SDF V1O4IF V2O1SAO2CM 240 REM **** FOURTH MEASURE 250 DATA V2O1IB V1O4SFD V2O2ID V1O3SBO4DM 260 DATA V2O2IG V1O3SGB V2O2IB V1O3SDFM 270 DATA V1O3IE V2O2SGE V1O3IG V2O2SEGM 280 DATA V1O4IC V2O2SCE V1O4IE V2O1SGBM 290 REM **** FIFTH MEASURE 300 DATA V2O1IA V1O4SEC V2O2IC V1O3SAO4CM 310 DATA V1O3IF V2O2SDF V1O4ID V2O1SBO2DM 320 DATA V2O1IG V1O3SDB V2O1IB V1O3SGBM 330 DATA V1O3IE V2O2SCE V1O4IC V2O1SAO2CM 340 REM **** SIXTH MEASURE 350 DATA V2O1IF V1O4SCO3A V2O1ID V1O3SFAM 360 DATA V1O3ID V2O1SGO2G V1O3IB V2O2SFGM 370 DATA V2O1IA V1O4SCO3A V2O2I#F V1O4SCEM 380 DATA V2O1IB V1O4SDO3B V2O2I#G V1O4SDFM 390 REM **** SEVENTH MEASURE 400 DATA V2O2IC V1O4SEC V2O2IA V1O4SEGM 410 DATA V2O2ID V1O4SFE V2O2I$B V1O4SDCM 420 DATA V2O2I#G V1O3SBO4C V2O2IF V1O4SDEM 430 DATA V2O2ID V1O4SFD V2O1IB V1O4S#GDM 440 REM **** EIGHTH MEASURE 450 DATA V2O2I#G V1O4SBD V2O2IA V1O4SCAM 460 DATA V2O2ID V1O4SFD V2O2IE V1O3SBO4DM 470 DATA V2O2IF V1O3S#GB V2O2I#D V1O4SCO3AM 480 DATA V2O2IE V1O3SEA V2O2IE V1O3SB#GM 490 REM **** NINTH MEASURE 500 DATA V2O1HA V1O3SAECEO2QAM 510 REM **** END OF MUSIC **** 520 DATA END OF MUSIC You can use the technique described in this section to code your favorite sheet music and play it on your Commodore 128. *************************************************************************** You now have been introduced to most of the powerful new commands of the BASIC 7.0 language that you can use in C128 mode. In the following section you will learn to use both 40- and 80-column screen displays with the Commodore 128. |
page URL: www.bigfoot.com/~c128page/c128sg/sect-07c.htm
contact: c128page@bigfoot.com