1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > libharmony</ title >
6
+ <!-- Bootstrap -->
7
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css " integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u " crossorigin ="anonymous ">
8
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css " integrity ="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp " crossorigin ="anonymous ">
9
+ </ head >
10
+ < body >
11
+ < div class ="jumbotron ">
12
+ < div class ="container ">
13
+ < h1 > libharmony</ h1 >
14
+ < h3 > musical computation made easy</ h3 >
15
+ </ div >
16
+ </ div >
17
+
18
+ < div class ="container ">
19
+ < p >
20
+ Harmony is a DSL for music. It's written in Kotlin and supports JVM and JS compilation targets.
21
+ Harmony is licensed under the LGPL, so use it in your proprietary project and acknowledge us! Also
22
+ feel free to < a href ="https://github.com/jonlatane/libharmony "> fork or contribute</ a > .
23
+ </ p >
24
+ < p >
25
+ Here's an example of what the Harmony library is capable of (you'll need a modern browser here):
26
+ </ p >
27
+ < div class ="row ">
28
+ < div class ="col-sm-6 ">
29
+ < h4 > Input</ h4 >
30
+ < p >
31
+ < input type ="text " value ="C "/>
32
+ </ p >
33
+ < p >
34
+ < input type ="text " value ="E "/>
35
+ </ p >
36
+ < p >
37
+ < input type ="text " value ="G "/>
38
+ </ p >
39
+ < p >
40
+ < input type ="text " value =""/>
41
+ </ p >
42
+ < p >
43
+ < input type ="text " value =""/>
44
+ </ p >
45
+ < p >
46
+ < input type ="text " value =""/>
47
+ </ p >
48
+ < p >
49
+ < input type ="text " value =""/>
50
+ </ p >
51
+ </ div >
52
+ < div class ="col-sm-6 ">
53
+ < h4 > Output</ h4 >
54
+ < div id ="example-results "> </ div >
55
+ </ div >
56
+ </ div >
57
+ </ div >
58
+
59
+ < script type ="text/javascript " src ="dist/web/kotlin.js "> </ script >
60
+ < script type ="text/javascript " src ="dist/web/libharmony-0.2.js "> </ script >
61
+ < script type ="text/javascript ">
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 ( ) ;
90
+ </ script >
91
+ </ body >
92
+ </ html >
0 commit comments