Volume and sustain controls

Let's add some controls to our piano to allow the user to change the volume and sustain. As you may recall, the volume of an audio element may be set to any value from 0 to 1.0. We will use a range input control that allows the user to control that via a slider.

The sustain control allows a note to remain playing after the piano key is released. When sustain is turned off, the note will stop playing as soon as the key is released. We will add a checkbox to turn this off and on.

You can find the source code for this section in chapter6/example6.3.

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.