Skip to content
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

Add a speed modifier slider #103

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/renderer/src/components/song/song-detail/SongControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import {
song,
setVolume,
volume,
setSpeed,
speed,
handleMuteSong,
} from "../song.utils";
import Button from "@renderer/components/button/Button";
import Slider from "@renderer/components/slider/Slider";
import {
CirclePlusIcon,
GaugeIcon,
PauseIcon,
PlayIcon,
RepeatIcon,
Expand Down Expand Up @@ -162,6 +165,26 @@ const LeftPart = () => {
<Slider.Thumb class="mt-2 block h-4 w-4 rounded-full bg-white" />
</Slider>
</Show>

<Button size="icon" variant="ghost" title="Set speed">
<GaugeIcon size={20} />
</Button>

<Show when={isHoveringVolume()}>
<Slider
class="flex h-8 w-28 flex-grow items-center"
min={1}
max={2}
value={speed}
onValueChange={setSpeed}
enableWheelSlide
>
<Slider.Track class="h-1 flex-1 rounded bg-thick-material ring-1 ring-stroke">
<Slider.Range class="block h-1 rounded bg-white" />
</Slider.Track>
<Slider.Thumb class="mt-2 block h-4 w-4 rounded-full bg-white" />
</Slider>
</Show>
</div>
</div>
);
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/src/components/song/song.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ export const setVolume = (newValue: ZeroToOne) => {
_setVolume(newValue);
setValueBeforeMute(undefined);
};
export { volume };

const [speed, _setSpeed] = createSignal<ZeroToOne>(1);
export const setSpeed = (newValue: ZeroToOne) => {
_setSpeed(newValue);
speedNum = newValue;
player.playbackRate = newValue;
};
export { volume, speed };

let bgPath: Optional<string>;
let speedNum = 1;

const player = new Audio();

Expand Down Expand Up @@ -295,6 +303,7 @@ window.api.listen("queue::songChanged", async (s) => {
setSong(s);
await window.api.request("discord::play", s);
await play();
player.playbackRate = speedNum;
Plextora marked this conversation as resolved.
Show resolved Hide resolved
});

player.addEventListener("ended", async () => {
Expand Down