Skip to content

Commit 11b53a2

Browse files
committed
Remove input path
1 parent cac619f commit 11b53a2

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
lines changed

Diff for: NotaGenNode.py

+38-30
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ def INPUT_TYPES(s):
5858
"top_k": ("INT", {"default": 50, "min": 0}),
5959
"top_p": ("FLOAT", {"default": 0.95, "min": 0, "max": 1, "step": 0.01}),
6060
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
61-
"comfy_python_path": ("STRING", {
62-
"default": "",
63-
"multiline": False,
64-
"tooltip": "Absolute path of python.exe in ComfyUI environment"
65-
}),
66-
"musescore4_path": ("STRING", {
67-
"default": "",
68-
"tooltip": r"Absolute path e.g. D:\APP\MuseScorePortable\App\MuseScore\bin\MuseScore4.exe"
69-
}),
7061
},
7162
}
7263

@@ -77,8 +68,6 @@ def INPUT_TYPES(s):
7768

7869
def inference_patch(self, model, period, composer, instrumentation,
7970
custom_prompt,
80-
comfy_python_path,
81-
musescore4_path,
8271
unload_model,
8372
temperature,
8473
top_k,
@@ -256,10 +245,11 @@ def inference_patch(self, model, period, composer, instrumentation,
256245
with open(unreduced_output_path, 'w') as file:
257246
file.writelines(abc_lines)
258247
print(f"Saved to {unreduced_output_path}",)
259-
unreduced_xml_path = self.abc2xml(unreduced_output_path, INTERLEAVED_OUTPUT_FOLDER, comfy_python_path)
248+
unreduced_xml_path = self.convert_abc2xml(unreduced_output_path, INTERLEAVED_OUTPUT_FOLDER)
260249
if unreduced_xml_path:
261250
save_xml_original = True
262251
else:
252+
print("Conversion xml failed.")
263253
num_gen += 1
264254
save_xml_original = False
265255

@@ -274,7 +264,7 @@ def inference_patch(self, model, period, composer, instrumentation,
274264
print(f"Saved to {original_output_path}",)
275265

276266
if save_xml_original:
277-
original_xml_path = self.abc2xml(original_output_path, ORIGINAL_OUTPUT_FOLDER, comfy_python_path)
267+
original_xml_path = self.convert_abc2xml(original_output_path, ORIGINAL_OUTPUT_FOLDER)
278268
if original_xml_path:
279269
print(f"Conversion to {original_xml_path}",)
280270
break
@@ -289,8 +279,8 @@ def inference_patch(self, model, period, composer, instrumentation,
289279
raise Exception("All generation attempts failed after 6 tries. Try again.")
290280

291281
if unreduced_xml_path:
292-
mp3_path = self.xml2mp3(unreduced_xml_path, musescore4_path)
293-
png_paths = self.xml2png(unreduced_xml_path, musescore4_path)
282+
mp3_path = self.xml2mp3(unreduced_xml_path)
283+
png_paths = self.xml2png(unreduced_xml_path)
294284

295285
# 处理音频
296286
audio = None
@@ -499,7 +489,7 @@ def wait_for_png_sequence(self, base_path, timeout=15, check_interval=0.3):
499489

500490
return None
501491

502-
def xml2mp3(self, xml_path, musescore4_path):
492+
def xml2mp3(self, xml_path):
503493
import subprocess
504494
import sys
505495
import tempfile
@@ -532,7 +522,7 @@ def xml2mp3(self, xml_path, musescore4_path):
532522

533523
# 运行 mscore 命令
534524
subprocess.run(
535-
[musescore4_path, '-o', mp3_path, xml_path],
525+
['mscore', '-o', mp3_path, xml_path],
536526
check=True,
537527
capture_output=True,
538528
)
@@ -553,8 +543,11 @@ def xml2mp3(self, xml_path, musescore4_path):
553543
xvfb_process.wait()
554544
else:
555545
try:
546+
import shutil
547+
musescore_executable_path = shutil.which('MuseScore4')
548+
print(musescore_executable_path)
556549
subprocess.run(
557-
[musescore4_path, '-o', mp3_path, xml_path],
550+
[musescore_executable_path, '-o', mp3_path, xml_path],
558551
check=True,
559552
capture_output=True,
560553
)
@@ -569,7 +562,7 @@ def xml2mp3(self, xml_path, musescore4_path):
569562
print(f"Conversion failed: {e.stderr}" if e.stderr else "Unknown error")
570563
return None
571564

572-
def xml2png(self, xml_path, musescore4_path):
565+
def xml2png(self, xml_path):
573566
import subprocess
574567
import sys
575568
import tempfile
@@ -602,7 +595,7 @@ def xml2png(self, xml_path, musescore4_path):
602595

603596
# 运行 mscore 命令
604597
subprocess.run(
605-
[musescore4_path, '-o', f"{base_png_path}.png", xml_path],
598+
['mscore', '-o', f"{base_png_path}.png", xml_path],
606599
check=True,
607600
capture_output=True,
608601
)
@@ -623,8 +616,11 @@ def xml2png(self, xml_path, musescore4_path):
623616
xvfb_process.wait()
624617
else:
625618
try:
619+
import shutil
620+
musescore_executable_path = shutil.which('MuseScore4')
621+
print(musescore_executable_path)
626622
subprocess.run(
627-
[musescore4_path, '-o', f"{base_png_path}.png", xml_path],
623+
[musescore_executable_path, '-o', f"{base_png_path}.png", xml_path],
628624
check=True,
629625
capture_output=True,
630626
)
@@ -640,19 +636,31 @@ def xml2png(self, xml_path, musescore4_path):
640636
print(f"Conversion failed: {e.stderr}" if e.stderr else "Unknown error")
641637
return None
642638

643-
def abc2xml(self, abc_path, output_dir, python_path):
644-
import subprocess
639+
def convert_abc2xml(self, abc_path, output_dir):
640+
import sys
641+
import os
642+
sys.path.append(self.node_dir)
643+
from abc2xml import getXmlDocs, writefile, readfile, info
645644
xml_path = abc_path.rsplit(".", 1)[0] + ".xml"
646645
try:
647-
subprocess.run(
648-
[python_path, f"{self.node_dir}/abc2xml.py", '-o', output_dir, abc_path, ],
649-
check=True,
650-
capture_output=True,
651-
)
646+
fnm, ext = os.path.splitext(abc_path)
647+
abctext = readfile(abc_path)
648+
649+
# 设置参数,对应原命令行参数
650+
skip, num = 0, 1 # 对应 -m 参数
651+
show_whole_rests = False # 对应 -r 参数
652+
line_breaks = False # 对应 -b 参数
653+
force_string_fret = False # 对应 -f 参数
654+
655+
xml_docs = getXmlDocs(abctext, skip, num, show_whole_rests, line_breaks, force_string_fret)
656+
657+
for itune, xmldoc in enumerate(xml_docs):
658+
fnmNum = '%02d' % (itune + 1) if len(xml_docs) > 1 else ''
659+
writefile(output_dir, fnm, fnmNum, xmldoc, '', False) # '' 对应 -mxl 参数,False 对应 -t 参数
652660
print(f"Conversion to {xml_path}",)
653661
return xml_path
654-
except subprocess.CalledProcessError as e:
655-
print(f"Conversion failed: {e.stderr}" if e.stderr else "Unknown error")
662+
except Exception as e:
663+
print(f"Conversion failed: {str(e)}")
656664
return None
657665

658666

Diff for: README-CN.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ https://github.com/user-attachments/assets/0671657f-e66b-4000-a0aa-48520f15b782
99

1010
## 📣 更新
1111

12+
[2025-04-09]⚒️: 不再需要输入 MuseScore4 或 mscore 以及 python 路径, 只需要将 MuseScore4 或 mscore 安装目录例如 `C:\Program Files\MuseScore 4\bin` 添加到系统 path 环境变量即可.
13+
1214
[2025-03-21]⚒️: 增加更多可调参数, 更自由畅玩. 可选是否卸载模型.
1315

1416
[2025-03-15]⚒️: 支持 Linux Ubuntu/Debian 系列, 以及服务器, 其他未测试.
@@ -19,7 +21,6 @@ sudo apt update
1921
sudo apt install musescore
2022
sudo apt install libxcb-xinerama0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 libxcb-xkb1 libxkbcommon-x11-0
2123
```
22-
然后将 `mscore` 路径输入节点即可, 如 `/bin/mscore`. 以及 comfyui 中 `python` 的绝对路径, 如 `/root/comfy/ComfyUI/bin/python`.
2324

2425
服务器, 安装虚拟显示器 Xvfb, 其他操作同上:
2526
```
@@ -33,8 +34,6 @@ sudo apt install xvfb
3334

3435
- 支持自定义 prompt, 格式必须保持 `<period>|<composer>|<instrumentation>` 的格式, `period`, `composer`, `instrumentation` 的顺序不能乱, 而且以 `|` 分割.
3536

36-
- 为了避免配置环境变量的麻烦, 请安装 [MuseScore4](https://musescore.org/en/download), 并将 `MuseScore4.exe` 的绝对路径输入节点中, 如 `D:\APP\MuseScorePortable\App\MuseScore\bin\MuseScore4.exe`, 以及 comfyui 中 `python.exe` 的绝对路径, 如 `D:\AIGC\APP\ComfyUI_v1\python_embeded\python.exe`.
37-
3837
## 安装
3938

4039
```

Diff for: README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ https://github.com/user-attachments/assets/0671657f-e66b-4000-a0aa-48520f15b782
88

99
## 📣 Updates
1010

11+
[2025-04-09]⚒️: It is no longer necessary to input MuseScore4 or mscore and the Python path. You only need to add the MuseScore4 or mscore installation directory (e.g., `C:\Program Files\MuseScore 4\bin`) to the system path environment variable.
12+
1113
[2025-03-21] ⚒️: Added more tunable parameters for more creative freedom. Optional model unloading.
1214

1315
[2025-03-15]⚒️: Supports Linux Ubuntu/Debian series, as well as servers, others untested, as well as servers.
@@ -18,7 +20,6 @@ sudo apt update
1820
sudo apt install musescore
1921
sudo apt install libxcb-xinerama0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 libxcb-xkb1 libxkbcommon-x11-0
2022
```
21-
Then input the `mscore` path into the node, such as `/bin/mscore`. And the absolute path of `python` in ComfyUI, such as `/root/comfy/ComfyUI/bin/python`.
2223

2324
For servers, install the virtual display Xvfb, other operations are the same as above:
2425
```
@@ -32,8 +33,6 @@ sudo apt install xvfb
3233

3334
- Supports custom prompts. The format must be maintained as `<period>|<composer>|<instrumentation>`, with the order of `period`, `composer`, and `instrumentation` strictly enforced and separated by `|`.
3435

35-
- To avoid the hassle of configuring environment variables, please install [MuseScore4](https://musescore.org/en/download) and enter the absolute path of `MuseScore4.exe` into the node, such as `D:\APP\MuseScorePortable\App\MuseScore\bin\MuseScore4.exe`, as well as the absolute path of `python.exe` in ComfyUI, such as `D:\AIGC\APP\ComfyUI_v1\python_embeded\python.exe`.
36-
3736
## Installation
3837

3938
```

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "notagen-mw"
33
description = "Symbolic Music Generation, NotaGen node for ComfyUI."
4-
version = "2.2.3"
4+
version = "2.2.4"
55
license = {file = "LICENSE"}
66

77
[project.urls]

0 commit comments

Comments
 (0)