Skip to content

Commit 6f04eb0

Browse files
committed
Lint
1 parent d481572 commit 6f04eb0

File tree

2 files changed

+75
-71
lines changed

2 files changed

+75
-71
lines changed

gui/src/sounds/sounds.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const tones = [
1010
['G5', 'C6', 'E6'],
1111
];
1212

13-
const xylophone = new Xylophone()
13+
const xylophone = new Xylophone();
1414

1515
export async function playSoundOnResetEnded(resetType: ResetType, volume = 1) {
1616
switch (resetType) {
@@ -19,26 +19,26 @@ export async function playSoundOnResetEnded(resetType: ResetType, volume = 1) {
1919
notes: ['C4'],
2020
offset: 0.15,
2121
type: 'square',
22-
volume
23-
})
22+
volume,
23+
});
2424
break;
2525
}
2626
case ResetType.Full: {
2727
xylophone.play({
2828
notes: ['C4', 'E4'],
2929
offset: 0.15,
3030
type: 'square',
31-
volume
32-
})
31+
volume,
32+
});
3333
break;
3434
}
3535
case ResetType.Mounting: {
3636
xylophone.play({
3737
notes: ['C4', 'E4', 'G4'],
3838
offset: 0.15,
3939
type: 'square',
40-
volume
41-
})
40+
volume,
41+
});
4242
break;
4343
}
4444
}
@@ -49,8 +49,8 @@ export async function playSoundOnResetStarted(volume = 1) {
4949
notes: ['A4'],
5050
offset: 0.4,
5151
type: 'square',
52-
volume
53-
})
52+
volume,
53+
});
5454
}
5555

5656
let lastTap = 0;
@@ -60,17 +60,16 @@ export async function playTapSetupSound(volume = 1) {
6060
notes: tones[lastTap],
6161
offset: 0.15,
6262
type: 'square',
63-
volume
64-
})
65-
}
66-
else {
63+
volume,
64+
});
65+
} else {
6766
xylophone.play({
6867
notes: ['D4', 'E4', 'G4', 'E4', 'B4', 'B4', 'A4'],
6968
offset: 0.15,
7069
length: 1,
7170
type: 'sawtooth',
72-
volume
73-
})
71+
volume,
72+
});
7473
}
7574
lastTap++;
7675
if (lastTap >= tones.length) {

gui/src/sounds/xylophone.ts

+61-56
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,26 @@ export const NOTES: { [note: string]: number } = {
157157
'A#7': 3729.31,
158158
Bb7: 3729.31,
159159
B7: 3951.07,
160-
C8: 4186.01
161-
}
160+
C8: 4186.01,
161+
};
162162

163163
/**
164164
* A measure that can be played on a Xylophone
165165
*/
166166
export interface IMeasure {
167-
notes: string[]
168-
length?: number
169-
offset?: number
170-
type?: OscillatorOptions['type'],
171-
volume?: number
167+
notes: string[];
168+
length?: number;
169+
offset?: number;
170+
type?: OscillatorOptions['type'];
171+
volume?: number;
172172
}
173173

174174
export interface INote {
175-
note: string
176-
length?: number
177-
offset?: number
178-
type?: OscillatorOptions['type'],
179-
volume?: number
175+
note: string;
176+
length?: number;
177+
offset?: number;
178+
type?: OscillatorOptions['type'];
179+
volume?: number;
180180
}
181181

182182
/**
@@ -187,21 +187,21 @@ export default class Xylophone {
187187
* Returns the AudioContext that's used under the hood
188188
*/
189189
get audioContext() {
190-
return this.context
190+
return this.context;
191191
}
192192

193193
/**
194194
* Converts a named note to hertz (e.g. `toHertz('A4') => 440.00`)
195195
*/
196196
private static toHertz(note: string): number {
197-
note = note.trim()
198-
if (note in NOTES) return NOTES[note]
199-
throw new Error(`${note} is not a valid note`)
197+
note = note.trim();
198+
if (note in NOTES) return NOTES[note];
199+
throw new Error(`${note} is not a valid note`);
200200
}
201201

202-
private oscillator: OscillatorNode | undefined
203-
private gainNode: GainNode | undefined
204-
private context: AudioContext = new (window.AudioContext)()
202+
private oscillator: OscillatorNode | undefined;
203+
private gainNode: GainNode | undefined;
204+
private context: AudioContext = new window.AudioContext();
205205

