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

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
- data.putDouble("frequency", pitchInHz.toDouble())
44
- data.putString("tone", tone)
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
 
@@ -1,12 +1,16 @@
1
1
  package expo.modules.simplenotepitchdetector
2
2
 
3
+ import android.Manifest
4
+ import android.content.pm.PackageManager
5
+ import androidx.core.app.ActivityCompat
3
6
  import expo.modules.kotlin.modules.Module
4
7
  import expo.modules.kotlin.modules.ModuleDefinition
5
8
  import expo.modules.simplepitchdetector.PitchAnalyzer
9
+ import androidx.core.os.bundleOf
6
10
 
7
11
  class ReactNativeSimpleNotePitchDetectorModule : Module() {
8
12
 
9
- private val pitchAnalyzer = PitchAnalyzer()
13
+ private var permissions = arrayOf(Manifest.permission.RECORD_AUDIO)
10
14
 
11
15
  override fun definition() = ModuleDefinition {
12
16
  Name("ReactNativeSimpleNotePitchDetector")
@@ -14,7 +18,23 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
14
18
  Events("onChange")
15
19
 
16
20
  Function("hello") {
17
- pitchAnalyzer.start()
21
+
22
+ val context = appContext.reactContext!!
23
+
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()
37
+ }
18
38
  }
19
39
  }
20
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-simple-note-pitch-detector",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "asdf",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",