react-native-simple-note-pitch-detector 0.1.4 → 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
 
@@ -1,5 +1,8 @@
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
@@ -7,20 +10,36 @@ import androidx.core.os.bundleOf
7
10
 
8
11
  class ReactNativeSimpleNotePitchDetectorModule : Module() {
9
12
 
10
-
11
13
  override fun definition() = ModuleDefinition {
12
14
  Name("ReactNativeSimpleNotePitchDetector")
13
15
 
14
- Events("onChange")
16
+ Events("onChangePitch")
17
+
18
+ Function("start") {
15
19
 
16
- Function("hello") {
17
- val pitchAnalyzer = PitchAnalyzer {
20
+ val pitchAnalyzer = PitchAnalyzer { tone: String, frequency: Double ->
18
21
  this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
19
- "onChange",
20
- bundleOf("tone" to it)
22
+ "onChangePitch",
23
+ bundleOf("tone" to tone, "frequency" to frequency)
21
24
  )
22
25
  }
26
+
23
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
+ // }
24
43
  }
25
44
  }
26
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-simple-note-pitch-detector",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "asdf",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",