react-native-simple-note-pitch-detector 0.1.7 → 0.1.8

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.
@@ -16,6 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.static_framework = true
17
17
 
18
18
  s.dependency 'ExpoModulesCore'
19
+ s.dependency 'Beethoven', '~> 5.0'
19
20
 
20
21
  # Swift/Objective-C compatibility
21
22
  s.pod_target_xcconfig = {
@@ -1,25 +1,45 @@
1
1
  import ExpoModulesCore
2
+ import Beethoven
3
+ import Pitchy
2
4
 
3
5
  public class ReactNativeSimpleNotePitchDetectorModule: Module {
6
+
7
+ lazy var pitchEngine: PitchEngine = { [weak self] in
8
+ let config = Config(estimationStrategy: .yin)
9
+ let pitchEngine = PitchEngine(config: config, delegate: self)
10
+ return pitchEngine
11
+ }()
4
12
 
5
13
  public func definition() -> ModuleDefinition {
6
14
 
7
15
  Name("ReactNativeSimpleNotePitchDetector")
8
16
 
9
- Events("onChange")
17
+ Events("onChangePitch")
10
18
 
11
- Function("hello") {
12
- return "Hello world! 👋"
19
+ Function("start") {
20
+ pitchEngine.start()
13
21
  }
22
+ }
23
+ }
14
24
 
15
- // Defines a JavaScript function that always returns a Promise and whose native code
16
- // is by default dispatched on the different thread than the JavaScript runtime runs on.
17
- AsyncFunction("setValueAsync") { (value: String) in
18
- // Send an event to JavaScript.
19
- self.sendEvent("onChange", [
20
- "value": value
21
- ])
22
- }
25
+ extension ReactNativeSimpleNotePitchDetectorModule: PitchEngineDelegate {
26
+ public func pitchEngine(_ pitchEngine: PitchEngine, didReceivePitch pitch: Pitch) {
27
+
28
+ let offsetPercentage = pitch.closestOffset.percentage
29
+ let absOffsetPercentage = abs(offsetPercentage)
30
+
31
+ guard absOffsetPercentage > 1.0 else {
32
+ return
33
+ }
34
+
35
+ self.sendEvent("onChangePitch", ["note" : pitch.note.string, "frequency" : pitch.frequency, "wave" : pitch.wave.wavelength])
36
+ }
37
+
38
+ public func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error) {
39
+
40
+ }
23
41
 
42
+ public func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine) {
43
+
24
44
  }
25
45
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-simple-note-pitch-detector",
3
- "version": "0.1.7",
4
- "description": "asdf",
3
+ "version": "0.1.8",
4
+ "description": "a simple react native library to detect the pitch of the input recording",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "scripts": {