206206
/**
207207
* Plays a series of notes in an `IMeasure`. If an array of `IMeasure`s is given then
@@ -210,28 +210,28 @@ export default class Xylophone {
210210
*/
211211
public async play(measure: IMeasure | IMeasure[]): Promise<void> {
212212
if (measure instanceof Array) {
213-
const arr = []
213+
const arr = [];
214214

215-
for (const m of measure) arr.push(await this.play(m))
215+
for (const m of measure) arr.push(await this.play(m));
216216

217-
return
217+
return;
218218
}
219-
let i = 0
219+
let i = 0;
220220
await Promise.all(
221-
measure.notes.map(note => {
222-
let offset
223-
if (measure.offset) offset = measure.offset * i++
221+
measure.notes.map((note) => {
222+
let offset;
223+
if (measure.offset) offset = measure.offset * i++;
224224

225225
return this.playTone({
226226
length: measure.length,
227227
note,
228228
offset,
229229
type: measure.type,
230230
volume: measure.volume,
231-
})
231+
});
232232
})
233-
)
234-
return
233+
);
234+
return;
235235
}
236236

237237
/**
@@ -241,49 +241,54 @@ export default class Xylophone {
241241
* @returns {function} Stops the loop when called
242242
*/
243243
public loop(measure: IMeasure | IMeasure[]): Promise<() => void> {
244-
return new Promise(resolve => {
245-
let canceled = false
244+
return new Promise((resolve) => {
245+
let canceled = false;
246246

247-
resolve(() => (canceled = true))
247+
resolve(() => (canceled = true));
248248

249249
const loop = async () => {
250-
if (canceled) return
250+
if (canceled) return;
251251

252-
await this.play(measure)
252+
await this.play(measure);
253253

254-
loop()
255-
}
254+
loop();
255+
};
256256

257-
loop()
258-
})
257+
loop();
258+
});
259259
}
260260

261261
/**
262262
* Plays an `INote`
263263
* @param note The tone to play
264264
*/
265-
private playTone({ note, length = 1, offset = 1, type = 'sine', volume }: INote): Promise<void> {
266-
return new Promise(resolve => {
267-
offset = this.context.currentTime + offset
268-
269-
this.oscillator = this.context.createOscillator()
270-
this.gainNode = this.context.createGain()
265+
private playTone({
266+
note,
267+
length = 1,
268+
offset = 1,
269+
type = 'sine',
270+
volume,
271+
}: INote): Promise<void> {
272+
return new Promise((resolve) => {
273+
offset = this.context.currentTime + offset;
271274

275+
this.oscillator = this.context.createOscillator();
276+
this.gainNode = this.context.createGain();
272277

273-
this.oscillator.connect(this.gainNode)
274-
this.gainNode.connect(this.context.destination)
275-
this.oscillator.type = type
278+
this.oscillator.connect(this.gainNode);
279+
this.gainNode.connect(this.context.destination);
280+
this.oscillator.type = type;
276281

277-
const gain = Math.min(1, Math.pow((volume ?? 1) * 0.5, Math.E) + 0.05)
282+
const gain = Math.min(1, Math.pow((volume ?? 1) * 0.5, Math.E) + 0.05);
278283

279-
this.oscillator.frequency.value = Xylophone.toHertz(note)
280-
this.gainNode.gain.setValueAtTime(0, offset)
281-
this.gainNode.gain.linearRampToValueAtTime(1 * gain, offset + 0.01)
284+
this.oscillator.frequency.value = Xylophone.toHertz(note);
285+
this.gainNode.gain.setValueAtTime(0, offset);
286+
this.gainNode.gain.linearRampToValueAtTime(1 * gain, offset + 0.01);
282287

283-
this.oscillator.start(offset)
284-
this.gainNode.gain.exponentialRampToValueAtTime(0.001 * gain, offset + length)
285-
this.oscillator.stop(offset + length)
286-
this.oscillator.onended = () => resolve()
287-
})
288+
this.oscillator.start(offset);
289+
this.gainNode.gain.exponentialRampToValueAtTime(0.001 * gain, offset + length);
290+
this.oscillator.stop(offset + length);
291+
this.oscillator.onended = () => resolve();
292+
});
288293
}
289294
}

0 commit comments

Comments
 (0)