Skip to content

feat(synced-lyrics): lyrics offset #3240

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@
},
"tooltip": "Choose the effect to apply to the current line"
},
"offset": {
"label": "Lyrics offset",
"tooltip": "Set the offset for the lyrics (useful when using bluetooth speakers)",
"prompt": {
"title": "Lyrics offset",
"label": "Set the lyrics offset in ms"
}
},
"precise-timing": {
"label": "Make the lyrics perfectly synced",
"tooltip": "Calculate to the milisecond the display of the next line (can have a small impact on performance)"
Expand Down
1 change: 1 addition & 0 deletions src/plugins/synced-lyrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default createPlugin({
config: {
enabled: false,
preciseTiming: true,
lyricsOffset: 0,
showLyricsEvenIfInexact: true,
showTimeCodes: false,
defaultTextString: '♪',
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/synced-lyrics/menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import prompt from 'custom-electron-prompt';

import { t } from '@/i18n';
import promptOptions from '@/providers/prompt-options';

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

return [
{
label: t('plugins.synced-lyrics.menu.offset.label'),
toolTip: t('plugins.synced-lyrics.menu.offset.tooltip'),
type: 'normal',
async click() {
const config = await ctx.getConfig();
const newOffset = await prompt(
{
title: t('plugins.synced-lyrics.menu.offset.prompt.title'),
label: t('plugins.synced-lyrics.menu.offset.prompt.label'),
value: config.lyricsOffset || 0,
type: 'counter',
counterOptions: { multiFire: true },
width: 380,
...promptOptions(),
},
ctx.window,
);

ctx.setConfig({
lyricsOffset: newOffset ?? config.lyricsOffset,
});
},
},
{
label: t('plugins.synced-lyrics.menu.precise-timing.label'),
toolTip: t('plugins.synced-lyrics.menu.precise-timing.tooltip'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface SyncedLineProps {

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

if (props.line.timeInMs >= current) return 'upcoming';
if (current - props.line.timeInMs >= props.line.duration) return 'previous';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/synced-lyrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type SyncedLyricsPluginConfig = {
enabled: boolean;
preciseTiming: boolean;
showTimeCodes: boolean;
lyricsOffset: number;
defaultTextString: string;
showLyricsEvenIfInexact: boolean;
lineEffect: LineEffect;
Expand Down