timidity drumkit import script



   Hi!

Here is my first version of an import script for timidity drumkits
(needs latest CVS with bsewavetool; you also need to enable the GUS
patch loader in the Makefile.am in bse).

One issue with the script is that for notes which are _not_ defined in
the drumkit, timidity plays silence, whereas the imported version will
simply use the closest drum available and resample it. Maybe a flag
should be added to bsewave files for not playing notes.

Other than that, if the name is ok (or if a better name was found), I
can also add it somewhere to the CVS.

Also note that as long as the GUS Patchloader is not stable, imported
versions are likely to not work with some further version of BEAST.

Maybe there are bugs, if so, I'd be interested in hearing about them. It
works with the debian freepats package, though.

   Cu... Stefan
-- 
Stefan Westerfeld, Hamburg/Germany, http://space.twc.de/~stefan
#!/bin/sh
# 
# Copyright (C) 2004-2005 Stefan Westerfeld, stefan space twc de
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

#
# usage: timidity-cfg-drumkit-import <timidity_cfg_file> ...
#
#   this script imports drumkits specified in a timidity cfg file, and
#   creates a .bsewave file containing the drumkit
#
# example: timidity-cfg-drumkit-import /etc/timidity/timidity.cfg
#
#   will import the drumkits defined by /etc/timidity/timidity.cfg,
#   and create one output file per drumkit found, and write them
#   to files such as timidity_drumset_0.bsewave
#

for cfg_file in "$@"
do
  # read_cfg is implemented (recursively) to handle source directives
  # (inclusion of another cfg file) in a preprocessor like way
  echo cfg "$(basename $cfg_file | sed s/.cfg$//)"
  read_cfg()
  {
    cat "$(dirname $cfg_file)/$(basename $1)" | while read a b
    do
      if [ "$a" == "source" ]; then
	read_cfg "$b"
      else
	echo "$a" "$b"
      fi
    done
  }
  read_cfg "$cfg_file"
done | grep -v "^#" | awk '
# this awk script implements the keywords from the cfg files,
# and generates appropriate shell commands for bsewavetool, to
# create and import the .pat files

BEGIN {
  dir = ".";
}

{
  # we do not implement the dir directive correctly:
  #
  # we should be searching _all_ directories in the list for sample files
  # however, we currently only search the _last_ directory in the list for sample files
  if ($1 == "dir")
    {
      dir = $2;
      in_drumset = 0;
    }
  else if ($1 == "cfg") # generated by the "preprocessing stage" to indicate the file we are processing
    {
      cfg = $2;
      in_drumset = 0;
    }
  else if ($1 == "drumset") # a new drumset definition starts
    {
      set = $2;
      in_drumset = 1;
      filename = sprintf ("%s_drumkit_%s.bsewave", cfg, set);
      printf ("if test -f \"%s\"; then echo \"***\n*** %s already exists\n***\"; exit 1; fi\n", filename, filename);
      printf ("bsewavetool create %s 1\n", filename);
    }
  else if ($1 == "bank") # a tone bank definition starts (we do not process these)
    {
      in_drumset = 0;
    }
  else if (NF == 2 && in_drumset) # if we are currently parsing a drumset, import chunks:
    {
      note = $1;
      patch_file = $2;
      printf ("bsewavetool add-chunk %s_drumkit_%d.bsewave -m=%d %s/%s\n", cfg, set, note, dir, patch_file);
    }
}' | /bin/sh -x


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]