!0.......^.........^.........^.. !B \H11\H07\H10\H00 TUNING UP! !2.......^.........^.........^.........^.........^.........^.... ZX Spectrums may not be the most musical of micros ... but, if you're like Chris Somerville, you're not exactly a Beethoven in the making anyway! So, compose yourself for the musically illiterate's guide to writing music ... !1.......^.........^.........^.........^........ Apart from enhancing the variety of zaps and zings which accompany alien annihilation, the Spectrum BEEP commands can be used quite effectively to produce simple tunes and jingles; witness the somewhat over-used 'Funeral March' that signifies failure in many commercial programs. Of course, you could always call suitable snippets of music from sheet music for your own programs - these are often available for a few pence from a local secondhand bookshop. But this is where the catch comes in! The musical notation has to be translated into the numerical pitch and tempo required by the Spectrum. Fine if you can read music, especially as a number of commercial programs allow you to use the Spectrum as a sort of piano keyboard. But if you can't read music ... !0.......^.........^.........^.. !B NOTA BENE !1.......^.........^.........^.........^........ Very few programmers can claim to be conversant with musical notation but anyone could, by laboriously counting lines and spaces, work out the individual notes. This program allows leisurely entry of each note as a musical letter, followed by a number to signify the duration of that note. You can even indicate the use of a sharp or flat! Musical notation generally conveys two pieces of information: the pitch of each sound and how long it should last. Although it may look confusing it's really not that difficult to translate. The pitch of a note is shown by its position on a stave, which is a row of five lines; notes can be placed on a line, or in the space between two lines. Take a look at the diagrams provided and you should be able to figure out which note is which in most any sheet music you can find. Of course, there are one or two things to watch out for. For example, to make a note higher or lower, you'll find that the composer has introduced a sharp (#) or a flat (\H91) respectively. If these symbols appear next to an individual note, then it must be altered appropriately; if, however, the sharp or flat symbol appears at the very beginning of the stave, all the notes on that particular line, or in the space, should be altered. You'll also find that there are a number of different shaped notes, each offering varying length notes; there's a separate diagram showing all the musical notation you'll need to master. Unfortunately, this program can't deal with musical pauses. However, these can be included as PAUSE commands in between the BEEP commands when you transcribe the program for future use. Since the PAUSE command works in fiftieths of a second, its duration number can't be in the same range as used for BEEP. However, provided with this article you'll find a table illustrating the various musical rest symbols and the corresponding PAUSE duration. Most music is written within two sets of five lines - the upper stave carrying the melody and the lower stave containing the accompaniment. Since the Spectrum can only cope with one note at a time (Unless you're Sandy White, of course! Ed.) you'd be best advised to stick with the melody only. !0.......^.........^.........^.. !B ON A FINAL NOTE !1.......^.........^.........^.........^........ Anyone who's had any formal musical training will probably be experiencing an extreme case of the vapours by now. Yes, I know it's cheating - but for readers who want to 'SingalongaSpectrum', well, this could be your only chance. Armed with this program and the "oh so brief" guide to reading music, you should be able to transcribe any sheet music. A word of advice though; before you start converting Beethoven's Fifth for the Spectrum, don't be tempted to add too much sound to your program - generally a recognisable snippet will do. You only need to set the scene and you'll find that a five second blast of an old familiar tune will be a lot more successful than a long tune that keeps repeating. !0.......^.........^.........^.. !B THE ART OF NOISE! !2.......^.........^.........^.........^.........^.........^.... Once you've RUN Chris' Music Writer program, you're greeted with a menu offering eight options: to create a tune, to play the tune back through the Spectrum, to raise/lower the octave, to increase/decrease the tempo, to print out the data for the tune, and to reset the octave/tempo. So, let's take it from the top and transcribe a tune ... !SYR12_231 !SYR12_232 !SYR12_233 !0.......^.........^.........^.. !B 10 RESTORE 20 DATA 0,56,68,130,68,56,0,0 30 DATA 8,8,8,56,72,136,144,96 40 DATA 8,8,8,56,120,248,240,9 6 50 DATA 14,8,8,56,120,248,240, 96 60 DATA 14,8,14,56,120,248,240 ,96 70 FOR i=USR "A" TO USR "E"+7: READ c: POKE i,c: NEXT i !2.......^.........^.........^.........^.........^.........^.... Lines 10-70 Set up the graphics for the program. !0.......^.........^.........^.. 80 LET oct=0: LET tempo=16 90 DATA "a%","a ","a#","b%","b ","c","c#","d%","d","d#","e%","e ","f","f#","g%","g","g#" 100 DATA -4,-3,-2,-2,-1,0,1,1,2 ,3,3,4,5,6,6,7,8 110 DATA "A%","A","A#","B%","B" ,"C","C#","D%","D","D#","E%","E" ,"F","F#","G%","G","G#" 120 DATA 8,9,10,10,11,12,13,13, 14,15,15,16,17,18,18,19,20 130 DIM a$(34,2): DIM a(34) 140 FOR i=1 TO 17: READ a$(i): NEXT i 150 FOR i=1 TO 17: READ a(i): N EXT i 160 FOR i=18 TO 34: READ a$(i): NEXT i 170 FOR i=18 TO 34: READ a(i): NEXT i 180 GO TO 500 !2.......^.........^.........^.........^.........^.........^.... Lines 80-180 Initialise the variables. !0.......^.........^.........^.. 200 CLS : PRINT '" YOU CAN ENT ER NOTES WITHIN TWO OCTAVES": PRINT '" a b c d e f g A B C D E F G" 210 PRINT '" Enter each note as a letter, which may be follo wed by: # for Sharp or % f or Flat": PRINT '" After each no te you will be asked to ente r the note length which should be a number:": PRINT '" 1 2 4 8 16 e d c b a" 220 PRINT ''" When all notes h ave been entered you shou ld enter ""end""" 230 LET n$="": LET t$="" 240 INPUT "NOTE or END";i$: IF i$="" THEN GO TO 240 250 IF i$="end" OR i$="END" THE N GO TO 370 260 IF LEN i$=2 THEN IF i$(2)< >"%" AND i$(2)<>"#" THEN BEEP . 5,-5: GO TO 240 270 IF CODE i$<65 OR CODE i$>71 AND CODE i$<97 OR CODE i$>103 T HEN BEEP .5,-5: GO TO 240 280 IF i$="b#" OR i$="c%" OR i$ ="e#" OR i$="f%" THEN BEEP .5,- 5: GO TO 240 290 IF i$="B#" OR i$="C%" OR i$ ="E#" OR i$="F%" THEN BEEP .5,- 5: GO TO 240 300 BEEP .1,19: BEEP .1,12 310 INPUT "LENGTH OF NOTE";j$: IF j$="" THEN GO TO 310 320 IF CODE j$<49 OR CODE j$>59 THEN BEEP .5,-5: GO TO 310 330 BEEP .1,19: BEEP .1,12 340 IF LEN i$=1 THEN LET i$=i$ +" " 350 IF LEN j$=1 THEN LET j$="0 "+j$ 360 LET t$=t$+j$: LET n$=n$+i$: GO TO 240 370 CLS : PRINT AT 10,10; FLASH 1;"PLEASE WAIT": LET t$=t$+" " 380 LET p$="": FOR i=1 TO LEN n $ STEP 2: FOR j=1 TO 34: IF n$(i TO i+1)<>a$(j) THEN NEXT j 390 LET k$=STR$ a(j): IF LEN k$ =1 THEN LET k$="+"+k$ 400 LET p$=p$+k$+t$( TO 2): LET t$=t$(3 TO ) 410 NEXT i 420 LET q$="" 430 FOR i=1 TO LEN p$ 440 LET q$=q$+p$(i): NEXT i 450 RETURN !2.......^.........^.........^.........^.........^.........^.... Lines 200-450 Comprise the input subroutine. Full instructions for the input of the musical data are provided as on-screen instructions. !0.......^.........^.........^.. 470 FOR i=1 TO (LEN q$)-3 STEP 4 480 LET d=VAL q$(i+2 TO i+3): L ET p=VAL q$(i TO i+1): BEEP d/te mpo,p+oct 490 NEXT i: RETURN !2.......^.........^.........^.........^.........^.........^.... Lines 470-490 This routine plays back the tune you've input. !0.......^.........^.........^.. 510 CLS : PRINT " MENU " 520 PRINT '" 1) ENTER A TUNE" 530 PRINT '" 2) PLAY A TUNE" 540 PRINT '" 3) PLAY AN OCTAVE HIGHER" 550 PRINT '" 4) PLAY AN OCTAVE LOWER" 560 PRINT '" 5) INCREASE TEMPO " 570 PRINT '" 6) DECREASE TEMPO " 580 PRINT '" 7) PRINT DATA" 590 PRINT '" 8) RESET OCTAVE & TEMPO" 600 IF INKEY$<>"" THEN GO TO 6 00 610 LET i$=INKEY$: IF i$="" THE N GO TO 610 620 IF CODE i$<49 OR CODE i$>56 THEN GO TO 600 630 IF i$="8" THEN LET tempo=1 6: LET oct=0: GO TO 500 640 GO SUB (190 AND i$="1")+(46 0 AND i$="2")+(660 AND i$="3")+( 670 AND i$="4")+(680 AND i$="5") +(690 AND i$="6")+(700 AND i$="7 ") 650 CLS : GO TO 510 !2.......^.........^.........^.........^.........^.........^.... Lines 510-650 Provide the on-screen menu of eight options you're greeted with once you've booted the program. Choose an option and this routine will send the program flow to the subroutines in lines 660-800. !0.......^.........^.........^.. 660 LET oct=oct+(12 AND oct<=49 ): GO SUB 470: RETURN 670 LET oct=oct-(12 AND oct>=-3 3): GO SUB 470: RETURN 680 LET tempo=tempo+2: GO SUB 4 70: RETURN 690 LET tempo=tempo-1 AND tempo >1: GO SUB 470: RETURN 700 CLS : FOR i=1 TO LEN q$-3 S TEP 4 710 LET d=VAL q$(i+2 TO i+3): L ET p=VAL q$(i TO i+1): PRINT "BE EP ";d/tempo;",";p+oct;":"; 720 IF PEEK 23689=4 THEN GO SU B 750 730 NEXT i 740 GO SUB 750: RETURN 750 PRINT AT 21,0;" SEND TO PRI NTER Y(yes) N(no)" 760 IF INKEY$<>"" THEN GO TO 7 60 770 LET i$=INKEY$: IF i$="" THE N GO TO 770 780 IF i$="y" OR i$="Y" THEN C OPY : CLS : RETURN 790 POKE 23692,255: RETURN 800 SAVE "music" LINE 10 !2.......^.........^.........^.........^.........^.........^.... Lines 660-800 Contain the subroutines for the options available on the menu screen. !1.......^.........^.........^.........^........ !B -- from Your Spectrum #12 (Mar.1985) -- !$