Skip to content

Commit a985df1

Browse files
feat(synced-lyrics): lyrics offset
1 parent 5853523 commit a985df1

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

Diff for: src/i18n/resources/en.json

+8
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,14 @@
752752
},
753753
"tooltip": "Choose the effect to apply to the current line"
754754
},
755+
"offset": {
756+
"label": "Lyrics offset",
757+
"tooltip": "Set the offset for the lyrics (useful when using bluetooth speakers)",
758+
"prompt": {
759+
"title": "Lyrics offset",
760+
"label": "Set the lyrics offset in ms"
761+
}
762+
},
755763
"precise-timing": {
756764
"label": "Make the lyrics perfectly synced",
757765
"tooltip": "Calculate to the milisecond the display of the next line (can have a small impact on performance)"

Diff for: src/plugins/synced-lyrics/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default createPlugin({
1616
config: {
1717
enabled: false,
1818
preciseTiming: true,
19+
lyricsOffset: 0,
1920
showLyricsEvenIfInexact: true,
2021
showTimeCodes: false,
2122
defaultTextString: '♪',

Diff for: src/plugins/synced-lyrics/menu.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import prompt from 'custom-electron-prompt';
2+
13
import { t } from '@/i18n';
4+
import promptOptions from '@/providers/prompt-options';
25

36
import type { MenuItemConstructorOptions } from 'electron';
47
import type { MenuContext } from '@/types/contexts';
@@ -10,6 +13,30 @@ export const menu = async (
1013
const config = await ctx.getConfig();
1114

1215
return [
16+
{
17+
label: t('plugins.synced-lyrics.menu.offset.label'),
18+
toolTip: t('plugins.synced-lyrics.menu.offset.tooltip'),
19+
type: 'normal',
20+
async click() {
21+
const config = await ctx.getConfig();
22+
const newOffset = await prompt(
23+
{
24+
title: t('plugins.synced-lyrics.menu.offset.prompt.title'),
25+
label: t('plugins.synced-lyrics.menu.offset.prompt.label'),
26+
value: config.lyricsOffset || 0,
27+
type: 'counter',
28+
counterOptions: { multiFire: true },
29+
width: 380,
30+
...promptOptions(),
31+
},
32+
ctx.window,
33+
);
34+
35+
ctx.setConfig({
36+
lyricsOffset: newOffset ?? config.lyricsOffset,
37+
});
38+
},
39+
},
1340
{
1441
label: t('plugins.synced-lyrics.menu.precise-timing.label'),
1542
toolTip: t('plugins.synced-lyrics.menu.precise-timing.tooltip'),

Diff for: src/plugins/synced-lyrics/renderer/components/SyncedLine.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface SyncedLineProps {
2424

2525
export const SyncedLine = (props: SyncedLineProps) => {
2626
const status = createMemo(() => {
27-
const current = currentTime();
27+
const current = Math.max(0, currentTime() - (config()?.lyricsOffset ?? 0));
2828

2929
if (props.line.timeInMs >= current) return 'upcoming';
3030
if (current - props.line.timeInMs >= props.line.duration) return 'previous';

Diff for: src/plugins/synced-lyrics/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type SyncedLyricsPluginConfig = {
44
enabled: boolean;
55
preciseTiming: boolean;
66
showTimeCodes: boolean;
7+
lyricsOffset: number;
78
defaultTextString: string;
89
showLyricsEvenIfInexact: boolean;
910
lineEffect: LineEffect;

0 commit comments

Comments
 (0)