Skip to content

Commit 221abdc

Browse files
author
Jon Latane
committedApr 3, 2017
Final improvements
1 parent bcfc2f6 commit 221abdc

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
 

‎dist/web/libharmony-0.2.js

-3
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,6 @@ this['libharmony-0.2'] = function (Kotlin) {
11721172
var data = _.com.jonlatane.libharmony.Chord.Companion.guessCharacteristic_frz5om$(c, n);
11731173
var name = data.first;
11741174
var score = data.second;
1175-
if (n === c.root.tone) {
1176-
score += 1000;
1177-
}
11781175
var bucket = result.get_za3rmp$(score);
11791176
if (bucket == null) {
11801177
bucket = Kotlin.kotlin.collections.mutableListOf_9mqe4v$([]);

‎index.html

+30-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h3>musical computation made easy</h3>
2222
feel free to <a href="https://github.com/jonlatane/libharmony">fork or contribute</a>.
2323
</p>
2424
<p>
25-
Here's an example of what the Harmony library is capable of:
25+
Here's an example of what the Harmony library is capable of (you'll need a modern browser here):
2626
</p>
2727
<div class="row">
2828
<div class="col-sm-6">
@@ -51,14 +51,42 @@ <h4>Input</h4>
5151
</div>
5252
<div class="col-sm-6">
5353
<h4>Output</h4>
54+
<div id="example-results"></div>
5455
</div>
5556
</div>
5657
</div>
5758

5859
<script type="text/javascript" src="dist/web/kotlin.js"></script>
5960
<script type="text/javascript" src="dist/web/libharmony-0.2.js"></script>
6061
<script type="text/javascript">
61-
var libharmony = this["libharmony-0.2"].com.jonlatane.libharmony;
62+
var libharmony = window["libharmony-0.2"].com.jonlatane.libharmony;
63+
var resultDiv = document.getElementById('example-results');
64+
var blah;
65+
function getChord() {
66+
let notes = Array.from(document.querySelectorAll('input')).
67+
filter((input) => input.value).
68+
map((input) => input.value);
69+
let result = null;
70+
try {
71+
result = libharmony.getChordsInCMajor(notes);
72+
} catch(e) {
73+
resultDiv.innerHTML = '<div class="alert alert-danger">Invalid input</div>';
74+
}
75+
if(result) {
76+
blah = result;
77+
let scores = Object.keys(result.bucketsByHash).sort((a,b) => b-a);
78+
let resultHTML = '';
79+
scores.forEach((score) => {
80+
let size = 1 + 3*(score/50);
81+
result.bucketsByHash[score].entries[0][1].array.forEach((chord) => {
82+
resultHTML += `<p style="font-size: ${size}em">${chord}</p>`;
83+
});
84+
});
85+
resultDiv.innerHTML = resultHTML;
86+
}
87+
}
88+
Array.from(document.querySelectorAll('input')).forEach((input) => input.onkeyup = getChord);
89+
getChord();
6290
</script>
6391
</body>
6492
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.