To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / miditojson.sh
History | View | Annotate | Download (867 Bytes)
| 1 | 9:d3c644cd010e | Chris | #!/bin/bash |
|---|---|---|---|
| 2 | |||
| 3 | # Hacky script to create a JSON file listing only the notes from the |
||
| 4 | # given input MIDI file. Does not take into account tempo changes and |
||
| 5 | # uses a fixed timebase. |
||
| 6 | |||
| 7 | # Set this to the number of MIDI ticks per second. |
||
| 8 | # This assumes MIDI timebase = 480ppq and tempo = 120bpm. |
||
| 9 | divisor=960 |
||
| 10 | |||
| 11 | set -e |
||
| 12 | |||
| 13 | if [ -z "$1" -o -n "$2" ]; then |
||
| 14 | echo "Usage: miditojson.sh <midifile.mid>" 1>&2 |
||
| 15 | exit 2 |
||
| 16 | fi |
||
| 17 | |||
| 18 | infile="$1" |
||
| 19 | |||
| 20 | set -u |
||
| 21 | |||
| 22 | mydir="$(dirname $0)" |
||
| 23 | |||
| 24 | echo '['; |
||
| 25 | "$mydir"/midifile "$infile" | |
||
| 26 | grep 'Note:' | |
||
| 27 | awk -F: '{ print $1/'"$divisor"'.0,$3 } ' |
|
||
| 28 | awk '{ print $1,$2,$3,$4,$5/'"$divisor"'.0,$6,$7,$8,$9 }' |
|
||
| 29 | sed -e 's/channel [0-9] //' \ |
||
| 30 | -e 's/^/{ "time": /' \
|
||
| 31 | -e 's/ pitch /, "pitch": /' \ |
||
| 32 | -e 's/ duration /, "duration": /' \ |
||
| 33 | -e 's/ velocity /, "velocity": /' \ |
||
| 34 | -e 's/$/ },/' | |
||
| 35 | sed '$s/,$//' |
||
| 36 | echo ']' |
||
| 37 | |||
| 38 |