Musical Objects Interlude!
Goals:
- Use custom objects to access advanced music features
Coding Snippets:
- Pass an object to the
Piano
constructor to change its default properties. Thetimbre
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, passplay
an object with asong
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
, andrelease
, 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.
- EbonyAndIvory: Use additional instrument object properties to specify a tricked-out, customized keyboard. These properties include the number of keys (
keys
), the color of the white keys (color
),the color of the black keys (blackColor
), the color of the key outlines (lineColor
), the key outline line's width (lineWidth
), and the overall keyboard pixel dimensions (width
andheight
). - Use output from
sizexy
to code a FullScreenPiano. Show only the minimum number of keys necessary to see all notes that get played. - MaestroTurtle: create single-key pianos for the notes C,D,E,F,G,A,B, positioning them so their images don't overlap. Then make the turtle randomly jump around the space occupied by the keys, and have the key or keys it lands on play a note. For an extra challenge, add a label above each sprite showing which key it is.
- Write a WaveSampler program that plays a short song once for each of the six wave options. Consider adding drawings, images, or animations that show the shape of the wave as it plays.