開發者資訊

MuseScore 批次匯出: MusicXML/PNG/PDF

請先確認已安裝 MuseScore

執行結果若顯示 MuseScore not found,請先將 MuseScore 的 bin 資料夾加入 PATH 再重試

  1. .mscz (MuseScore 樂譜檔)所在資料夾,建立 記事本
  2. 記事本 貼上下方程式碼
  3. 記事本另存新檔 再次儲存,並留意:副檔名改為 .bat、編碼選 ANSI不可為預設的 UTF-8)。
  4. .bat 檔,連按兩下(執行)
  5. 每份 .mscz 會在同資料夾產生相同名稱的 .musicxml.pdf.png

以網頁開啟下方程式碼文字檔

@echo off
setlocal EnableExtensions EnableDelayedExpansion

set "WORKDIR=%~dp0"
set "TEMPDIR=__mscz_tmp__"
set "MSCORE="

set "CAND[0]=%ProgramFiles%\MuseScore 4\bin\MuseScore4.exe"
set "CAND[1]=%ProgramFiles%\MuseScore 3\bin\MuseScore3.exe"
set "CAND[2]=%ProgramFiles(x86)%\MuseScore 4\bin\MuseScore4.exe"
set "CAND[3]=%ProgramFiles(x86)%\MuseScore 3\bin\MuseScore3.exe"

for /l %%i in (0,1,3) do if not defined MSCORE if exist "!CAND[%%i]!" set "MSCORE=!CAND[%%i]!"
if not defined MSCORE for %%e in (MuseScore4.exe MuseScore3.exe MuseScore.exe) do if not defined MSCORE for /f "delims=" %%p in ('where %%e 2^>nul') do if not defined MSCORE set "MSCORE=%%p"

if not defined MSCORE (
  echo [ERROR] MuseScore not found. Please install it or add its bin folder to PATH.
  pause
  exit /b 1
)

echo Using MuseScore: "!MSCORE!"
echo Work folder    : "%WORKDIR%"
echo.

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; Add-Type -AssemblyName System.IO.Compression.FileSystem; $enc=New-Object System.Text.UTF8Encoding($false); $q=[char]34; $root=$env:WORKDIR; $msc=$env:MSCORE; $tmp=Join-Path $root $env:TEMPDIR; if(Test-Path -LiteralPath $tmp){Remove-Item -LiteralPath $tmp -Recurse -Force}; New-Item -ItemType Directory -Path $tmp | Out-Null; $files=Get-ChildItem -LiteralPath $root -Filter *.mscz -File; if($files.Count -eq 0){ Write-Host 'No .mscz files found.'; exit 0 }; foreach($f in $files){ Write-Host ('[file] ' + $f.Name); $base=[IO.Path]::GetFileNameWithoutExtension($f.Name); $pdf=Join-Path $root ($base+'.pdf'); $png=Join-Path $root ($base+'.png'); $xml=Join-Path $root ($base+'.musicxml'); $ex=Join-Path $tmp $base; if(Test-Path -LiteralPath $ex){Remove-Item -LiteralPath $ex -Recurse -Force}; [System.IO.Compression.ZipFile]::ExtractToDirectory($f.FullName,$ex); Get-ChildItem -LiteralPath $ex -Recurse -Filter *.mscx -File | ForEach-Object{ $t=[IO.File]::ReadAllText($_.FullName,$enc); $t=$t.Replace('<visible>0</visible>','<visible>1</visible>'); [IO.File]::WriteAllText($_.FullName,$t,$enc) }; $uh=Join-Path $tmp ($base+'.unhidden.mscz'); if(Test-Path -LiteralPath $uh){Remove-Item -LiteralPath $uh -Force}; [System.IO.Compression.ZipFile]::CreateFromDirectory($ex,$uh); $jobs=@(@($f.FullName,$pdf),@($f.FullName,$png),@($uh,$xml)); foreach($j in $jobs){ $p=Start-Process -FilePath $msc -ArgumentList @('-o',($q+$j[1]+$q),($q+$j[0]+$q)) -Wait -PassThru -NoNewWindow; Write-Host ('   exit ' + $p.ExitCode + '  ' + (Split-Path $j[1] -Leaf)) } }; Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue"

echo.
echo Done.
pause
endlocal

樂譜檔案瀏覽與下載

檔案類型