Skip to content

Commit

Permalink
Merge pull request #17 from 1fabiopereira/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
1fabiopereira authored Apr 30, 2023
2 parents a7156ad + 01a7e89 commit ec4791f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pitch-detector",
"version": "0.1.2",
"version": "0.1.3",
"description": "High performance real time pitch detection.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -140,4 +140,4 @@
"dependencies": {
"react-native-permissions": "^3.8.0"
}
}
}
14 changes: 7 additions & 7 deletions src/internal/erros/__tests__/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PicthDetectorErrors } from '../../../types';
import { PicthDetectorError } from '..';
import { PitchDetectorErrors } from '../../../types';
import { PitchDetectorError } from '..';

describe('Errors', () => {
it('should create base error', () => {
const error: any = new PicthDetectorError(PicthDetectorErrors.BASE);
const error: any = new PitchDetectorError(PitchDetectorErrors.BASE);

expect(error?.message).toMatch(/You are not using Expo Go/);
expect(error?.message).toMatch(
Expand All @@ -12,16 +12,16 @@ describe('Errors', () => {
});

it('should create link error', () => {
const error: any = new PicthDetectorError(
PicthDetectorErrors.LINKING_ERROR
const error: any = new PitchDetectorError(
PitchDetectorErrors.LINKING_ERROR
);

expect(error?.message).toMatch(/doesn't seem to be linked/);
});

it('should create permission error', () => {
const error: any = new PicthDetectorError(
PicthDetectorErrors.PERMISSIONS_ERROR
const error: any = new PitchDetectorError(
PitchDetectorErrors.PERMISSIONS_ERROR
);

expect(error?.message).toMatch(/need audio record permission/);
Expand Down
10 changes: 5 additions & 5 deletions src/internal/erros/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform } from 'react-native';
import { PicthDetectorErrors } from '../../types';
import { PitchDetectorErrors } from '../../types';

const base =
`The package 'react-native-pitch-detector' find a error. Make sure: \n\n` +
Expand All @@ -22,13 +22,13 @@ const permission =
android: `- You have added '<uses-permission android:name="android.permission.RECORD_AUDIO" />' on AndroidManifest.xml and request permission before start record.\n`,
});

export class PicthDetectorError {
constructor(type: PicthDetectorErrors) {
if (type === PicthDetectorErrors.LINKING_ERROR) {
export class PitchDetectorError {
constructor(type: PitchDetectorErrors) {
if (type === PitchDetectorErrors.LINKING_ERROR) {
return new Error(linking);
}

if (type === PicthDetectorErrors.PERMISSIONS_ERROR) {
if (type === PitchDetectorErrors.PERMISSIONS_ERROR) {
return new Error(permission);
}

Expand Down
6 changes: 3 additions & 3 deletions src/internal/pitch-detector/__tests__/pitch-detector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NativeModules } from 'react-native';

import { PicthDetectorErrors } from '../../../types';
import { PicthDetectorError } from '../../erros';
import { PitchDetectorErrors } from '../../../types';
import { PitchDetectorError } from '../../erros';

import { Permissions } from '../../permissions';
import { PitchDetector } from '..';
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('PitchDetector', () => {
});

it('should throw error when start method will be called and not have audio record permission', async () => {
const error = new PicthDetectorError(PicthDetectorErrors.PERMISSIONS_ERROR);
const error = new PitchDetectorError(PitchDetectorErrors.PERMISSIONS_ERROR);
const spy = jest.spyOn(console, 'warn');

Permissions.audio = asyncMock(false);
Expand Down
26 changes: 13 additions & 13 deletions src/internal/pitch-detector/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
import { Permissions } from '../permissions';
import { PicthDetectorError } from '../erros';
import { PitchDetectorError } from '../erros';
import { merge } from '../utils';

import {
type Callback,
type NativeModuleImplementation,
type PicthDetectorConfig,
type PitchDetectorConfig,
type Subscription,
type PicthDetectorAndroidConfig,
type PicthDetectorIOSConfig,
PicthDetectorErrors,
type PitchDetectorAndroidConfig,
type PitchDetectorIOSConfig,
PitchDetectorErrors,
} from '../../types';

export class InternalPitchDetector {
Expand All @@ -24,13 +24,13 @@ export class InternalPitchDetector {
this.event = new NativeEventEmitter(this.module);
} else {
/* istanbul ignore next */
throw new PicthDetectorError(PicthDetectorErrors.LINKING_ERROR);
throw new PitchDetectorError(PitchDetectorErrors.LINKING_ERROR);
}
}

/**
* Returns a default PicthDetector configs
* @returns PicthDetectorConfig
* Returns a default PitchDetector configs
* @returns PitchDetectorConfig
* @example
* ```ts
* {
Expand All @@ -46,7 +46,7 @@ export class InternalPitchDetector {
* }
* }
*/
private getDefaultConfig(): PicthDetectorConfig {
private getDefaultConfig(): PitchDetectorConfig {
return {
android: {
algorithm: 'YIN',
Expand Down Expand Up @@ -88,23 +88,23 @@ export class InternalPitchDetector {
* @param config
* @returns Promise<void>
*/
async start(config?: PicthDetectorConfig): Promise<void> {
async start(config?: PitchDetectorConfig): Promise<void> {
try {
const permission = await this.hasPermissions();

if (!permission) {
throw new PicthDetectorError(PicthDetectorErrors.PERMISSIONS_ERROR);
throw new PitchDetectorError(PitchDetectorErrors.PERMISSIONS_ERROR);
}

const configuration = merge<PicthDetectorConfig>(
const configuration = merge<PitchDetectorConfig>(
this.getDefaultConfig(),
config || {}
);

const params = Platform.select({
android: configuration.android as unknown,
ios: configuration.ios as unknown,
}) as PicthDetectorIOSConfig | PicthDetectorAndroidConfig;
}) as PitchDetectorIOSConfig | PitchDetectorAndroidConfig;

await this.module?.start(params);
} catch (err: unknown) {
Expand Down
14 changes: 7 additions & 7 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PermissionsHandlers = {
CheckPermission: (compare?: Comparable) => Response;
};

export enum PicthDetectorErrors {
export enum PitchDetectorErrors {
BASE,
LINKING_ERROR,
PERMISSIONS_ERROR,
Expand Down Expand Up @@ -100,24 +100,24 @@ export type PitchEstimationIOSAlgorithm =
| 'QUINNS_SECOND'
| 'YIN';

export type PicthDetectorAndroidConfig = {
export type PitchDetectorAndroidConfig = {
algorithm?: PitchEstimationAndroidAlgorithm;
bufferOverLap?: Int32;
bufferSize?: Int32;
sampleRate?: Float;
};

export type PicthDetectorIOSConfig = {
export type PitchDetectorIOSConfig = {
algorithm?: PitchEstimationIOSAlgorithm;
bufferSize?: Int32;
};

/**
* Pitch detector configuration.
*/
export type PicthDetectorConfig = {
android?: PicthDetectorAndroidConfig;
ios?: PicthDetectorIOSConfig;
export type PitchDetectorConfig = {
android?: PitchDetectorAndroidConfig;
ios?: PitchDetectorIOSConfig;
};

/**
Expand All @@ -130,7 +130,7 @@ export interface NativeModuleImplementation extends NativeModule {
* @returns Promise<void>
*/
start: (
config: PicthDetectorAndroidConfig | PicthDetectorIOSConfig
config: PitchDetectorAndroidConfig | PitchDetectorIOSConfig
) => Promise<void>;

/**
Expand Down
2 changes: 1 addition & 1 deletion website/docs/before-you-start.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Before you start

React Native Picth Detector is a module created to be used alongside [React Native](https://github.com/facebook/react-native), so previous experience is required. If you need, can start with their [Getting Started](https://reactnative.dev/docs/getting-started) tutorial and come back here after.
React Native Pitch Detector is a module created to be used alongside [React Native](https://github.com/facebook/react-native), so previous experience is required. If you need, can start with their [Getting Started](https://reactnative.dev/docs/getting-started) tutorial and come back here after.

This module is compatible with Android and iOS devices, we assume that you have Android and iOS environment configured, in the case that you don't have, we suggest that you setup enviroment before.

Expand Down
6 changes: 3 additions & 3 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const darkCodeTheme = require('prism-react-renderer/themes/dracula');

/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'React Native Picth Detector',
title: 'React Native Pitch Detector',
staticDirectories: ['static'],
tagline: 'High performance real time pitch detection.',
url: 'https://1fabiopereira.github.io/',
Expand Down Expand Up @@ -51,9 +51,9 @@ const config = {
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
navbar: {
title: 'React Native Picth Detector',
title: 'React Native Pitch Detector',
logo: {
alt: 'React Native Picth Detector',
alt: 'React Native Pitch Detector',
src: 'img/react-native-pitch-detector.svg',
},
items: [
Expand Down

0 comments on commit ec4791f

Please sign in to comment.