-
Notifications
You must be signed in to change notification settings - Fork 44
feat: Support for modifying playback pitch #507
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
8 commits
Select commit
Hold shift + click to select a range
bcce343
chore: Initial Playback Pitch implementation
cyanChill aebe73b
fix: Changing pitch sometimes breaking playback
cyanChill 5d8eec3
chore: Create a "shared base" for both playback pitch & speed sliders
cyanChill 74b9f6d
chore: Have slider mimic the design for Pre-amp
cyanChill b7ff2d4
fix: Debounce accuracy in slider
cyanChill 69abace
fix: Issue where it took several seconds for ReplayGain to be applied
cyanChill 2bb2555
fix: Prevent slider from triggering when dragging in incorrect direction
cyanChill 59d7752
chore: Unnecessary import
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
mobile/src/modules/audio/_components/PlaybackParameterSettings.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,24 @@ | ||
| import AudioBrowser from "react-native-audio-browser"; | ||
|
|
||
| import { SlowMotionVideo } from "~/resources/icons/SlowMotionVideo"; | ||
| import { VoiceSelection } from "~/resources/icons/VoiceSelection"; | ||
|
|
||
| import { SegmentedList } from "~/components/List/Segmented"; | ||
| import { PlaybackParameterSlider } from "./PlaybackParameterSlider"; | ||
|
|
||
| export function PlaybackParameterSettings() { | ||
| return ( | ||
| <SegmentedList> | ||
| <PlaybackParameterSlider | ||
| field="pitch" | ||
| onUpdate={AudioBrowser.setPitch} | ||
| Icon={VoiceSelection} | ||
| /> | ||
| <PlaybackParameterSlider | ||
| field="speed" | ||
| onUpdate={AudioBrowser.setRate} | ||
| Icon={SlowMotionVideo} | ||
| /> | ||
| </SegmentedList> | ||
| ); | ||
| } |
89 changes: 89 additions & 0 deletions
89
mobile/src/modules/audio/_components/PlaybackParameterSlider.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 { useCallback, useMemo } from "react"; | ||
| import { View } from "react-native"; | ||
| import { useSharedValue } from "react-native-reanimated"; | ||
|
|
||
| import type { Icon } from "~/resources/icons/type"; | ||
| import { sessionStore, useSessionStore } from "~/stores/Session/store"; | ||
|
|
||
| import { capitalize } from "~/utils/string"; | ||
| import { Button } from "~/components/Form/Button"; | ||
| import { CachedSlider } from "~/components/Form/Slider"; | ||
| import { SegmentedList } from "~/components/List/Segmented"; | ||
| import { Em, TStyledText } from "~/components/Typography/StyledText"; | ||
|
|
||
| const PRESET_OPTIONS = [1, 1.25, 1.5, 2] as const; | ||
|
|
||
| export function PlaybackParameterSlider(props: { | ||
| field: "pitch" | "speed"; | ||
| onUpdate: (value: number) => void; | ||
| Icon: (props: Icon) => React.JSX.Element; | ||
| }) { | ||
| const fieldName = `playback${capitalize(props.field)}` as const; | ||
| const fieldNameKey = `feat.playback.extra.${props.field}` as const; | ||
|
|
||
| const storedValue = useSessionStore((s) => s[fieldName]); | ||
| const cachedValue = useSharedValue(storedValue); | ||
|
|
||
| const setField = useCallback( | ||
| (value: number) => { | ||
| sessionStore.setState({ [fieldName]: value }); | ||
| props.onUpdate(value); | ||
| }, | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [props.onUpdate, fieldName], | ||
| ); | ||
|
|
||
| const PresetButtons = useMemo(() => { | ||
| return PRESET_OPTIONS.map((preset) => ( | ||
| <Button | ||
| key={preset} | ||
| onPress={() => { | ||
| setField(preset); | ||
| cachedValue.set(preset); | ||
| }} | ||
| className="min-h-8 flex-1 rounded-full bg-surfaceContainerLow py-2 active:bg-surfaceContainer" | ||
| > | ||
| <Em>{formatValue(preset)}</Em> | ||
| </Button> | ||
| )); | ||
| }, [cachedValue, setField]); | ||
|
|
||
| return ( | ||
| <SegmentedList.CustomItem className="gap-4 p-4"> | ||
| <TStyledText textKey={fieldNameKey} className="text-sm" /> | ||
| <View className="flex-row items-center gap-2"> | ||
| <CachedSlider | ||
| initValue={storedValue} | ||
| liveValue={cachedValue} | ||
| min={0.25} | ||
| max={2} | ||
| step={0.05} | ||
| onChange={setField} | ||
| hitSlop={10} | ||
| trackColor="surfaceContainer" | ||
| roundedEndStop | ||
| _debounceMultiplier={1} | ||
| _className="shrink grow" | ||
| /> | ||
| <View className="w-14 flex-row items-center justify-center gap-2"> | ||
| {<props.Icon size={20} />} | ||
| <Em style={{ fontVariant: ["tabular-nums"] }}> | ||
| {numberFormatter.format(storedValue)}x | ||
| </Em> | ||
| </View> | ||
| </View> | ||
| <View className="flex-row items-center gap-4">{PresetButtons}</View> | ||
| </SegmentedList.CustomItem> | ||
| ); | ||
| } | ||
|
|
||
| //#region Helpers | ||
| const numberFormatter = new Intl.NumberFormat("en-US", { | ||
| notation: "compact", | ||
| maximumFractionDigits: 2, | ||
| }); | ||
|
|
||
| function formatValue(val: number) { | ||
| return `${numberFormatter.format(val)}x`; | ||
| } | ||
| //#endregion | ||
83 changes: 0 additions & 83 deletions
83
mobile/src/modules/audio/_components/PlaybackSpeedSetting.tsx
This file was deleted.
Oops, something went wrong.
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
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,13 @@ | ||
| import Svg, { Path } from "react-native-svg"; | ||
|
|
||
| import { useColor } from "~/modules/customization/theme/hooks"; | ||
| import type { Icon } from "./type"; | ||
|
|
||
| export function VoiceSelection({ size = 24, color }: Icon) { | ||
| const usedColor = useColor(color, "onSurface"); | ||
| return ( | ||
| <Svg width={size} height={size} viewBox="0 -960 960 960" fill={usedColor}> | ||
| <Path d="M728.17-99.96q-11.67 0-19.79-8.24-8.11-8.24-8.11-19.9 0-5.82 2.01-10.81 2.02-4.99 5.8-8.71 43.69-43.69 67.71-100.15 24.02-56.46 24.02-121.1 0-64.17-24.02-120.69-24.02-56.52-67.71-100.21-3.78-3.75-5.8-8.78-2.01-5.03-2.01-11.02 0-11.43 7.99-19.64t19.65-8.21q5.82 0 10.89 2.2 5.06 2.2 8.81 5.91 51.2 51.2 79.68 118.1 28.48 66.9 28.48 142.36 0 75.89-28.48 142.73-28.48 66.85-79.68 118.04-3.76 3.72-8.59 5.92-4.83 2.2-10.85 2.2Zm-104.7-104.85q-11.62 0-19.83-8.14-8.22-8.15-8.22-19.81 0-6.01 2.2-10.83 2.2-4.81 5.92-8.56 23.23-23.23 35.9-53.22 12.68-29.98 12.68-63.32 0-33.35-12.83-63.33-12.83-29.98-35.75-53.21-4.15-3.76-6.14-8.85-1.98-5.08-1.98-11.1 0-11.47 8.24-19.53t19.9-8.06q5.82 0 10.81 2.08t8.71 6.04q30.42 30.61 47.71 70.53 17.29 39.93 17.29 85.43 0 45.5-17.29 85.42-17.29 39.93-47.71 70.35-3.75 4.15-8.78 6.13-5.03 1.98-10.83 1.98ZM336.15-369.89h-92.11v14.08q0 36.27 23.44 63.48 23.44 27.21 58.79 36.21l12 3q34.15 8.93 37.81 45.41 3.65 36.48-29.93 52.53-49.42 24.14-102.38 34.45-52.96 10.31-107.62 12.04-11.65.61-19.86-7.61-8.21-8.23-8.21-19.87 0-11.45 8.22-19.59 8.22-8.15 19.85-8.89 41.35-1.62 81.64-7.89t79.83-21.19q4.61-1.73 4.23-7.02-.39-5.29-6.93-6.83-47.38-18.19-77.11-58.36-29.73-40.18-29.73-90.64v-35.03q0-14.25 9.99-24.24 9.99-10 24.24-10h113.46q5.38 0 8.85-3.46 3.46-3.46 3.46-8.84v-68q0-14.25 9.99-24.24 9.99-9.99 24.24-9.99h88.23q6.92 0 10.48-5.58 3.56-5.58.67-11.73L372.08-780.27q-5.39-10.34-1.67-21.15 3.71-10.81 14.25-16.58 10.34-5.77 21.53-1.77 11.2 4 16.58 14.35l109.5 223.46q16.58 34.23-2.98 65.88-19.55 31.66-57.75 31.66h-67.5v46.65q0 28.35-19.87 48.12-19.86 19.76-48.02 19.76Z" /> | ||
| </Svg> | ||
| ); | ||
| } |
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
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.