react-native-simple-note-pitch-detector 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,6 +14,12 @@ import kotlin.math.round
|
|
|
14
14
|
|
|
15
15
|
class PitchAnalyzer {
|
|
16
16
|
|
|
17
|
+
var callback: (String) -> Unit
|
|
18
|
+
|
|
19
|
+
constructor(callback: (String) -> Unit) {
|
|
20
|
+
this.callback = callback
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
private val tones = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
|
|
18
24
|
|
|
19
25
|
private var dispatcher: AudioDispatcher? = null
|
|
@@ -38,10 +44,12 @@ class PitchAnalyzer {
|
|
|
38
44
|
|
|
39
45
|
if (!index.isNaN() && pitchInHz > 0) {
|
|
40
46
|
val tone = tones[index.toInt()]
|
|
41
|
-
val data: WritableMap = WritableNativeMap()
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
data
|
|
48
|
+
this.callback(tone)
|
|
49
|
+
// val data: WritableMap = WritableNativeMap()
|
|
50
|
+
//
|
|
51
|
+
// data.putDouble("frequency", pitchInHz.toDouble())
|
|
52
|
+
// data.putString("tone", tone)
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
|
|
@@ -3,10 +3,10 @@ package expo.modules.simplenotepitchdetector
|
|
|
3
3
|
import expo.modules.kotlin.modules.Module
|
|
4
4
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
5
|
import expo.modules.simplepitchdetector.PitchAnalyzer
|
|
6
|
+
import androidx.core.os.bundleOf
|
|
6
7
|
|
|
7
8
|
class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
8
9
|
|
|
9
|
-
private val pitchAnalyzer = PitchAnalyzer()
|
|
10
10
|
|
|
11
11
|
override fun definition() = ModuleDefinition {
|
|
12
12
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
@@ -14,6 +14,12 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
14
14
|
Events("onChange")
|
|
15
15
|
|
|
16
16
|
Function("hello") {
|
|
17
|
+
val pitchAnalyzer = PitchAnalyzer {
|
|
18
|
+
this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
|
|
19
|
+
"onChange",
|
|
20
|
+
bundleOf("tone" to it)
|
|
21
|
+
)
|
|
22
|
+
}
|
|
17
23
|
pitchAnalyzer.start()
|
|
18
24
|
}
|
|
19
25
|
}
|