Skip to content

Commit a63cfd6

Browse files
committed
Update builtin scripts
1 parent 7af8696 commit a63cfd6

12 files changed

Lines changed: 218 additions & 33 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"freezeGeneratedContent": {
3+
"title": "Freeze Generated Content",
4+
"description": "Freezes generated content in the selected singing clips or notes.",
5+
"selectionWarning": "Select one or more singing clips or notes.",
6+
"contents": {
7+
"parameters": "Parameters",
8+
"phonemes": "Phonemes",
9+
"pronunciation": "Pronunciation"
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"freezeGeneratedContent": {
3+
"title": "生成された内容を固定",
4+
"description": "選択した歌声クリップまたは音符の生成内容を固定します。",
5+
"selectionWarning": "歌声クリップまたは音符を 1 つ以上選択してください。",
6+
"contents": {
7+
"parameters": "パラメーター",
8+
"phonemes": "音素",
9+
"pronunciation": "発音"
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"freezeGeneratedContent": {
3+
"title": "固定生成内容",
4+
"description": "固定所选歌声剪辑或音符中已生成的内容。",
5+
"selectionWarning": "请选择一个或多个歌声剪辑,或选择一个或多个音符。",
6+
"contents": {
7+
"parameters": "参数",
8+
"phonemes": "音素",
9+
"pronunciation": "发音"
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"freezeGeneratedContent": {
3+
"title": "固定生成內容",
4+
"description": "固定所選歌聲剪輯或音符中已生成的內容。",
5+
"selectionWarning": "請選取一個或多個歌聲剪輯,或選取一個或多個音符。",
6+
"contents": {
7+
"parameters": "參數",
8+
"phonemes": "音素",
9+
"pronunciation": "發音"
10+
}
11+
}
12+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
const { application } = require("diffscope:core");
2+
const { dialogs } = require("diffscope:shell");
3+
const { loadI18n, t } = require("diffscope:runtime");
4+
5+
loadI18n("i18n");
6+
7+
function showSelectionWarning(project) {
8+
dialogs.alert(t("freezeGeneratedContent.selectionWarning"), {
9+
title: t("freezeGeneratedContent.title"),
10+
severity: "warning",
11+
parent: project.window
12+
});
13+
}
14+
15+
function freezeParameter(parameter) {
16+
const original = parameter.original.toArray();
17+
const edited = parameter.freeEdited;
18+
const samples = edited.toArray().slice();
19+
let changed = false;
20+
for (let index = 0; index < original.length; ++index) {
21+
const value = original[index];
22+
if (value === null || (index < samples.length && samples[index] !== null)) {
23+
continue;
24+
}
25+
while (samples.length < index) {
26+
samples.push(null);
27+
}
28+
samples[index] = value;
29+
changed = true;
30+
}
31+
if (changed) {
32+
edited.splice(0, edited.length, samples);
33+
}
34+
return changed;
35+
}
36+
37+
module.exports = defineScript({
38+
id: "org.diffscope.freeze-generated-content",
39+
name: t("freezeGeneratedContent.title"),
40+
version: "1.0.0",
41+
description: t("freezeGeneratedContent.description"),
42+
actions: [
43+
{
44+
name: t("freezeGeneratedContent.title"),
45+
description: t("freezeGeneratedContent.description"),
46+
requiresProject: true,
47+
execute() {
48+
const project = application.project;
49+
const document = project.document;
50+
const selection = document.selection;
51+
const notes = new Map();
52+
let clips = [];
53+
54+
if (selection.type === "clip") {
55+
clips = selection.clips.items.filter(clip => clip.kind === "singing");
56+
for (const clip of clips) {
57+
for (const note of clip.notes) {
58+
notes.set(note.handle, note);
59+
}
60+
}
61+
} else if (selection.type === "note") {
62+
for (const note of selection.notes.items) {
63+
notes.set(note.handle, note);
64+
}
65+
}
66+
67+
if (clips.length === 0 && notes.size === 0) {
68+
showSelectionWarning(project);
69+
return;
70+
}
71+
72+
const fields = [];
73+
if (clips.length !== 0) {
74+
fields.push({
75+
type: "boolean",
76+
name: "parameters",
77+
label: t("freezeGeneratedContent.contents.parameters"),
78+
value: true
79+
});
80+
}
81+
fields.push({
82+
type: "boolean",
83+
name: "phonemes",
84+
label: t("freezeGeneratedContent.contents.phonemes"),
85+
value: true
86+
});
87+
fields.push({
88+
type: "boolean",
89+
name: "pronunciation",
90+
label: t("freezeGeneratedContent.contents.pronunciation"),
91+
value: true
92+
});
93+
94+
const readLock = document.mustAcquireReadLock();
95+
const result = dialogs.form({
96+
title: t("freezeGeneratedContent.title"),
97+
fields,
98+
parent: project.window
99+
});
100+
readLock.release();
101+
if (result === null) {
102+
return;
103+
}
104+
105+
const transaction = document.beginTransaction();
106+
let changed = false;
107+
if (result.parameters) {
108+
for (const clip of clips) {
109+
for (const [, parameter] of clip.parameters) {
110+
if (freezeParameter(parameter)) {
111+
changed = true;
112+
}
113+
}
114+
}
115+
}
116+
if (result.phonemes) {
117+
for (const note of notes.values()) {
118+
if (note.editedPhonemes.length === 0 && note.originalPhonemes.length !== 0) {
119+
note.editedPhonemes.fromOpenDSPX(note.originalPhonemes.toOpenDSPX());
120+
changed = true;
121+
}
122+
}
123+
}
124+
if (result.pronunciation) {
125+
for (const note of notes.values()) {
126+
const pronunciation = note.originalPronunciation;
127+
if (note.editedPronunciation === "" && pronunciation !== "") {
128+
note.editedPronunciation = pronunciation;
129+
changed = true;
130+
}
131+
}
132+
}
133+
134+
if (!changed) {
135+
transaction.abort();
136+
return;
137+
}
138+
139+
transaction.commit(t("freezeGeneratedContent.title"));
140+
}
141+
}
142+
]
143+
});

‎src/plugins/batchprocess/res/builtin/lrc-labels/i18n/en.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"positionLabel": "Position",
1313
"textLabel": "Lyrics",
1414
"fontSizeTitle": "Font Size",
15-
"fontSizeLabel": "Font size",
16-
"projectBusy": "The project is busy."
15+
"fontSizeLabel": "Font size"
1716
},
1817
"import": {
1918
"title": "Import LRC as Labels",

‎src/plugins/batchprocess/res/builtin/lrc-labels/i18n/ja.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"positionLabel": "位置",
1313
"textLabel": "歌詞",
1414
"fontSizeTitle": "フォントサイズ",
15-
"fontSizeLabel": "フォントサイズ",
16-
"projectBusy": "プロジェクトで別の操作が進行中です。"
15+
"fontSizeLabel": "フォントサイズ"
1716
},
1817
"import": {
1918
"title": "LRCをラベルとしてインポート",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"positionLabel": "位置",
1313
"textLabel": "歌词",
1414
"fontSizeTitle": "字体大小",
15-
"fontSizeLabel": "字体大小",
16-
"projectBusy": "工程正在处理其他操作。"
15+
"fontSizeLabel": "字体大小"
1716
},
1817
"import": {
1918
"title": "将 LRC 导入为标签",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"positionLabel": "位置",
1313
"textLabel": "歌詞",
1414
"fontSizeTitle": "字型大小",
15-
"fontSizeLabel": "字型大小",
16-
"projectBusy": "專案正在處理其他操作。"
15+
"fontSizeLabel": "字型大小"
1716
},
1817
"import": {
1918
"title": "將 LRC 匯入為標籤",

‎src/plugins/batchprocess/res/builtin/lrc-labels/index.js‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { application } = require("diffscope:core");
22
const { parse: parsePath } = require("diffscope:fs");
3-
const { loadI18n, MethodLogicError, t } = require("diffscope:runtime");
3+
const { loadI18n, t } = require("diffscope:runtime");
44
const { dialogs } = require("diffscope:shell");
55
const { storage } = require("diffscope:storage");
66

@@ -224,29 +224,23 @@ function editKaraokeLyrics({ add, position }) {
224224
});
225225
}
226226

227-
const readLock = document.tryAcquireReadLock();
228-
if (readLock === null) {
229-
throw new MethodLogicError(t("lrcLabels.karaoke.projectBusy"));
230-
}
227+
const readLock = document.mustAcquireReadLock();
231228

232229
let label;
233-
let originalText;
234-
let form;
235-
try {
236-
if (!add) {
237-
label = labels.toArray().filter(item => item.position === position).pop();
238-
}
239-
originalText = add ? "" : label.text;
240-
fields.push({
241-
type: "text",
242-
name: "text",
243-
label: t("lrcLabels.karaoke.textLabel"),
244-
value: originalText
245-
});
246-
form = dialogs.form({ title, fields, parent: project.window });
247-
} finally {
248-
readLock.release();
230+
if (!add) {
231+
label = labels.toArray().filter(item => item.position === position).pop();
249232
}
233+
const originalText = add ? "" : label.text;
234+
fields.push({
235+
type: "text",
236+
name: "text",
237+
label: t("lrcLabels.karaoke.textLabel"),
238+
value: originalText
239+
});
240+
const form = dialogs.form({ title, fields, parent: project.window });
241+
242+
readLock.release();
243+
250244
if (form === null || (!add && form.text === originalText)) {
251245
return;
252246
}

0 commit comments

Comments
 (0)