-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor: optimize sound-controller (@fehmer) #7884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
108c50a
refactor: optimize sound-controller (@fehmer)
fehmer ce959f3
playNote
fehmer bc2d2cb
scales
fehmer 9368f63
fix
fehmer d2d85cf
add validation
fehmer f543748
fix click4
fehmer 954682a
fix workflow to run for sounds
fehmer c29c900
fix all filenames
fehmer d4ea34e
only load needed click sounds
fehmer 175c603
cleanup
fehmer bfc0ff5
remove unused farts
fehmer e7928ff
remove todo
fehmer f426ab7
Merge branch 'master' into feature/refactor-soundcontroller
fehmer 61e46e8
always init error sounds
fehmer 3825990
review comments
fehmer 833e9bc
Merge branch 'master' into feature/refactor-soundcontroller
fehmer 277b58a
remove variants from sounds
fehmer dba93ee
rename files
fehmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { PlaySoundOnClick } from "@monkeytype/schemas/configs"; | ||
|
|
||
| export const soundsConfig: SoundConfigType = { | ||
| 1: { numberOfSounds: 3 }, | ||
| 2: { numberOfSounds: 3 }, | ||
| 3: { numberOfSounds: 3 }, | ||
| 4: { numberOfSounds: 6, hasSecondVariant: true }, | ||
| 5: { numberOfSounds: 6, hasSecondVariant: true }, | ||
| 6: { numberOfSounds: 3, hasSecondVariant: true }, | ||
| 7: { numberOfSounds: 3, hasSecondVariant: true }, | ||
| 8: { oscillatorType: "sine" }, | ||
| 9: { oscillatorType: "sawtooth" }, | ||
| 10: { oscillatorType: "square" }, | ||
| 11: { oscillatorType: "triangle" }, | ||
| 12: { validNotes: ["C", "D", "E", "G", "A"] }, | ||
| 13: { validNotes: ["C", "D", "E", "Gb", "Ab", "Bb"] }, | ||
| 14: { numberOfSounds: 8 }, | ||
| 15: { numberOfSounds: 5 }, | ||
| 16: { numberOfSounds: 8 }, | ||
| }; | ||
|
|
||
| export type ClickSoundConfig = { | ||
| numberOfSounds: number; | ||
| hasSecondVariant?: true; | ||
| }; | ||
|
|
||
| export type SupportedOscillatorTypes = Exclude<OscillatorType, "custom">; | ||
| export type OscillatorSoundConfig = { | ||
| oscillatorType: SupportedOscillatorTypes; | ||
| }; | ||
|
|
||
| export type ScaleSoundConfig = { | ||
| validNotes: ValidNotes[]; | ||
| }; | ||
|
|
||
| export type SoundConfigType = Record< | ||
| Exclude<PlaySoundOnClick, "off">, | ||
| ClickSoundConfig | OscillatorSoundConfig | ScaleSoundConfig | ||
| >; | ||
|
|
||
| export type ValidNotes = | ||
| | "C" | ||
| | "Db" | ||
| | "D" | ||
| | "Eb" | ||
| | "E" | ||
| | "F" | ||
| | "Gb" | ||
| | "G" | ||
| | "Ab" | ||
| | "A" | ||
| | "Bb" | ||
| | "B"; | ||
|
|
||
| type ClickSoundConfigType = Partial< | ||
| Record< | ||
| Exclude<PlaySoundOnClick, "off">, | ||
| { | ||
| sounds: string[]; | ||
| counter: number; | ||
| }[] | ||
| > | ||
| >; | ||
|
|
||
| export const clickSoundConfig: ClickSoundConfigType = | ||
| extractClickSounds(soundsConfig); | ||
|
|
||
| function extractClickSounds( | ||
| shortConfig: SoundConfigType, | ||
| ): ClickSoundConfigType { | ||
| return Object.fromEntries( | ||
| Object.entries(shortConfig) | ||
| .filter(([_, cfg]) => "numberOfSounds" in cfg) | ||
| .map(([key, cfg]) => { | ||
| const config = cfg as ClickSoundConfig; | ||
| const fullConfig = new Array(config.numberOfSounds) | ||
| .fill(0) | ||
| .map((_, index) => { | ||
| const sounds = config.hasSecondVariant | ||
| ? [ | ||
| `../sound/click${key}/click${key}_${index + 1}.wav`, | ||
| `../sound/click${key}/click${key}_${index + 1}_2.wav`, | ||
| ] | ||
| : [`../sound/click${key}/click${key}_${index + 1}.wav`]; | ||
|
|
||
| return { sounds, counter: 0 }; | ||
| }); | ||
| return [key, fullConfig]; | ||
| }), | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.