Skip to content

Commit af7d010

Browse files
authored
Merge pull request #11 from hemit-s/jat-70
JAT-70 Use Equalizer APO directly rather than Peace
2 parents 6246c11 + 67904c4 commit af7d010

21 files changed

+836
-427
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ npm-debug.log.*
2828
*.css.d.ts
2929
*.sass.d.ts
3030
*.scss.d.ts
31+
32+
state.txt

src/__tests__/cucumber_tests/shared_steps/peace.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { peaceGainOutputToDb } from 'common/peaceConversions';
1+
import { peaceGainOutputToDb } from 'common/constants';
22
import {
33
getPeaceWindowHandle,
44
isPeaceRunning,
55
sendPeaceCommand,
66
} from 'common/peaceIPC';
77
import { DefineStepFunction } from 'jest-cucumber';
88
import { Driver } from '__tests__/utils/webdriver';
9-
import registry from '../../../main/registry';
9+
import { isPeaceInstalled } from '../../../main/registry';
1010

1111
export const givenPeaceIsInstalled = (given: DefineStepFunction) => {
1212
given('Peace is installed', async () => {
13-
if (!(await registry.isPeaceInstalled())) {
13+
if (!(await isPeaceInstalled())) {
1414
throw new Error('Peace not installed');
1515
}
1616
// TODO find a way to install peace

src/__tests__/unit_tests/NumberInput.test.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,97 @@ describe('NumberInput', () => {
216216
await user.keyboard('{Enter}');
217217
expect(handleSubmit).toBeCalledWith(0.13);
218218
});
219+
220+
it('should be able to enter a number in the range without a 0 prior to the decimal point', async () => {
221+
const testValue = 1;
222+
const { user } = setup(
223+
<NumberInput
224+
name={id}
225+
min={-5}
226+
max={5}
227+
handleSubmit={handleSubmit}
228+
value={testValue}
229+
isDisabled={false}
230+
floatPrecision={2}
231+
/>
232+
);
233+
const input = screen.getByLabelText(id);
234+
expect(input).toHaveValue(`${testValue}`);
235+
236+
await clearAndType(user, input, '-.12');
237+
await user.keyboard('{Enter}');
238+
expect(handleSubmit).toBeCalledWith(-0.12);
239+
240+
await clearAndType(user, input, '.56');
241+
await user.keyboard('{Enter}');
242+
expect(handleSubmit).toBeCalledWith(0.56);
243+
});
244+
245+
it('should not be able to enter a negative sign for integers when min is non-negative', async () => {
246+
const testValue = 1;
247+
const { user } = setup(
248+
<NumberInput
249+
name={id}
250+
min={0}
251+
max={5}
252+
handleSubmit={handleSubmit}
253+
value={testValue}
254+
isDisabled={false}
255+
/>
256+
);
257+
const input = screen.getByLabelText(id);
258+
expect(input).toHaveValue(`${testValue}`);
259+
260+
await clearAndType(user, input, '-1');
261+
expect(input).toHaveValue('1');
262+
await user.keyboard('{Enter}');
263+
expect(handleSubmit).toBeCalledWith(1);
264+
});
265+
266+
it('should not be able to enter a negative sign for floats when min is non-negative', async () => {
267+
const testValue = 1;
268+
const { user } = setup(
269+
<NumberInput
270+
name={id}
271+
min={0}
272+
max={5}
273+
handleSubmit={handleSubmit}
274+
value={testValue}
275+
isDisabled={false}
276+
floatPrecision={2}
277+
/>
278+
);
279+
const input = screen.getByLabelText(id);
280+
expect(input).toHaveValue(`${testValue}`);
281+
282+
await clearAndType(user, input, '-1.12');
283+
expect(input).toHaveValue('1.12');
284+
await user.keyboard('{Enter}');
285+
expect(handleSubmit).toBeCalledWith(1.12);
286+
});
287+
288+
it('should be able to enter a decimal number with the leading 0 between -1 and 1', async () => {
289+
const testValue = 1;
290+
const { user } = setup(
291+
<NumberInput
292+
name={id}
293+
min={-5}
294+
max={5}
295+
handleSubmit={handleSubmit}
296+
value={testValue}
297+
isDisabled={false}
298+
floatPrecision={2}
299+
/>
300+
);
301+
const input = screen.getByLabelText(id);
302+
expect(input).toHaveValue(`${testValue}`);
303+
304+
await clearAndType(user, input, '-0.12');
305+
await user.keyboard('{Enter}');
306+
expect(handleSubmit).toBeCalledWith(-0.12);
307+
308+
await clearAndType(user, input, '0.6');
309+
await user.keyboard('{Enter}');
310+
expect(handleSubmit).toBeCalledWith(0.6);
311+
});
219312
});

src/common/channels.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
enum ChannelEnum {
2+
HEALTH_CHECK = 'healthCheck',
3+
GET_ENABLE = 'getEnable',
4+
SET_ENABLE = 'setEnable',
5+
GET_PREAMP = 'getPreamp',
6+
SET_PREAMP = 'setPreamp',
7+
GET_FILTER_GAIN = 'getFilterGain',
8+
SET_FILTER_GAIN = 'setFilterGain',
9+
GET_FILTER_FREQUENCY = 'getFilterFrequency',
10+
SET_FILTER_FREQUENCY = 'setFilterFrequency',
11+
GET_FILTER_QUALITY = 'getFilterQuality',
12+
SET_FILTER_QUALITY = 'setFilterQuality',
13+
GET_FILTER_COUNT = 'getFilterCount',
14+
ADD_FILTER = 'addFilter',
15+
REMOVE_FILTER = 'removeFilter',
16+
}
17+
18+
export default ChannelEnum;

src/common/peaceConversions.ts renamed to src/common/constants.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
// Peace returns numerical values as unsigned integers
1+
import { clamp } from '../renderer/utils';
22

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

5-
// This is the offset for the value -1000, used when fetching gain values
6-
const OVERFLOW_OFFSET = 4294967296;
75
export const MAX_GAIN = 30;
86
export const MIN_GAIN = -30;
7+
98
export const MAX_FREQUENCY = 20000; // Peace's actual limit is 22050
10-
export const MIN_FREQUENCY = 0; // graph input's limit is 10 Hz
9+
export const MIN_FREQUENCY = 10; // graph input's limit is 10 Hz
1110
export const MAX_QUALITY = 999.999;
1211
export const MIN_QUALITY = 0.001;
1312

13+
export const MAX_NUM_FILTERS = 20; // TODO: Investigate an appropriate value for this
14+
export const MIN_NUM_FILTERS = 1;
15+
16+
/** ----- Peace specific ----- */
17+
18+
// Peace returns numerical values as unsigned integers
19+
// This is the offset for the value -1000, used when fetching gain values
20+
const OVERFLOW_OFFSET = 4294967296;
21+
1422
export const peaceGainOutputToDb = (result: number) => {
1523
// If gain is larger than MAX_GAIN, assume that Peace returned an unsigned negative number
1624
// If after adjusting for the unsigned number gives a positive value, default to -30

src/common/errors.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
export enum ErrorCode {
2-
PEACE_UNKNOWN_ERROR = 0,
3-
PEACE_NOT_INSTALLED = 1,
4-
PEACE_NOT_RUNNING = 2,
5-
PEACE_NOT_READY = 3,
6-
PEACE_TIMEOUT = 4,
7-
NEGATIVE_FREQUENCY = 5,
2+
EQUALIZER_APO_NOT_INSTALLED,
3+
CONFIG_NOT_FOUND,
4+
TIMEOUT,
5+
INVALID_PARAMETER,
6+
FAILURE,
87
}
98

109
export type ErrorDescription = {
@@ -14,37 +13,33 @@ export type ErrorDescription = {
1413
};
1514

1615
export const errors: Record<ErrorCode, ErrorDescription> = {
17-
[ErrorCode.PEACE_UNKNOWN_ERROR]: {
18-
shortError: 'Unknown error occured with Peace.',
19-
action: 'Please restart PeaceGUI and try again.',
20-
code: ErrorCode.PEACE_UNKNOWN_ERROR,
16+
[ErrorCode.EQUALIZER_APO_NOT_INSTALLED]: {
17+
shortError: 'Equalizer APO is not installed.',
18+
action: 'Please install Equalizer APO before retrying.',
19+
code: ErrorCode.EQUALIZER_APO_NOT_INSTALLED,
2120
},
22-
[ErrorCode.PEACE_NOT_INSTALLED]: {
23-
shortError: 'Peace not installed.',
21+
[ErrorCode.CONFIG_NOT_FOUND]: {
22+
shortError: 'Unable to locate the configuration file for EqualizerAPO.',
2423
action:
25-
'Please install PeaceGUI and launch Peace outside of the Peace Installation GUI before retrying.',
26-
code: ErrorCode.PEACE_NOT_INSTALLED,
24+
'Please check whether the config.txt file exists in the config folder of EqualizerAPO.',
25+
code: ErrorCode.CONFIG_NOT_FOUND,
2726
},
28-
[ErrorCode.PEACE_NOT_RUNNING]: {
29-
shortError: 'Peace not running.',
30-
action: 'Please launch PeaceGUI before retrying.',
31-
code: ErrorCode.PEACE_NOT_RUNNING,
32-
},
33-
[ErrorCode.PEACE_NOT_READY]: {
34-
shortError: 'Peace not ready yet.',
35-
action: 'Please launch PeaceGUI before retrying.',
36-
code: ErrorCode.PEACE_NOT_READY,
37-
},
38-
[ErrorCode.PEACE_TIMEOUT]: {
27+
[ErrorCode.TIMEOUT]: {
3928
shortError: 'Timeout waiting for a response.',
4029
action:
4130
'Please restart the application. If the error persists, try reaching out to the developers to resolve the issue.',
42-
code: ErrorCode.PEACE_TIMEOUT,
31+
code: ErrorCode.TIMEOUT,
32+
},
33+
[ErrorCode.INVALID_PARAMETER]: {
34+
shortError: 'Internal Error: Invalid parameter.',
35+
action: 'Please reach out to the developers to resolve the issue.',
36+
code: ErrorCode.INVALID_PARAMETER,
4337
},
44-
[ErrorCode.NEGATIVE_FREQUENCY]: {
45-
shortError: 'Invalid frequency - frequency is negative',
46-
action: '',
47-
code: ErrorCode.NEGATIVE_FREQUENCY,
38+
[ErrorCode.FAILURE]: {
39+
shortError: 'Internal Error: Failed to apply equalizer settings.',
40+
action:
41+
'Please restart the application. If the error persists, try reaching out to the developers to resolve the issue.',
42+
code: ErrorCode.FAILURE,
4843
},
4944
};
5045

0 commit comments

Comments
 (0)