1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
#!/usr/bin/perl
# TiMidity++ -- MIDI to WAVE converter and player
# Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.co.jp>
# Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
#
# 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
#
# lspatch.pl
#
# List the entire instrument configuration
my (@tonebank, @drumset);
my (@pathlist, @patch_ext_list);
my $rcf_count;
my $def_instr_name;
my ($cfg, $cfgroot);
my $MAX_AMPLIFICATION;
@pathlist = ( '.' );
@patch_ext_list = ( '', '.pat', '.shn', '.pat.shn', '.gz', '.pat.gz' );
$rcf_count = 0;
$MAX_AMPLIFICATION = 800;
if (@ARGV != 1) {
print STDERR "Usage: $0 cfg-file\n";
exit 1;
}
$cfgroot = $cfg = $ARGV[0];
if ($cfgroot =~ s/\/[^\/]+$//) {
unshift(@pathlist, $cfgroot);
}
! &read_config_file($cfg) or exit 1;
$rcf_count++;
&lspatch('bank', @tonebank);
&lspatch('drumset', @drumset);
exit 0;
sub read_config_file
{
my ($name) = @_;
local *CFG;
my ($status, $i, $x, $y, $k);
my (@args, $bank, $orig_name, $line, $patch, @options);
if ($rcf_count > 50) {
print STDERR "Probable source loop in configuration files";
return -1;
}
$orig_name = $name;
undef $_;
$name = &open_file(*CFG, $name) or return -1;
undef $_;
$line = 0;
while (<CFG>) {
$line++;
s/^\s+|\r?\n$//;
@args = split(/[ \t\r\n\240]+/, $_);
next if @args == 0 || $args[0] =~ /^$|^#/;
if ($args[0] eq 'dir') {
if (@args < 2) {
print STDERR "$name: line $line: No directory given\n";
return -2;
}
shift @args;
map(s/\/+$//, @args);
unshift(@pathlist, reverse(@args));
} elsif ($args[0] eq 'source') {
if (@args < 2) {
print STDERR "$name: line $line: No file name given\n";
return -2;
}
shift @args;
for (@args) {
$rcf_count++;
print "source $_\n";
$status = &read_config_file($_);
$rcf_count--;
return $status if $status;
}
} elsif ($args[0] eq 'progbase') {
;
} elsif ($args[0] eq 'bank') {
if (@args < 2) {
print STDERR "$name: line $line: No bank number given\n";
return -2;
}
$i = $args[1];
if ($i < 0 || $i > 127) {
print STDERR "$name: line $line: ";
print STDERR "Tone bank must be between 0 and 127\n";
return -2;
}
$tonebank[$i] = [] if ! defined $tonebank[$i];
$bank = $tonebank[$i];
} elsif ($args[0] eq 'drumset') {
if (@args < 2) {
print STDERR "$name: line $line: No drum set number given\n";
return -2;
}
$i = $args[1];
if ($i < 0 || $i > 127) {
print STDERR "$name: line $line: ";
print STDERR "Drum set must be between 0 and 127\n";
return -2;
}
$drumset[$i] = [] if ! defined $drumset[$i];
$bank = $drumset[$i];
} elsif ($args[0] eq 'default') {
if (@args < 2) {
print STDERR "$name: line $line: ";
print STDERR "Must specify exactly one patch name\n";
return -2;
}
$def_instr_name = $args[1];
} elsif ($args[0] eq 'map') {
;
} elsif ($args[0] eq 'soundfont') {
;
} elsif ($args[0] eq 'font') {
;
} else {
if (@args < 2 || $args[0] !~ /^[0-9]/) {
print STDERR "$name: line $line: syntax error\n";
return -2;
}
$i = shift @args;
$patch = shift @args;
if ($i < 0 || $i > 127) {
printf STDERR "$name: line $line: ";
printf STDERR "Program must be between 0 and 127\n";
return -2;
}
if (! defined $bank) {
print STDERR "$name: line $line: ";
print STDERR "Must specify tone bank or drum set ";
print STDERR "before assignment\n";
return -2;
}
@options = ( );
for (@args) {
last if $_ =~ /^#/;
($x, $y) = split(/=/, $_, 2);
if ($x eq 'amp') {
if ($y < 0 || $y > $MAX_AMPLIFICATION || $y !~ /^[0-9]/) {
print STDERR "$name: line $line: ";
print STDERR "amplification must be ";
print STDERR "between 0 and $MAX_AMPLIFICATION\n";
return -2;
}
} elsif ($x eq 'note') {
if ($y < 0 || $y > 127 || $y !~ /^[0-9]/) {
print STDERR "$name: line $line: ";
print STDERR "note must be between 0 and 127\n";
return -2;
}
} elsif ($x eq 'pan') {
if ($y eq 'center') {
$k = 64;
} elsif ($y eq 'left') {
$k = 0;
} elsif ($y eq 'right') {
$k = 127;
} else {
$k = int(($y + 100) * 100 / 157);
}
if ($k < 0 || $k > 127 || ($k == 0 && $y !~ /^[0-9\-]/)) {
print STDERR "$name: line $line: ";
print STDERR "panning must be left, right, center, ";
print STDERR "or between -100 and 100\n";
return -2;
}
} elsif ($x eq 'tune') {
;
} elsif ($x eq 'rate') {
;
} elsif ($x eq 'offset') {
;
} elsif ($x eq 'keep') {
if ($y ne 'env' && $y ne 'loop') {
print STDERR "$name: line $line: ";
print STDERR "keep must be env or loop\n";
return -2;
}
} elsif ($x eq 'strip') {
if ($y ne 'env' && $y ne 'loop' && $y ne 'tail') {
print STDERR "$name: line $line: ";
print STDERR "strip must be env, loop, or tail\n";
return -2;
}
} elsif ($x eq 'tremolo') {
;
} elsif ($x eq 'vibrato') {
;
} elsif ($x eq 'sclnote') {
;
} elsif ($x eq 'scltune') {
;
} elsif ($x eq 'comm') {
;
} elsif ($x eq 'modrate') {
;
} elsif ($x eq 'modoffset') {
;
} elsif ($x eq 'envkeyf') {
;
} elsif ($x eq 'envvelf') {
;
} elsif ($x eq 'modkeyf') {
;
} elsif ($x eq 'modvelf') {
;
} elsif ($x eq 'trempitch') {
;
} elsif ($x eq 'tremfc') {
;
} elsif ($x eq 'modpitch') {
;
} elsif ($x eq 'modfc') {
;
} elsif ($x eq 'fc') {
;
} elsif ($x eq 'q') {
;
} elsif ($x eq 'fckeyf') {
;
} elsif ($x eq 'fcvelf') {
;
} elsif ($x eq 'qvelf') {
;
} else {
print STDERR "$name: line $line: bad patch option\n";
return -2;
}
push(@options, $_);
}
$bank->[$i] = ["$name:$line", $patch, @options];
}
}
close CFG;
return 0;
}
sub open_file
{
local (*fiz) = shift;
my ($fname) = shift;
if ($fname =~ /^\//) {
return $fname if open(*fiz, $fname);
return 0;
}
for (@pathlist) {
return "$_/$fname" if open(*fiz, "$_/$fname");
}
print STDERR "$fname: $!\n" if $rcf_count == 0;
return 0;
}
sub lspatch
{
my ($tag, @insts) = @_;
my ($i, $j, $bank, $p, @inst, $pos);
for ($i = 0; $i < 128; $i++) {
next if ! defined $insts[$i];
$bank = $insts[$i];
for ($j = 0; $j < 128; $j++) {
next if ! defined $bank->[$j];
$p = $bank->[$j];
@inst = @$p;
$pos = shift @inst;
# $p = $bank->[$j]->[1];
print "$tag $i $pos: $j @inst ", &find_patch($inst[0]), "\n";
}
}
}
sub find_patch
{
my ($f) = @_;
local *FIZ;
my $realpath;
for (@patch_ext_list) {
$realpath = &open_file(*FIZ, "$f$_");
return $realpath if $realpath;
}
return "-";
}
|