Mercurial > hg > midifile
changeset 9:d3c644cd010e midifile tip
Add to-json script, also add #! to Perl script
| author | Chris Cannam |
|---|---|
| date | Fri, 31 Mar 2017 15:17:42 +0100 |
| parents | 5f3e9ec11201 |
| children | |
| files | midisort.pl miditojson.sh |
| diffstat | 2 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/midisort.pl Wed Feb 03 13:32:00 2016 +0000 +++ b/midisort.pl Fri Mar 31 15:17:42 2017 +0100 @@ -1,4 +1,5 @@ - +#!/bin/perl +# # This file copyright 2010 Chris Cannam. # # Permission is hereby granted, free of charge, to any person
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/miditojson.sh Fri Mar 31 15:17:42 2017 +0100 @@ -0,0 +1,39 @@ +#!/bin/bash + +# Hacky script to create a JSON file listing only the notes from the +# given input MIDI file. Does not take into account tempo changes and +# uses a fixed timebase. + +# Set this to the number of MIDI ticks per second. +# This assumes MIDI timebase = 480ppq and tempo = 120bpm. +divisor=960 + +set -e + +if [ -z "$1" -o -n "$2" ]; then + echo "Usage: miditojson.sh <midifile.mid>" 1>&2 + exit 2 +fi + +infile="$1" + +set -u + +mydir="$(dirname $0)" + +echo '['; +"$mydir"/midifile "$infile" | + grep 'Note:' | + awk -F: '{ print $1/'"$divisor"'.0,$3 } ' | + awk '{ print $1,$2,$3,$4,$5/'"$divisor"'.0,$6,$7,$8,$9 }' | + sed -e 's/channel [0-9] //' \ + -e 's/^/{ "time": /' \ + -e 's/ pitch /, "pitch": /' \ + -e 's/ duration /, "duration": /' \ + -e 's/ velocity /, "velocity": /' \ + -e 's/$/ },/' | + sed '$s/,$//' +echo ']' + + +
