react-native-simple-note-pitch-detector 0.1.5 → 0.1.6

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,10 +14,10 @@ import kotlin.math.round
14
14
 
15
15
  class PitchAnalyzer {
16
16
 
17
- var callback: (String) -> Unit
17
+ var onChangePitch: (String, Double) -> Unit
18
18
 
19
- constructor(callback: (String) -> Unit) {
20
- this.callback = callback
19
+ constructor(callback: (String, Double) -> Unit) {
20
+ this.onChangePitch = callback
21
21
  }
22
22
 
23
23
  private val tones = arrayOf("C","C#","D","D#","E","F","F#","G","G#","A","A#","B")
@@ -44,12 +44,9 @@ class PitchAnalyzer {
44
44
 
45
45
  if (!index.isNaN() && pitchInHz > 0) {
46
46
  val tone = tones[index.toInt()]
47
+ val frequency = pitchInHz.toDouble()
47
48
 
48
- this.callback(tone)
49
- // val data: WritableMap = WritableNativeMap()
50
- //
51
- // data.putDouble("frequency", pitchInHz.toDouble())
52
- // data.putString("tone", tone)
49
+ this.onChangePitch(tone, frequency)
53
50
  }
54
51
  }
55
52
 
@@ -10,31 +10,36 @@ import androidx.core.os.bundleOf
10
10
 
11
11
  class ReactNativeSimpleNotePitchDetectorModule : Module() {
12
12
 
13
- private var permissions = arrayOf(Manifest.permission.RECORD_AUDIO)
14
-
15
13
  override fun definition() = ModuleDefinition {
16
14
  Name("ReactNativeSimpleNotePitchDetector")
17
15
 
18
- Events("onChange")
19
-
20
- Function("hello") {
16
+ Events("onChangePitch")
21
17
 
22
- val context = appContext.reactContext!!
18
+ Function("start") {
23
19
 
24
- var activity = appContext.currentActivity!!
25
-
26
- var permissionsGranted = ActivityCompat.checkSelfPermission(context, permissions[0]) == PackageManager.PERMISSION_GRANTED
27
- if (!permissionsGranted) {
28
- ActivityCompat.requestPermissions(activity, permissions, 200)
29
- } else {
30
- val pitchAnalyzer = PitchAnalyzer {
31
- this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
32
- "onChange",
33
- bundleOf("tone" to it)
34
- )
35
- }
36
- pitchAnalyzer.start()
20
+ val pitchAnalyzer = PitchAnalyzer { tone: String, frequency: Double ->
21
+ this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
22
+ "onChangePitch",
23
+ bundleOf("tone" to tone, "frequency" to frequency)
24
+ )
37
25
  }
26
+
27
+ pitchAnalyzer.start()
28
+
29
+ // val context = appContext.reactContext!!
30
+ // var activity = appContext.currentActivity!!
31
+ // var permissionsGranted = ActivityCompat.checkSelfPermission(context, permissions[0]) == PackageManager.PERMISSION_GRANTED
32
+ // if (!permissionsGranted) {
33
+ // ActivityCompat.requestPermissions(activity, permissions, 200)
34
+ // } else {
35
+ // val pitchAnalyzer = PitchAnalyzer {
36
+ // this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
37
+ // "onChange",
38
+ // bundleOf("tone" to it)
39
+ // )
40
+ // }
41
+ // pitchAnalyzer.start()
42
+ // }
38
43
  }
39
44
  }
40
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-simple-note-pitch-detector",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "asdf",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",