m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/mscz2pdfs
blob: e037086df50c76d3a8c5ec93af2a3c3d4a87ff4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash

# Converts a MuseScore file to PDFs, one for each part.
# USAGE: mscz2pdfs -s <score file> -o <output directory>

score=
output_dir='.'

while getopts 's:o:' flag; do
  case "${flag}" in
    s) score=$OPTARG ;;
    o) output_dir=$OPTARG ;;
    *) error "Unexpected option ${flag}" ;;
  esac
done

if [ -z "$score" ]; then
    echo "Provide score"
fi

base_filename=${score%.mscz}
base_filename=${score##*/}
json=`mktemp "/tmp/tmp-XXXXXXX.json"`
echo "putting json in $json"

musescore --score-parts-pdf "$score" > "$json"

parts=`jq --raw-output '.parts[]' "$json"`

i=0
IFS=$'\n';
for part in $parts; do
    jq --raw-output ".partsBin[$i]" "$json" | base64 --decode > "$output_dir"/"$base_filename-$part.pdf"
    i=$((i + 1))
done
IFS=' '