-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.html
114 lines (93 loc) · 3.16 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html>
<head>
<script src="js/Tone.min.js"></script>
<script src="js/tune.js"></script>
<script src="js/nexusUI.js"></script>
<script src="js/qwerty-hancock2.js"></script>
<link href='http://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='style2.css'>
</head>
<body>
<h1>Tune.js Demo</h1>
<h2>A Web Audio Microtonal Piano</h2>
<h3>Use your computer keyboard to play</h3>
<div id="keyboard">
</div>
<div id="scales">
<p>Scale:</p>
<canvas nx="select" choices="ji_12,young-lm_piano,partch-barstow,pyth_12,couperin,johnston,bach2,ptolemy,chin_bronze,slendro,xenakis_chrom,partch_43,et-mix6"></canvas><br>
<p id="scaledesc"></p>
</div>
<div id="loading">
Loading Samples...
</div>
<div id="fork">
Visit the <a href="http://abbernie.github.io/tune/scales.html" target="blank">Tune.js Scale Archive</a> for a full list of scales and descriptions.<br>
<a href="http://www.github.com/abbernie/tune">Fork</a> this project on github.
<footer> Tune.js was written by <a href="http://andrewbernstein.tumblr.com">Andrew Bernstein</a> and <a href="http://www.whitechord.org">Ben Taylor</a>.
</div>
</body>
<script>
/*
*
* Interface
*
*/
var keyboard = new QwertyHancock({
id: 'keyboard',
width: 800,
height: 100,
octaves: 2,
startNote: 'c4',
whiteNotesColour: 'white',
blackNotesColour: 'black',
activeColour: '#f00'
});
var gui = document.getElementById('keyboard')
gui.style.margin = '65px auto'
gui.style.padding = '20px'
nx.onload = function(){
select1.on('*',function(){
var scale = select1.val.text;
tune.loadScale(scale);
select1.canvas.blur();
document.getElementById("scaledesc").innerHTML = TuningList[scale].description
});
select1.canvas.selectedIndex = 0;
document.getElementById("scaledesc").innerHTML = TuningList["ji_12"].description
}
var loading = document.getElementById('loading')
loading.style.left = '40%';
loading.style.top = '40%';
loading.style.padding = '50px';
/*
*
*
* AUDIO SYNTHESIS CODE
*
*
*/
// Create a new Tune object
var tune = new Tune();
// Load a 12 tone just intonation scale
tune.loadScale('ji_12');
// Set the output mode to 'MIDI'
tune.mode.output = 'MIDI';
//tune.setKey(69);
var actx = new (AudioContext || wedkitAudioContext)();
var piano = new Tone.Sampler({
"C4":"samples/c4.mp3"
});
piano.toMaster();
Tone.Buffer.onload = function(){
document.getElementById('loading').style.display = 'none';
keyboard.keyDown = function(note, freq) {
var midi = 69 + 12*Math.log(freq/440)/Math.log(2)
piano.triggerAttack("C4");
// Detune each piano sample
piano.pitch = tune.note(midi-tune.scale.length)-tune.key;
};
}
</script>
</html>