function playNote(id) //id format: distortion_atari note index { activeKeyID = id; var dist = activeKeyID.substring(0,activeKeyID.indexOf("_")); var atariIndex = activeKeyID.substring(activeKeyID.indexOf("_")+1); if (atariIndex != "nil") { if (dist == "square") dist = 0; else if (dist == "lead") dist = 1; else if (dist == "saw") dist = 2; else if (dist == "bass") dist = 3; const audio = document.getElementById('sound'); audio.src = "midi/"+noteArray[dist][atariIndex][0]; audio.play(); writeNoteData(dist,atariIndex); } } function writeNoteData(dist,atariIndex) { var nv = noteValue; if (dotted) { nv = 2*noteValue/3; nv = nv.toString().substring(0,nv.toString().indexOf(".")+3); } if (channel == 1) document.createMidiForm.c1_display.value += noteArray[dist][atariIndex][1]+" "+dist+" "+atariIndex+" "+nv+"\n"; else if (channel == 2) document.createMidiForm.c2_display.value += noteArray[dist][atariIndex][1]+" "+dist+" "+atariIndex+" "+nv+"\n"; updateBufferArray(); } function writeRestData(restVal) { if (dotted) { restVal = 2*restVal/3; restVal = restVal.toString().substring(0,restVal.toString().indexOf(".")+3); } if (channel == 1) document.createMidiForm.c1_display.value += "x x x "+restVal+"\n"; else if (channel == 2) document.createMidiForm.c2_display.value += "x x x "+restVal+"\n"; updateBufferArray(); } function disableNils() { var x = document.getElementsByTagName("button"); for (i = 0; i < x.length; i++) { if (x[i].id.match(/nil/)) { x[i].disabled = "disabled"; x[i].style.backgroundColor = "#CCCCCC"; x[i].style.cursor = "default"; } } } function selectNote(val) { var x = document.getElementsByName("note-select"); for (i = 0; i < x.length; i++) { if (Math.pow(2,i) == val) { x[i].disabled = "disabled"; x[i].style.cursor = "default"; } else { x[i].disabled = ""; x[i].style.cursor = "pointer"; } } noteValue = val; } function validateForm() { var x = document.createMidiForm; if (isNaN(Number(x.tempo.value)) || isNaN(parseInt(x.tempo.value)) || x.tempo.value == "0") { x.tempo.value = ""; alert("Invalid tempo"); x.tempo.focus(); } else if (isNaN(Number(x.timesig_num.value)) || isNaN(parseInt(x.timesig_num.value)) || x.timesig_num.value == "0") { x.timesig_num.value = ""; alert("Invalid time signature"); x.timesig_num.focus(); } } function toggleColor() { showColor = !showColor; var x = document.getElementsByName('key'); if (showColor) { for (i = 0; i < x.length; i++) { var dist = x[i].id.substring(0,x[i].id.indexOf("_")); var atariIndex = x[i].id.substring(x[i].id.indexOf("_")+1); if (atariIndex != "nil") { if (dist == "square") dist = 0; else if (dist == "lead") dist = 1; else if (dist == "saw") dist = 2; else if (dist == "bass") dist = 3; x[i].style.backgroundColor = noteArray[dist][atariIndex][8]; } } } else { for (i = 0; i < x.length; i++) { var dist = x[i].id.substring(0,x[i].id.indexOf("_")); var atariIndex = x[i].id.substring(x[i].id.indexOf("_")+1); if (atariIndex != "nil") { if (dist == "square") dist = 0; else if (dist == "lead") dist = 1; else if (dist == "saw") dist = 2; else if (dist == "bass") dist = 3; if (x[i].className.match("wkey")) x[i].style.backgroundColor = "#FFFFFF"; else x[i].style.backgroundColor = "#000000"; } } } } function showFloatingDiv(keyID,e) { activeKeyID = keyID; mouseX = e.clientX-50; mouseY = e.clientY+10; if (mouseX > screen.width-125) mouseX = screen.width-130; else if (mouseX < 5) mouseX = 5; var dist = activeKeyID.substring(0,activeKeyID.indexOf("_")); var atariIndex = activeKeyID.substring(activeKeyID.indexOf("_")+1); if (dist == "square") dist = 0; else if (dist == "lead") dist = 1; else if (dist == "saw") dist = 2; else if (dist == "bass") dist = 3; var x = document.getElementById('floatDiv'); x.style.top = mouseY+"px"; x.style.left = mouseX+"px"; x.style.visibility = "visible"; x.innerHTML = "X"; x.innerHTML += ""+noteArray[dist][atariIndex][1]+"
Pitch: "+atariIndex+"
"; x.innerHTML += "Freq: "+noteArray[dist][atariIndex][3]+" Hz
"; if (noteArray[dist][atariIndex][4] > 0) x.innerHTML += "Error: +"+noteArray[dist][atariIndex][4]+""; else x.innerHTML += "Error: "+noteArray[dist][atariIndex][4]+""; for (i = 0; i < 32; i++) { if (i != atariIndex) if (noteArray[dist][atariIndex][1] == noteArray[dist][i][1]) //two pitches with same note name { x.innerHTML += "
Exchange"; break; } } } function exchange() { var dist = activeKeyID.substring(0,activeKeyID.indexOf("_")); var atariIndex = activeKeyID.substring(activeKeyID.indexOf("_")+1); if (dist == "square") dist = 0; else if (dist == "lead") dist = 1; else if (dist == "saw") dist = 2; else if (dist == "bass") dist = 3; for (j = 0; j < 32; j++) if (j != atariIndex && noteArray[dist][atariIndex][1] == noteArray[dist][j][1]) { document.getElementById(activeKeyID).id = dist+"_"+j; activeKeyID = dist+"_"+j; atariIndex = j; break; } //update floating div var x = document.getElementById('floatDiv'); x.style.top = mouseY+"px"; x.style.left = mouseX+"px"; x.style.visibility = "visible"; x.innerHTML = "X"; x.innerHTML += ""+noteArray[dist][atariIndex][1]+"
Pitch: "+atariIndex+"
"; x.innerHTML += "Freq: "+noteArray[dist][atariIndex][3]+" Hz
"; if (noteArray[dist][atariIndex][4] > 0) x.innerHTML += "Error: +"+noteArray[dist][atariIndex][4]; else x.innerHTML += "Error: "+noteArray[dist][atariIndex][4]; x.innerHTML += "
Exchange"; //change color, if necessary if (showColor) { showColor = !showColor; toggleColor(); } } function showFAQ() { document.getElementById('faq').style.visibility = "visible"; document.getElementById('faq').style.top = "50px"; document.getElementById('faq').style.left = "50px"; document.getElementById('faq').style.width = "910px"; document.getElementById('faq').style.height = "500px"; } function updateBufferArray() { bufferArray[0][bufferCount] = document.getElementById('c1_display').value; bufferArray[1][bufferCount] = document.getElementById('c2_display').value; bufferCount++; } function undoLastKeypress() { if (bufferCount >= bufferMin) { document.getElementById('c1_display').value = bufferArray[0][bufferCount-2].toString(); document.getElementById('c2_display').value = bufferArray[1][bufferCount-2].toString(); bufferCount--; } } function hideFAQ() {document.getElementById('faq').style.visibility = "hidden";} function clearChannelData(x) {document.getElementById("c"+x.toString()+"_display").value = "";} function setDotted() {dotted = !dotted;} function toggleChannel(c) {channel = c;} function hideFloatingDiv() {document.getElementById('floatDiv').style.visibility = "hidden";}