Controllers

Downloads

Download the files used in the above examples by right-clicking the links, and then selecting "Save Link As...".

Vocabulary

Self-Study

  1. Change the playMiddleC() function to playNote(hz), where hz is an argument to get assigned to oscillator.frequency.value.
  2. Add an object called asciiToHz, that maps different ASCII values to different frequencies of your choosing. Then, change the keydown event handler to use that object to pass different Hz values to playNote(hz).
  3. A fairly common computer-keyboard-to-note-name mapping is to have the "home row" of the QWERTY keyboard act as the "white keys" on the piano. So, lowercase "a" is C, lowercase "s" is D, lowercase "d" is E, and so on. Implement this mapping in your asciiToHz object.
  4. Create a toplevel variable called octave. Then create an object called asciiToOctave that maps the ASCII values of the number row of the computer keyboard to different octave designations. Then, modify the playNote(hz) function to have those octave designations affect the octave of each selected note.

Additional Resources