-
-
Save battaglia01/0554f26ab7faea367a66a8e2267aac41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div style="float:right; padding: 0 1em; font-size: x-small; color: grey;">Version 0.7</div> | |
<!-- Wolf Peuker 2013-07-09 --> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
function MultipleCharsBy(ch, count) | |
{ | |
var result = ch; | |
for (var i=1; i<count; ++i) | |
result += ch; | |
return result; | |
} | |
function format(f, digs, width) | |
{ | |
if (typeof digs == 'undefined') digs=3; | |
if (typeof width == 'undefined') width=1; | |
var vorkomma = width -1 -digs; | |
var space = MultipleCharsBy('#', width); | |
var zeros = MultipleCharsBy('0', digs); | |
var factor = Math.round(Math.pow(10, digs)); | |
var zahl = String(Math.floor((f*factor)+0.5)/factor); | |
var kpos = zahl.indexOf('.'); | |
if (kpos == -1) { | |
if (digs > 0) { | |
kpos = zahl.length; | |
zahl += '.0'; | |
} | |
} | |
zahl = space.substring(0, vorkomma-kpos)+zahl; | |
zahl = zahl+zeros.substring(0, width-zahl.length); | |
zahl = zahl.replace(/#/g, " "); | |
return zahl; | |
} | |
function purdals(opart) | |
{ | |
return 9900.0*opart; | |
} | |
function cents(opart) | |
{ | |
return 1200.0*opart; | |
} | |
function millioctaves(opart) | |
{ | |
return 1000.0*opart; | |
} | |
function convert() | |
{ | |
var inputval = document.getElementById("number").value; | |
var notation = "Unknown notation"; | |
var text = ''; | |
var val = ''; | |
var fval | |
if (inputval.match(/^\s*\d+(\.\d*)?\s*$/) || inputval.match(/^\s*\.\d+?$\s*/)) { | |
notation = "Decimal notation"; | |
val = parseFloat(inputval.match(/(\S+)/)); | |
} else { | |
var rval = inputval.match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/); | |
if (rval) { | |
notation = "Fractional notation"; | |
if (rval.length == 3) { | |
var num = parseInt(rval[1]); | |
var den = parseInt(rval[2]); | |
if (den != 0) { | |
if (num != 0) { | |
val = 1.0*num/den; | |
} else { | |
text += "Error: numerator must be a positive number.\n <br/>"; | |
} | |
} else { | |
text += "Error: denominator must be a positive number.\n <br/>"; | |
val = num; | |
} | |
} | |
} else { | |
var pval = inputval.match(/^\s*(\d+)\s*\\\s*(\d+)\s*$/); | |
if (pval) { | |
notation = "EDO degree notation"; | |
if (pval.length == 3) { | |
var num = parseInt(pval[1]); | |
var den = parseInt(pval[2]); | |
if (den != 0) { | |
e = num/den; | |
val = Math.pow(2, e); | |
} else { | |
text += "Error: denominator must be a positive number.\n <br/>"; | |
val = num; | |
} | |
} | |
} else { | |
var gval = inputval.match(/^\s*(\d+)\s*\\\s*(\d+)\s*[Ee][Dd]\s*(\d+)\s*$/); | |
if (gval) { | |
notation = "Generic ED* degree notation"; | |
if (gval.length == 4) { | |
var num = parseInt(gval[1]); | |
var den = parseInt(gval[2]); | |
var ed = parseInt(gval[3]); | |
if (ed > 0) { | |
if (den != 0) { | |
e = num/den; | |
val = Math.pow(ed, e); | |
} else { | |
text += "Error: denominator must be a positive number.\n <br/>"; | |
val = num; | |
} | |
} else { | |
text += "Error: ed must be followed by a positive number. <br/>"; | |
} | |
} | |
} | |
} | |
} | |
} | |
function mkRef(addr, text) { | |
var prefix = "http://xenharmonic.wikispaces.com/"; | |
return '<a href="'+prefix+addr+'">'+text+'<\/a>'; | |
} | |
// var lval = Math.log(val)/log(2); | |
text += notation+" <br/>"; | |
var result = "???"; | |
if (val != '') { | |
if (val == 0.0) { | |
result = "zero ???"; | |
} | |
var lval = Math.log(val)/Math.log(2); | |
var digits = document.getElementById("precision").selectedIndex; | |
result = format(purdals(lval), digits); | |
text += "Decimal value: "+format(val, 8)+" <br/>" | |
text += "Log2: "+format(lval, 8)+" <br/>" | |
text += mkRef("Cent","Cents")+": "+format(cents(lval), digits+2)+" <br/>"; | |
text += mkRef("Millioctave","Millioctaves")+": "+format(millioctaves(lval), digits+2)+" <br/>"; | |
text += mkRef("Microtone","Microtones (µt)")+": "+format(lval*5884949.1923617, 0); | |
} else { | |
text = "Unknown Notation"; | |
} | |
document.getElementById("result").innerHTML = "Purdals: "+result; | |
document.getElementById("details").innerHTML = text; | |
} | |
//]]> | |
</script> | |
<div style="border: 1px black; padding: 1em; background-color: #d9d8ed;"><img style="float:right;" src="http://purdal.wikispaces.com/file/view/g3803.png/438779918/g3803.png" /> <b>Please input an expression for the interval.</b><br /> | |
<small>These notations are currently supported:</small> | |
<ul> | |
<li><small>Fractional: 3/2, 7 /6, 5/ 6</small></li> | |
<li><small>EDO degrees: 7\12, 1\ 17, 3 \17</small></li> | |
<li><small>Generic ED* degrees: 7\19 ed 3, 11\19 ED2, 11\53ed7</small></li> | |
<li><small>Decimal: 1, 1.5, 0.7, .9</small></li> | |
</ul> | |
<div style="float:right;">precision: <select id="precision" name="precision" onclick="convert()"> | |
<option value="0">0</option> | |
<option value="1" selected="selected">1</option> | |
<option value="2">2</option> | |
<option value="3">3</option> | |
<option value="4">4</option> | |
</select> (decimal digits)</div> | |
<p><input id="number" name="number" value="3/2" onchange="convert()" /><input type="button" value="Go!" onclick="convert()" /></p> | |
<big><span id="result">results</span></big><br /> | |
<div id="details" style=" border: gray solid 1px; background-color: #eee; font-family: monospace; font-size: smaller; margin: 1em 0; padding: 1em 1em">details</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment