xstudio-linux 0.0.0-stage → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +443 -0
- package/LICENSE +31 -0
- package/README.md +527 -2
- package/dist/adapter-cli/cli.d.ts +28 -0
- package/dist/adapter-cli/cli.js +235 -0
- package/dist/adapter-cli/cli.js.map +1 -0
- package/dist/adapter-mcp/server.d.ts +81 -0
- package/dist/adapter-mcp/server.js +477 -0
- package/dist/adapter-mcp/server.js.map +1 -0
- package/dist/config.d.ts +45 -0
- package/dist/config.js +78 -0
- package/dist/config.js.map +1 -0
- package/dist/core/catalog/pronunciation.d.ts +47 -0
- package/dist/core/catalog/pronunciation.js +402 -0
- package/dist/core/catalog/pronunciation.js.map +1 -0
- package/dist/core/catalog/singers.d.ts +46 -0
- package/dist/core/catalog/singers.js +122 -0
- package/dist/core/catalog/singers.js.map +1 -0
- package/dist/core/contracts.d.ts +348 -0
- package/dist/core/contracts.js +17 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/degrade/chain.d.ts +80 -0
- package/dist/core/degrade/chain.js +137 -0
- package/dist/core/degrade/chain.js.map +1 -0
- package/dist/core/diagnose/error-resolver.d.ts +51 -0
- package/dist/core/diagnose/error-resolver.js +202 -0
- package/dist/core/diagnose/error-resolver.js.map +1 -0
- package/dist/core/guard/skill-gate.d.ts +89 -0
- package/dist/core/guard/skill-gate.js +121 -0
- package/dist/core/guard/skill-gate.js.map +1 -0
- package/dist/core/midi/convert.d.ts +31 -0
- package/dist/core/midi/convert.js +125 -0
- package/dist/core/midi/convert.js.map +1 -0
- package/dist/core/midi/smf.d.ts +37 -0
- package/dist/core/midi/smf.js +422 -0
- package/dist/core/midi/smf.js.map +1 -0
- package/dist/core/render/artifacts.d.ts +37 -0
- package/dist/core/render/artifacts.js +417 -0
- package/dist/core/render/artifacts.js.map +1 -0
- package/dist/core/render/orchestrator.d.ts +110 -0
- package/dist/core/render/orchestrator.js +974 -0
- package/dist/core/render/orchestrator.js.map +1 -0
- package/dist/core/svip/codec.d.ts +30 -0
- package/dist/core/svip/codec.js +664 -0
- package/dist/core/svip/codec.js.map +1 -0
- package/dist/core/svip/document.d.ts +31 -0
- package/dist/core/svip/document.js +158 -0
- package/dist/core/svip/document.js.map +1 -0
- package/dist/core/svip/editor.d.ts +71 -0
- package/dist/core/svip/editor.js +245 -0
- package/dist/core/svip/editor.js.map +1 -0
- package/dist/core/svip/model.d.ts +74 -0
- package/dist/core/svip/model.js +158 -0
- package/dist/core/svip/model.js.map +1 -0
- package/dist/core/svip/tick.d.ts +21 -0
- package/dist/core/svip/tick.js +59 -0
- package/dist/core/svip/tick.js.map +1 -0
- package/dist/core/svip/validator.d.ts +39 -0
- package/dist/core/svip/validator.js +267 -0
- package/dist/core/svip/validator.js.map +1 -0
- package/dist/host/linux.d.ts +15 -0
- package/dist/host/linux.js +42 -0
- package/dist/host/linux.js.map +1 -0
- package/dist/host/sidecar.d.ts +61 -0
- package/dist/host/sidecar.js +365 -0
- package/dist/host/sidecar.js.map +1 -0
- package/dist/host/wine-launch.d.ts +60 -0
- package/dist/host/wine-launch.js +77 -0
- package/dist/host/wine-launch.js.map +1 -0
- package/dist/host/wine-paths.d.ts +30 -0
- package/dist/host/wine-paths.js +103 -0
- package/dist/host/wine-paths.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/services.d.ts +55 -0
- package/dist/services.js +78 -0
- package/dist/services.js.map +1 -0
- package/dist/shared/errors.d.ts +61 -0
- package/dist/shared/errors.js +125 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/paths.d.ts +8 -0
- package/dist/shared/paths.js +30 -0
- package/dist/shared/paths.js.map +1 -0
- package/dist/shared/schema.d.ts +26 -0
- package/dist/shared/schema.js +68 -0
- package/dist/shared/schema.js.map +1 -0
- package/dist/shared/types.d.ts +43 -0
- package/dist/shared/types.js +19 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/tests/unit/artifacts.test.d.ts +1 -0
- package/dist/tests/unit/artifacts.test.js +243 -0
- package/dist/tests/unit/artifacts.test.js.map +1 -0
- package/dist/tests/unit/data-plane.test.d.ts +1 -0
- package/dist/tests/unit/data-plane.test.js +153 -0
- package/dist/tests/unit/data-plane.test.js.map +1 -0
- package/dist/tests/unit/degrade.test.d.ts +1 -0
- package/dist/tests/unit/degrade.test.js +133 -0
- package/dist/tests/unit/degrade.test.js.map +1 -0
- package/dist/tests/unit/diagnosis.test.d.ts +1 -0
- package/dist/tests/unit/diagnosis.test.js +66 -0
- package/dist/tests/unit/diagnosis.test.js.map +1 -0
- package/dist/tests/unit/errors.test.d.ts +1 -0
- package/dist/tests/unit/errors.test.js +83 -0
- package/dist/tests/unit/errors.test.js.map +1 -0
- package/dist/tests/unit/mcp-server.test.d.ts +1 -0
- package/dist/tests/unit/mcp-server.test.js +267 -0
- package/dist/tests/unit/mcp-server.test.js.map +1 -0
- package/dist/tests/unit/mcp-smoke.d.ts +6 -0
- package/dist/tests/unit/mcp-smoke.js +7 -0
- package/dist/tests/unit/mcp-smoke.js.map +1 -0
- package/dist/tests/unit/mcp-smoke.test.d.ts +1 -0
- package/dist/tests/unit/mcp-smoke.test.js +196 -0
- package/dist/tests/unit/mcp-smoke.test.js.map +1 -0
- package/dist/tests/unit/midi.test.d.ts +1 -0
- package/dist/tests/unit/midi.test.js +255 -0
- package/dist/tests/unit/midi.test.js.map +1 -0
- package/dist/tests/unit/pronunciation.test.d.ts +1 -0
- package/dist/tests/unit/pronunciation.test.js +83 -0
- package/dist/tests/unit/pronunciation.test.js.map +1 -0
- package/dist/tests/unit/registry-contract.test.d.ts +1 -0
- package/dist/tests/unit/registry-contract.test.js +114 -0
- package/dist/tests/unit/registry-contract.test.js.map +1 -0
- package/dist/tests/unit/render-orchestrator.test.d.ts +1 -0
- package/dist/tests/unit/render-orchestrator.test.js +548 -0
- package/dist/tests/unit/render-orchestrator.test.js.map +1 -0
- package/dist/tests/unit/sidecar.test.d.ts +1 -0
- package/dist/tests/unit/sidecar.test.js +299 -0
- package/dist/tests/unit/sidecar.test.js.map +1 -0
- package/dist/tests/unit/singers.test.d.ts +1 -0
- package/dist/tests/unit/singers.test.js +73 -0
- package/dist/tests/unit/singers.test.js.map +1 -0
- package/dist/tests/unit/skill-gate.test.d.ts +1 -0
- package/dist/tests/unit/skill-gate.test.js +182 -0
- package/dist/tests/unit/skill-gate.test.js.map +1 -0
- package/dist/tests/unit/svip-codec.test.d.ts +1 -0
- package/dist/tests/unit/svip-codec.test.js +182 -0
- package/dist/tests/unit/svip-codec.test.js.map +1 -0
- package/dist/tests/unit/svip-document.test.d.ts +1 -0
- package/dist/tests/unit/svip-document.test.js +137 -0
- package/dist/tests/unit/svip-document.test.js.map +1 -0
- package/dist/tests/unit/svip-editor.test.d.ts +1 -0
- package/dist/tests/unit/svip-editor.test.js +275 -0
- package/dist/tests/unit/svip-editor.test.js.map +1 -0
- package/dist/tests/unit/svip-tick.test.d.ts +1 -0
- package/dist/tests/unit/svip-tick.test.js +66 -0
- package/dist/tests/unit/svip-tick.test.js.map +1 -0
- package/dist/tools/common.d.ts +80 -0
- package/dist/tools/common.js +167 -0
- package/dist/tools/common.js.map +1 -0
- package/dist/tools/control.d.ts +21 -0
- package/dist/tools/control.js +376 -0
- package/dist/tools/control.js.map +1 -0
- package/dist/tools/data.d.ts +37 -0
- package/dist/tools/data.js +680 -0
- package/dist/tools/data.js.map +1 -0
- package/dist/tools/definition.d.ts +60 -0
- package/dist/tools/definition.js +44 -0
- package/dist/tools/definition.js.map +1 -0
- package/dist/tools/degrade.d.ts +3 -0
- package/dist/tools/degrade.js +30 -0
- package/dist/tools/degrade.js.map +1 -0
- package/dist/tools/guide.d.ts +10 -0
- package/dist/tools/guide.js +66 -0
- package/dist/tools/guide.js.map +1 -0
- package/dist/tools/open.d.ts +3 -0
- package/dist/tools/open.js +74 -0
- package/dist/tools/open.js.map +1 -0
- package/dist/tools/probe.d.ts +8 -0
- package/dist/tools/probe.js +132 -0
- package/dist/tools/probe.js.map +1 -0
- package/dist/tools/registry.d.ts +10 -0
- package/dist/tools/registry.js +16 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +19 -0
- package/dist/version.js.map +1 -0
- package/docs/DESIGN.md +553 -0
- package/docs/RECON-GUI.md +271 -0
- package/docs/RECON.md +339 -0
- package/docs/SPEC.md +786 -0
- package/docs/WINE.md +192 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-demo.svip3 +0 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-melody.mid +0 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-roundtrip.mid +0 -0
- package/examples/.scratch/02-three-singers/melody.chenziyu.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.hechang.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.wudi.svip3 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-200 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-203 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-204 +0 -0
- package/examples/.scratch/04-unknown-dialog-abort/dialog-demo.svip3 +0 -0
- package/examples/01-midi-to-wudi.mjs +144 -0
- package/examples/02-three-singers-compare.mjs +140 -0
- package/examples/03-velocity-diction-rerender.mjs +160 -0
- package/examples/04-unknown-dialog-abort.mjs +126 -0
- package/examples/README.md +101 -0
- package/examples/lib/harness.mjs +274 -0
- package/fixtures/midi/melody-480.mid +0 -0
- package/fixtures/midi/melody-96.mid +0 -0
- package/fixtures/svip/1.svip3 +0 -0
- package/fixtures/svip/3.svip3 +0 -0
- package/fixtures/uia/README.md +37 -0
- package/fixtures/uia/export-dialog.snapshot.json +446 -0
- package/fixtures/uia/main-window.snapshot.json +2997 -0
- package/fixtures/uia/open-dialog.snapshot.json +103 -0
- package/icon.svg +10 -0
- package/package.json +84 -4
- package/proto/xstudio.proto +128 -0
- package/scripts/check-contract.mjs +184 -0
- package/scripts/entry-smoke.mjs +26 -0
- package/scripts/inspect-svip.mjs +161 -0
- package/scripts/setup-venv.sh +93 -0
- package/scripts/wine-gui-probe.py +302 -0
- package/sidecar/xstudio_uia.py +1478 -0
- package/skills/xstudio-gui/SKILL.md +194 -0
- package/skills/xstudio-gui/assertions.md +103 -0
- package/skills/xstudio-gui/dialogs.md +90 -0
- package/skills/xstudio-gui/gestures.md +158 -0
- package/skills/xstudio-gui/ui-map.json +242 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-plane tools (§5.1): every tool here edits .svip3 files directly through
|
|
3
|
+
* the pure core and needs no GUI.
|
|
4
|
+
* @module xstudio-linux/tools/data
|
|
5
|
+
*/
|
|
6
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
7
|
+
import { dirname, extname } from 'node:path';
|
|
8
|
+
import { defineTool, jsonRender } from './definition.js';
|
|
9
|
+
import { envelopeSchema } from '../shared/schema.js';
|
|
10
|
+
import { ok } from '../shared/types.js';
|
|
11
|
+
import { ErrorCode, XStudioError } from '../shared/errors.js';
|
|
12
|
+
import { normalizeSourcePath } from '../shared/paths.js';
|
|
13
|
+
import { addNote, editNote, getTrack, removeNote, setGain, setTempo, setTimeSignature, setVelocityOffset, summarize, } from '../core/svip/editor.js';
|
|
14
|
+
import { validateProject } from '../core/svip/validator.js';
|
|
15
|
+
import { createEmptyProject } from '../core/svip/model.js';
|
|
16
|
+
import { encodeProject } from '../core/svip/codec.js';
|
|
17
|
+
import { parseSmf, writeSmf } from '../core/midi/smf.js';
|
|
18
|
+
import { midiToNotes, notesToMidi } from '../core/midi/convert.js';
|
|
19
|
+
import { mutateProject, noteSchema, noteToWire, readDocument, runTool, summarySchema, summaryToWire, success, writeResultSchema, writeResultToWire, wireToNoteFields, wireToNoteRef, } from './common.js';
|
|
20
|
+
/** Common parameter: a .svip3 path. */
|
|
21
|
+
const projectPathParam = { type: 'string', required: true, description: 'Absolute path, or a path relative to the session working directory.' };
|
|
22
|
+
/** Common parameter: track index (only singing tracks are editable in this release). */
|
|
23
|
+
const trackIdxParam = { type: 'integer', description: 'Track index; defaults to 0.' };
|
|
24
|
+
/** Common parameter: note reference. */
|
|
25
|
+
const noteRefParam = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: true,
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
description: 'Identify one note by index, or by position_tick (+ optional midi_pitch).',
|
|
30
|
+
properties: {
|
|
31
|
+
index: { type: 'integer', description: '0-based index in the note list.' },
|
|
32
|
+
position_tick: { type: 'integer', description: 'Absolute position tick (PPQ 480).' },
|
|
33
|
+
midi_pitch: { type: 'integer', description: 'Optional pitch disambiguator.' },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
/** The singer id must carry the product-line prefix. */
|
|
37
|
+
export function normalizeSingerId(input) {
|
|
38
|
+
return input.includes(':') ? input : `beta-netease:${input}`;
|
|
39
|
+
}
|
|
40
|
+
/** Resolve a display name for a singer id, tolerating a cold catalog. */
|
|
41
|
+
async function resolveSinger(services, singerId) {
|
|
42
|
+
const id = normalizeSingerId(singerId);
|
|
43
|
+
const warnings = [];
|
|
44
|
+
try {
|
|
45
|
+
const meta = await services.singers.get(id);
|
|
46
|
+
if (meta)
|
|
47
|
+
return { meta, displayName: meta.name, warnings };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
warnings.push('Singer catalog unavailable; used the id suffix as the display name.');
|
|
51
|
+
}
|
|
52
|
+
return { displayName: id.slice(id.indexOf(':') + 1), warnings };
|
|
53
|
+
}
|
|
54
|
+
/** Convert a model note input from wire args. */
|
|
55
|
+
function noteInputFrom(args) {
|
|
56
|
+
return {
|
|
57
|
+
positionTick: args.pos,
|
|
58
|
+
lengthTick: args.len,
|
|
59
|
+
midiPitch: args.pitch,
|
|
60
|
+
lyricText: args.lyric,
|
|
61
|
+
phonemeRoman: args.phoneme ?? '',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** §5.1 `xstudio_singers_list`. */
|
|
65
|
+
export function singersListTool(services) {
|
|
66
|
+
return defineTool({
|
|
67
|
+
name: 'xstudio_singers_list',
|
|
68
|
+
description: 'List available X Studio singers from the built-in local catalog. Reports via "pb"; refresh:true is accepted for compatibility but only adds a warning (Tavily enrichment was removed in xstudio-linux).',
|
|
69
|
+
parameters: {
|
|
70
|
+
filter: { type: 'string', description: 'Case-insensitive substring filter on id, name, style or language.' },
|
|
71
|
+
lang: { type: 'string', description: 'Language filter, e.g. "zh-CN".' },
|
|
72
|
+
refresh: { type: 'boolean', description: 'Force a remote refresh even when the cache is fresh.' },
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
schema: envelopeSchema({
|
|
76
|
+
type: 'object',
|
|
77
|
+
additionalProperties: true,
|
|
78
|
+
properties: {
|
|
79
|
+
singers: { type: 'array', required: true, items: { type: 'object', additionalProperties: true, properties: { id: { type: 'string', required: true }, name: { type: 'string', required: true }, style: { type: 'array', items: { type: 'string' } }, language: { type: 'string', required: true }, requires_download: { type: 'boolean', required: true }, is_paid: { type: 'boolean', required: true }, source: { type: 'string', required: true } } } },
|
|
80
|
+
count: { type: 'integer', required: true },
|
|
81
|
+
cached: { type: 'boolean', required: true },
|
|
82
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
render: jsonRender,
|
|
86
|
+
},
|
|
87
|
+
async execute(args) {
|
|
88
|
+
return runTool('pb', async () => {
|
|
89
|
+
const result = await services.singers.list({ refresh: args.refresh === true, filter: args.filter, lang: args.lang });
|
|
90
|
+
return ok(result.via, {
|
|
91
|
+
singers: result.singers.map((s) => ({
|
|
92
|
+
id: s.id,
|
|
93
|
+
name: s.name,
|
|
94
|
+
style: s.style,
|
|
95
|
+
language: s.language,
|
|
96
|
+
requires_download: s.requiresDownload,
|
|
97
|
+
is_paid: s.isPaid,
|
|
98
|
+
source: s.source,
|
|
99
|
+
})),
|
|
100
|
+
count: result.singers.length,
|
|
101
|
+
cached: result.cached,
|
|
102
|
+
warnings: result.warnings,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** §5.1 `xstudio_project_read`. */
|
|
109
|
+
export function projectReadTool(services) {
|
|
110
|
+
return defineTool({
|
|
111
|
+
name: 'xstudio_project_read',
|
|
112
|
+
description: 'Read a .svip3 project into a structured summary, optionally including the full note list. Unknown protobuf fields are preserved internally and never exposed.',
|
|
113
|
+
parameters: {
|
|
114
|
+
path: projectPathParam,
|
|
115
|
+
include: { type: 'string', enum: ['summary', 'notes', 'all'], description: 'How much detail to return; defaults to "summary".' },
|
|
116
|
+
track_idx: trackIdxParam,
|
|
117
|
+
},
|
|
118
|
+
output: {
|
|
119
|
+
schema: envelopeSchema({
|
|
120
|
+
type: 'object',
|
|
121
|
+
additionalProperties: true,
|
|
122
|
+
properties: {
|
|
123
|
+
summary: summarySchema,
|
|
124
|
+
notes: { type: 'array', items: noteSchema },
|
|
125
|
+
note_count: { type: 'integer', required: true },
|
|
126
|
+
unknown_field_count: { type: 'integer' },
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
render: jsonRender,
|
|
130
|
+
},
|
|
131
|
+
async execute(args, exec) {
|
|
132
|
+
return runTool('pb', async () => {
|
|
133
|
+
const doc = await readDocument(services, args.path, exec.agent);
|
|
134
|
+
const summary = summarize(doc.model);
|
|
135
|
+
const include = args.include ?? 'summary';
|
|
136
|
+
const trackIdx = args.track_idx ?? 0;
|
|
137
|
+
const track = getTrack(doc.model, trackIdx);
|
|
138
|
+
const unknownCount = countUnknowns(doc.model);
|
|
139
|
+
return ok('pb', {
|
|
140
|
+
summary: summaryToWire(summary),
|
|
141
|
+
...(include === 'summary' ? {} : { notes: track.payload.notes.map(noteToWire) }),
|
|
142
|
+
note_count: track.payload.notes.length,
|
|
143
|
+
unknown_field_count: unknownCount,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/** Count preserved unknown fields across the whole model. */
|
|
150
|
+
function countUnknowns(model) {
|
|
151
|
+
let total = 0;
|
|
152
|
+
const walk = (value) => {
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
for (const item of value)
|
|
155
|
+
walk(item);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (value === null || typeof value !== 'object')
|
|
159
|
+
return;
|
|
160
|
+
for (const [key, child] of Object.entries(value)) {
|
|
161
|
+
if (key === '$unknowns' && Array.isArray(child))
|
|
162
|
+
total += child.length;
|
|
163
|
+
else
|
|
164
|
+
walk(child);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
walk(model);
|
|
168
|
+
return total;
|
|
169
|
+
}
|
|
170
|
+
/** §5.1 `xstudio_project_create`. */
|
|
171
|
+
export function projectCreateTool(services) {
|
|
172
|
+
return defineTool({
|
|
173
|
+
name: 'xstudio_project_create',
|
|
174
|
+
description: 'Create a new .svip3 project from a MIDI file or an explicit note list, plus lyrics and a singer. The singer id must be product-line prefixed (e.g. "beta-netease:wudi"); an unprefixed id is prefixed automatically. Prefer editing an existing template project when you need forward-compatible unknown fields.',
|
|
175
|
+
parameters: {
|
|
176
|
+
out_path: { type: 'string', required: true, description: 'Output .svip3 path (created or overwritten).' },
|
|
177
|
+
singer_id: { type: 'string', required: true, description: 'Singer id, e.g. "beta-netease:wudi".' },
|
|
178
|
+
bpm: { type: 'number', description: 'Tempo in BPM; defaults to 120.' },
|
|
179
|
+
time_sig: { type: 'string', description: 'Time signature "N/D"; defaults to "4/4".' },
|
|
180
|
+
midi_path: { type: 'string', description: 'Source MIDI file; mutually exclusive with notes.' },
|
|
181
|
+
lyrics: { type: 'array', items: { type: 'string' }, description: 'One lyric per note, applied in MIDI order.' },
|
|
182
|
+
notes: {
|
|
183
|
+
type: 'array',
|
|
184
|
+
description: 'Explicit note list; mutually exclusive with midi_path.',
|
|
185
|
+
items: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
additionalProperties: false,
|
|
188
|
+
properties: {
|
|
189
|
+
pos: { type: 'integer', required: true },
|
|
190
|
+
len: { type: 'integer', required: true },
|
|
191
|
+
pitch: { type: 'integer', required: true },
|
|
192
|
+
lyric: { type: 'string', required: true },
|
|
193
|
+
phoneme: { type: 'string' },
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
track_label: { type: 'string', description: 'Track label; defaults to "未命名".' },
|
|
198
|
+
},
|
|
199
|
+
output: {
|
|
200
|
+
schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { summary: summarySchema, note_count: { type: 'integer', required: true }, warnings: { type: 'array', items: { type: 'string' } } } }),
|
|
201
|
+
render: jsonRender,
|
|
202
|
+
},
|
|
203
|
+
async execute(args, exec) {
|
|
204
|
+
return runTool('pb', async () => {
|
|
205
|
+
const warnings = [];
|
|
206
|
+
if (args.midi_path !== undefined && args.notes !== undefined) {
|
|
207
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'Provide either midi_path or notes, not both.');
|
|
208
|
+
}
|
|
209
|
+
const outPath = await services.resolvePath(args.out_path, exec.agent);
|
|
210
|
+
const singer = await resolveSinger(services, args.singer_id);
|
|
211
|
+
warnings.push(...singer.warnings);
|
|
212
|
+
const [numerator, denominator] = parseTimeSig(args.time_sig ?? '4/4');
|
|
213
|
+
const model = createEmptyProject({
|
|
214
|
+
singerName: singer.displayName,
|
|
215
|
+
bpm: args.bpm ?? 120,
|
|
216
|
+
numerator,
|
|
217
|
+
denominator,
|
|
218
|
+
});
|
|
219
|
+
model.sourcePath = normalizeSourcePath(outPath);
|
|
220
|
+
if (args.track_label !== undefined)
|
|
221
|
+
model.trackData.singing.payload.label = args.track_label;
|
|
222
|
+
let notes;
|
|
223
|
+
if (args.midi_path !== undefined) {
|
|
224
|
+
const midiPath = await services.resolvePath(args.midi_path, exec.agent);
|
|
225
|
+
const bytes = await readFile(midiPath);
|
|
226
|
+
const midi = parseSmf(new Uint8Array(bytes));
|
|
227
|
+
notes = midiToNotes(midi, { lyrics: args.lyrics });
|
|
228
|
+
}
|
|
229
|
+
else if (args.notes !== undefined) {
|
|
230
|
+
notes = args.notes.map((n, index) => ({
|
|
231
|
+
positionTick: n.pos,
|
|
232
|
+
lengthTick: n.len,
|
|
233
|
+
midiPitch: n.pitch,
|
|
234
|
+
lyricText: n.lyric,
|
|
235
|
+
phonemeRoman: n.phoneme ?? args.lyrics?.[index] ?? '',
|
|
236
|
+
noteFlag: 1,
|
|
237
|
+
exprParam1: -1,
|
|
238
|
+
exprParam2: -1,
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
notes = [];
|
|
243
|
+
}
|
|
244
|
+
model.trackData.singing.payload.notes = notes;
|
|
245
|
+
validateProject(model);
|
|
246
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
247
|
+
await writeFile(outPath, encodeProject(model));
|
|
248
|
+
const doc = await readDocument(services, outPath, exec.agent);
|
|
249
|
+
return success('pb', {
|
|
250
|
+
summary: summaryToWire(summarize(doc.model)),
|
|
251
|
+
note_count: notes.length,
|
|
252
|
+
warnings,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/** Parse "N/D" with a clear error. */
|
|
259
|
+
export function parseTimeSig(input) {
|
|
260
|
+
const match = /^(\d{1,2})\/(\d{1,2})$/.exec(input.trim());
|
|
261
|
+
if (!match)
|
|
262
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `Invalid time_sig "${input}"; expected "N/D".`);
|
|
263
|
+
return [Number(match[1]), Number(match[2])];
|
|
264
|
+
}
|
|
265
|
+
/** §5.1 `xstudio_note_add`. */
|
|
266
|
+
export function noteAddTool(services) {
|
|
267
|
+
return defineTool({
|
|
268
|
+
name: 'xstudio_note_add',
|
|
269
|
+
description: 'Add one note to a singing track. Positions are absolute ticks (PPQ 480: 480 = quarter note) and other notes are never re-indexed or moved.',
|
|
270
|
+
parameters: {
|
|
271
|
+
project_path: projectPathParam,
|
|
272
|
+
track_idx: trackIdxParam,
|
|
273
|
+
pos: { type: 'integer', required: true, description: 'Absolute position tick.' },
|
|
274
|
+
len: { type: 'integer', required: true, description: 'Length in ticks (240 = eighth, 480 = quarter).' },
|
|
275
|
+
pitch: { type: 'integer', required: true, description: 'MIDI pitch (60 = C4).' },
|
|
276
|
+
lyric: { type: 'string', required: true, description: 'Lyric text for this note.' },
|
|
277
|
+
phoneme: { type: 'string', description: 'Romanized phoneme, e.g. "la".' },
|
|
278
|
+
},
|
|
279
|
+
output: {
|
|
280
|
+
schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { note_index: { type: 'integer', required: true }, note_count: { type: 'integer', required: true }, note: noteSchema, write: writeResultSchema } }),
|
|
281
|
+
render: jsonRender,
|
|
282
|
+
},
|
|
283
|
+
async execute(args, exec) {
|
|
284
|
+
return runTool('pb', async () => {
|
|
285
|
+
const trackIdx = args.track_idx ?? 0;
|
|
286
|
+
const { result, doc, write } = await mutateProject(services, args.project_path, (model) => addNote(model, trackIdx, noteInputFrom(args)), { agent: exec.agent });
|
|
287
|
+
return ok('pb', {
|
|
288
|
+
note_index: result.index,
|
|
289
|
+
note_count: getTrack(doc.model, trackIdx).payload.notes.length,
|
|
290
|
+
note: noteToWire(result.note),
|
|
291
|
+
write: writeResultToWire(write),
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/** §5.1 `xstudio_note_remove`. */
|
|
298
|
+
export function noteRemoveTool(services) {
|
|
299
|
+
return defineTool({
|
|
300
|
+
name: 'xstudio_note_remove',
|
|
301
|
+
description: 'Remove one note from a singing track. Other notes keep their absolute position ticks; the note list is spliced, not re-timed.',
|
|
302
|
+
parameters: { project_path: projectPathParam, track_idx: trackIdxParam, note_ref: noteRefParam },
|
|
303
|
+
output: {
|
|
304
|
+
schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { removed: noteSchema, note_count: { type: 'integer', required: true }, write: writeResultSchema } }),
|
|
305
|
+
render: jsonRender,
|
|
306
|
+
},
|
|
307
|
+
async execute(args, exec) {
|
|
308
|
+
return runTool('pb', async () => {
|
|
309
|
+
const trackIdx = args.track_idx ?? 0;
|
|
310
|
+
const ref = wireToNoteRef(args.note_ref);
|
|
311
|
+
const { result, doc, write } = await mutateProject(services, args.project_path, (model) => removeNote(model, trackIdx, ref), { agent: exec.agent });
|
|
312
|
+
return ok('pb', {
|
|
313
|
+
removed: noteToWire(result),
|
|
314
|
+
note_count: getTrack(doc.model, trackIdx).payload.notes.length,
|
|
315
|
+
write: writeResultToWire(write),
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** §5.1 `xstudio_note_edit`. */
|
|
322
|
+
export function noteEditTool(services) {
|
|
323
|
+
return defineTool({
|
|
324
|
+
name: 'xstudio_note_edit',
|
|
325
|
+
description: 'Edit one note (position, length, pitch, lyric or phoneme). Only the supplied fields change; every other byte of the project is preserved.',
|
|
326
|
+
parameters: {
|
|
327
|
+
project_path: projectPathParam,
|
|
328
|
+
track_idx: trackIdxParam,
|
|
329
|
+
note_ref: noteRefParam,
|
|
330
|
+
fields: {
|
|
331
|
+
type: 'object',
|
|
332
|
+
required: true,
|
|
333
|
+
additionalProperties: false,
|
|
334
|
+
properties: {
|
|
335
|
+
pos: { type: 'integer', description: 'New absolute position tick.' },
|
|
336
|
+
len: { type: 'integer', description: 'New length in ticks.' },
|
|
337
|
+
pitch: { type: 'integer', description: 'New MIDI pitch.' },
|
|
338
|
+
lyric: { type: 'string', description: 'New lyric text.' },
|
|
339
|
+
phoneme: { type: 'string', description: 'New phoneme.' },
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
output: {
|
|
344
|
+
schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { note: noteSchema, note_count: { type: 'integer', required: true }, write: writeResultSchema } }),
|
|
345
|
+
render: jsonRender,
|
|
346
|
+
},
|
|
347
|
+
async execute(args, exec) {
|
|
348
|
+
return runTool('pb', async () => {
|
|
349
|
+
const trackIdx = args.track_idx ?? 0;
|
|
350
|
+
const ref = wireToNoteRef(args.note_ref);
|
|
351
|
+
const patch = wireToNoteFields(args.fields);
|
|
352
|
+
const { result, doc, write } = await mutateProject(services, args.project_path, (model) => editNote(model, trackIdx, ref, patch), { agent: exec.agent });
|
|
353
|
+
return ok('pb', {
|
|
354
|
+
note: noteToWire(result),
|
|
355
|
+
note_count: getTrack(doc.model, trackIdx).payload.notes.length,
|
|
356
|
+
write: writeResultToWire(write),
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
/** Shared output schema for scalar setters. */
|
|
363
|
+
const scalarSetterSchema = envelopeSchema({
|
|
364
|
+
type: 'object',
|
|
365
|
+
additionalProperties: true,
|
|
366
|
+
properties: { summary: summarySchema, write: writeResultSchema },
|
|
367
|
+
});
|
|
368
|
+
/** §5.1 `xstudio_tempo_set`. */
|
|
369
|
+
export function tempoSetTool(services) {
|
|
370
|
+
return defineTool({
|
|
371
|
+
name: 'xstudio_tempo_set',
|
|
372
|
+
description: 'Set the project tempo in BPM (stored as bpm_x100, e.g. 120 -> 12000). No other field changes.',
|
|
373
|
+
parameters: { project_path: projectPathParam, bpm: { type: 'number', required: true, description: 'Tempo in BPM, 20-300.' } },
|
|
374
|
+
output: { schema: scalarSetterSchema, render: jsonRender },
|
|
375
|
+
async execute(args, exec) {
|
|
376
|
+
return runTool('pb', async () => {
|
|
377
|
+
if (!(args.bpm >= 20 && args.bpm <= 300))
|
|
378
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'bpm must be between 20 and 300.');
|
|
379
|
+
const { doc, write } = await mutateProject(services, args.project_path, (model) => setTempo(model, args.bpm), { agent: exec.agent });
|
|
380
|
+
return ok('pb', { summary: summaryToWire(summarize(doc.model)), write: writeResultToWire(write) });
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
/** §5.1 `xstudio_timesig_set`. */
|
|
386
|
+
export function timesigSetTool(services) {
|
|
387
|
+
return defineTool({
|
|
388
|
+
name: 'xstudio_timesig_set',
|
|
389
|
+
description: 'Set the project time signature (numerator/denominator). Only these two values change.',
|
|
390
|
+
parameters: {
|
|
391
|
+
project_path: projectPathParam,
|
|
392
|
+
numerator: { type: 'integer', required: true, description: 'Beats per bar, 1-32.' },
|
|
393
|
+
denominator: { type: 'integer', required: true, description: 'Note value denominator: 1, 2, 4, 8, 16 or 32.' },
|
|
394
|
+
},
|
|
395
|
+
output: { schema: scalarSetterSchema, render: jsonRender },
|
|
396
|
+
async execute(args, exec) {
|
|
397
|
+
return runTool('pb', async () => {
|
|
398
|
+
if (![1, 2, 4, 8, 16, 32].includes(args.denominator))
|
|
399
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'denominator must be one of 1, 2, 4, 8, 16, 32.');
|
|
400
|
+
if (!(args.numerator >= 1 && args.numerator <= 32))
|
|
401
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'numerator must be between 1 and 32.');
|
|
402
|
+
const { doc, write } = await mutateProject(services, args.project_path, (model) => setTimeSignature(model, args.numerator, args.denominator), { agent: exec.agent });
|
|
403
|
+
return ok('pb', { summary: summaryToWire(summarize(doc.model)), write: writeResultToWire(write) });
|
|
404
|
+
});
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
/** §5.1 `xstudio_velocity_set`. */
|
|
409
|
+
export function velocitySetTool(services) {
|
|
410
|
+
return defineTool({
|
|
411
|
+
name: 'xstudio_velocity_set',
|
|
412
|
+
description: 'Set the global velocity offset of a singing track (linear float, 0.0-10.0).',
|
|
413
|
+
parameters: {
|
|
414
|
+
project_path: projectPathParam,
|
|
415
|
+
track_idx: trackIdxParam,
|
|
416
|
+
value: { type: 'number', required: true, description: 'Velocity offset, 0.0-10.0.' },
|
|
417
|
+
},
|
|
418
|
+
output: { schema: scalarSetterSchema, render: jsonRender },
|
|
419
|
+
async execute(args, exec) {
|
|
420
|
+
return runTool('pb', async () => {
|
|
421
|
+
if (!(args.value >= 0 && args.value <= 10))
|
|
422
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'value must be between 0 and 10.');
|
|
423
|
+
const trackIdx = args.track_idx ?? 0;
|
|
424
|
+
const { doc, write } = await mutateProject(services, args.project_path, (model) => setVelocityOffset(model, trackIdx, args.value), { agent: exec.agent });
|
|
425
|
+
return ok('pb', { summary: summaryToWire(summarize(doc.model)), write: writeResultToWire(write) });
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
/** §5.1 `xstudio_gain_set`. */
|
|
431
|
+
export function gainSetTool(services) {
|
|
432
|
+
return defineTool({
|
|
433
|
+
name: 'xstudio_gain_set',
|
|
434
|
+
description: 'Set the project-level linear gain (observed range 1.0-6.0; higher values accepted up to 10).',
|
|
435
|
+
parameters: { project_path: projectPathParam, linear_gain: { type: 'number', required: true, description: 'Linear gain, 0.0-10.0.' } },
|
|
436
|
+
output: { schema: scalarSetterSchema, render: jsonRender },
|
|
437
|
+
async execute(args, exec) {
|
|
438
|
+
return runTool('pb', async () => {
|
|
439
|
+
if (!(args.linear_gain >= 0 && args.linear_gain <= 10))
|
|
440
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'linear_gain must be between 0 and 10.');
|
|
441
|
+
const { doc, write } = await mutateProject(services, args.project_path, (model) => setGain(model, args.linear_gain), { agent: exec.agent });
|
|
442
|
+
return ok('pb', { summary: summaryToWire(summarize(doc.model)), write: writeResultToWire(write) });
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/** §5.1 `xstudio_lyrics_align`. */
|
|
448
|
+
export function lyricsAlignTool(services) {
|
|
449
|
+
return defineTool({
|
|
450
|
+
name: 'xstudio_lyrics_align',
|
|
451
|
+
description: 'Assign lyrics to notes in position order. auto mode fills every note in order; manual mode only fills notes whose lyric_text is empty. Phonemes come from the local pronunciation rule table; characters outside the table are reported in unresolved with an empty phoneme.',
|
|
452
|
+
parameters: {
|
|
453
|
+
project_path: projectPathParam,
|
|
454
|
+
track_idx: trackIdxParam,
|
|
455
|
+
lyrics: { type: 'array', required: true, items: { type: 'string' }, description: 'One lyric entry per note, in note order.' },
|
|
456
|
+
mode: { type: 'string', enum: ['auto', 'manual'], description: 'Defaults to "auto".' },
|
|
457
|
+
},
|
|
458
|
+
output: {
|
|
459
|
+
schema: envelopeSchema({
|
|
460
|
+
type: 'object',
|
|
461
|
+
additionalProperties: true,
|
|
462
|
+
properties: {
|
|
463
|
+
aligned: { type: 'integer', required: true },
|
|
464
|
+
unresolved: { type: 'array', items: { type: 'object', additionalProperties: true, properties: { char: { type: 'string', required: true }, pinyin: { type: 'string', required: true }, confidence: { type: 'number', required: true } } } },
|
|
465
|
+
summary: summarySchema,
|
|
466
|
+
write: writeResultSchema,
|
|
467
|
+
},
|
|
468
|
+
}),
|
|
469
|
+
render: jsonRender,
|
|
470
|
+
},
|
|
471
|
+
async execute(args, exec) {
|
|
472
|
+
return runTool('pb', async () => {
|
|
473
|
+
const trackIdx = args.track_idx ?? 0;
|
|
474
|
+
const mode = args.mode ?? 'auto';
|
|
475
|
+
const lookups = [];
|
|
476
|
+
let aligned = 0;
|
|
477
|
+
const { doc, write } = await mutateProject(services, args.project_path, async (model) => {
|
|
478
|
+
const notes = getTrack(model, trackIdx).payload.notes;
|
|
479
|
+
const ordered = [...notes].sort((a, b) => a.positionTick - b.positionTick);
|
|
480
|
+
const target = mode === 'manual' ? ordered.filter((n) => n.lyricText === '') : ordered;
|
|
481
|
+
const count = Math.min(target.length, args.lyrics.length);
|
|
482
|
+
for (let index = 0; index < count; index += 1) {
|
|
483
|
+
const note = target[index];
|
|
484
|
+
const lyric = args.lyrics[index];
|
|
485
|
+
const char = [...lyric][0] ?? '';
|
|
486
|
+
const context = [args.lyrics[index - 1] ?? '', lyric, args.lyrics[index + 1] ?? ''].join('');
|
|
487
|
+
let phoneme = '';
|
|
488
|
+
if (char !== '') {
|
|
489
|
+
const result = await services.pronunciation.lookup(char, context);
|
|
490
|
+
phoneme = result.pinyin;
|
|
491
|
+
if (result.confidence < 0.9)
|
|
492
|
+
lookups.push({ char, pinyin: result.pinyin, confidence: result.confidence });
|
|
493
|
+
}
|
|
494
|
+
note.lyricText = lyric;
|
|
495
|
+
note.phonemeRoman = phoneme;
|
|
496
|
+
aligned += 1;
|
|
497
|
+
}
|
|
498
|
+
return undefined;
|
|
499
|
+
}, { agent: exec.agent });
|
|
500
|
+
return ok('pb', {
|
|
501
|
+
aligned,
|
|
502
|
+
unresolved: lookups,
|
|
503
|
+
summary: summaryToWire(summarize(doc.model)),
|
|
504
|
+
write: writeResultToWire(write),
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/** §5.1 `xstudio_midi_import`. */
|
|
511
|
+
export function midiImportTool(services) {
|
|
512
|
+
return defineTool({
|
|
513
|
+
name: 'xstudio_midi_import',
|
|
514
|
+
description: 'Import a Standard MIDI File into the project, replacing the note list of the chosen track. Optionally maps lyrics onto the imported notes in order.',
|
|
515
|
+
parameters: {
|
|
516
|
+
project_path: projectPathParam,
|
|
517
|
+
midi_path: { type: 'string', required: true, description: 'Source .mid file.' },
|
|
518
|
+
map_lyrics: { type: 'array', items: { type: 'string' }, description: 'Optional lyrics, one per imported note.' },
|
|
519
|
+
track_idx: trackIdxParam,
|
|
520
|
+
},
|
|
521
|
+
output: { schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { imported: { type: 'integer', required: true }, note_count: { type: 'integer', required: true }, summary: summarySchema, write: writeResultSchema } }), render: jsonRender },
|
|
522
|
+
async execute(args, exec) {
|
|
523
|
+
return runTool('pb', async () => {
|
|
524
|
+
const midiPath = await services.resolvePath(args.midi_path, exec.agent);
|
|
525
|
+
const bytes = await readFile(midiPath);
|
|
526
|
+
const midi = parseSmf(new Uint8Array(bytes));
|
|
527
|
+
const notes = midiToNotes(midi, { lyrics: args.map_lyrics });
|
|
528
|
+
const trackIdx = args.track_idx ?? 0;
|
|
529
|
+
const { doc, write } = await mutateProject(services, args.project_path, (model) => {
|
|
530
|
+
getTrack(model, trackIdx).payload.notes = notes;
|
|
531
|
+
}, { agent: exec.agent });
|
|
532
|
+
return ok('pb', {
|
|
533
|
+
imported: notes.length,
|
|
534
|
+
note_count: getTrack(doc.model, trackIdx).payload.notes.length,
|
|
535
|
+
summary: summaryToWire(summarize(doc.model)),
|
|
536
|
+
write: writeResultToWire(write),
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/** §5.1 `xstudio_midi_export`. */
|
|
543
|
+
export function midiExportTool(services) {
|
|
544
|
+
return defineTool({
|
|
545
|
+
name: 'xstudio_midi_export',
|
|
546
|
+
description: 'Export the project note list as a Standard MIDI File.',
|
|
547
|
+
parameters: { project_path: projectPathParam, out_path: { type: 'string', required: true, description: 'Output .mid path.' }, track_idx: trackIdxParam },
|
|
548
|
+
output: { schema: envelopeSchema({ type: 'object', additionalProperties: true, properties: { path: { type: 'string', required: true }, bytes: { type: 'integer', required: true }, note_count: { type: 'integer', required: true } } }), render: jsonRender },
|
|
549
|
+
async execute(args, exec) {
|
|
550
|
+
return runTool('pb', async () => {
|
|
551
|
+
const doc = await readDocument(services, args.project_path, exec.agent);
|
|
552
|
+
const trackIdx = args.track_idx ?? 0;
|
|
553
|
+
const track = getTrack(doc.model, trackIdx);
|
|
554
|
+
const outPath = await services.resolvePath(args.out_path, exec.agent);
|
|
555
|
+
const midi = notesToMidi(track.payload.notes, { bpm: doc.model.tempo.bpmX100 / 100 });
|
|
556
|
+
const bytes = writeSmf(midi);
|
|
557
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
558
|
+
await writeFile(outPath, bytes);
|
|
559
|
+
return ok('pb', { path: outPath, bytes: bytes.length, note_count: track.payload.notes.length });
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
/** §5.1 `xstudio_batch`: one melody, several singers. */
|
|
565
|
+
export function batchTool(services) {
|
|
566
|
+
return defineTool({
|
|
567
|
+
name: 'xstudio_batch',
|
|
568
|
+
description: 'Produce one .svip3 per singer from the same melody. Data-plane only: it writes files and reports the estimated number of cloud render requests so the caller can confirm before any GUI run. Concurrency is capped at 3.',
|
|
569
|
+
parameters: {
|
|
570
|
+
jobs: {
|
|
571
|
+
type: 'array',
|
|
572
|
+
required: true,
|
|
573
|
+
items: {
|
|
574
|
+
type: 'object',
|
|
575
|
+
additionalProperties: false,
|
|
576
|
+
properties: {
|
|
577
|
+
project_path: { type: 'string', required: true },
|
|
578
|
+
singer_id: { type: 'string', required: true },
|
|
579
|
+
out_path: { type: 'string' },
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
concurrency: { type: 'integer', description: 'Parallel writes, 1-3; defaults to 2.' },
|
|
584
|
+
dry_run: { type: 'boolean', description: 'Estimate only: validate every job and report the cloud-request count without writing files.' },
|
|
585
|
+
},
|
|
586
|
+
output: {
|
|
587
|
+
schema: envelopeSchema({
|
|
588
|
+
type: 'object',
|
|
589
|
+
additionalProperties: true,
|
|
590
|
+
properties: {
|
|
591
|
+
jobs: { type: 'array', items: { type: 'object', additionalProperties: true, properties: { project_path: { type: 'string', required: true }, singer_id: { type: 'string', required: true }, out_path: { type: 'string', required: true }, ok: { type: 'boolean', required: true }, error: { type: 'string' } } } },
|
|
592
|
+
concurrency: { type: 'integer', required: true },
|
|
593
|
+
estimated_cloud_requests: { type: 'integer', required: true },
|
|
594
|
+
},
|
|
595
|
+
}),
|
|
596
|
+
render: jsonRender,
|
|
597
|
+
},
|
|
598
|
+
async execute(args, exec) {
|
|
599
|
+
return runTool('pb', async () => {
|
|
600
|
+
const concurrency = Math.max(1, Math.min(3, args.concurrency ?? 2));
|
|
601
|
+
if (args.dry_run === true) {
|
|
602
|
+
return ok('pb', {
|
|
603
|
+
jobs: args.jobs.map((job) => ({ project_path: job.project_path, singer_id: normalizeSingerId(job.singer_id), out_path: job.out_path ?? '', ok: true })),
|
|
604
|
+
concurrency,
|
|
605
|
+
estimated_cloud_requests: args.jobs.length,
|
|
606
|
+
dry_run: true,
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
const results = new Array(args.jobs.length);
|
|
610
|
+
let cursor = 0;
|
|
611
|
+
const worker = async () => {
|
|
612
|
+
for (;;) {
|
|
613
|
+
const index = cursor;
|
|
614
|
+
cursor += 1;
|
|
615
|
+
if (index >= args.jobs.length)
|
|
616
|
+
return;
|
|
617
|
+
const job = args.jobs[index];
|
|
618
|
+
try {
|
|
619
|
+
const singer = await resolveSinger(services, job.singer_id);
|
|
620
|
+
const doc = await readDocument(services, job.project_path, exec.agent);
|
|
621
|
+
doc.model.trackData.singing.singerName = singer.displayName;
|
|
622
|
+
validateProject(doc.model);
|
|
623
|
+
const outPath = job.out_path === undefined
|
|
624
|
+
? deriveBatchPath(await services.resolvePath(job.project_path, exec.agent), normalizeSingerId(job.singer_id))
|
|
625
|
+
: await services.resolvePath(job.out_path, exec.agent);
|
|
626
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
627
|
+
const write = await services.svip.write({ ...doc, path: outPath }, { backup: false, normalizeSourcePath: true });
|
|
628
|
+
// When the model is unchanged (target singer equals the source singer) the
|
|
629
|
+
// document writer is a no-op and writes nothing; a batch job still promises a
|
|
630
|
+
// distinct output file, so materialize it explicitly.
|
|
631
|
+
let changed = write.changed;
|
|
632
|
+
if (!changed) {
|
|
633
|
+
await writeFile(outPath, encodeProject(doc.model));
|
|
634
|
+
changed = true;
|
|
635
|
+
}
|
|
636
|
+
results[index] = { project_path: job.project_path, singer_id: normalizeSingerId(job.singer_id), out_path: outPath, ok: true, changed };
|
|
637
|
+
}
|
|
638
|
+
catch (error) {
|
|
639
|
+
results[index] = { project_path: job.project_path, singer_id: normalizeSingerId(job.singer_id), out_path: job.out_path ?? '', ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, args.jobs.length) }, () => worker()));
|
|
644
|
+
return ok('pb', {
|
|
645
|
+
jobs: results,
|
|
646
|
+
concurrency,
|
|
647
|
+
estimated_cloud_requests: args.jobs.filter((_, index) => results[index]?.ok === true).length,
|
|
648
|
+
dry_run: false,
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
},
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
/** Derive a batch output path beside the source project. */
|
|
655
|
+
export function deriveBatchPath(sourcePath, singerId) {
|
|
656
|
+
const ext = extname(sourcePath);
|
|
657
|
+
const stem = sourcePath.slice(0, sourcePath.length - ext.length);
|
|
658
|
+
const slug = singerId.slice(singerId.indexOf(':') + 1).replace(/[^A-Za-z0-9_-]+/g, '-');
|
|
659
|
+
return `${stem}.${slug}${ext}`;
|
|
660
|
+
}
|
|
661
|
+
/** All data-plane tools in registration order. */
|
|
662
|
+
export function dataTools(services) {
|
|
663
|
+
return [
|
|
664
|
+
singersListTool(services),
|
|
665
|
+
projectReadTool(services),
|
|
666
|
+
projectCreateTool(services),
|
|
667
|
+
noteAddTool(services),
|
|
668
|
+
noteRemoveTool(services),
|
|
669
|
+
noteEditTool(services),
|
|
670
|
+
tempoSetTool(services),
|
|
671
|
+
timesigSetTool(services),
|
|
672
|
+
velocitySetTool(services),
|
|
673
|
+
gainSetTool(services),
|
|
674
|
+
lyricsAlignTool(services),
|
|
675
|
+
midiImportTool(services),
|
|
676
|
+
midiExportTool(services),
|
|
677
|
+
batchTool(services),
|
|
678
|
+
];
|
|
679
|
+
}
|
|
680
|
+
//# sourceMappingURL=data.js.map
|