Comparing Scratch  to Pencil Code  for teaching computing through music immediately reveals a major difference: Scratch represents notes as MIDI numbers, while Pencil Code represents notes as letters using ABC notation . To someone who reads music, Pencil Code is clearly preferable because it is far easier to map, for example, a major third to C and E than 60 and 64. But to those who generate music algorithmically, ABC is not as easy as MIDI. For example, a major third in the key of D is not D and F, it is D and F#. Using MIDI values, however, the interval is always 4 semitones: 62 (D) + 4 = 66 (F#), just as before.
A Solution: If one wants both the clarity of ABC notation and the algorithmic power of MIDI values, a conversion is indeed necessary. The code below runs in Pencil Code and plays the chromatic scale from C3 to C6 by passing MIDI values 48 (C3) through 84 (C6) to a MIDItoABC function that is generalized to convert any MIDI value to its proper representation in ABC notation and play it for a specified duration.
A Note on ABC Duration Notation: Unrelated to MIDI but germane to ABC, duration strings are based on quarter notes, which have a duration of 1. A half note has a duration of 2, and a whole note a duration of 4. Going the other way, an eighth note has a duration of 1/2, designated as "/2". Similarly, a 16th note has a duration of "/4", and a 32nd note has a duration of "/8".
The code below includes a test routine to play the chromatic scale from C3 to C6 with random note durations from a half note ("2") to a 32nd note ("/8").
1. ABC Notation; http://abcnotation.com. Accessed 22 February 2016.
2. CoffeeScript; http://coffeescript.org. Accessed 22 February 2016.
3. PencilCode; http://pencilcode.net. Accessed 22 February 2016.
4. Scratch; http://scratch.mit.edu. Accessed 22 February 2016.
Jesse M. Heines
UMass Lowell—Computer Science
One University Avenue
Lowell, Massachusetts 01854 USA
Copyright held by author.
The Digital Library is published by the Association for Computing Machinery. Copyright © 2016 ACM, Inc.Contents available in PDF
View Full Citation and Bibliometrics in the ACM DL.
To comment you must create or log in with your ACM account.