-
Notifications
You must be signed in to change notification settings - Fork 44
refactor: More centralization of "Audio Effect" code #505
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8abdd33
chore: Move `PreAmpSlider` to its own file
cyanChill f15f3b6
chore: Show a `+` when frequency slider value is 0
cyanChill bfef52b
chore: Equalizer settings screen is now accessed from "Audio Effects"…
cyanChill c04ce42
chore: Show link to "Audio Effects" screen instead of "Equalizer" fro…
cyanChill b98d998
chore: Have equalizer code be under `~/modules/audio`
cyanChill 490e2cd
chore: Move Equalizer Settings "screen" into a "card"
cyanChill 8162c2b
fix: Seeing the marquee when pressing on the miniplayer
cyanChill 18b876d
chore: Display "Playback Speed" setting in "Audio Effects" screen
cyanChill 6df987e
fix: Lint
cyanChill 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
89 changes: 89 additions & 0 deletions
89
mobile/src/modules/audio/equalizer/components/EqualizerSettings.tsx
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,89 @@ | ||
| import type { ParseKeys } from "i18next"; | ||
| import { useMemo } from "react"; | ||
| import { View } from "react-native"; | ||
| import { useEqualizerSettings } from "react-native-audio-browser"; | ||
|
|
||
| import { useEqualizerStore } from "../core/store"; | ||
| import { toggleEQ, setEQPreset } from "../core/actions"; | ||
|
|
||
| import { OnRTL } from "~/lib/react"; | ||
| import { cn } from "~/lib/style"; | ||
| import { Button } from "~/components/Form/Button"; | ||
| import { SegmentedList } from "~/components/List/Segmented"; | ||
| import { TStyledText } from "~/components/Typography/StyledText"; | ||
| import { Switch } from "~/components/UI/Switch"; | ||
| import { EQGraph } from "../components/EQGraph"; | ||
| import { FrequencySlider } from "../components/FrequencySlider"; | ||
|
|
||
| export function EqualizerSettings() { | ||
| const eqFreqs = useEqualizerStore((s) => s.defaultFrequencies); | ||
| const eqPresets = useEqualizerStore((s) => s.defaultPresets); | ||
| const activePreset = useEqualizerStore((s) => s.preset); | ||
|
|
||
| const currEQ = useEqualizerSettings(); | ||
| const isEQEnabled = Boolean(currEQ?.enabled); | ||
|
|
||
| const eqDataPoints = useMemo( | ||
| () => | ||
| eqFreqs.map((freq, index) => ({ | ||
| x: freq, | ||
| y: currEQ?.bandLevels[index] ?? 0, | ||
| })), | ||
| [eqFreqs, currEQ?.bandLevels], | ||
| ); | ||
|
|
||
| return ( | ||
| <SegmentedList> | ||
| <SegmentedList.Item | ||
| labelTextKey="feat.equalizer.title" | ||
| onPress={toggleEQ} | ||
| RightElement={<Switch enabled={isEQEnabled} />} | ||
| /> | ||
| <SegmentedList.CustomItem className="p-4"> | ||
| <View | ||
| needsOffscreenAlphaCompositing={!isEQEnabled} | ||
| renderToHardwareTextureAndroid={!isEQEnabled} | ||
| className={cn("gap-4", { "opacity-25": !isEQEnabled })} | ||
| > | ||
| <EQGraph points={eqDataPoints} /> | ||
|
|
||
| <View | ||
| style={{ flexDirection: OnRTL.decide("row-reverse", "row") }} | ||
| className="justify-evenly gap-2" | ||
| > | ||
| {currEQ?.bandLevels.map((level, index) => ( | ||
| <FrequencySlider | ||
| key={`${currEQ.activePreset}_${index}`} | ||
| bandIndex={index} | ||
| value={level} | ||
| disabled={activePreset !== "Custom" || !currEQ.enabled} | ||
| /> | ||
| ))} | ||
| </View> | ||
|
|
||
| <View className="flex-row flex-wrap gap-2"> | ||
| {eqPresets.map((preset) => { | ||
| const isActive = activePreset === preset; | ||
| return ( | ||
| <Button | ||
| key={preset} | ||
| onPress={() => setEQPreset(preset)} | ||
| disabled={!currEQ?.enabled} | ||
| className={cn( | ||
| "min-h-auto rounded-full bg-surfaceContainerLow py-2 active:bg-surfaceContainer disabled:opacity-100", | ||
| { "bg-primary active:bg-primaryDim": isActive }, | ||
| )} | ||
| > | ||
| <TStyledText | ||
| textKey={`feat.equalizer.extra.${preset}` as ParseKeys} | ||
| className={cn("text-xs", { "text-onPrimary": isActive })} | ||
| /> | ||
| </Button> | ||
| ); | ||
| })} | ||
| </View> | ||
| </View> | ||
| </SegmentedList.CustomItem> | ||
| </SegmentedList> | ||
| ); | ||
| } |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
mobile/src/modules/audio/replayGain/components/PreAmpSlider.tsx
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,51 @@ | ||
| import { memo } from "react"; | ||
| import { View } from "react-native"; | ||
|
|
||
| import { usePlaybackStore } from "~/stores/Playback/store"; | ||
| import * as ReplayGain from "../core/actions"; | ||
| import { DB_OFFSET } from "../core/constants"; | ||
|
|
||
| import { CachedSlider } from "~/components/Form/Slider"; | ||
| import { Em, TEm } from "~/components/Typography/StyledText"; | ||
|
|
||
| export const PreAmpSlider = memo(function PreAmpSlider(props: { | ||
| field: "preAmpWTags" | "preAmpWOTags"; | ||
| disabled: boolean; | ||
| }) { | ||
| const preAmpValue = usePlaybackStore((s) => s[props.field]); | ||
| return ( | ||
| <View className="gap-2"> | ||
| <TEm | ||
| textKey={`feat.replayGain.extra.${props.field === "preAmpWTags" ? "adjustWithTags" : "adjustWithoutTags"}`} | ||
| /> | ||
| <View className="flex-row items-center gap-2"> | ||
| <CachedSlider | ||
| initValue={preAmpValue} | ||
| min={DB_OFFSET.min} | ||
| max={DB_OFFSET.max} | ||
| step={0.1} | ||
| onChange={ | ||
| props.field === "preAmpWTags" | ||
| ? ReplayGain.updatePreAmpWithTags | ||
| : ReplayGain.updatePreAmpWithoutTags | ||
| } | ||
| disabled={props.disabled} | ||
| hitSlop={10} | ||
| anchorAt={0} | ||
| trackColor="surfaceContainer" | ||
| roundedEndStop | ||
| _debounceMultiplier={0} | ||
| _className="shrink grow" | ||
| /> | ||
|
|
||
| <Em | ||
| style={{ fontVariant: ["tabular-nums"] }} | ||
| className="w-14 text-center" | ||
| > | ||
| {preAmpValue >= 0 ? "+" : ""} | ||
| {preAmpValue.toFixed(1)} dB | ||
| </Em> | ||
| </View> | ||
| </View> | ||
| ); | ||
| }); |
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.