Multitrack output

2006-04-13
2013-05-08
  • Dieter Demerre
    Dieter Demerre
    2006-04-13

    I have a script:

    Following script will create (in existing directories) tracks.

    <file name="towav">
    #!/bin/bash
    # Usage:
    #   towav file.mid voice1 voice2 ...
    # Will create voice-specific .wav files into
    # track 1 into ../wave-files/voice1/file.wav
    # track 2 into ../wave-files/voice2/file.wav
    #
    #  e.g.
    #  towav fn001heavn.mid sop alt ten1 bas1
    # will put
    # track 1 into ../wave-files/sop/fn001heavn.wav
    # track 2 into ../wave-files/alt/fn001heavn.wav
    # track 3 into ../wave-files/ten1/fn001heavn.wav
    # track 4 into ../wave-files/bas1/fn001heavn.wav

    target=../wave-files
    overwrite=0;

    function allmidi2wav
    {
      # Usage:
      #  allmidi2wav <midi-file> <voice>+
      # with <voice>+ in order they are in midi-file.
      #
      midi_file=$1;
      voicenr=1;
      shift 1;
      while [ $# -gt 0 ]; do
        only_one_voice2wav $midi_file $voicenr $1
        shift 1;
        voicenr=$[ $voicenr + 1 ]
      done
    }

    function only_one_voice2wav
    {
      # Usage:
      #  only_one_voice2wav <midifile> <voicenr> <dir>
      m=$1;
      voice=$2;
      dir=${target}/$3;
      if [ ! -d ${dir ]; then
        echo "Directory ${dir} is not found.">&2
        exit
      fi
      w=${dir}/`echo $m|sed 's/\.mid$/\.wav/'`;
      if [ ${overwrite} -eq 0 -a -s ${w} ]; then
        echo found already existing File ${w}
      else
        echo "converting $f for voice $dir"
        # option --trace causes silence at start of voices that start delayed.
        # so all wav tracks are equally initiated.
        timidity --trace --mute=0,-${voice} --output-mode=w --output-file=${w} ${m}
      fi
    }

    allmidi2wav $@
    </file>