Stop naming filler syllables in tags (they conditioned the model); default prefer_lean_tags; hard-fail intro_filler in QC; add plugins/ hook bus as thin microkernel extension point. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+35
-22
@@ -66,11 +66,28 @@ def _extra_hint(cfg, dur):
|
||||
return "(额外放行区间:%s)" % ", ".join("%d~%ds" % (a, b) for a, b in ex)
|
||||
|
||||
|
||||
def resolve_lean(args, cfg):
|
||||
"""是否走 lean tags。
|
||||
|
||||
默认 prefer_lean_tags=true(少注入 RULE_NEG,避免开曲衬词)。
|
||||
--full-tags 强制完整否定句;--lean-tags 强制 lean。
|
||||
"""
|
||||
if bool(getattr(args, "full_tags", False)):
|
||||
return False
|
||||
if bool(getattr(args, "lean_tags", False)):
|
||||
return True
|
||||
return bool((cfg.get("rules") or {}).get("prefer_lean_tags", True))
|
||||
|
||||
|
||||
def assemble(args, cfg, st, lyrics_raw, title):
|
||||
"""套用铁律:生成 tags、补器乐前奏、清洗中文标记。"""
|
||||
from ..plugins.hooks import bus
|
||||
|
||||
chill = bool(getattr(args, "chill_vocal", False))
|
||||
inst = bool(getattr(args, "instrumental", False))
|
||||
lean = bool(getattr(args, "lean_tags", False))
|
||||
lean = resolve_lean(args, cfg)
|
||||
bus.emit("before_build_tags", args=args, cfg=cfg, style=st,
|
||||
chill=chill, instrumental=inst, lean=lean)
|
||||
tags = ironlaw.build_tags(
|
||||
style=st.get("style", ""), instruments=st.get("instruments", ""),
|
||||
mood=st.get("mood", ""), extra=st.get("extra", ""),
|
||||
@@ -82,8 +99,7 @@ def assemble(args, cfg, st, lyrics_raw, title):
|
||||
lyrics = ironlaw.build_inst_lyrics(
|
||||
st.get("intro_detail") or st.get("instruments"),
|
||||
bars=ibars)
|
||||
return tags, lyrics
|
||||
if chill:
|
||||
elif chill:
|
||||
# chill 走独立结构体:器乐段整体排在人声段之前。
|
||||
# 实测这只降低人声密度,并不推迟起点(chill 3 第一句仍在 0 秒),
|
||||
# 标签侧的时间/时机约束同样无效。详见 ironlaw 顶部实测结论。
|
||||
@@ -93,26 +109,23 @@ def assemble(args, cfg, st, lyrics_raw, title):
|
||||
vocal_sections(lyrics_raw),
|
||||
st.get("intro_detail") or st.get("instruments"),
|
||||
bars=ibars, total_bars=cap["total_bars"])
|
||||
return tags, lyrics
|
||||
lyrics = lyrics_raw
|
||||
if not lyrics.lstrip().lower().startswith("[intro]"):
|
||||
lyrics = ironlaw.build_lyrics(
|
||||
split_sections(lyrics_raw),
|
||||
st.get("intro_detail") or st.get("instruments"),
|
||||
bars=ibars)
|
||||
else:
|
||||
# 已有 [intro] 头的歌词文件:强制把前奏小节数对齐到标签写的值。
|
||||
# 标签写 16 小节而歌词头写 8 小节时,check_rules 会判两处不一致
|
||||
# ——这是故意留的闸门,不是 bug。
|
||||
lyrics = ironlaw.force_intro_bars(lyrics, ibars)
|
||||
# 前奏括号里的配器也要过 rhythm 过滤(2026-10-05 补)。
|
||||
# 之前这条分支只改小节数,作者手写的 [Instrumental: ...] 直接
|
||||
# 原样送进模型。ckfunk 批次的 8 首歌词前奏括号里就带着
|
||||
# "half time feel" 这类非节奏组描述,而作者也可能写 pad、
|
||||
# riser、sweep——intro_rhythm_only() 存在的全部理由就是把这些
|
||||
# 空场信号从前奏里剔掉,只留节奏组。手写歌词不等于免检。
|
||||
lyrics = ironlaw.filter_intro_bracket(lyrics)
|
||||
lyrics = "\n".join(ironlaw.strip_cn_instrumental(lyrics.splitlines())) + "\n"
|
||||
lyrics = lyrics_raw
|
||||
if not lyrics.lstrip().lower().startswith("[intro]"):
|
||||
lyrics = ironlaw.build_lyrics(
|
||||
split_sections(lyrics_raw),
|
||||
st.get("intro_detail") or st.get("instruments"),
|
||||
bars=ibars)
|
||||
else:
|
||||
# 已有 [intro] 头:对齐小节数 + 前奏括号 rhythm 过滤。
|
||||
lyrics = ironlaw.force_intro_bars(lyrics, ibars)
|
||||
lyrics = ironlaw.filter_intro_bracket(lyrics)
|
||||
lyrics = "\n".join(
|
||||
ironlaw.strip_cn_instrumental(lyrics.splitlines())) + "\n"
|
||||
out = bus.emit("after_assemble", tags=tags, lyrics=lyrics,
|
||||
args=args, cfg=cfg, style=st, lean=lean)
|
||||
if isinstance(out, dict) and out.get("tags") and out.get("lyrics"):
|
||||
return out["tags"], out["lyrics"]
|
||||
return tags, lyrics
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -15,7 +15,8 @@ from ..core.errors import ConfigError, ServerError
|
||||
from ..lyrics import meter
|
||||
from ..log.logger import Logger, Run
|
||||
from ..rules import ironlaw
|
||||
from .assemble import (_extra_hint, assemble, do_validate, duration_allowed)
|
||||
from .assemble import (_extra_hint, assemble, do_validate, duration_allowed,
|
||||
resolve_lean)
|
||||
from .common import (ROOT, build_cfg, chill_intro_bars, gen_day_root, now_id,
|
||||
read_lyrics, resolve_profile, runs_root, safe_name,
|
||||
session_logger, style_of)
|
||||
@@ -208,7 +209,7 @@ def cmd_check(args):
|
||||
prof = resolve_profile(args)
|
||||
errs, stats = do_validate(lyrics, tags, cfg, st, lexicon, strict=False,
|
||||
instrumental=inst, profile=prof,
|
||||
lean=bool(getattr(args, "lean_tags", False)))
|
||||
lean=resolve_lean(args, cfg))
|
||||
run.save_text("lyrics.txt", lyrics)
|
||||
run.save_text("tags.txt", tags)
|
||||
print("== 密度 ==")
|
||||
@@ -260,7 +261,7 @@ def cmd_gen(args):
|
||||
cfg, bool(getattr(args, "chill_vocal", False)))
|
||||
errs, stats = do_validate(lyrics, tags, cfg, st, lexicon, strict=True,
|
||||
instrumental=inst, profile=prof,
|
||||
lean=bool(getattr(args, "lean_tags", False)))
|
||||
lean=resolve_lean(args, cfg))
|
||||
|
||||
day_root = gen_day_root(cfg)
|
||||
pmod.ensure_dir(day_root)
|
||||
|
||||
+6
-4
@@ -81,8 +81,9 @@ def build_parser():
|
||||
c.add_argument("--density-profile", dest="density_profile",
|
||||
help="密度档:default(人声填满)/ sparse(音乐主导、人声点缀)")
|
||||
c.add_argument("--lean-tags", dest="lean_tags", action="store_true",
|
||||
help="精简正向标签:保留'前奏器乐+第一拍鼓'硬约束,"
|
||||
"但不注入 RULE_NEG 那 20+ 条人声否定句")
|
||||
help="强制 lean(默认已开启 prefer_lean_tags)")
|
||||
c.add_argument("--full-tags", dest="full_tags", action="store_true",
|
||||
help="注入完整 RULE_NEG(默认关闭;易诱发开曲衬词)")
|
||||
c.set_defaults(func=cmds.cmd_check)
|
||||
|
||||
g = sub.add_parser("gen", help="生成歌曲")
|
||||
@@ -114,8 +115,9 @@ def build_parser():
|
||||
g.add_argument("--density-profile", dest="density_profile",
|
||||
help="密度档:default(人声填满)/ sparse(音乐主导、人声点缀)")
|
||||
g.add_argument("--lean-tags", dest="lean_tags", action="store_true",
|
||||
help="精简正向标签:保留'前奏器乐+第一拍鼓'硬约束,"
|
||||
"但不注入 RULE_NEG 那 20+ 条人声否定句")
|
||||
help="强制 lean(默认已开启 prefer_lean_tags)")
|
||||
g.add_argument("--full-tags", dest="full_tags", action="store_true",
|
||||
help="注入完整 RULE_NEG(默认关闭;易诱发开曲衬词)")
|
||||
g.add_argument("--dry-run", dest="dry_run", action="store_true",
|
||||
help="只写 workflow 与 API 预览,不提交 ComfyUI")
|
||||
g.set_defaults(func=cmds.cmd_gen)
|
||||
|
||||
@@ -345,7 +345,17 @@ def _render(rep, args, rundir=None, cfg=None):
|
||||
r.get("coverage", 0) * 100, r.get("filler_ratio", 0) * 100,
|
||||
r.get("f0_med", 0),
|
||||
r.get("f0_drift_st", 0), r.get("tempo_drift", 0) * 100))
|
||||
print(" (衬词%% = ASR 语气/哼唱占比,弱参考,不单独否决)")
|
||||
print(" (衬词%% = 全曲 ASR 语气占比,弱参考;开曲衬词见结论里 intro_filler 硬门)")
|
||||
print("\n== 开曲衬词(硬门)==")
|
||||
print("%-22s %8s %8s %8s"
|
||||
% ("file", "前奏衬词", "前奏ASR", "衬词比"))
|
||||
for r in rows:
|
||||
if "error" in r:
|
||||
continue
|
||||
print("%-22s %8d %8d %7.0f%%"
|
||||
% (r["file"][:22], r.get("intro_filler_n", 0),
|
||||
r.get("intro_asr_n", 0),
|
||||
float(r.get("intro_filler_ratio") or 0) * 100))
|
||||
|
||||
print("\n== 结论 ==")
|
||||
npass = 0
|
||||
|
||||
+54
-13
@@ -122,12 +122,15 @@ def _t_model_locked():
|
||||
|
||||
|
||||
def _t_ironlaw():
|
||||
tags = ironlaw.build_tags("Chinese pop")
|
||||
# 默认路径现与 lean 对齐:完整 RULE_NEG 用 lean=False 测
|
||||
tags = ironlaw.build_tags("Chinese pop", lean=False)
|
||||
for kw in ("swlvoice", "8 bar instrumental intro hook", "no opening vocals",
|
||||
"no pure vocal intro", "no humming",
|
||||
"no pure vocal intro", "no wordless vocals",
|
||||
"solo lead vocal only", "no backing vocals",
|
||||
"sing only the exact words"):
|
||||
assert kw in tags, "tags 缺少 %s" % kw
|
||||
for bad in ("mm mm", "ooh ooh", "wu wu wu", "en en"):
|
||||
assert bad not in tags.lower(), "tags 点名衬词音节 %s" % bad
|
||||
assert "call and response" not in tags.lower() or \
|
||||
"no call and response vocals" in tags.lower(), \
|
||||
"MEMO 仍鼓励 call and response 且未禁叠唱"
|
||||
@@ -143,12 +146,17 @@ def _t_ironlaw():
|
||||
# 中文结构标记必须被拦
|
||||
marked = lyrics.replace("[verse]", "[主歌]")
|
||||
assert ironlaw.check_rules(marked, tags), "中文结构标记未被拦截"
|
||||
# lean 也必须带衬音硬禁
|
||||
# lean 也必须带衬音硬禁,且默认配置 prefer_lean
|
||||
lean = ironlaw.build_tags("Chinese pop", lean=True)
|
||||
for kw in ("solo lead vocal only", "no backing vocals"):
|
||||
for kw in ("solo lead vocal only", "no backing vocals",
|
||||
"no wordless vocals"):
|
||||
assert kw in lean, "lean tags 缺少衬音禁令 %s" % kw
|
||||
assert "no opening vocals" not in lean.lower(), \
|
||||
"lean 不应注入 RULE_NEG 的 opening 否定堆"
|
||||
cfg = loader.load({})
|
||||
assert cfg["rules"].get("prefer_lean_tags") is True, "默认未开 prefer_lean_tags"
|
||||
return [("铁律注入",
|
||||
"8 小节前奏 + 无衬音/无和声叠唱 + lean 齐备,缺前奏/中文标记均被拦")]
|
||||
"无音节点名 + lean 默认 + 无衬音/无和声,缺前奏/中文标记均被拦")]
|
||||
|
||||
|
||||
def _t_sparse_profile():
|
||||
@@ -204,11 +212,13 @@ def _t_instrumental():
|
||||
mood="vast uplifting EDM",
|
||||
extra="male low whisper vocal, hushed and intimate",
|
||||
instrumental=True)
|
||||
# 反人声条款必须在
|
||||
# 反人声条款必须在(抽象禁令,不点名音节)
|
||||
for kw in ("no vocals anywhere", "instrumental only", "no voice at all",
|
||||
"no humming", "no choir", "no vocal sample", "swlvoice",
|
||||
"no wordless vocals", "no choir", "no vocal sample", "swlvoice",
|
||||
"8 bar instrumental intro hook"):
|
||||
assert kw in tags, "纯器乐 tags 缺少 %s" % kw
|
||||
for bad in ("mm mm", "ooh ooh", "wu wu wu"):
|
||||
assert bad not in tags.lower(), "纯器乐 tags 点名音节 %s" % bad
|
||||
# 关键回归点:风格字典的唱法描述绝不能混进来跟 "no vocals" 对撞。
|
||||
for bad in ("whisper vocal", "sparse English words", "no belting"):
|
||||
assert bad not in tags, "纯器乐 tags 混入了唱法描述: %s" % bad
|
||||
@@ -488,17 +498,16 @@ def _t_chill_no_conflict():
|
||||
"""
|
||||
tags = ironlaw.build_tags(style="s", instruments="i", mood="m",
|
||||
chill_vocal=True)
|
||||
for bad in ("no humming", "no mm mm syllables", "no oh oh syllables",
|
||||
"no droning sustained vowels"):
|
||||
for bad in ("mm mm", "ooh ooh", "oh oh syllables", "wu wu wu", "en en"):
|
||||
assert bad not in tags.lower(), \
|
||||
"chill tags 含 %s,与要求的低音语气词直接冲突" % bad
|
||||
"chill tags 点名衬词音节 %s" % bad
|
||||
# 反过来,"稀疏低音语气词"必须真的在标签里,否则就退化成纯器乐了。
|
||||
for need in ("male low whisper vocal", "low register vocal texture",
|
||||
"soft breathy phrases"):
|
||||
assert need in tags.lower(), "chill tags 丢了低音唱腔描述: %s" % need
|
||||
|
||||
return [("吟唱无冲突",
|
||||
"no humming / no mm mm / no oh oh 三条禁令未回归")]
|
||||
"未点名衬词音节,低音吟唱描述保留")]
|
||||
|
||||
|
||||
def _t_chill_integration():
|
||||
@@ -518,10 +527,12 @@ def _t_chill_integration():
|
||||
class _A(object):
|
||||
chill_vocal = True
|
||||
instrumental = False
|
||||
lean_tags = False
|
||||
full_tags = False
|
||||
|
||||
raw = open(_CHILL_DEMO, encoding="utf-8").read()
|
||||
tags2, lyrics2 = assemble(_A, cfg, st, raw, "selftest")
|
||||
errs = ironlaw.check_rules(lyrics2, tags2)
|
||||
errs = ironlaw.check_rules(lyrics2, tags2, lean=True)
|
||||
assert not errs, "chill 集成校验不通过: %s" % errs
|
||||
|
||||
# 结构核心断言:第一个有人唱的段之前,纯器乐段必须占满前半段。
|
||||
@@ -763,6 +774,35 @@ def _t_window():
|
||||
"pop/punk/urbanhiphop 的 target 区间 == check 放行窗口,边界确实生效")]
|
||||
|
||||
|
||||
def _t_plugins_and_lean_default():
|
||||
"""微内核钩子已加载;默认 prefer_lean_tags;assemble 不注入 RULE_NEG 堆。"""
|
||||
from ..plugins.hooks import bus
|
||||
assert bus._handlers.get("after_assemble"), "intro_guard 未挂 after_assemble"
|
||||
cfg = loader.load({})
|
||||
assert cfg["rules"].get("prefer_lean_tags") is True
|
||||
|
||||
class _A(object):
|
||||
chill_vocal = False
|
||||
instrumental = False
|
||||
lean_tags = False
|
||||
full_tags = False
|
||||
density_profile = None
|
||||
|
||||
st = {"bpm": 104, "duration": 180, "key": "F major",
|
||||
"style": "Chinese pop", "instruments": "kick snare bass",
|
||||
"mood": "bright", "extra": ""}
|
||||
# 密度够过闸的短样
|
||||
raw = ("[verse]\n" + "\n".join(
|
||||
["街口的灯还亮着我往前走一步"] * 20))
|
||||
tags, _ly = assemble(_A(), cfg, st, raw, "selftest")
|
||||
assert "no opening vocals" not in tags.lower(), \
|
||||
"默认 lean 仍注入了 RULE_NEG opening 堆"
|
||||
assert "no wordless vocals" in tags.lower()
|
||||
assert "mm mm" not in tags.lower()
|
||||
return [("微内核与 lean 默认",
|
||||
"plugins.after_assemble 已挂;默认 tags 为 lean 且无音节点名")]
|
||||
|
||||
|
||||
def cmd_selftest(args):
|
||||
from .common import session_logger
|
||||
cfg = loader.load({})
|
||||
@@ -773,7 +813,8 @@ def cmd_selftest(args):
|
||||
_t_intro_instrument_filter, _t_chill_no_conflict,
|
||||
_t_chill_integration,
|
||||
_t_sparse_profile, _t_lexicon,
|
||||
_t_density, _t_window, _t_regression, _t_parity, _t_fallback]
|
||||
_t_density, _t_window, _t_regression, _t_parity, _t_fallback,
|
||||
_t_plugins_and_lean_default]
|
||||
npass = 0
|
||||
print("== songforge selftest ==")
|
||||
log.info("selftest 开始", cases=len(cases))
|
||||
|
||||
Reference in New Issue
Block a user