dsh-game-material-master 0.7.0 → 0.9.0
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/README.en.md +173 -16
- package/README.md +136 -17
- package/lib/client.js +4145 -259
- package/lib/comfy.js +769 -0
- package/lib/config.js +83 -2
- package/lib/directions.js +9 -2
- package/lib/index.js +677 -26
- package/lib/links.js +152 -10
- package/lib/mapdoc.js +178 -14
- package/lib/mapexport.js +30 -2
- package/lib/mapgen.js +643 -44
- package/lib/maprender.js +155 -13
- package/lib/mapsamplegen.js +139 -12
- package/lib/maptiles.js +1014 -1
- package/lib/media.js +106 -4
- package/lib/midifile.js +390 -0
- package/lib/midipreview.js +326 -0
- package/lib/minimax.js +2 -2
- package/lib/musicapi.js +883 -0
- package/lib/musicaudio.js +249 -0
- package/lib/musicgen.js +2215 -0
- package/lib/musicguide.js +287 -0
- package/lib/musicmodels.js +200 -0
- package/lib/musicscore.js +931 -0
- package/lib/musicscoreguide.js +496 -0
- package/lib/pipeline.js +102 -51
- package/lib/riggen.js +7 -1
- package/lib/seqgen.js +31 -23
- package/lib/sfxapi.js +391 -0
- package/lib/sfxgen.js +819 -0
- package/lib/store.js +81 -0
- package/lib/tilegen.js +3 -2
- package/lib/tools.js +621 -37
- package/lib/videogen.js +150 -0
- package/lib/wire.js +366 -10
- package/package.json +20 -6
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 谱曲模式的内置指南(中 / 英)。
|
|
3
|
+
*
|
|
4
|
+
* 内容改写自用户提供的 `scoremill-skill/SKILL.md` 与 scoremill 官方文档,
|
|
5
|
+
* 并结合本插件的「方案先落盘 → 宿主跑脚本 → 本地渲染试听 → 逐版修改 →
|
|
6
|
+
* 可选交 Suno」流程。scoremill 以 MIT 许可发布,特此致谢:
|
|
7
|
+
* https://github.com/CharlesCNorton/scoremill
|
|
8
|
+
*
|
|
9
|
+
* 这份文件是给对话里的 agent 读的,不是用户手册。宿主通过
|
|
10
|
+
* `getMusicScoreGuide` 返回它;界面「创作技巧」也直接展示。
|
|
11
|
+
*/
|
|
12
|
+
export const MUSIC_SCORE_GUIDE_SOURCES = [
|
|
13
|
+
{
|
|
14
|
+
name: "CharlesCNorton / scoremill",
|
|
15
|
+
url: "https://github.com/CharlesCNorton/scoremill",
|
|
16
|
+
license: "MIT",
|
|
17
|
+
note: "文本记谱 → MIDI 的库与记谱约定;本指南的语法与避坑清单据此改写"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "XIAODUOLU / Midra",
|
|
21
|
+
url: "https://github.com/XIAODUOLU/Midra",
|
|
22
|
+
license: "见原仓库",
|
|
23
|
+
note: "「prompt-to-code MIDI、可编辑、再决定是否生成音频」的产品思路参考"
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
const ZH = `# 游戏素材大师 · 谱曲模式指南(scoremill)
|
|
27
|
+
|
|
28
|
+
> 这份指南是给**对话里的 agent** 用的。目标:把用户的想法变成一份**可读、可改、
|
|
29
|
+
> 可试听**的 MIDI,用户满意后再可选交给 Suno 生成正式音频。
|
|
30
|
+
> scoremill 是 MIT 许可的文本记谱库(https://github.com/CharlesCNorton/scoremill)。
|
|
31
|
+
|
|
32
|
+
## 0. 固定流程(不要跳步)
|
|
33
|
+
|
|
34
|
+
1. \`getMusicJob({jobId})\` 读任务:用户原文、补充要求、纯音乐、审核模式、\`scorePlan\`。
|
|
35
|
+
2. 分析用户的想法,写一份**方案**(曲风、情绪、调性、BPM、拍号、段落表、配器、主题动机、
|
|
36
|
+
力度弧、循环/收尾),用**用户的语言**在回答里输出。
|
|
37
|
+
3. \`saveMusicScorePlan({jobId, plan})\` 把方案落盘。
|
|
38
|
+
4. 审核模式 \`manual\`:**停在这里**等用户确认或改方案;\`auto\`:可以继续。
|
|
39
|
+
5. 写 \`compose.py\`(scoremill),调 \`runMusicScore({jobId, title, plan, script, label?})\`。
|
|
40
|
+
6. 宿主会跑 Python、解析 \`score.mid\`、渲染试听,返回 \`openUrl\`。把链接原样贴给用户,
|
|
41
|
+
说清 BPM / 调性 / 时长 / 段落,让用户点开试听。
|
|
42
|
+
7. 用户提意见 → 改方案/脚本的**对应段落** → 再调 \`runMusicScore\`(\`basedOn\` 指上一版)。
|
|
43
|
+
8. 只有用户**明确要求**「用 Suno 生成正式版」时,才调
|
|
44
|
+
\`submitMusicScoreToSuno({jobId, scoreId, confirm:true})\`。这会真实计费;先说明。
|
|
45
|
+
提交后 \`game_material_wait\`,再把新的 \`openUrl\` 贴回来。
|
|
46
|
+
|
|
47
|
+
⚠️ **永远不要自动提交 Suno。** 谱曲和试听都是本地免费;Suno 才花钱。
|
|
48
|
+
⚠️ **每版都是新版本**:不要覆盖旧 MIDI/试听;用户可能想回到上一版。
|
|
49
|
+
⚠️ **报错按 scoremill 的小节号修**,不要整段重写;连续 3 次失败就停下说明原因。
|
|
50
|
+
|
|
51
|
+
## 1. 先分析,再规划(方案要写给人看)
|
|
52
|
+
|
|
53
|
+
在写任何音符之前,先回答这几个问题:
|
|
54
|
+
|
|
55
|
+
- **用途**:主题曲 / 战斗 / 菜单 / 环境床 / 循环 / 短 stinger / 过场。用途决定长度、
|
|
56
|
+
情绪强度、能不能循环,比堆曲风词更重要。
|
|
57
|
+
- **情绪弧**:从什么情绪到什么情绪?哪一段是高潮?安静段落在哪里?
|
|
58
|
+
- **调性与主音**:大调/小调/调式;全曲尽量围绕一个主音,转调要写清目的。
|
|
59
|
+
- **速度与拍号**:BPM、4/4 还是 3/4 / 6/8;循环曲建议固定 BPM。
|
|
60
|
+
- **段落表**:每段名字、小节数、能量、配器变化。例:
|
|
61
|
+
\`INTRO 8(p,古筝 + 垫音)→ MAIN 16(f,弦乐主题 + 鼓)→ CLIMAX 12(ff,全奏)→ CODA 6(mp,回到主音)\`。
|
|
62
|
+
- **配器**:GM 音色名 + program + 通道;一条通道一个音色,鼓在通道 9。
|
|
63
|
+
- **主题动机**:一句话说清旋律的性格(跳进/级进、节奏型、落音)。
|
|
64
|
+
- **循环/收尾**:循环曲要回到开头能接上;有结尾的曲子写清最后落哪个和弦。
|
|
65
|
+
|
|
66
|
+
**方案 JSON**(传给 \`saveMusicScorePlan\` / \`runMusicScore\`):
|
|
67
|
+
|
|
68
|
+
\`\`\`json
|
|
69
|
+
{
|
|
70
|
+
"summary": "给用户看的完整方案(用户语言,可多段)",
|
|
71
|
+
"style": "仙侠、管弦、战斗配乐",
|
|
72
|
+
"mood": "压抑到爆发,最后 unresolved",
|
|
73
|
+
"key": "D minor / D 弗里几亚",
|
|
74
|
+
"tempo": 150,
|
|
75
|
+
"timeSignature": "4/4",
|
|
76
|
+
"lengthBars": 42,
|
|
77
|
+
"instrumental": true,
|
|
78
|
+
"structure": [
|
|
79
|
+
{ "name": "INTRO", "bars": 8, "energy": "p", "description": "古筝提问,垫音铺底" },
|
|
80
|
+
{ "name": "MAIN", "bars": 16, "energy": "f", "description": "弦乐主题 + 鼓" }
|
|
81
|
+
],
|
|
82
|
+
"instrumentation": [
|
|
83
|
+
{ "name": "弦乐", "program": 48, "channel": 1, "role": "主题" },
|
|
84
|
+
{ "name": "暖垫", "program": 89, "channel": 2, "role": "和声" }
|
|
85
|
+
],
|
|
86
|
+
"motif": "D 为中心,三度与小三度争夺,最后落到 D",
|
|
87
|
+
"notes": "循环曲,最后 2 小节回到开头",
|
|
88
|
+
"sunoTags": "xianxia, orchestral battle, instrumental, erhu, taiko, 150 BPM, D minor, game soundtrack",
|
|
89
|
+
"sunoPrompt": "Instrumental xianxia battle soundtrack, 150 BPM, D minor, 4/4. Intro sparse, main theme soaring strings, climax full orchestra and taiko.",
|
|
90
|
+
"negativeTags": "vocals, edm drop"
|
|
91
|
+
}
|
|
92
|
+
\`\`\`
|
|
93
|
+
|
|
94
|
+
\`sunoTags\` / \`sunoPrompt\` / \`negativeTags\` 尽量用**英文**(Suno 更认英文标签),
|
|
95
|
+
其余字段可以用用户的语言。没有歌词时 \`instrumental\` 设 \`true\`。
|
|
96
|
+
|
|
97
|
+
## 2. scoremill 三十秒骨架
|
|
98
|
+
|
|
99
|
+
\`\`\`python
|
|
100
|
+
from scoremill import Song
|
|
101
|
+
import json
|
|
102
|
+
|
|
103
|
+
s = Song(tempo=120, time="4/4", key="Dm",
|
|
104
|
+
humanize=2, expressive=True, pitch_range=(0, 127))
|
|
105
|
+
|
|
106
|
+
A = s.section("A")
|
|
107
|
+
lead = A.voice("lead", vel=60, octave=5, program=48, channel=1) # 弦乐
|
|
108
|
+
lead.bars("!mf a4q d5q f#5h | e5q d5q bn4h |")
|
|
109
|
+
bass = A.voice("bass", vel=45, octave=2, program=89, channel=5) # 垫音
|
|
110
|
+
bass.bars("!mp [d2 a2]w | [d2 a2]w |")
|
|
111
|
+
kit = A.drums(vel=70)
|
|
112
|
+
kit.bars("bdq bde sne bdq [sn hh]e hhe | bdq bde sne bdq hhe hhe |")
|
|
113
|
+
|
|
114
|
+
s.arrange("A")
|
|
115
|
+
s.save("score.mid")
|
|
116
|
+
print(json.dumps(s.report(), ensure_ascii=False))
|
|
117
|
+
\`\`\`
|
|
118
|
+
|
|
119
|
+
## 3. 三条铁律
|
|
120
|
+
|
|
121
|
+
1. **每个小节必须正好是该段拍号的拍数,并且以 \`|\` 结尾**。
|
|
122
|
+
2. **同一 section 里所有声部必须一样长**(短的用 \`rw\` 休止补齐)。
|
|
123
|
+
3. **一个 MIDI 通道 = 一个音色,全曲不变**;鼓固定通道 9。
|
|
124
|
+
|
|
125
|
+
## 4. 记谱速查
|
|
126
|
+
|
|
127
|
+
### 4.1 音高
|
|
128
|
+
|
|
129
|
+
- \`c4\` \`d4\` \`e4\` … 字母 + 八度;\`b\` 在 \`key="Dm"\` 里是 B♭,要还原写 \`bn\`,升号写 \`f#\`。
|
|
130
|
+
- 八度和时值都是 **sticky**:同一 voice 里 \`d4q e f\` 都是 4 八度、四分音符。
|
|
131
|
+
- 建议多声部密集写作时每个音都写全八度(\`e4\` 而不是 \`e\`)。
|
|
132
|
+
|
|
133
|
+
### 4.2 时值 / 休止 / 和弦 / 连音
|
|
134
|
+
|
|
135
|
+
| 写法 | 含义 |
|
|
136
|
+
|---|---|
|
|
137
|
+
| \`c4w\` \`c4h\` \`c4q\` \`c4e\` \`c4s\` \`c4t\` | 全 / 二 / 四 / 八 / 十六 / 三十二分音符 |
|
|
138
|
+
| \`c4q.\` | 附点四分 |
|
|
139
|
+
| \`r\` | 休止(时值 sticky;**永远写 \`rq\` / \`rh\` / \`rw\`**) |
|
|
140
|
+
| \`[c4 e g]h\` | 和弦 |
|
|
141
|
+
| \`{c4 d4 e4}q\` | 连音(成员平分这一拍) |
|
|
142
|
+
| \`+d5\` | 倚音(不带时值,音高写全) |
|
|
143
|
+
| \`c5h~\` | 连线;下一个音必须同音高;voice 末尾的 \`~\` 是自由延长 |
|
|
144
|
+
| \`c5q>\` \`c5q'\` \`c5q_\` \`c5q^\` \`c5q&\` \`c5q%\` | 重音 / 断奏 / 连奏 / 延长 / 滚奏 / 颤音(写在时值后面) |
|
|
145
|
+
| \`!pp\` … \`!fff\` | 力度(sticky) |
|
|
146
|
+
| \`cresc\` / \`dim\` | 渐强 / 渐弱;**必须落到下一个力度记号**,段落最后一小节也要落 |
|
|
147
|
+
| \`s.tempo_change("MAIN", 1, 150)\` | 该段从第 1 小节起 150 BPM |
|
|
148
|
+
| \`s.ritardando("CODA", 5, 8, 66)\` | 5→8 小节线性变化到 66 BPM |
|
|
149
|
+
|
|
150
|
+
### 4.3 鼓(通道 9)
|
|
151
|
+
|
|
152
|
+
\`\`\`python
|
|
153
|
+
kit = A.drums(vel=70)
|
|
154
|
+
kit.bars("bdq bde sne bdq [sn hh]e hhe | bdq bde sne bdq hhe hhe |")
|
|
155
|
+
\`\`\`
|
|
156
|
+
|
|
157
|
+
可用名字(前缀匹配,时值紧贴其后;叠击用方括号):
|
|
158
|
+
\`bd bd2 sn esn rim clap lt mt ht lft hft hh hc ho hp cr cr2 sp ch rd rb cb tamb clave wood tri\`。
|
|
159
|
+
|
|
160
|
+
**名字和时值必须粘在一起**:\`bdq\` / \`bde\` / \`sne\`,不能写 \`bd q\`。
|
|
161
|
+
|
|
162
|
+
### 4.4 通道 / GM 音色
|
|
163
|
+
|
|
164
|
+
可用通道 0–8 + 10–15(9 固定鼓),一共 15 个音色。常用 GM program:
|
|
165
|
+
|
|
166
|
+
| 音色 | program | 音色 | program |
|
|
167
|
+
|---|---:|---|---:|
|
|
168
|
+
| 竖琴 | 46 | 弦乐 | 48 |
|
|
169
|
+
| 人声/合唱 | 52 | 铜管 | 61 |
|
|
170
|
+
| 定音鼓 | 47 | 暖垫 | 89 |
|
|
171
|
+
| 古筝/Koto | 107 | 尺八 | 77 |
|
|
172
|
+
| 竹笛 | 73 | 钢琴 | 0 |
|
|
173
|
+
| 贝斯 | 32–39 | 合成主音 | 80–87 |
|
|
174
|
+
|
|
175
|
+
## 5. 高频报错 → 改法
|
|
176
|
+
|
|
177
|
+
| 报错片段 | 原因 | 改法 |
|
|
178
|
+
|---|---|---|
|
|
179
|
+
| \`has 64.0 beats, expected 4.0 — over by 60.0 beats\` | 用空格拼小节,丢了 \`|\` | \`" | ".join(bars) + " |"\` |
|
|
180
|
+
| \`bar 9: has 0.0 beats, expected 4.0\` | 尾部已经有 \`|\`,又加了一个 | 只补空格,不要补竖线 |
|
|
181
|
+
| \`unrecognized token '|a5q'\` | 字符串直接粘在 \`|\` 后面 | 加一个空格 |
|
|
182
|
+
| \`voices differ in length\` | 某声部少写小节 | 用 \`rw |\` 补齐到最长声部 |
|
|
183
|
+
| \`cresc never reaches a dynamic mark\` | 写了 cresc 但后面没有力度记号 | 1–4 小节内落 \`!f\` 等 |
|
|
184
|
+
| \`cresc while an earlier one is still open\` | 上一个 cresc 没落目标力度 | 先收口再开 |
|
|
185
|
+
| \`tie: next note must repeat the pitch\` | \`~\` 后面不是同音高 | 删掉 \`~\` 或改成同音 |
|
|
186
|
+
| \`note would leave the range 21-108\` | 默认钢琴音域 | 构造时传 \`pitch_range=(0, 127)\` |
|
|
187
|
+
| \`unknown drum token 'e'\` | 鼓写成 \`bd q\` | 粘成 \`bdq\` |
|
|
188
|
+
| \`trailing partial bar\` | 最后没写 \`|\` | 补上 |
|
|
189
|
+
|
|
190
|
+
有些错误(cresc 未收口、声部不等长)要到 \`report()\` / \`save()\` 才触发;
|
|
191
|
+
写完一段就跑一次 \`s.report()\`。
|
|
192
|
+
|
|
193
|
+
## 6. 游戏配乐的建议
|
|
194
|
+
|
|
195
|
+
- **循环**:固定 BPM;最后 1–2 小节回到开头能接上;避免在接缝处留长混响尾。
|
|
196
|
+
- **短曲 / stinger**:30–90 秒,段落少(INTRO → MAIN → END),不要写完整主歌副歌。
|
|
197
|
+
- **战斗**:节奏明确、低频扎实;主题要在中高音区能听出来;不要让固定音型吃掉主题。
|
|
198
|
+
- **环境床**:弱旋律、少鼓、留出对白/音效频段。
|
|
199
|
+
- **力度弧**:引子 p → 主题 f → 高潮 ff → 尾声 mp;不要 16 小节全 ff。
|
|
200
|
+
- **重复段落靠配器/鼓/力度区分**,不要靠改旋律。
|
|
201
|
+
- **两个主题要能叠**:共享主音;对立写在一个具体的音(三度、三全音)上。
|
|
202
|
+
- **音区就是立场**:不要把两条旋律塞进同一八度,否则会硬撞。
|
|
203
|
+
- **扩大(augmentation)比换旋律有用**:\`stretch(theme, 2)\` + \`rebar(..., 4)\` 能得到更宽的高潮主题。
|
|
204
|
+
|
|
205
|
+
## 7. 脚本输出契约(宿主怎么跑)
|
|
206
|
+
|
|
207
|
+
- 脚本必须放在任务目录里由宿主执行;你只需要通过 \`runMusicScore\` 传 \`script\` 全文。
|
|
208
|
+
- **必须**在 cwd 里产出 \`score.mid\`:\`s.save("score.mid")\`。
|
|
209
|
+
- **不要**自己渲染音频、不要联网、不要写任务目录以外的文件。
|
|
210
|
+
- 推荐最后 \`print(json.dumps(s.report(), ensure_ascii=False))\`,宿主会把这段 JSON 存进 report。
|
|
211
|
+
- 建议 \`pitch_range=(0, 127)\`;鼓在通道 9;一条通道一个 program。
|
|
212
|
+
- 曲子控制在 **10 分钟以内**(宿主上限 600 秒;内置试听合成器上限 480 秒)。
|
|
213
|
+
- 需要随机时用固定种子(例如 \`random.Random(20)\`),保证同一份谱重复渲染一致。
|
|
214
|
+
- 出错时宿主会把 stderr 尾部原样返回给你;按小节号只改那一处。
|
|
215
|
+
|
|
216
|
+
## 8. 修改协议
|
|
217
|
+
|
|
218
|
+
用户说「太吵 / 太慢 / 鼓太多 / 主题不明显 / 第二段太长」时:
|
|
219
|
+
|
|
220
|
+
1. 先判断改**哪一段**、改什么(配器/力度/旋律/速度/段落长度)。
|
|
221
|
+
2. 改方案里的对应字段(段落表、配器、力度)与脚本里的对应小节。
|
|
222
|
+
3. 调 \`runMusicScore({jobId, ..., basedOn: "<上一版 scoreId>"})\`。
|
|
223
|
+
4. 在回答里说清「改了什么、为什么、听感上应该有什么变化」。
|
|
224
|
+
5. 不要顺手改用户没提的段落;不要整首重写。
|
|
225
|
+
|
|
226
|
+
## 9. 交给 Suno(可选,★计费)
|
|
227
|
+
|
|
228
|
+
- Suno **不接受 MIDI 原文件,但接受音频**。正确链路是:插件先把这一版 MIDI 渲染成
|
|
229
|
+
试听音频(\`preview.mp3\` / \`preview.wav\`),上传到 \`/v1/suno/audio/upload\` 拿到参考
|
|
230
|
+
song id,再走 **cover** 生成。这样 Suno 听到的是你的配器、节奏和段落,而不是只看文字标签。
|
|
231
|
+
- 标准音频上传免费;如果 Suno 判定音频有版权,需要走**付费版权通道**(会扣积分),
|
|
232
|
+
必须由用户确认后传 \`copyrightAudio:true\`。
|
|
233
|
+
- 结果**不会逐音一致**;它是「按这段音频重新演奏/编曲」,不是把 MIDI 原样合成。
|
|
234
|
+
- 只有用户明确说「用 Suno 生成正式版 / 交给 Suno」才调:
|
|
235
|
+
\`submitMusicScoreToSuno({jobId, scoreId, confirm:true, model?, regenerate?, copyrightAudio?, audioWeight?})\`
|
|
236
|
+
- 返回 \`needsCopyrightConsent:true\` 时,先把原因告诉用户,确认后再传 \`copyrightAudio:true\` 重试。
|
|
237
|
+
- 已有歌曲时再提交会再计费:先问用户,并传 \`regenerate:true\`。
|
|
238
|
+
- 提交后 \`game_material_wait\`;把新的 \`openUrl\` 贴回来,说清生成了几首。
|
|
239
|
+
- 原曲超过 360 秒时,Suno 只能按 360 秒提交;在回答里说明。
|
|
240
|
+
- 参考音频权重 \`audioWeight\` 默认 0.75;想更贴 MIDI 可以调高(0–1),想更像 Suno 的编曲可以调低。
|
|
241
|
+
|
|
242
|
+
## 10. 提交前自检
|
|
243
|
+
|
|
244
|
+
- [ ] 方案已保存,用户看得到;manual 模式已等用户确认。
|
|
245
|
+
- [ ] 每个 section 的声部等长;每小节拍数正确;最后有 \`|\`。
|
|
246
|
+
- [ ] 一条通道一个 program;鼓在通道 9。
|
|
247
|
+
- [ ] \`s.report()\` 的 bars 与方案一致(不一致要在回答里说明)。
|
|
248
|
+
- [ ] 没有卡音(\`note-off\` 成对);没有空白段;主题能听出来。
|
|
249
|
+
- [ ] 力度弧有层次;循环曲最后能接回开头。
|
|
250
|
+
- [ ] 试听链接已贴给用户;没有伪造音频 URL,没有说「我听过了」。
|
|
251
|
+
`;
|
|
252
|
+
const EN = `# Game Material Master · Compose Mode Guide (scoremill)
|
|
253
|
+
|
|
254
|
+
> This guide is for **the agent in the conversation**. Goal: turn the user's idea into a
|
|
255
|
+
> **readable, editable, auditionable** MIDI, then optionally hand it to Suno for a produced track.
|
|
256
|
+
> scoremill is an MIT-licensed text-notation MIDI library
|
|
257
|
+
> (https://github.com/CharlesCNorton/scoremill).
|
|
258
|
+
|
|
259
|
+
## 0. Fixed flow (do not skip)
|
|
260
|
+
|
|
261
|
+
1. \`getMusicJob({jobId})\` — read the user's text, extra requirements, instrumental flag,
|
|
262
|
+
review mode, and \`scorePlan\`.
|
|
263
|
+
2. Analyse the idea and write a **plan** (style, mood, key, BPM, meter, section map,
|
|
264
|
+
instrumentation, motif, dynamic arc, loop/ending). Output it in the **user's language**.
|
|
265
|
+
3. \`saveMusicScorePlan({jobId, plan})\` — persist the plan.
|
|
266
|
+
4. Review mode \`manual\`: **stop here** and wait for confirmation. \`auto\`: continue.
|
|
267
|
+
5. Write \`compose.py\` (scoremill) and call \`runMusicScore({jobId, title, plan, script, label?})\`.
|
|
268
|
+
6. The host runs Python, parses \`score.mid\`, renders a preview, and returns \`openUrl\`.
|
|
269
|
+
Paste the link verbatim; state BPM / key / duration / sections so the user can audition.
|
|
270
|
+
7. User feedback → change the **specific section** in the plan and script → call
|
|
271
|
+
\`runMusicScore\` again with \`basedOn\` pointing at the previous version.
|
|
272
|
+
8. Only when the user **explicitly asks** for "Suno version" call
|
|
273
|
+
\`submitMusicScoreToSuno({jobId, scoreId, confirm:true})\`. It costs credits; say so first.
|
|
274
|
+
Then \`game_material_wait\` and paste the new \`openUrl\`.
|
|
275
|
+
|
|
276
|
+
⚠️ **Never auto-submit to Suno.** Composing and auditioning are local/free; Suno is paid.
|
|
277
|
+
⚠️ **Every revision is a new version**; never overwrite old MIDI/preview.
|
|
278
|
+
⚠️ **Fix the exact bar named by the error**; do not rewrite the whole piece. After 3 failures, stop and explain.
|
|
279
|
+
|
|
280
|
+
## 1. Analyse, then plan (the plan is for the user)
|
|
281
|
+
|
|
282
|
+
Before writing any notes, answer:
|
|
283
|
+
|
|
284
|
+
- **Use**: theme / battle / menu / ambience / loop / short stinger / cutscene. The use decides
|
|
285
|
+
length, intensity, and loopability far more than genre words.
|
|
286
|
+
- **Emotional arc**: from what to what? Where is the climax? Where is the quiet section?
|
|
287
|
+
- **Key / tonic**: major, minor, or mode; keep one tonic unless a modulation has a purpose.
|
|
288
|
+
- **Tempo / meter**: BPM, 4/4 vs 3/4 / 6/8; loops should keep a fixed BPM.
|
|
289
|
+
- **Section map**: name, bars, energy, instrumentation changes. Example:
|
|
290
|
+
\`INTRO 8 (p, koto + pad) → MAIN 16 (f, strings theme + drums) → CLIMAX 12 (ff, tutti) → CODA 6 (mp, back to tonic)\`.
|
|
291
|
+
- **Instrumentation**: GM name + program + channel; one program per channel; drums on channel 9.
|
|
292
|
+
- **Motif**: one sentence about the melodic character (leaps/steps, rhythm, landing note).
|
|
293
|
+
- **Loop / ending**: loops must connect back to the start; endings must state the final chord.
|
|
294
|
+
|
|
295
|
+
**Plan JSON** (for \`saveMusicScorePlan\` / \`runMusicScore\`):
|
|
296
|
+
|
|
297
|
+
\`\`\`json
|
|
298
|
+
{
|
|
299
|
+
"summary": "The full plan in the user's language, may be multi-paragraph",
|
|
300
|
+
"style": "xianxia, orchestral battle",
|
|
301
|
+
"mood": "suppressed to explosive, unresolved ending",
|
|
302
|
+
"key": "D minor / D phrygian",
|
|
303
|
+
"tempo": 150,
|
|
304
|
+
"timeSignature": "4/4",
|
|
305
|
+
"lengthBars": 42,
|
|
306
|
+
"instrumental": true,
|
|
307
|
+
"structure": [
|
|
308
|
+
{ "name": "INTRO", "bars": 8, "energy": "p", "description": "koto question, pad bed" },
|
|
309
|
+
{ "name": "MAIN", "bars": 16, "energy": "f", "description": "strings theme + drums" }
|
|
310
|
+
],
|
|
311
|
+
"instrumentation": [
|
|
312
|
+
{ "name": "strings", "program": 48, "channel": 1, "role": "theme" },
|
|
313
|
+
{ "name": "warm pad", "program": 89, "channel": 2, "role": "harmony" }
|
|
314
|
+
],
|
|
315
|
+
"motif": "D-centric, third vs minor third, resolves to D",
|
|
316
|
+
"notes": "loop track; last 2 bars lead back to the top",
|
|
317
|
+
"sunoTags": "xianxia, orchestral battle, instrumental, erhu, taiko, 150 BPM, D minor, game soundtrack",
|
|
318
|
+
"sunoPrompt": "Instrumental xianxia battle soundtrack, 150 BPM, D minor, 4/4. Intro sparse, main theme soaring strings, climax full orchestra and taiko.",
|
|
319
|
+
"negativeTags": "vocals, edm drop"
|
|
320
|
+
}
|
|
321
|
+
\`\`\`
|
|
322
|
+
|
|
323
|
+
Write \`sunoTags\` / \`sunoPrompt\` / \`negativeTags\` in **English** (Suno understands English tags best);
|
|
324
|
+
the other fields may be in the user's language. Set \`instrumental: true\` when there are no vocals.
|
|
325
|
+
|
|
326
|
+
## 2. scoremill in 30 seconds
|
|
327
|
+
|
|
328
|
+
\`\`\`python
|
|
329
|
+
from scoremill import Song
|
|
330
|
+
import json
|
|
331
|
+
|
|
332
|
+
s = Song(tempo=120, time="4/4", key="Dm",
|
|
333
|
+
humanize=2, expressive=True, pitch_range=(0, 127))
|
|
334
|
+
|
|
335
|
+
A = s.section("A")
|
|
336
|
+
lead = A.voice("lead", vel=60, octave=5, program=48, channel=1) # strings
|
|
337
|
+
lead.bars("!mf a4q d5q f#5h | e5q d5q bn4h |")
|
|
338
|
+
bass = A.voice("bass", vel=45, octave=2, program=89, channel=5) # pad
|
|
339
|
+
bass.bars("!mp [d2 a2]w | [d2 a2]w |")
|
|
340
|
+
kit = A.drums(vel=70)
|
|
341
|
+
kit.bars("bdq bde sne bdq [sn hh]e hhe | bdq bde sne bdq hhe hhe |")
|
|
342
|
+
|
|
343
|
+
s.arrange("A")
|
|
344
|
+
s.save("score.mid")
|
|
345
|
+
print(json.dumps(s.report(), ensure_ascii=False))
|
|
346
|
+
\`\`\`
|
|
347
|
+
|
|
348
|
+
## 3. Three iron rules
|
|
349
|
+
|
|
350
|
+
1. **Every bar must contain exactly the meter's beats and end with \`|\`.**
|
|
351
|
+
2. **All voices in a section must have the same length** (pad short ones with \`rw\`).
|
|
352
|
+
3. **One MIDI channel = one program for the whole piece**; drums are channel 9.
|
|
353
|
+
|
|
354
|
+
## 4. Notation cheat sheet
|
|
355
|
+
|
|
356
|
+
### 4.1 Pitch
|
|
357
|
+
|
|
358
|
+
- \`c4\` \`d4\` \`e4\` … letter + octave; with \`key="Dm"\`, \`b\` is B♭. Write \`bn\` for B natural, \`f#\` for F♯.
|
|
359
|
+
- Octave and duration are **sticky** within a voice: \`d4q e f\` are all octave 4 quarter notes.
|
|
360
|
+
- In dense multi-voice writing, write the octave on every note (\`e4\`, not \`e\`).
|
|
361
|
+
|
|
362
|
+
### 4.2 Duration / rests / chords / tuplets
|
|
363
|
+
|
|
364
|
+
| Syntax | Meaning |
|
|
365
|
+
|---|---|
|
|
366
|
+
| \`c4w\` \`c4h\` \`c4q\` \`c4e\` \`c4s\` \`c4t\` | whole / half / quarter / eighth / sixteenth / 32nd |
|
|
367
|
+
| \`c4q.\` | dotted quarter |
|
|
368
|
+
| \`r\` | rest (duration is sticky; **always write \`rq\` / \`rh\` / \`rw\`**) |
|
|
369
|
+
| \`[c4 e g]h\` | chord |
|
|
370
|
+
| \`{c4 d4 e4}q\` | tuplet (members share the beat) |
|
|
371
|
+
| \`+d5\` | grace note (no duration; write the full pitch) |
|
|
372
|
+
| \`c5h~\` | tie; the next note must repeat the pitch; a trailing \`~\` is a free fermata |
|
|
373
|
+
| \`c5q>\` \`c5q'\` \`c5q_\` \`c5q^\` \`c5q&\` \`c5q%\` | accent / staccato / legato / tenuto / roll / trill (after the duration) |
|
|
374
|
+
| \`!pp\` … \`!fff\` | dynamics (sticky) |
|
|
375
|
+
| \`cresc\` / \`dim\` | crescendo / diminuendo; **must land on a dynamic**; close it even in the last bar |
|
|
376
|
+
| \`s.tempo_change("MAIN", 1, 150)\` | section starts at 150 BPM from bar 1 |
|
|
377
|
+
| \`s.ritardando("CODA", 5, 8, 66)\` | linear 5→8 bar change to 66 BPM |
|
|
378
|
+
|
|
379
|
+
### 4.3 Drums (channel 9)
|
|
380
|
+
|
|
381
|
+
\`\`\`python
|
|
382
|
+
kit = A.drums(vel=70)
|
|
383
|
+
kit.bars("bdq bde sne bdq [sn hh]e hhe | bdq bde sne bdq hhe hhe |")
|
|
384
|
+
\`\`\`
|
|
385
|
+
|
|
386
|
+
Names (prefix match, duration attached; stack with brackets):
|
|
387
|
+
\`bd bd2 sn esn rim clap lt mt ht lft hft hh hc ho hp cr cr2 sp ch rd rb cb tamb clave wood tri\`.
|
|
388
|
+
|
|
389
|
+
**Name and duration must be glued**: \`bdq\` / \`bde\` / \`sne\`, never \`bd q\`.
|
|
390
|
+
|
|
391
|
+
### 4.4 Channels / GM programs
|
|
392
|
+
|
|
393
|
+
Channels 0–8 + 10–15 (9 is drums) = 15 programs. Common GM programs:
|
|
394
|
+
|
|
395
|
+
| Instrument | program | Instrument | program |
|
|
396
|
+
|---|---:|---|---:|
|
|
397
|
+
| Harp | 46 | Strings | 48 |
|
|
398
|
+
| Choir | 52 | Brass | 61 |
|
|
399
|
+
| Timpani | 47 | Warm pad | 89 |
|
|
400
|
+
| Koto | 107 | Shakuhachi | 77 |
|
|
401
|
+
| Flute | 73 | Piano | 0 |
|
|
402
|
+
| Bass | 32–39 | Synth lead | 80–87 |
|
|
403
|
+
|
|
404
|
+
## 5. Common errors → fixes
|
|
405
|
+
|
|
406
|
+
| Error fragment | Cause | Fix |
|
|
407
|
+
|---|---|---|
|
|
408
|
+
| \`has 64.0 beats, expected 4.0 — over by 60.0 beats\` | bars joined without \`|\` | \`" | ".join(bars) + " |"\` |
|
|
409
|
+
| \`bar 9: has 0.0 beats, expected 4.0\` | already ended with \`|\`, added another | add a space, not a barline |
|
|
410
|
+
| \`unrecognized token '|a5q'\` | string glued to \`|\` | add a space |
|
|
411
|
+
| \`voices differ in length\` | a voice is short | pad with \`rw |\` |
|
|
412
|
+
| \`cresc never reaches a dynamic mark\` | no target dynamic | add \`!f\` within 1–4 bars |
|
|
413
|
+
| \`cresc while an earlier one is still open\` | previous cresc not closed | close it first |
|
|
414
|
+
| \`tie: next note must repeat the pitch\` | \`~\` followed by a different pitch | remove \`~\` or repeat the pitch |
|
|
415
|
+
| \`note would leave the range 21-108\` | default piano range | pass \`pitch_range=(0, 127)\` |
|
|
416
|
+
| \`unknown drum token 'e'\` | wrote \`bd q\` | glue to \`bdq\` |
|
|
417
|
+
| \`trailing partial bar\` | missing final \`|\` | add it |
|
|
418
|
+
|
|
419
|
+
Some errors (open cresc, unequal voices) only surface at \`report()\` / \`save()\`;
|
|
420
|
+
call \`s.report()\` after each section.
|
|
421
|
+
|
|
422
|
+
## 6. Game-music guidance
|
|
423
|
+
|
|
424
|
+
- **Loops**: fixed BPM; last 1–2 bars lead back to the top; avoid a long reverb tail at the seam.
|
|
425
|
+
- **Short cues / stingers**: 30–90s, few sections (INTRO → MAIN → END).
|
|
426
|
+
- **Battle**: clear rhythm, solid low end; the theme must be audible in the mid/high register;
|
|
427
|
+
don't let an ostinato eat the theme.
|
|
428
|
+
- **Ambience**: weak melody, little percussion, leave room for dialogue/SFX.
|
|
429
|
+
- **Dynamic arc**: intro p → theme f → climax ff → coda mp; don't stay ff for 16 bars.
|
|
430
|
+
- **Differentiate repeated sections with orchestration/drums/dynamics**, not new melodies.
|
|
431
|
+
- **Two themes must stack**: share a tonic; write the conflict on a specific note (third, tritone).
|
|
432
|
+
- **Register is stance**: don't put two melodies in the same octave; they will collide.
|
|
433
|
+
- **Augmentation beats new material**: \`stretch(theme, 2)\` + \`rebar(..., 4)\` widens a climax theme.
|
|
434
|
+
|
|
435
|
+
## 7. Script contract (how the host runs it)
|
|
436
|
+
|
|
437
|
+
- You pass the full \`script\` via \`runMusicScore\`; the host writes and runs it in the job directory.
|
|
438
|
+
- **Must** produce \`score.mid\` in the cwd: \`s.save("score.mid")\`.
|
|
439
|
+
- **Do not** render audio yourself, access the network, or write outside the job directory.
|
|
440
|
+
- Recommended: end with \`print(json.dumps(s.report(), ensure_ascii=False))\`; the host stores that JSON.
|
|
441
|
+
- Use \`pitch_range=(0, 127)\`; drums on channel 9; one program per channel.
|
|
442
|
+
- Keep the piece under **10 minutes** (host cap 600s; built-in preview synth cap 480s).
|
|
443
|
+
- Use a fixed seed for any randomness (\`random.Random(20)\`), so re-renders match.
|
|
444
|
+
- On failure the host returns the stderr tail; fix the exact bar.
|
|
445
|
+
|
|
446
|
+
## 8. Revision protocol
|
|
447
|
+
|
|
448
|
+
When the user says "too loud / too slow / too many drums / theme not clear / second section too long":
|
|
449
|
+
|
|
450
|
+
1. Decide **which section** and what to change (orchestration/dynamics/melody/tempo/length).
|
|
451
|
+
2. Change the plan fields and the matching bars in the script.
|
|
452
|
+
3. Call \`runMusicScore({jobId, ..., basedOn: "<previous scoreId>"})\`.
|
|
453
|
+
4. Explain what changed, why, and what the user should hear differently.
|
|
454
|
+
5. Don't change sections the user didn't mention; don't rewrite the whole piece.
|
|
455
|
+
|
|
456
|
+
## 9. Handing to Suno (optional, paid)
|
|
457
|
+
|
|
458
|
+
- Suno **does not accept MIDI files, but it does accept audio**. The correct chain is: the plugin
|
|
459
|
+
renders this version's MIDI to a preview (\`preview.mp3\` / \`preview.wav\`), uploads it to
|
|
460
|
+
\`/v1/suno/audio/upload\` to get a reference song id, and then generates a **cover**. Suno therefore
|
|
461
|
+
hears your instrumentation, rhythm, and structure instead of only text tags.
|
|
462
|
+
- Standard audio upload is free. If Suno flags the audio as copyrighted, the **paid copyright upload
|
|
463
|
+
channel** is required (credits are deducted); only use it after the user confirms and pass
|
|
464
|
+
\`copyrightAudio:true\`.
|
|
465
|
+
- The result is **not note-for-note**; it is a re-performance / re-arrangement based on that audio.
|
|
466
|
+
- Only call this when the user explicitly asks for a Suno version:
|
|
467
|
+
\`submitMusicScoreToSuno({jobId, scoreId, confirm:true, model?, regenerate?, copyrightAudio?, audioWeight?})\`.
|
|
468
|
+
- If it returns \`needsCopyrightConsent:true\`, explain why to the user first; retry with
|
|
469
|
+
\`copyrightAudio:true\` only after confirmation.
|
|
470
|
+
- If songs already exist, another batch costs credits: ask first and pass \`regenerate:true\`.
|
|
471
|
+
- After submitting, \`game_material_wait\`; paste the new \`openUrl\` and say how many songs were produced.
|
|
472
|
+
- If the piece is longer than 360s, Suno is submitted at 360s; state that in the answer.
|
|
473
|
+
- \`audioWeight\` defaults to 0.75; raise it (0–1) to stay closer to the MIDI, lower it to let Suno
|
|
474
|
+
arrange more freely.
|
|
475
|
+
|
|
476
|
+
## 10. Pre-submit checklist
|
|
477
|
+
|
|
478
|
+
- [ ] Plan saved and visible to the user; manual mode waited for confirmation.
|
|
479
|
+
- [ ] Every section's voices are equal length; every bar has the right beats; final \`|\`.
|
|
480
|
+
- [ ] One program per channel; drums on channel 9.
|
|
481
|
+
- [ ] \`s.report()\` bars match the plan (if not, explain in the answer).
|
|
482
|
+
- [ ] No stuck notes (note-off pairs); no empty sections; the theme is audible.
|
|
483
|
+
- [ ] The dynamic arc has layers; loops connect back to the start.
|
|
484
|
+
- [ ] The preview link is posted; no fake audio URLs; never claim you listened.
|
|
485
|
+
`;
|
|
486
|
+
export function musicScoreGuide(lang) {
|
|
487
|
+
return String(lang ?? "zh").toLowerCase().startsWith("en") ? EN : ZH;
|
|
488
|
+
}
|
|
489
|
+
export function musicScoreGuidePayload(lang) {
|
|
490
|
+
const normalized = String(lang ?? "zh").toLowerCase().startsWith("en") ? "en" : "zh";
|
|
491
|
+
return {
|
|
492
|
+
lang: normalized,
|
|
493
|
+
guide: normalized === "en" ? EN : ZH,
|
|
494
|
+
sources: MUSIC_SCORE_GUIDE_SOURCES.map((entry) => ({ ...entry }))
|
|
495
|
+
};
|
|
496
|
+
}
|