@@ -22,7 +22,7 @@ <h3>musical computation made easy</h3>
22
22
feel free to < a href ="https://github.com/jonlatane/libharmony "> fork or contribute</ a > .
23
23
</ p >
24
24
< 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) :
26
26
</ p >
27
27
< div class ="row ">
28
28
< div class ="col-sm-6 ">
@@ -51,14 +51,42 @@ <h4>Input</h4>
51
51
</ div >
52
52
< div class ="col-sm-6 ">
53
53
< h4 > Output</ h4 >
54
+ < div id ="example-results "> </ div >
54
55
</ div >
55
56
</ div >
56
57
</ div >
57
58
58
59
< script type ="text/javascript " src ="dist/web/kotlin.js "> </ script >
59
60
< script type ="text/javascript " src ="dist/web/libharmony-0.2.js "> </ script >
60
61
< 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 ( ) ;
62
90
</ script >
63
91
</ body >
64
92
</ html >
0 commit comments