Skip to content

Commit

Permalink
Merge pull request #11 from hemit-s/jat-70
Browse files Browse the repository at this point in the history
JAT-70 Use Equalizer APO directly rather than Peace
  • Loading branch information
xenown authored Jul 5, 2022
2 parents 6246c11 + 67904c4 commit af7d010
Show file tree
Hide file tree
Showing 21 changed files with 836 additions and 427 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ npm-debug.log.*
*.css.d.ts
*.sass.d.ts
*.scss.d.ts

state.txt
6 changes: 3 additions & 3 deletions src/__tests__/cucumber_tests/shared_steps/peace.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { peaceGainOutputToDb } from 'common/peaceConversions';
import { peaceGainOutputToDb } from 'common/constants';
import {
getPeaceWindowHandle,
isPeaceRunning,
sendPeaceCommand,
} from 'common/peaceIPC';
import { DefineStepFunction } from 'jest-cucumber';
import { Driver } from '__tests__/utils/webdriver';
import registry from '../../../main/registry';
import { isPeaceInstalled } from '../../../main/registry';

export const givenPeaceIsInstalled = (given: DefineStepFunction) => {
given('Peace is installed', async () => {
if (!(await registry.isPeaceInstalled())) {
if (!(await isPeaceInstalled())) {
throw new Error('Peace not installed');
}
// TODO find a way to install peace
Expand Down
93 changes: 93 additions & 0 deletions src/__tests__/unit_tests/NumberInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,97 @@ describe('NumberInput', () => {
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(0.13);
});

it('should be able to enter a number in the range without a 0 prior to the decimal point', async () => {
const testValue = 1;
const { user } = setup(
<NumberInput
name={id}
min={-5}
max={5}
handleSubmit={handleSubmit}
value={testValue}
isDisabled={false}
floatPrecision={2}
/>
);
const input = screen.getByLabelText(id);
expect(input).toHaveValue(`${testValue}`);

await clearAndType(user, input, '-.12');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(-0.12);

await clearAndType(user, input, '.56');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(0.56);
});

it('should not be able to enter a negative sign for integers when min is non-negative', async () => {
const testValue = 1;
const { user } = setup(
<NumberInput
name={id}
min={0}
max={5}
handleSubmit={handleSubmit}
value={testValue}
isDisabled={false}
/>
);
const input = screen.getByLabelText(id);
expect(input).toHaveValue(`${testValue}`);

await clearAndType(user, input, '-1');
expect(input).toHaveValue('1');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(1);
});

it('should not be able to enter a negative sign for floats when min is non-negative', async () => {
const testValue = 1;
const { user } = setup(
<NumberInput
name={id}
min={0}
max={5}
handleSubmit={handleSubmit}
value={testValue}
isDisabled={false}
floatPrecision={2}
/>
);
const input = screen.getByLabelText(id);
expect(input).toHaveValue(`${testValue}`);

await clearAndType(user, input, '-1.12');
expect(input).toHaveValue('1.12');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(1.12);
});

it('should be able to enter a decimal number with the leading 0 between -1 and 1', async () => {
const testValue = 1;
const { user } = setup(
<NumberInput
name={id}
min={-5}
max={5}
handleSubmit={handleSubmit}
value={testValue}
isDisabled={false}
floatPrecision={2}
/>
);
const input = screen.getByLabelText(id);
expect(input).toHaveValue(`${testValue}`);

await clearAndType(user, input, '-0.12');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(-0.12);

await clearAndType(user, input, '0.6');
await user.keyboard('{Enter}');
expect(handleSubmit).toBeCalledWith(0.6);
});
});
18 changes: 18 additions & 0 deletions src/common/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum ChannelEnum {
HEALTH_CHECK = 'healthCheck',
GET_ENABLE = 'getEnable',
SET_ENABLE = 'setEnable',
GET_PREAMP = 'getPreamp',
SET_PREAMP = 'setPreamp',
GET_FILTER_GAIN = 'getFilterGain',
SET_FILTER_GAIN = 'setFilterGain',
GET_FILTER_FREQUENCY = 'getFilterFrequency',
SET_FILTER_FREQUENCY = 'setFilterFrequency',
GET_FILTER_QUALITY = 'getFilterQuality',
SET_FILTER_QUALITY = 'setFilterQuality',
GET_FILTER_COUNT = 'getFilterCount',
ADD_FILTER = 'addFilter',
REMOVE_FILTER = 'removeFilter',
}

export default ChannelEnum;
18 changes: 13 additions & 5 deletions src/common/peaceConversions.ts → src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// Peace returns numerical values as unsigned integers
import { clamp } from '../renderer/utils';

import { clamp } from 'renderer/utils';
/** ----- Application Constants ----- */

// This is the offset for the value -1000, used when fetching gain values
const OVERFLOW_OFFSET = 4294967296;
export const MAX_GAIN = 30;
export const MIN_GAIN = -30;

export const MAX_FREQUENCY = 20000; // Peace's actual limit is 22050
export const MIN_FREQUENCY = 0; // graph input's limit is 10 Hz
export const MIN_FREQUENCY = 10; // graph input's limit is 10 Hz
export const MAX_QUALITY = 999.999;
export const MIN_QUALITY = 0.001;

export const MAX_NUM_FILTERS = 20; // TODO: Investigate an appropriate value for this
export const MIN_NUM_FILTERS = 1;

/** ----- Peace specific ----- */

// Peace returns numerical values as unsigned integers
// This is the offset for the value -1000, used when fetching gain values
const OVERFLOW_OFFSET = 4294967296;

export const peaceGainOutputToDb = (result: number) => {
// If gain is larger than MAX_GAIN, assume that Peace returned an unsigned negative number
// If after adjusting for the unsigned number gives a positive value, default to -30
Expand Down
55 changes: 25 additions & 30 deletions src/common/errors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export enum ErrorCode {
PEACE_UNKNOWN_ERROR = 0,
PEACE_NOT_INSTALLED = 1,
PEACE_NOT_RUNNING = 2,
PEACE_NOT_READY = 3,
PEACE_TIMEOUT = 4,
NEGATIVE_FREQUENCY = 5,
EQUALIZER_APO_NOT_INSTALLED,
CONFIG_NOT_FOUND,
TIMEOUT,
INVALID_PARAMETER,
FAILURE,
}

export type ErrorDescription = {
Expand All @@ -14,37 +13,33 @@ export type ErrorDescription = {
};

export const errors: Record<ErrorCode, ErrorDescription> = {
[ErrorCode.PEACE_UNKNOWN_ERROR]: {
shortError: 'Unknown error occured with Peace.',
action: 'Please restart PeaceGUI and try again.',
code: ErrorCode.PEACE_UNKNOWN_ERROR,
[ErrorCode.EQUALIZER_APO_NOT_INSTALLED]: {
shortError: 'Equalizer APO is not installed.',
action: 'Please install Equalizer APO before retrying.',
code: ErrorCode.EQUALIZER_APO_NOT_INSTALLED,
},
[ErrorCode.PEACE_NOT_INSTALLED]: {
shortError: 'Peace not installed.',
[ErrorCode.CONFIG_NOT_FOUND]: {
shortError: 'Unable to locate the configuration file for EqualizerAPO.',
action:
'Please install PeaceGUI and launch Peace outside of the Peace Installation GUI before retrying.',
code: ErrorCode.PEACE_NOT_INSTALLED,
'Please check whether the config.txt file exists in the config folder of EqualizerAPO.',
code: ErrorCode.CONFIG_NOT_FOUND,
},
[ErrorCode.PEACE_NOT_RUNNING]: {
shortError: 'Peace not running.',
action: 'Please launch PeaceGUI before retrying.',
code: ErrorCode.PEACE_NOT_RUNNING,
},
[ErrorCode.PEACE_NOT_READY]: {
shortError: 'Peace not ready yet.',
action: 'Please launch PeaceGUI before retrying.',
code: ErrorCode.PEACE_NOT_READY,
},
[ErrorCode.PEACE_TIMEOUT]: {
[ErrorCode.TIMEOUT]: {
shortError: 'Timeout waiting for a response.',
action:
'Please restart the application. If the error persists, try reaching out to the developers to resolve the issue.',
code: ErrorCode.PEACE_TIMEOUT,
code: ErrorCode.TIMEOUT,
},
[ErrorCode.INVALID_PARAMETER]: {
shortError: 'Internal Error: Invalid parameter.',
action: 'Please reach out to the developers to resolve the issue.',
code: ErrorCode.INVALID_PARAMETER,
},
[ErrorCode.NEGATIVE_FREQUENCY]: {
shortError: 'Invalid frequency - frequency is negative',
action: '',
code: ErrorCode.NEGATIVE_FREQUENCY,
[ErrorCode.FAILURE]: {
shortError: 'Internal Error: Failed to apply equalizer settings.',
action:
'Please restart the application. If the error persists, try reaching out to the developers to resolve the issue.',
code: ErrorCode.FAILURE,
},
};

Expand Down
Loading

0 comments on commit af7d010

Please sign in to comment.