Skip to content

Commit

Permalink
bncm: 支持传参FFT到背景
Browse files Browse the repository at this point in the history
core: 修正背景 setLowFreqVolume 传参
  • Loading branch information
Steve-xmh committed Dec 18, 2023
1 parent 90ab6b5 commit 9ab0911
Show file tree
Hide file tree
Showing 6 changed files with 11,820 additions and 11,764 deletions.
23,539 changes: 11,782 additions & 11,757 deletions packages/bncm/dist/amll-bncm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/bncm/dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"manifest_version":1,"name":"类苹果歌词","slug":"Apple-Musiclike-lyrics","author":"SteveXMH","author_links":["https://github.com/Steve-xmh","https://github.com/Steve-xmh/applemusic-like-lyrics"],"description":"类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验","preview":"preview.svg","version":"3.0.3","commit":"5e45dbd238fbd9f2af51bfe8c71bf227dd7c80fb","branch":"dev","type":"extension","noDevReload":true,"ncm3-compatible":true,"betterncm_version":">=1.0.0","injects":{"Main":[{"file":"amll-bncm.js"}]},"hijacks":{">= 1.0.0":{"orpheus://orpheus/pub/app.html":{"type":"replace","id":"csp-worker","from":"<meta http-equiv=\"Content-Security-Policy\" content=\"script-src ","to":"<meta http-equiv=\"Content-Security-Policy\" content=\"script-src data: blob: "}},">= 3.0.0":{"orpheus://orpheus/pub/hybrid/vendors":{"type":"replace","id":"redux-dispatch-hook","from":"\"sagaEffects.put\"),","to":"\"sagaEffects.put\"),window?.amllDispatchHook?.(n),"}}}}
{"manifest_version":1,"name":"类苹果歌词","slug":"Apple-Musiclike-lyrics","author":"SteveXMH","author_links":["https://github.com/Steve-xmh","https://github.com/Steve-xmh/applemusic-like-lyrics"],"description":"类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验","preview":"preview.svg","version":"3.0.3","commit":"90ab6b5463e66b34b0c0003212cd07b840631da6","branch":"dev","type":"extension","noDevReload":true,"ncm3-compatible":true,"betterncm_version":">=1.0.0","injects":{"Main":[{"file":"amll-bncm.js"}]},"hijacks":{">= 1.0.0":{"orpheus://orpheus/pub/app.html":{"type":"replace","id":"csp-worker","from":"<meta http-equiv=\"Content-Security-Policy\" content=\"script-src ","to":"<meta http-equiv=\"Content-Security-Policy\" content=\"script-src data: blob: "}},">= 3.0.0":{"orpheus://orpheus/pub/hybrid/vendors":{"type":"replace","id":"redux-dispatch-hook","from":"\"sagaEffects.put\"),","to":"\"sagaEffects.put\"),window?.amllDispatchHook?.(n),"}}}}
37 changes: 34 additions & 3 deletions packages/bncm/src/player/common/background.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAtomValue } from "jotai";
import type { FC } from "react";
import { useState, type FC, useEffect } from "react";
import {
backgroundStaticModeAtom,
backgroundTypeAtom,
Expand All @@ -21,6 +21,7 @@ import {
import "./background.sass";
import { EplorRenderer } from "@applemusic-like-lyrics/core";
import { fftDataAtom } from "./fft-context";
import { globalStore } from "../../injector";

export const Background: FC = () => {
const enableBackground = useAtomValue(enableBackgroundAtom);
Expand All @@ -34,28 +35,58 @@ export const Background: FC = () => {
const wsStatus = useAtomValue(wsConnectionStatusAtom);
const backgroundFakeLiquidStaticMode = useAtomValue(backgroundStaticModeAtom);
const backgroundType = useAtomValue(backgroundTypeAtom);
const fftData = useAtomValue(fftDataAtom);
const [lowFreqVolume, setLowFreqVolume] = useState(1);

useEffect(() => {
let maxValue = 1;
let curValue = 1;

let stopped = false;
let lt = 0;
const onFrame = (dt: number) => {
if (stopped) return;
// const delta = dt - lt;

const value = globalStore.get(fftDataAtom)[0] ?? 1;
setLowFreqVolume(curValue / maxValue);

maxValue = (maxValue * 99 + Math.max(maxValue, curValue * 2, 1)) / 100;
curValue = (curValue * 9 + value) / 10;

requestAnimationFrame(onFrame);
lt = dt;
};

onFrame(0);

return () => {
stopped = true;
}
}, [wsStatus.color, enableBackground, backgroundType])

if (wsStatus.color !== ConnectionColor.Active && enableBackground) {
if (
backgroundType === BackgroundType.FakeLiquid ||
backgroundType === BackgroundType.LiquidEplor
) {
return (
<>
<BackgroundRender
className="amll-background-render-wrapper"
staticMode={backgroundFakeLiquidStaticMode}
disabled={!lyricPageOpened}
albumImageUrl={musicCoverUrl}
fps={backgroundMaxFPS}
lowFreqVolume={fftData[0]}
lowFreqVolume={lowFreqVolume}
renderScale={backgroundRenderScale}
renderer={
backgroundType === BackgroundType.LiquidEplor
? EplorRenderer
: undefined
}
/>
<span>{lowFreqVolume}</span>
</>
);
} else if (backgroundType === BackgroundType.CustomSolidColor) {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/dist/amll-core.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/dist/amll-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/src/bg-render/eplor-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class EplorRenderer extends BaseRenderer {
}

override setLowFreqVolume(volume: number): void {
this._lowFreqVolume = Math.max(0, Math.min(1, volume));
this._lowFreqVolume = volume;
}

override setStaticMode(enable: boolean): void {
Expand Down

0 comments on commit 9ab0911

Please sign in to comment.