#!/bin/bash
#
# Author:  Yotam Medini  yotam.medini@gmail.com -- Created: 2012/August/04
# With the help of:  Alexandre Ratchov alex@caoua.org
#

set -u

if [[ $# -ne 4 ]]
then
  echo Usage ${0} '<midi-in> <midi-out> <measure-begin> <measure-end>' 1>&2
  exit 1
fi

midiin=${1}
midiout=${2}
measureb=${3}
measuree=${4}

rm -f ${midiout}

(
midish <<EOF
import "${midiin}"
g ${measuree}
sel [mend]
mcut
g 0
sel ${measureb}
mcut
export "${midiout}"
EOF
) 2>&1 | grep -v 'track_check:'

ls -lG ${midiout}
