Tuesday, August 29, 2017

(A Very) Modest Model 100 Music Masterpiece

The first Model 100 project I planned to tackle was to have my ancient laptop produce some sweet tunes. You know, something along a Red Means Recording creation, but with a 34 year old(!) laptop. Mind you, I've got no experience actually creating music, but I figured that would hardly get in my way. What can I say, programmers are optimists.

While I could get the Model 100 to beep with relative ease, getting it produce anything along the lines of a tune was considerably more tricky. And then there's the hell that is line number BASIC. Besides the obvious annoyance of line numbers, you've got no named functions and only 1 and 2 character global variables to at your disposal. And of course, the Model 100 has an 8 line screen, which is another obstacle to deal with. Still, trying to create order out of such programming chaos was surprisingly fun, so I stuck with it.

For my musical creation, I give you a simple application which will play the notes of your choice. You can even control the octave and duration of the notes with relative ease (global variables for the win).

And here's my very first tune, carefully transcribed from an Internet resource.

Can you name that tune?

As I mentioned above, this exercise had less to do with creating interesting music and more to do with developing a sort of coding style that made reasoning on the Model 100 a doable task. For my tiny little program, I got there. Check out the code that powers the above song:

10 REM more music
20 REM Song: Yankee Doodle
30 DATA "C","C","D","E","C","E","D"
31 DATA "C","C","D","E","C","B"
32 DATA "C","C","D","E","F","E","D"
33 DATA "C","B","G","A","B","C","C"
39 DATA "X"
40 LET D = 7
50 FOR O = 1 TO 5 STEP 1
60 GOSUB 1000
70 RESTORE 30
80 NEXT O
99 END
1000 REM iterate through notes
1010 READ N$
1020 IF N$ = "X" THEN GOTO 1999
1030 GOSUB 2000
1040 GOTO 1010
1999 RETURN
2000 REM Let's Play the note in n$
2010 FQ(1) = 698
2020 FQ(2) = 622
2030 FQ(3) = 587
2040 FQ(4) = 523
2050 FQ(5) = 466
2060 FQ(6) = 439
2070 FQ(7) = 783
2080 I = ASC(N$) - 64
2090 F = FQ(I)
2100 FOR S = 1 TO O-1 STEP 1 
2110 F = F * 2
2120 NEXT S
2130 PRINT "playing "; N$ ; F ; I
2140 SOUND F, D
2999 RETURN

There's actually quite a few 'features' in the above code, including: support for playing arbitrary length songs, the ability to code in simple music notation ("C" for a C note) and as I bragged about above, the ability to control the duration and octave of each note. Heck, thanks to GOSUB I even achieved something resembling modularity.

I'm not quite sure where I go from here. I suppose I could continue this musical journey and see if I can't eek out something resembling unique (and perhaps even pleasant?!) music from this device. Or maybe it's time to find a new challenge.

This was a fascinating exercise in programming deprivation. Trying to hack my way out of line numbers and global variables was a great way to see classic programming challenges in a new light.

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails