Skip to content

Commit bcfc2f6

Browse files
author
Jon Latane
committedApr 3, 2017
Some nice stuff
1 parent 7bb3c9c commit bcfc2f6

File tree

11 files changed

+1145
-51
lines changed

11 files changed

+1145
-51
lines changed
 

‎dist/web/libharmony-0.2.js

+1,100-36
Large diffs are not rendered by default.

‎dist/web/libharmony-0.2.meta.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ <h3>musical computation made easy</h3>
1818
<div class="container">
1919
<p>
2020
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!
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>.
2223
</p>
2324
<p>
2425
Here's an example of what the Harmony library is capable of:

‎javascript/build.gradle

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
buildscript {
22
ext.kotlin_version = '1.0.7'
3+
ext.kotlin_js_version = '1.0.7'
34

45
repositories {
56
mavenCentral()
@@ -11,8 +12,14 @@ buildscript {
1112

1213
apply plugin: 'kotlin2js'
1314

15+
repositories {
16+
maven {
17+
url 'https://dl.bintray.com/kotlin/kotlin-dev/'
18+
}
19+
}
20+
1421
dependencies {
15-
compile "org.jetbrains.kotlin:kotlin-js-library:$kotlin_version"
22+
compile "org.jetbrains.kotlin:kotlin-js-library:$kotlin_js_version"
1623
}
1724

1825
compileKotlin2Js {
@@ -32,7 +39,7 @@ compileKotlin2Js {
3239
into "${rootProject.projectDir}/dist/web"
3340
include { fileTreeElement ->
3441
def path = fileTreeElement.path
35-
path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
42+
path.endsWith('.js') && (path.startsWith('META-INF/resources/') || !path.startsWith('META-INF/'))
3643
}
3744
}
3845
}

‎javascript/src/main/kotlin/com/jonlatane/libharmony/KotlinJSCompat.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package com.jonlatane.libharmony
55

66
fun String.toInt() = parseInt(this)
77

8-
@native fun Char.isDigit(): Boolean {
8+
fun Char.isDigit(): Boolean {
99
try {
1010
parseInt(this.toString())
1111
return true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.jonlatane.libharmony
2+
3+
/**
4+
* Things that are handy to have in JS for testing purposes.
5+
*
6+
* Created by jonlatane on 4/3/17.
7+
*/
8+
@JsName("getChordsInCMajor")
9+
fun getChordsInCMajor(vararg notes: String): Map<Int, List<String>> {
10+
val pitches = notes.toList().map {Pitch(it)}.toTypedArray()
11+
val chord = Chord(*pitches)
12+
val data = Keys.CMajor.getRootLikelihoodsAndNames(chord)
13+
return data
14+
}

‎jvm/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ jar {
2525
sourceSets {
2626
main.kotlin.srcDirs += 'src/main/kotlin'
2727
main.kotlin.srcDirs += '../shared/src/main/kotlin'
28+
test.kotlin.srcDirs += 'src/main/kotlin'
29+
test.kotlin.srcDirs += 'src/test/kotlin'
30+
test.kotlin.srcDirs += '../shared/src/test/kotlin'
2831
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.jonlatane.libharmony
22

3+
/**
4+
* Kotlin's JVM standard library does not include a JSName annotation.
5+
*/
36
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION,
47
AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION)
5-
annotation class native
8+
annotation class JsName(val name: String)

‎shared/src/main/kotlin/com/jonlatane/libharmony/Chord.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.jonlatane.libharmony.Modulus.Companion.TWELVETONE
2323
* *
2424
* @getCharacteristic and @guessCharacteristic, for guessing the characteristic of a chord
2525
*/
26-
@native open class Chord(vararg elements: Pitch) : PitchSet(Modulus.TWELVETONE, *elements) {
26+
open class Chord(vararg elements: Pitch) : PitchSet(Modulus.TWELVETONE, *elements) {
2727
var root: Pitch = elements.elementAtOrElse(0, {Pitch(0)})
2828
override fun toString(): String {
2929
return super.toString() + " / $root"
@@ -123,7 +123,7 @@ import com.jonlatane.libharmony.Modulus.Companion.TWELVETONE
123123
* *
124124
* @return
125125
*/
126-
@native fun guessCharacteristic(c: Chord, root: Int): Pair<String, Int> {
126+
fun guessCharacteristic(c: Chord, root: Int): Pair<String, Int> {
127127
var name = ""
128128
var certainty = 0
129129

‎shared/src/main/kotlin/com/jonlatane/libharmony/Key.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.jonlatane.libharmony.Modulus.Companion.TWELVETONE
1212
1313
* @author Jon
1414
*/
15-
@native class Key(root: Pitch) : Scale(root) {
15+
class Key(root: Pitch) : Scale(root) {
1616
constructor(scale: Scale) : this(scale.root) {
1717
addAll(scale)
1818
}
@@ -41,7 +41,7 @@ import com.jonlatane.libharmony.Modulus.Companion.TWELVETONE
4141
* *
4242
* @return
4343
*/
44-
@native fun getNoteName(tone: Int): String {
44+
fun getNoteName(tone: Int): String {
4545
val i: Int = tone % modulus!!
4646
var result = ""
4747

@@ -101,15 +101,15 @@ import com.jonlatane.libharmony.Modulus.Companion.TWELVETONE
101101
return result
102102
}
103103

104-
@native fun getRootLikelihoodsAndNames(c: Chord): Map<Int, List<String>> {
104+
fun getRootLikelihoodsAndNames(c: Chord): Map<Int, List<String>> {
105105
val result = mutableMapOf<Int, MutableList<String>>()
106106
for (n in 0..11) {
107107
val data = Chord.guessCharacteristic(c, n)
108108
val name = data.first
109-
var score = data.second
110-
if (n == c.root.tone) {
111-
score += 1000
112-
}
109+
val score = data.second
110+
//if (n == c.root.tone) {
111+
// score += 1000
112+
//}
113113
var bucket: MutableList<String>? = result[score]
114114
if (bucket == null) {
115115
bucket = mutableListOf<String>()

‎shared/src/main/kotlin/com/jonlatane/libharmony/Pitch.kt

+2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import com.jonlatane.libharmony.Pitch.Companion.getTone
1414
*
1515
* Created by jonlatane on 12/17/16.
1616
*/
17+
@JsName("Pitch")
1718
data class Pitch(
1819
val tone: Int,
1920
val enharmonic: String? = null
2021
) {
2122
/**
2223
* Convenience constructor from enharmonic only based on [getTone]
2324
*/
25+
@JsName("PitchFromEnharmonic")
2426
constructor(enharmonic: String) : this(getTone(enharmonic), enharmonic)
2527

2628
init {

0 commit comments

Comments
 (0)
Please sign in to comment.