Skip to content

Commit ff91da4

Browse files
committed
Update builtin scripts
1 parent d5a64b2 commit ff91da4

15 files changed

Lines changed: 325 additions & 73 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"lrcLabels": {
3+
"title": "LRC Labels",
4+
"description": "Imports and exports project labels in LRC format.",
5+
"fileFilter": "LRC Lyrics",
6+
"startPositionLabel": "Start position",
7+
"import": {
8+
"title": "Import LRC as Labels",
9+
"description": "Imports timestamped lyrics from an LRC file as project labels.",
10+
"openTitle": "Open LRC Lyrics",
11+
"failureTitle": "LRC Import Failed",
12+
"invalidLine": "The LRC file contains an invalid entry on line {{line}}.",
13+
"noTimestampedLines": "The LRC file contains no timestamped lines."
14+
},
15+
"export": {
16+
"title": "Export Labels to LRC",
17+
"description": "Exports project labels as timestamped lyrics in an LRC file.",
18+
"saveTitle": "Save LRC Lyrics",
19+
"noLabels": "The project contains no labels to export."
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"lrcLabels": {
3+
"title": "LRCラベル",
4+
"description": "プロジェクトのラベルをLRC形式でインポートおよびエクスポートします。",
5+
"fileFilter": "LRC歌詞ファイル",
6+
"startPositionLabel": "開始位置",
7+
"import": {
8+
"title": "LRCをラベルとしてインポート",
9+
"description": "LRCファイルのタイムスタンプ付き歌詞をプロジェクトのラベルとしてインポートします。",
10+
"openTitle": "LRC歌詞ファイルを開く",
11+
"failureTitle": "LRCのインポートに失敗しました",
12+
"invalidLine": "LRCファイルの{{line}}行目に無効な項目があります。",
13+
"noTimestampedLines": "LRCファイルにタイムスタンプ付きの行がありません。"
14+
},
15+
"export": {
16+
"title": "ラベルをLRCにエクスポート",
17+
"description": "プロジェクトのラベルをタイムスタンプ付きの歌詞としてLRCファイルにエクスポートします。",
18+
"saveTitle": "LRC歌詞ファイルを保存",
19+
"noLabels": "プロジェクトにエクスポートできるラベルがありません。"
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"lrcLabels": {
3+
"title": "LRC 标签",
4+
"description": "以 LRC 格式导入和导出工程标签。",
5+
"fileFilter": "LRC 歌词文件",
6+
"startPositionLabel": "起始位置",
7+
"import": {
8+
"title": "将 LRC 导入为标签",
9+
"description": "将 LRC 文件中带时间戳的歌词导入为工程标签。",
10+
"openTitle": "打开 LRC 歌词文件",
11+
"failureTitle": "LRC 导入失败",
12+
"invalidLine": "LRC 文件的第 {{line}} 行包含无效条目。",
13+
"noTimestampedLines": "LRC 文件中没有带时间戳的行。"
14+
},
15+
"export": {
16+
"title": "将标签导出为 LRC",
17+
"description": "将工程标签作为带时间戳的歌词导出到 LRC 文件。",
18+
"saveTitle": "保存 LRC 歌词文件",
19+
"noLabels": "工程中没有可导出的标签。"
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"lrcLabels": {
3+
"title": "LRC 標籤",
4+
"description": "以 LRC 格式匯入及匯出專案標籤。",
5+
"fileFilter": "LRC 歌詞檔案",
6+
"startPositionLabel": "起始位置",
7+
"import": {
8+
"title": "將 LRC 匯入為標籤",
9+
"description": "將 LRC 檔案中帶有時間戳記的歌詞匯入為專案標籤。",
10+
"openTitle": "開啟 LRC 歌詞檔案",
11+
"failureTitle": "LRC 匯入失敗",
12+
"invalidLine": "LRC 檔案的第 {{line}} 行包含無效項目。",
13+
"noTimestampedLines": "LRC 檔案中沒有帶有時間戳記的行。"
14+
},
15+
"export": {
16+
"title": "將標籤匯出為 LRC",
17+
"description": "將專案標籤以帶有時間戳記的歌詞形式匯出至 LRC 檔案。",
18+
"saveTitle": "儲存 LRC 歌詞檔案",
19+
"noLabels": "專案中沒有可匯出的標籤。"
20+
}
21+
}
22+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
const { application } = require("diffscope:core");
2+
const { parse: parsePath } = require("diffscope:fs");
3+
const { loadI18n, t } = require("diffscope:runtime");
4+
const { dialogs } = require("diffscope:shell");
5+
6+
loadI18n("i18n");
7+
8+
const lrcFileFilters = [{ name: t("lrcLabels.fileFilter"), patterns: ["*.lrc"] }];
9+
const timestampPattern = /^\[(\d+):([0-5]\d)(?:\.(\d{1,3}))?\]/;
10+
const wordTimestampPattern = /<\d+:[0-5]\d(?:\.\d{1,3})?>/g;
11+
const metadataPattern = /^\[([a-z][a-z\d_-]*|#):(.*)\]$/i;
12+
13+
function parseLrc(contents) {
14+
const entries = [];
15+
let offset = 0;
16+
17+
const lines = contents.split(/\r\n|\n|\r/);
18+
for (let index = 0; index < lines.length; ++index) {
19+
let text = lines[index].trim();
20+
if (text === "") {
21+
continue;
22+
}
23+
24+
const metadata = metadataPattern.exec(text);
25+
if (metadata !== null) {
26+
if (metadata[1].toLowerCase() === "offset") {
27+
const value = metadata[2].trim();
28+
if (!/^[+-]?\d+$/.test(value)) {
29+
return { errorLine: index + 1 };
30+
}
31+
offset = Number(value);
32+
}
33+
continue;
34+
}
35+
36+
const times = [];
37+
let timestamp = timestampPattern.exec(text);
38+
while (timestamp !== null) {
39+
const fraction = timestamp[3] || "";
40+
const milliseconds = (Number(timestamp[1]) * 60 + Number(timestamp[2])) * 1000
41+
+ Number(fraction) * 10 ** (3 - fraction.length);
42+
times.push(milliseconds);
43+
text = text.slice(timestamp[0].length).trim();
44+
timestamp = timestampPattern.exec(text);
45+
}
46+
47+
text = text.replace(wordTimestampPattern, "").trim();
48+
if (times.length === 0 || /^\[\s*[+-]?\d+:/.test(text) || /<\s*[+-]?\d+:/.test(text)) {
49+
return { errorLine: index + 1 };
50+
}
51+
for (const milliseconds of times) {
52+
entries.push({ milliseconds, text });
53+
}
54+
}
55+
56+
return { entries, offset };
57+
}
58+
59+
function formatTimestamp(milliseconds) {
60+
const time = Math.round(milliseconds);
61+
const minutes = Math.floor(time / 60000);
62+
const seconds = Math.floor(time / 1000) % 60;
63+
const fraction = time % 1000;
64+
return `[${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(fraction).padStart(3, "0")}]`;
65+
}
66+
67+
function promptStartTick(project, title, maximum = 2147483647) {
68+
const form = dialogs.form({
69+
title,
70+
fields: [
71+
{
72+
// TODO Replace this field with a musical position input when available.
73+
type: "integer",
74+
name: "startTick",
75+
label: t("lrcLabels.startPositionLabel"),
76+
value: Math.min(project.timeline.playhead, maximum),
77+
maximum,
78+
control: "spinBox"
79+
}
80+
],
81+
parent: project.window
82+
});
83+
return form === null ? null : form.startTick;
84+
}
85+
86+
function importLrc() {
87+
const project = application.project;
88+
const file = dialogs.openFile({
89+
title: t("lrcLabels.import.openTitle"),
90+
filters: lrcFileFilters,
91+
parent: project.window
92+
});
93+
if (file === null) {
94+
return;
95+
}
96+
97+
const title = t("lrcLabels.import.title");
98+
const startTick = promptStartTick(project, title);
99+
if (startTick === null) {
100+
return;
101+
}
102+
103+
const result = parseLrc(file.readText());
104+
if (result.errorLine !== undefined || result.entries.length === 0) {
105+
const message = result.errorLine !== undefined
106+
? t("lrcLabels.import.invalidLine", { line: result.errorLine.toLocaleString() })
107+
: t("lrcLabels.import.noTimestampedLines");
108+
dialogs.alert(message, {
109+
title: t("lrcLabels.import.failureTitle"),
110+
severity: "warning",
111+
parent: project.window
112+
});
113+
return;
114+
}
115+
116+
const document = project.document;
117+
const labels = document.model.labels;
118+
const timeline = project.timeline;
119+
const startMilliseconds = timeline.toMilliseconds(startTick);
120+
const transaction = document.beginTransaction();
121+
for (const { milliseconds, text } of result.entries) {
122+
const projectMilliseconds = startMilliseconds + (milliseconds - result.offset);
123+
const position = timeline.fromMilliseconds(Math.max(0, projectMilliseconds));
124+
labels.create({ position, text });
125+
}
126+
transaction.commit(title);
127+
}
128+
129+
function exportLrc() {
130+
const project = application.project;
131+
const title = t("lrcLabels.export.title");
132+
const labels = Array.from(project.document.model.labels);
133+
if (labels.length === 0) {
134+
dialogs.alert(t("lrcLabels.export.noLabels"), {
135+
title,
136+
severity: "warning",
137+
parent: project.window
138+
});
139+
return;
140+
}
141+
labels.sort((left, right) => left.position - right.position);
142+
143+
const projectPath = project.filePath;
144+
const file = dialogs.saveFile({
145+
title: t("lrcLabels.export.saveTitle"),
146+
suggestedName: projectPath === null ? "labels.lrc" : `${parsePath(projectPath).name}.lrc`,
147+
filters: lrcFileFilters,
148+
parent: project.window
149+
});
150+
if (file === null) {
151+
return;
152+
}
153+
154+
const startTick = promptStartTick(project, title, labels[0].position);
155+
if (startTick === null) {
156+
return;
157+
}
158+
159+
const timeline = project.timeline;
160+
const startMilliseconds = timeline.toMilliseconds(startTick);
161+
const lines = labels.map(({ position, text }) => {
162+
const timestamp = formatTimestamp(timeline.toMilliseconds(position) - startMilliseconds);
163+
return timestamp + text.replace(/\r\n|\n|\r/g, " ");
164+
});
165+
file.writeText(lines.join("\n") + "\n");
166+
}
167+
168+
module.exports = defineScript({
169+
id: "org.diffscope.lrc-labels",
170+
name: t("lrcLabels.title"),
171+
version: "1.0.0",
172+
description: t("lrcLabels.description"),
173+
actions: [
174+
{
175+
name: t("lrcLabels.import.title"),
176+
description: t("lrcLabels.import.description"),
177+
requiresProject: true,
178+
execute: importLrc
179+
},
180+
{
181+
name: t("lrcLabels.export.title"),
182+
description: t("lrcLabels.export.description"),
183+
requiresProject: true,
184+
execute: exportLrc
185+
}
186+
]
187+
});

‎src/plugins/batchprocess/res/builtin/quantize/i18n/en.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"title": "Quantize",
44
"description": "Quantizes the start positions and lengths of notes in the selected singing clips or the selected notes.",
55
"selectionWarning": "Select one or more singing clips containing notes, or select one or more notes.",
6-
"formDescription": "Choose the grid size, rhythm, and note properties to quantize.",
76
"gridLabel": "Grid size",
87
"rhythmLabel": "Rhythm",
98
"modeLabel": "Apply to",

‎src/plugins/batchprocess/res/builtin/quantize/i18n/ja.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"title": "クオンタイズ",
44
"description": "選択した歌声クリップ内の音符、または選択した音符の開始位置と長さをクオンタイズします。",
55
"selectionWarning": "音符を含む歌声クリップ、または音符を 1 つ以上選択してください。",
6-
"formDescription": "グリッドの間隔、リズム、およびクオンタイズする音符の属性を選択してください。",
76
"gridLabel": "グリッドの間隔",
87
"rhythmLabel": "リズム",
98
"modeLabel": "クオンタイズ対象",

‎src/plugins/batchprocess/res/builtin/quantize/i18n/zh-CN.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"title": "量化",
44
"description": "量化所选歌声剪辑中的音符或所选音符的起始位置和时长。",
55
"selectionWarning": "请选择一个或多个包含音符的歌声剪辑,或选择一个或多个音符。",
6-
"formDescription": "选择量化大小、节奏类型和需要量化的音符属性。",
76
"gridLabel": "量化大小",
87
"rhythmLabel": "节奏类型",
98
"modeLabel": "量化内容",

‎src/plugins/batchprocess/res/builtin/quantize/i18n/zh-TW.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"title": "量化",
44
"description": "量化所選歌聲剪輯中的音符或所選音符的起始位置和時長。",
55
"selectionWarning": "請選取一個或多個包含音符的歌聲剪輯,或選取一個或多個音符。",
6-
"formDescription": "選擇量化大小、節奏類型和需要量化的音符屬性。",
76
"gridLabel": "量化大小",
87
"rhythmLabel": "節奏類型",
98
"modeLabel": "量化內容",

0 commit comments

Comments
 (0)