-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8674fa
commit 094faf6
Showing
13 changed files
with
192 additions
and
53 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
plugins { | ||
java | ||
kotlin("jvm") version "1.9.21" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":chord-analyzer")) | ||
api(project(":chord-analyzer")) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ repositories { | |
} | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0-RC2") | ||
} |
62 changes: 62 additions & 0 deletions
62
...in/chord-analyzer/src/main/kotlin/com/eimsound/daw/builtin/chordanalyzer/ChordAnalyzer.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.eimsound.daw.builtin.chordanalyzer | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
import kotlinx.coroutines.withContext | ||
import java.io.BufferedReader | ||
import java.io.BufferedWriter | ||
import java.nio.file.Path | ||
import kotlin.io.path.absolutePathString | ||
|
||
data class Chords( | ||
val chords: List<String>, | ||
val durations: List<Float> | ||
) | ||
|
||
interface ChordAnalyzer : AutoCloseable { | ||
suspend fun analyze(chord: List<String>, starts: List<Int>, durations: List<Int>): Chords | ||
} | ||
|
||
class ChordAnalyzerImpl(file: Path) : ChordAnalyzer { | ||
private val mutex = Mutex() | ||
private val input: BufferedReader | ||
private val output: BufferedWriter | ||
private val process = ProcessBuilder(file.absolutePathString(), "chords").run { | ||
redirectError() | ||
start().apply { | ||
input = inputStream.bufferedReader() | ||
output = outputStream.bufferedWriter() | ||
} | ||
} | ||
|
||
override suspend fun analyze(chord: List<String>, starts: List<Int>, durations: List<Int>) = withContext(Dispatchers.IO) { | ||
mutex.withLock { | ||
// val gg = StringWriter() | ||
// val output = BufferedWriter(gg) | ||
output.write("chords_detect\n") | ||
output.write(chord.joinToString(",")) | ||
output.write("\n") | ||
starts.forEachIndexed { i, it -> | ||
if (i != 0) output.write(",") | ||
output.write(it.toString()) | ||
} | ||
output.write("\n") | ||
durations.forEachIndexed { i, it -> | ||
if (i != 0) output.write(",") | ||
output.write(it.toString()) | ||
} | ||
output.write("\n") | ||
output.flush() | ||
// println(gg.buffer.toString()) | ||
// gg.close() | ||
|
||
Chords( | ||
input.readLine().split(","), | ||
input.readLine().split(",").map { it.toFloatOrNull() ?: Float.MAX_VALUE } | ||
) | ||
} | ||
} | ||
|
||
override fun close() { process.destroy() } | ||
} |
13 changes: 13 additions & 0 deletions
13
...rd-analyzer/src/main/kotlin/com/eimsound/daw/builtin/chordanalyzer/GlobalChordAnalyzer.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.eimsound.daw.builtin.chordanalyzer | ||
|
||
import kotlin.io.path.Path | ||
|
||
var chordAnalyzerInitialized = false | ||
private set | ||
val chordAnalyzer: ChordAnalyzer by lazy { | ||
val fallback = if (System.getProperty("os.name").contains("Windows")) "EIMUtils/EIMUtils.exe" | ||
else "EIMUtils/EIMUtils" | ||
ChordAnalyzerImpl(Path(System.getProperty("eim.eimutils.file", fallback))).apply { | ||
chordAnalyzerInitialized = true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
include( | ||
":chord-analyzer" | ||
) | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/EIMHost-MacOS.zip | ||
/EIMHost.app | ||
/EIMHost | ||
|
||
/EIMUtils-MacOS.zip | ||
/EIMUtils |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,4 @@ include( | |
":daw" | ||
) | ||
|
||
includeBuild( | ||
"builtin" | ||
) | ||
includeBuild("builtin") |