FROM:
[ccie_html]
<div class=”starter-template”>
<p>Press Play to hear how the pitch sounds. <button onclick=”turn_on();”>Play</button></p>
<p>Press Stop to turn it off. <button onclick=”turn_off();”>Stop</button></p>
<center><p><input id=”slider” type=”range” min=”0″ max=”1000″ value=”600″ onchange=”changePitch(this.value)”></p></center>
</div>
[/ccie_html]
TO:
[ccie_html]
<div class=”starter-template”>
<p>Press Play to hear how the pitch sounds. <button onclick=”turn_on();”>Play</button></p>
<p>Press Stop to turn it off. <button onclick=”turn_off();”>Stop</button></p>
<center><p><input id=”slider” type=”range” min=”0″ max=”1000″ value=”600″ onchange=”changePitch(this.value)”></p></center>
</div>
[/ccie_html]
Next, create a file (slider.css) and add the following CSS logic to adjust the size of the slider:
[cc lang=”javascript”]
.slider-width200
{
width: 200px !important;
}
[/cc]
The “!important” text is needed to override some default Bootstrap CSS logic.
Finally, in pitch.js, add the following function to be called when the position of the slider changes:
[cc lang=”javascript”]
function changePitch(newValue)
{
osc.frequency(newValue);
};
[/cc]
When you have completed those changes, load index.html to see the following:
Click on the Play button, and you should hear the original pitch. Now move the slider to the right. When you release the slider, you should hear the pitch go up. If you move the slider to the left, the pitch will go down.
You can also go to the demo of this application and see if you can change the pitch.
Download the source code for all of the examples in this series from Github.
References:
WebTUTSDepot: Tutorial for HTML5 sliders
StackOverflow: How to Overwrite Styling In Twitter Bootstrap
Html5 has a synth built right in… who knew!? Awesome 🙂 Sounds like old school 90s hip hop.