Tone.js/examples/monoSynth.html

172 lines
3.8 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
2014-06-25 16:47:47 +00:00
<title>MONOSYNTH</title>
2014-09-06 19:35:31 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
2014-09-02 04:25:38 +00:00
<script type="text/javascript" src="./deps/jquery.min.js"></script>
<script type="text/javascript" src="./deps/jquery-ui.js"></script>
<script type="text/javascript" src="./deps/jquery.ui.touch-punch.js"></script>
<script type="text/javascript" src="../build/Tone.js"></script>
2014-09-05 03:56:34 +00:00
<script type="text/javascript" src="../build/Tone.Preset.js"></script>
2014-09-02 04:25:38 +00:00
<script type="text/javascript" src="./Widgets.js"></script>
<script type="text/javascript" src="./ExampleList.js"></script>
<link rel="stylesheet" type="text/css" href="./style/widgets.css">
<link rel="stylesheet" type="text/css" href="./style/jquery-ui.css">
<script type="text/javascript" src="./deps/qwerty-hancock.js"></script>
</head>
<body>
2014-09-02 04:25:38 +00:00
<div id="Container">
<div id="Explanation">
MonoSynth
2014-09-02 04:25:38 +00:00
<br>
<br>
MonoSynth is a monophonic synthesizer composed simply of one oscillator,
2014-09-02 16:15:20 +00:00
a filter and two envelopes (on amplitude and filter).
2014-09-02 04:25:38 +00:00
</div>
<div id="Content">
<div id="tabs">
<ul>
2014-09-02 16:15:20 +00:00
<li><a href="#envelope">Osc/Env</a></li>
<li><a href="#filter">FilterEnv</a></li>
<li><a href="#presets">Presets</a></li>
2014-09-02 04:25:38 +00:00
</ul>
<div id="envelope">
</div>
<div id="filter">
</div>
2014-09-02 16:15:20 +00:00
<div id="presets">
2014-09-02 04:25:38 +00:00
</div>
</div>
</div>
</div>
<script type="text/javascript">
2014-09-02 16:15:20 +00:00
/* globals Tone, GUI, QwertyHancock */
2014-09-02 04:25:38 +00:00
var synth = new Tone.MonoSynth();
2014-09-02 16:15:20 +00:00
synth.setVolume(-10);
2014-09-02 04:25:38 +00:00
synth.toMaster();
2014-09-02 04:25:38 +00:00
// GUI //
2014-09-02 16:15:20 +00:00
new GUI.TopBar(Tone);
2014-09-02 04:25:38 +00:00
$("#tabs").tabs();
var content = $("#Content");
var envelope = $("#envelope");
var filter = $("#filter");
2014-09-02 16:15:20 +00:00
var presets = $("#presets");
2014-09-02 04:25:38 +00:00
//envelopes
2014-09-02 16:15:20 +00:00
var ampEnv = new GUI.Envelope(envelope, synth.envelope, "amplitude");
2014-10-01 02:49:48 +00:00
var osc = new GUI.OmniOscillator(envelope, synth.oscillator, "oscillator");
2014-09-02 16:15:20 +00:00
//filter
var filtEnv =new GUI.Envelope(filter, synth.filterEnvelope, "filter");
2014-09-02 04:25:38 +00:00
var min = 20;
var max = 20000;
var minFilFreq = new GUI.Slider(filter, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.filterEnvelope.setMin(scaled);
2014-09-02 04:25:38 +00:00
return scaled;
2014-09-02 16:15:20 +00:00
}, min, "start freq", "hz");
2014-09-02 04:25:38 +00:00
var maxFilFreq = new GUI.Slider(filter, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.filterEnvelope.setMax(scaled);
2014-09-02 04:25:38 +00:00
return scaled;
2014-09-02 16:15:20 +00:00
}, min, "end freq", "hz");
2014-09-02 04:25:38 +00:00
2014-09-02 16:15:20 +00:00
//presets
var allPresets = [];
2014-09-04 23:13:55 +00:00
for (var name in synth.preset){
2014-09-02 16:15:20 +00:00
allPresets.push(name);
}
new GUI.DropDown(presets, allPresets, function(name){
setPreset(name);
});
2014-09-02 04:25:38 +00:00
//keyboard
$("<div>", {"id" : "Keyboard"}).appendTo(content);
var keyboard = new QwertyHancock({
id: "Keyboard",
width: 350,
height: 75,
octaves: 2,
2014-09-02 16:15:20 +00:00
startNote: "A3",
2014-09-02 04:25:38 +00:00
whiteNotesColour: "white",
blackNotesColour: "black",
hoverColour: "#f3e939"
});
keyboard.keyDown = function(note, freq){
synth.triggerAttack(freq);
};
2014-09-02 16:15:20 +00:00
keyboard.keyUp = function(){
2014-09-02 04:25:38 +00:00
synth.triggerRelease();
};
function setPreset(name){
synth.setPreset(name);
ampEnv.render();
filtEnv.render();
osc.render();
var minVal = Math.pow(Math.max((synth.filterEnvelope.min - min) / (max - min), 0), 0.5);
minFilFreq.render(minVal);
var maxVal = Math.pow(Math.max((synth.filterEnvelope.max - min) / (max - min), 0), 0.5);
maxFilFreq.render(maxVal);
}
2014-10-01 02:49:48 +00:00
setPreset("CoolGuy");
2014-09-02 04:25:38 +00:00
</script>
2014-09-02 04:25:38 +00:00
<style type="text/css">
#Content {
width: 350px;
}
#tabs {
height: 300px;
}
.Slider {
width: 80%;
margin-left: 10%;
margin-top: 10px;
}
.Oscillator {
width: 80%;
margin-left: 10%;
2014-09-02 16:15:20 +00:00
margin-top: 40px;
2014-09-02 04:25:38 +00:00
}
.Envelope {
margin: auto;
}
2014-09-02 16:15:20 +00:00
#Keyboard {
2014-09-02 04:25:38 +00:00
background-color: black;
}
2014-09-02 16:15:20 +00:00
#presets .DropDown {
margin: auto;
margin-top: 50px;
}
2014-09-02 04:25:38 +00:00
</style>
</body>
</html>