I bought a small accordion! It brought with it one liability – 25 keys of a standard keyboard, and the necessity to learn how to read music. From my extensive piano lessons as an eight-year old, I remembered that middle “C” was just below those two black keys in the center – and that was it. Now, with books full of tempting songs just waiting to be let loose from the page if only I could figure out what those little spots were, I was finally motivated to do something about learning to read music.
Since I work with people every day that were learning to read, surely I could learn how that staff was arranged – after all, I’ve gotten pretty comfortable with a keyboard for typing.
Well, Maybe. It turns out that music notation is a highly compressed form of “information storage” – a little like Hebrew, where the vowels are just assumed.
I thought of making a program that would draw a musical staff, then print a note, followed by sounding its pitch. I would watch, trying to hit the right key for each note before the machine beeped. I honestly started on the QL – getting as far as drawing a nice treble clef with ARC commands. Then I started reading the docs on the SOUND command. Oh well…
The QL can do all sorts of “sound effect” types of changes, but there was no documentation on the exact relation of frequency to pitch command. The Tandy docs, on the other hand, offered a four octave table of correct note frequencies. Besides, the T-102 would move to where I wanted to be while I was practicing. Its liability was MS-BASIC, and its creaky commands for string handling.
The program works pretty well as it stands, and I thought CATS members might enjoy looking through the listing, as much to cackle over the hoops I had to leap through as anything else. Here goes:
10 REM staff learning 1993 Mark Fisher
20 GOSUB 2000 :REM setup
This is where the information portion of the program is set up, then RETURNs to the operation portion:
30 CLS:X=2
40 PRINT@X,:INPUT "(P)lay scale (E)xamine
(R)andom note";BA$
(P)lay scale is useful, but (R)andom note is the prime exercise here. (E) only goes to a non-functional de-bugging utility.
50 R=INSTR("PERper",BA$):IF R<1 THEN GOTO
30
60 IF R>3 THEN R=R-3
70 CLS:ON R GOSUB 100,200,300
80 GOTO 30
“R” will be 1,2 or 3 after line 60, and will go to the corresponding sub in 70.
100 REM .... play scales ....
110 CLS:X=2
120 GOSUB 600: REM get key to play in
This subroutine selects the correct offset for the scale sequence, and runs into the sub at 650 that draws the staff.
130 FOR I=0 TO 7: GOSUB 1000: GOSUB 1500:
NEXT I:REM draw and sound note
140 FOR I=7 TO 0 STEP -1:GOSUB 1000: GOSUB
1500:NEXT I
150 BA$="":PRINT@0,:INPUT "Press <ENTER>
to cont. <KEY> to quit";BA$: IF BA$=""
THEN GOTO 100
180 RETURN
Line 150’s first statement is due to an amusing quirk of MS-BASIC: Pressing <ENTER> with no other key after an INPUT statement leaves the previous value of the variable unchanged. THAT took a while to figure out (undocumented, of course).
200 REM ... examine scale ....
210 REM nothing here
290 RETURN
Here’s the real meat; a random sequence of notes to follow, preventing me from memorizing a pattern of keys rather than reading what’s on the staff.
300 REM ....... random note .........
310 INPUT "How many notes";M:IF M>14 THEN
M=14
320 INPUT "Spread over";SP:SP=SP-1
325 IF SP>M THEN SP=M
“M” and “SP” control how many and from where the notes are selected: a few, and close together being easier to master. There’s a fault in the logic here – should the notes chosen cluster around the base note (songs don’t)?
330 GOSUB 600:REMget desired key;ba set
340 OF=14-N(0,BA):REM"OF"=number of staff
posns below ba
350 BA$=" 0 1 2 3 4 5 6 7 8 91011121314":
FOR I=0 TO M-1
360 IM=1+INT(RND(1)*SP)*2: J=VAL(MID$
(BA$,IM,2))-OF: BA$= LEFT$ (BA$,IM-1)+
RIGHT$(BA$,LEN(BA$)-(IM+1)):SP=SP-1
RND(1) means get a new value for RND – not the possible spread of values. The other choice is RND(0), which gives a repeat of the last value produced (???). In timexese, the second and third statements would read: J=BA$(IM to IM+1): BA$=BA$(to IM)&BA$(IM+2 to) Oh well…
370 P(I)=J:NEXT I
And now the “to play..” array is shuffled and built up.
380 J=RND(1)*M:REM which of the notes
shall we play?
390 I=P(J)
400 GOSUB 1000:FOR J=1 TO 500:NEXT J:
GOSUB 1500
The “J” loop is a delay – no pause on the T102.
410 IF X<225 THEN GOTO 380
420 CLS:INPUT"Again";BA$
430 IF BA$="N" OR BA$="n" THEN RETURN
440 CLS:X=2:GOSUB 650:GOTO 380
And now for the “works” of the program:
600 REM... set key & draw staff...
610 CLS:INPUT "Base? (bCDFG)";BA$
620 K=(INSTR("BCDFGbcdfg",BA$)-1)MOD5:IF
K<0 THEN GOTO 610
630 BA=ASC(K$(K))-48: REM decode info from
K$()
650 CLS:PRINT@0, "Key of ";BA$,BA;"
semitones up":REM entry for screen re-draw
Draw five staff lines… [Format is LINE (x1,y1)-(x2,y2)]
660 FOR I=1 TO 5
670 LINE (0,12+(I*8))-(239,12+(I*8))
680 NEXT I
And draw key signature, as coded in K$():
690 FOR I=2 TO LEN (K$(K)) STEP 2:IF
LEN(K$(K))=1 THEN RETURN
700 BA$=MID$(K$(K),I,1)
710 X=2:IFMID$(K$(K),I+1,1)>"a"THENX=6
720 Y=(ASC(MID$(K$(K),I+1,1))MOD 32)+12
730 IF BA$="#"THEN GOSUB 800
740 IF BA$="b"THEN GOSUB 900
750 NEXT I
760 X=X+3:RETURN
800 REM ... draw sharp @ x ...
810 FOR J=0 TO 2 STEP 2
820 LINE (X-2,Y+1-J)-(X+2,Y-J)
830 LINE (X-1+J,Y+2)-(X-1+J,Y-2)
840 NEXT J
890 RETURN
900 REM ... draw flat @ x...
910 LINE (X,Y)-(X+2,Y+2),1,B
(Adding ,1,B draws a box – ,0,b would be filled in.)
920 LINE (X,Y)-(X,Y-2)
990 RETURN
1000 REM ....note finder....(if I<0 then
note from next octave below is played)
1010 OF=INT(I/8)*12:IM=IMOD8:IF I<0 THEN
IM=(I+8) MOD 8: OF= -12
1020 REM ba=scale BAse at correct point
1030 REM of=OFfset (next higher or lower
octave) pointer, in # of semitones down.
1040 REM im=point in scale noted
1050 NO=BA+OF+(S(IM)):N=N(0,NO):X=X+7
1060 REM .... note draw ....
1070 REM no=note freq, n=staff position
1080 LINE (X,N*4+2)-(X+5,N*4+6),1,B
1090 IF N=0 OR N=2 OR N=14 THEN LINE
(X-1,N*4+4)-(X+6,N*4+4)
1100 RETURN
1500 REM note sound
1510 SOUND N(1,NO),30
1590 RETURN
2000 REM .... setup ....
2010 DEFINT A-Z:DIM N(1,24):REM n()=note
position, frequency
Dimensions have one more element than you expect – 0 to 2 is three elements, BUT string positions start at 1. Hmmm…
The note position is a relative index within the staff, counting middle “C” as 14. I chose this to simplify MY thought as I entered the data. I’ve inserted a procedure to translate that into actual screen position as the note is played.
The note frequencies give the values for each semitone of the musical scale within the given range. (Semitones correspond to ALL keys on the keyboard.)
2020 DATA 14,9394,14,8866,13,8368,12,7900,
12,7456,11,7032,11,6642,10,6269,10,5918,
9,5586,8,5272,8,4976
2030 DATA
7,4697,7,4433,6,4184,5,3950,5,3728,4,
3516,4,3321,3,3134,3,2959,2,2793,1,2636,
1,2484,0,2348
2040 RESTORE 2020
2050 FOR I=0 TO 24:READ
J:N(0,I)=J:READJ:N(1,I)=J:NEXT I
But music is not a smooth seamless flow of frequencies – what we think of as a scale follows the sequence in line 2060. (These point to what are the white keys in the key of “C”.) The numbers are pointers into the table of note positions and frequencies.
2060 DATA 0,2,4,5,7,9,11,12
2070 DIM S(7):RESTORE 2060:FOR I=0 TO
7:READ J:S(I)=J:NEXT I:REM s()=scale
sequence
Aah Microsoft… “RND” dosen’t give a random result. True with all machines, but this one sets the start point at one every time the program is run, resulting in the SAME sequence for each time the program is run. The following code moves the seed along a random amount each time the program starts.
2080 J=VAL(RIGHT$(TIME$,2))
2090 FOR I=1 TO J:J=RND(1):NEXT I:REM set
real rnd start
Since music is not a continuous flow of frequencies, there is a need to specify what sequence of notes you are using – the KEY. K$() holds the data to offset the base scale the correct number of semitones, and to draw the standard key signatures for the five most common keys.
2100 DATA ":bXbl","0","2#H#t","5bX","7#H"
2110 RESTORE 2100:DIMK$(4):FOR I=0 TO
4:READ BA$:K$(I)=BA$:NEXT I:REM key
signatures and base offset
P() will hold the allowable keys to play for a given exercise. Since MS-BASIC cannot re-dimension an array without clearing all variables, it gets set up here.
2120 DIM P(13):REM play key array
2130 RETURN
Now I’ll have to quit programming and start to learn music!
MTF
A QLuickie
MTF
…So I’m pasting up the n/l right now, see? And I want to reformat Mannie’s review of the label program, only it has aquired line feeds and carriage returns at the end of each line during its long journey from QL, BBS, IBM format disk, RAM disk image to Quill doc file – which QUILL interperets as hard paragraphs, so its like HOURS before I can manually replace them, since REPLACE won’t work on carriage returns, see?
The solution? Make sure paragraphs are separated by blank lines, then PRINT the page of the file that holds the document to a _LIS file. Dump everything, then IMPORT the _LIS file back, this time by paragraph, and reformat at will!
Like, Wow!
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.