PencilCoder

Musical Objects Interlude!

Goals:

  • Use custom objects to access advanced music features

Coding Snippets:

  • coding snippets
  • Pass an object to the Piano constructor to change its default properties. The timbre property controls the quality of sound ands its behavior over time based on key-value pairs in a nested object.
  • The play function accepts an ABC-notation string that represents a song. Alternatively, pass play an object with a song property and other optional properties. For example, tempo:480 specifies a quick pace, much faster than the default rate of 120 eighth notes per minute.

Math and Computer Concepts:

  • Sound is formed by audible waves of pressure. The wave property determines the shape of the wave used to generate sound, which significantly affects the sound produced. Variants include 'piano', 'triangle', 'square', 'sawtooth', 'sine', and 'noise'.
  • In sound and music, the term envelope describes how the amplitude (or loudness) of a sound changes over time. Components of the envelope include gain, attack, decay, sustain, and release, all of which can be specified as properties of a timbre object. Check out this example program for more details.

Activities:

Save each of the following in a folder called Music.