Tone.js/examples/duoSynth.html

241 lines
6.3 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
2014-09-02 20:57:46 +00:00
<html>
<head>
<meta charset="utf-8">
2014-09-02 20:57:46 +00:00
<title>DUOSYNTH</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 20:57:46 +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 20:57:46 +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>
2014-09-02 20:57:46 +00:00
</head>
<body>
<div id="Container">
<div id="Explanation">
DuoSynth
2014-09-02 20:57:46 +00:00
<br>
<br>
DuoSynth is a monophonic synthesizer composed of two MonoSyths in parellel.
2014-09-02 20:57:46 +00:00
</div>
<div id="Content">
<div id="tabs">
<ul>
<li><a href="#envelope0">Osc 0</a></li>
<li><a href="#filter0">Filt 0</a></li>
<li><a href="#envelope1">Osc 1</a></li>
<li><a href="#filter1">Filt 1</a></li>
2014-09-03 18:53:05 +00:00
<li><a href="#presets">Global</a></li>
2014-09-02 20:57:46 +00:00
</ul>
<div id="envelope0">
</div>
<div id="filter0">
</div>
<div id="envelope1">
</div>
<div id="filter1">
</div>
<div id="presets">
</div>
</div>
</div>
</div>
<script type="text/javascript">
/* globals Tone, GUI, QwertyHancock */
var synth = new Tone.DuoSynth();
synth.setVolume(-10);
synth.toMaster();
// GUI //
new GUI.TopBar(Tone);
$("#tabs").tabs();
var content = $("#Content");
var envelope0 = $("#envelope0");
var envelope1 = $("#envelope1");
var filter0 = $("#filter0");
var filter1 = $("#filter1");
var presets = $("#presets");
//osc 0
var ampEnv0 = new GUI.Envelope(envelope0, synth.voice0.envelope, "amplitude");
2014-10-01 02:49:48 +00:00
var osc0 = new GUI.OmniOscillator(envelope0, synth.voice0.oscillator, "oscillator");
2014-09-02 20:57:46 +00:00
var osc0Vol = new GUI.Slider(envelope0, function(val){
var vol = synth.gainToDb(val);
synth.voice0.setVolume(vol);
return vol;
}, 1, "volume", "db");
//osc 1
var ampEnv1 = new GUI.Envelope(envelope1, synth.voice1.envelope, "amplitude");
2014-10-01 02:49:48 +00:00
var osc1 = new GUI.OmniOscillator(envelope1, synth.voice1.oscillator, "oscillator");
2014-09-02 20:57:46 +00:00
var osc1Vol = new GUI.Slider(envelope1, function(val){
var vol = synth.gainToDb(val);
synth.voice1.setVolume(vol);
return vol;
}, 1, "volume", "db");
//filt 0
var min = 20;
var max = 20000;
var filtEnv0 =new GUI.Envelope(filter0, synth.voice0.filterEnvelope, "filter");
var minFilFreq0 = new GUI.Slider(filter0, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.voice0.filterEnvelope.setMin(scaled);
2014-09-02 20:57:46 +00:00
return scaled;
}, min, "start freq", "hz");
var maxFilFreq0 = new GUI.Slider(filter0, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.voice0.filterEnvelope.setMax(scaled);
2014-09-02 20:57:46 +00:00
return scaled;
}, min, "end freq", "hz");
//filt 1
var filtEnv1 =new GUI.Envelope(filter1, synth.voice1.filterEnvelope, "filter");
var minFilFreq1 = new GUI.Slider(filter1, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.voice1.filterEnvelope.setMin(scaled);
2014-09-02 20:57:46 +00:00
return scaled;
}, min, "start freq", "hz");
var maxFilFreq1 = new GUI.Slider(filter1, function(val){
var freq = Math.pow(val, 2);
var scaled = freq * (max - min) + min;
synth.voice1.filterEnvelope.setMax(scaled);
2014-09-02 20:57:46 +00:00
return scaled;
}, min, "end freq", "hz");
2014-09-03 18:53:05 +00:00
//global
var harmonicity = new GUI.Slider(presets, function(val){
var scaled = val * 10;
synth.setHarmonicity(scaled);
return scaled;
}, 1, "harmonicity");
var vibratoAmount = new GUI.Slider(presets, function(val){
synth.setVibratoAmount(val);
return val;
}, 1, "vibrato amount");
var vibratoRate = new GUI.Slider(presets, function(val){
synth.setVibratoRate(val * 10);
return val * 10;
}, 1, "vibrato rate");
2014-09-02 20:57:46 +00:00
var allPresets = [];
2014-09-04 23:13:55 +00:00
for (var name in synth.preset){
2014-09-02 20:57:46 +00:00
allPresets.push(name);
}
2014-09-03 18:53:05 +00:00
$("<div>", {"id" : "PresetText"}).appendTo(presets).text("presets:");
2014-09-02 20:57:46 +00:00
new GUI.DropDown(presets, allPresets, function(name){
setPreset(name);
});
//keyboard
$("<div>", {"id" : "Keyboard"}).appendTo(content);
var keyboard = new QwertyHancock({
id: "Keyboard",
width: 400,
height: 75,
octaves: 2,
startNote: "A3",
whiteNotesColour: "white",
blackNotesColour: "black",
hoverColour: "#f3e939"
});
keyboard.keyDown = function(note, freq){
synth.triggerAttack(freq);
};
keyboard.keyUp = function(){
synth.triggerRelease();
};
function setPreset(name){
synth.setPreset(name);
2014-09-04 23:13:55 +00:00
var preset = synth.preset[name];
2014-09-02 20:57:46 +00:00
ampEnv0.render();
ampEnv1.render();
osc0.render();
osc0Vol.render(synth.dbToGain(preset.voice0.volume));
2014-09-02 20:57:46 +00:00
osc1.render();
osc1Vol.render(synth.dbToGain(preset.voice1.volume));
2014-09-02 20:57:46 +00:00
filtEnv0.render();
var minVal0 = Math.pow(Math.max((synth.voice0.filterEnvelope.min - min) / (max - min), 0), 0.5);
minFilFreq0.render(minVal0);
var maxVal0 = Math.pow(Math.max((synth.voice0.filterEnvelope.max - min) / (max - min), 0), 0.5);
maxFilFreq0.render(maxVal0);
filtEnv1.render();
var minVal1 = Math.pow(Math.max((synth.voice1.filterEnvelope.min - min) / (max - min), 0), 0.5);
minFilFreq1.render(minVal1);
var maxVal1 = Math.pow(Math.max((synth.voice1.filterEnvelope.max - min) / (max - min), 0), 0.5);
maxFilFreq1.render(maxVal1);
2014-09-03 18:53:05 +00:00
harmonicity.render(preset.harmonicity / 10);
vibratoAmount.render(preset.vibratoAmount);
vibratoRate.render(preset.vibratoRate / 10);
2014-09-02 20:57:46 +00:00
}
2014-09-04 23:13:55 +00:00
setPreset("Steely");
2014-09-02 20:57:46 +00:00
</script>
<style type="text/css">
#Content {
width: 400px;
}
#tabs {
height: 300px;
}
.Slider {
width: 80%;
margin-left: 10%;
margin-top: 10px;
}
.Oscillator {
width: 80%;
margin-left: 10%;
margin-top: 10px;
}
#envelope1 .Oscillator {
margin-top: 10px;
}
.Envelope {
margin: auto;
}
#Keyboard {
background-color: black;
}
2014-09-03 18:53:05 +00:00
#presets #PresetText {
width: 100%;
text-align: center;
margin-top: 20px;
}
2014-09-02 20:57:46 +00:00
#presets .DropDown {
margin: auto;
2014-09-03 18:53:05 +00:00
margin-top: 5px;
2014-09-02 20:57:46 +00:00
}
</style>
</body>
</html>