<script>
$(document).ready(function() {
$("body").on("contextmenu", function(e) {
return false;
});
});
</script>
<?xml version="1.0" encoding="UTF-8"?>
<svg width="100%" height="100%" viewBox="0 0 12500 6000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>08 Chord buttons I</title>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Rectangle" fill="#000000" x="0" y="0" width="12500" height="6000"></rect>
<g id="Background" transform="translate(1000.000000, 2000.000000)" stroke-linejoin="round" stroke-width="75">
<rect id="JIminB" stroke="#577590" fill="#577590" x="6462.5" y="1962.5" width="1075" height="1075"></rect>
<rect id="JIminArpB" stroke="#577590" fill="#577590" x="-37.5" y="1962.5" width="1075" height="1075"></rect>
<rect id="JImajB" stroke="#F9C74F" fill="#F9C74F" x="6462.5" y="-37.5" width="1075" height="1075"></rect>
<rect id="JImajArpB" stroke="#F9C74F" fill="#F9C74F" x="-37.5" y="-37.5" width="1075" height="1075"></rect>
</g>
<g id="Keys" transform="translate(925.000000, 1925.000000)" fill="#000000" fill-opacity="0">
<rect id="JImin" x="6500" y="2000" width="1150" height="1150"></rect>
<rect id="JIminArp" x="0" y="2000" width="1150" height="1150"></rect>
<rect id="JImaj" x="6500" y="0" width="1150" height="1150"></rect>
<rect id="JImajArp" x="0" y="0" width="1150" height="1150"></rect>
</g>
<g id="Text" transform="translate(1000.000000, 700.000000)" fill="#FFFFFF" font-family="AvenirNext-Regular, Avenir Next" font-size="450" font-weight="normal">
<text id="Ratios-Maj">
<tspan x="1359.575" y="1950">Ratios: 1/1 - 5/4 - 3/2</tspan>
</text>
<text id="Ratios-Min">
<tspan x="1359.575" y="3950">Ratios: 1/1 - 6/5 - 3/2</tspan>
</text>
<text id="Minor-triad">
<tspan x="7866.9" y="3950">Minor triad</tspan>
</text>
<text id="Major-triad">
<tspan x="7877.25" y="1950">Major triad</tspan>
</text>
<text id="Play-notes">
<tspan x="0" y="450">Play notes</tspan>
</text>
<text id="Play-chord">
<tspan x="6500" y="450">Play chord</tspan>
</text>
</g>
</g>
</svg>
body {
background-color: #000000;
font-family: Avenir next;
font-size: 100%;
user-select: none;
touch-action: none;
}
svg{
display:block;
position: absolute;
z-index:0;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
touch-action: none;
background-color: #000000;
}
/* Portrait orientation */
/*
@media screen and (orientation: portrait) {
button{
display: block;
position: absolute;
background-color:#000000;
font-family: avenir next;
border-radius: 2px;
border-width: 2px;
border-style: solid;
user-select: none;
height: 7%;
width: 17%;
right: 2%;
z-index: 3;
font-size: 2vw
}
}
*/
/* Landscape orientation */
/*@media screen and (orientation: landscape) {*/
button{
display: block;
position: absolute;
background-color:#000000;
font-family: avenir next;
border-radius: 4px;
border-width: 2px;
border-style: solid;
user-select: none;
height: 10%;
width: 15%;
right: 2%;
z-index: 3;
font-size: 2.5vw
}
/*}*/
.ActiveButton {
color: #000000;
background-color: #577590;
border-color: #577590;
}
.OtherButton {
color: #577590;
background-color: #000000;
border-color: #577590;
}
#PureButton {
top: 35%;
left: 10%
}
#ReducedButton{
top: 55%;
left: 10%
}
#SelectorText{
display: none;
position: absolute;
left: 5%;
top: 8%;
color: #ffffff;
z-index: 5
}
// General
console.clear();
var elem = document.documentElement;
const baseFreq = 261.63
var root = baseFreq
var transpose=0
var voice = 0
var maxVoices = 4
var KeyArray = []
let index
//*** initialize tone.js synth ***
// core synthesizer
const voice1 = new Tone.Synth({oscillator: {type:"triangle"},
envelope: { attack : 0.05, decay : 3.50, sustain : 1, release : 7.5},
volume: -12});
const voice2 = new Tone.Synth({oscillator: {type:"triangle"},
envelope: { attack : 0.05, decay : 3.50, sustain : 1, release : 7.5},
volume: -12});
const voice3 = new Tone.Synth({oscillator: {type:"triangle"},
envelope: { attack : 0.05, decay : 3.50, sustain : 1, release : 7.5},
volume: -12});
const voice4 = new Tone.Synth({oscillator: {type:"triangle"},
envelope: { attack : 0.05, decay : 3.50, sustain : 1, release : 7.5},
volume: -12});
const reverb = new Tone.Reverb({wet:0.5}).toDestination();
Tone.connect(voice1, reverb);
Tone.connect(voice2, reverb);
Tone.connect(voice3, reverb);
Tone.connect(voice4, reverb);
// Interaction mode
let isTouchDevice
var interaction = 'click'
if ((navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)){isTouchDevice = true}
else {isTouchDevice = false}
if (isTouchDevice) {interaction = 'touchstart'}
// Make array of key elements by id
for(var i=0, n=document.getElementsByClassName("key"); i<n.length; i++) {
KeyArray.push(n[i].id);
};
// Trigger notes
//Tone.Transport.start()
function triggerNoteOnOff() {
var index = math.eval(this.id)
synth[voice].triggerAttackRelease(root*index, "32n");
if (voice >= (maxVoices-1)){voice = 0}
else {voice ++}
this.style.fillOpacity=0.75
const key = this.id;
function resetOpacity(key){
document.getElementById(key).style.fillOpacity=0}
setTimeout(function(){resetOpacity(key)}, 200)
}
for (const KeyValue of KeyArray) {
document.getElementById(KeyValue).addEventListener(interaction, triggerNoteOnOff)
}
document.getElementById("JImaj").addEventListener('click', function(){
voice1.triggerAttackRelease(root, "2n");
voice2.triggerAttackRelease(root*eval(5/4), "2n");
voice3.triggerAttackRelease(root*eval(3/2), "2n");
this.style.fillOpacity=0.5
const key = this.id;
function resetOpacity(key){
document.getElementById(key).style.fillOpacity=0}
setTimeout(function(){resetOpacity(key)}, 200)
})
document.getElementById("JImajArp").addEventListener('click', function(){
now = Tone.now()
voice1.triggerAttackRelease(root, "16n", now);
voice2.triggerAttackRelease(root*eval(5/4), "16n", now+0.5);
voice3.triggerAttackRelease(root*eval(3/2), "16n", now+1);
this.style.fillOpacity=0.5
const key = this.id;
function resetOpacity(key){
document.getElementById(key).style.fillOpacity=0}
setTimeout(function(){resetOpacity(key)}, 200)
})
document.getElementById("JImin").addEventListener('click', function(){
voice1.triggerAttackRelease(root, "2n");
voice2.triggerAttackRelease(root*eval(6/5), "2n");
voice3.triggerAttackRelease(root*eval(3/2), "2n");
this.style.fillOpacity=0.5
const key = this.id;
function resetOpacity(key){
document.getElementById(key).style.fillOpacity=0}
setTimeout(function(){resetOpacity(key)}, 200)
})
document.getElementById("JIminArp").addEventListener('click', function(){
now = Tone.now()
voice1.triggerAttackRelease(root, "16n", now);
voice2.triggerAttackRelease(root*eval(6/5), "16n", now+0.5);
voice3.triggerAttackRelease(root*eval(3/2), "16n", now+1);
this.style.fillOpacity=0.5
const key = this.id;
function resetOpacity(key){
document.getElementById(key).style.fillOpacity=0}
setTimeout(function(){resetOpacity(key)}, 200)
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.