From f8ded18dd5b4cb3faf1c9ce4deaa651c486f600d Mon Sep 17 00:00:00 2001 From: div0 Date: Thu, 11 Jun 2009 16:37:20 +0000 Subject: [PATCH] more midi2cfg stuff :P git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6982 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- misc/tools/midi2cfg-ng.conf | 347 +++++++++++++++++++++++++++++++++++- misc/tools/midi2cfg-ng.pl | 66 +++++-- 2 files changed, 390 insertions(+), 23 deletions(-) diff --git a/misc/tools/midi2cfg-ng.conf b/misc/tools/midi2cfg-ng.conf index 422fc32c9..b669a54a4 100644 --- a/misc/tools/midi2cfg-ng.conf +++ b/misc/tools/midi2cfg-ng.conf @@ -1,8 +1,10 @@ bot tuba - count 0 + channels 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 init time -2 cmd selectweapon 16 + raw g_balance_tuba_attenuation 0.1 + raw g_balance_tuba_damage 0 time 0 note on -18 time -0.05 @@ -381,10 +383,345 @@ bot tuba_blue cmd cc "color 221" super -bot red +bot rocket + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 9 + time 0 + percussion 25 + time 0 + buttons attack2 + time 0.05 + buttons + time 0.1 + busy 1.0 + +bot uzi + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 3 + time 0 + percussion 27 + time 0 + buttons attack2 + time 0.05 + buttons + time 0.1 + busy 0.2 + percussion 33 + percussion 27 + percussion 37 + percussion 27 + +bot crylink + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 6 + time 0 + percussion 31 + time 0 + buttons attack2 + time 0.05 + buttons + time 0.1 + busy 0.5 + percussion 34 + percussion 31 + percussion 42 + time 0 + buttons attack2 + time 0.05 + buttons + time 0.1 + busy 0.4 + percussion 44 + percussion 42 + percussion 46 + percussion 42 + +bot jetpack + percussion 42 + time 0 + buttons hook + time 0.05 + buttons + time 0.1 + percussion 44 + percussion 42 + percussion 46 + percussion 42 + +bot jump + percussion 42 + time -0.5 + buttons jump + time -0.45 + buttons + time 0 + percussion 44 + percussion 42 + percussion 46 + percussion 42 + +bot hagar + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 8 + raw g_balance_hagar_primary_lifetime 0.1 + time 0 + percussion 35 + time 0 + buttons attack1 + time 0.05 + buttons + time 0.1 + busy 0.15 + percussion 38 + percussion 35 + percussion 40 + percussion 35 + percussion 60 + percussion 35 + percussion 65 + percussion 35 + +bot tag + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 14 + raw g_balance_seeker_tag_lifetime 0.1 + time 0 + percussion 36 + time 0 + buttons attack1 + time 0.05 + buttons + time 0.1 + busy 0.7 + percussion 61 + percussion 36 + percussion 66 + percussion 36 + +bot laser + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 1 + raw g_balance_laser_primary_lifetime 0.2 + time 0 + percussion 39 + time 0 + buttons attack1 + time 0.05 + buttons + time 0.1 + busy 0.7 + +bot electro + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 5 + time 0 + +bot hook + channels 10 + init + time -2 + cmd aimtarget "tPercussion 1" + cmd selectweapon 12 + time 0 + percussion 58 + time 0 + buttons attack1 + time 0.05 + buttons + time 0.1 + busy 0 + +# instantiate our bots! + +bot tuba1 include tuba_red - count 256 + count 1 + init + time -15 + cmd movetotarget tUba1 + super + done + cmd movetotarget goaway1 -bot blue +bot tuba2 include tuba_blue - count 256 + count 1 + init + time -15 + cmd movetotarget tUba2 + super + done + cmd movetotarget goaway1 + +bot tuba3 + include tuba_red + count 1 + init + time -15 + cmd movetotarget tUba3 + super + done + cmd movetotarget goaway1 + +bot tuba4 + include tuba_red + count 1 + init + time -15 + cmd movetotarget tUba4 + super + done + cmd movetotarget goaway1 + +# percussion bots: + +bot chair11 + include rocket + count 1 + init + time -15 + cmd movetotarget tChr11 + super + done + cmd movetotarget goaway2 + +bot chair12 + include electro + count 1 + init + time -15 + cmd movetotarget tChr12 + super + done + cmd movetotarget goaway2 + +bot chair21 + include uzi + count 1 + init + time -15 + cmd movetotarget tChr21 + super + done + cmd movetotarget goaway2 + +bot chair22 + include crylink + count 0 + init + time -15 + cmd movetotarget tChr22 + super + done + cmd movetotarget goaway2 + +bot chair23 + include crylink + count 0 + init + time -15 + cmd movetotarget tChr22 + super + done + cmd movetotarget goaway2 + +bot chair23 + include hagar + count 1 + init + time -15 + cmd movetotarget tChr23 + super + done + cmd movetotarget goaway2 + +bot chair31 + include tag + count 1 + init + time -15 + cmd movetotarget tChr31 + super + done + cmd movetotarget goaway2 + +bot chair32 + include tag + count 1 + init + time -15 + cmd movetotarget tChr32 + super + done + cmd movetotarget goaway2 + +bot chair33 + include laser + count 1 + init + time -15 + cmd movetotarget tChr33 + super + done + cmd movetotarget goaway2 + +bot chair41 + include hook + count 1 + init + time -15 + cmd movetotarget tChr41 + super + done + cmd movetotarget goaway2 + +bot chair42 + include jetpack + count 1 + init + time -15 + cmd movetotarget tChr42 + super + done + cmd movetotarget goaway2 + +bot chair43 + include jetpack + count 1 + init + time -15 + cmd movetotarget tChr43 + super + done + cmd movetotarget goaway2 + +bot chair44 + include jetpack + count 1 + init + time -15 + cmd movetotarget tChr44 + super + done + cmd movetotarget goaway2 diff --git a/misc/tools/midi2cfg-ng.pl b/misc/tools/midi2cfg-ng.pl index f9c9580e7..d4e97cf30 100755 --- a/misc/tools/midi2cfg-ng.pl +++ b/misc/tools/midi2cfg-ng.pl @@ -13,7 +13,9 @@ use Storable; use constant MIDI_FIRST_NONCHANNEL => 17; use constant MIDI_DRUMS_CHANNEL => 10; -my ($filename, $transpose, $timeoffset, $timeoffset2, @preallocate) = @ARGV; +die "Usage: $0 filename.mid transpose timeoffset timeoffset2 timeoffset3 preallocatedbots..." + unless @ARGV >= 5; +my ($filename, $transpose, $timeoffset, $timeoffset2, $timeoffset3, @preallocate) = @ARGV; my $opus = MIDI::Opus->new({from_file => $filename}); #$opus->write_to_file("/tmp/y.mid"); @@ -102,7 +104,12 @@ sub botconfig_read($) my @cmd = split /\s+/, $_; if($cmd[0] eq 'super') { - push @$appendref, @$super; + push @$appendref, @$super + if $super; + } + elsif($cmd[0] eq 'percussion') # simple import + { + push @$appendref, @{$currentbot->{percussion}->{$cmd[1]}}; } else { @@ -144,6 +151,11 @@ sub botconfig_read($) $super = $currentbot->{init}; $currentbot->{init} = $appendref = []; } + elsif(/^done$/) + { + $super = $currentbot->{done}; + $currentbot->{done} = $appendref = []; + } elsif(/^note on (-?\d+)/) { $super = $currentbot->{notes_on}->{$1}; @@ -166,7 +178,7 @@ sub botconfig_read($) } elsif(/^bot (.*)/) { - $currentbot = ($bots{$1} ||= {}); + $currentbot = ($bots{$1} ||= {count => 0, transpose => 0}); } else { @@ -280,6 +292,10 @@ sub busybot_cmd_bot_execute($$@) { printf "sv_cmd bot_cmd %d %s\n", $bot->{id}, join " ", @{$_}[1..@$_-1]; } + elsif($_->[0] eq 'raw') + { + printf join " ", @{$_}[1..@$_-1]; + } } return 1; @@ -300,21 +316,25 @@ sub busybot_note_on_bot($$$$$) { my ($bot, $time, $channel, $note, $init) = @_; return -1 # I won't play on this channel - if defined $bot->{channels} and not grep { $_ == $channel } $bot->{channels}; + if defined $bot->{channels} and not $bot->{channels}->{$channel}; return 0 if $bot->{busy}; - my $cmds = $bot->{notes_on}->{$note - $bot->{transpose} - $transpose}; - my $cmds_off = $bot->{notes_off}->{$note - $bot->{transpose} - $transpose}; - if(defined $cmds_off) + my $cmds; + if($channel == 10) { - $bot->{busy} = 1; + $cmds = $bot->{percussion}->{$note}; } - if(not defined $cmds) + else { - $cmds = $bot->{percussion}->{$note}; - return -1 # I won't play this note - if not defined $cmds; + $cmds = $bot->{notes_on}->{$note - $bot->{transpose} - $transpose}; + my $cmds_off = $bot->{notes_off}->{$note - $bot->{transpose} - $transpose}; + if(defined $cmds and defined $cmds_off) + { + $bot->{busy} = 1; + } } + return -1 # I won't play this note + if not defined $cmds; if($init && $bot->{init}) { return 0 @@ -341,6 +361,9 @@ sub busybot_note_off($$$) { my ($time, $channel, $note) = @_; + return 0 + if $channel == 10; + if(my $bot = $notechannelbots{$channel}{$note}) { busybot_note_off_bot $bot, $time, $channel, $note; @@ -395,9 +418,7 @@ sub busybot_note_on($$$) if($overflow) { - warn "Not enough bots to play this"; - use Data::Dumper; - print STDERR Dumper \@busybots_allocated; + warn "Not enough bots to play this (when playing $channel:$note)"; } else { @@ -428,17 +449,18 @@ my %midinotes = (); my $note_min = undef; my $note_max = undef; my $notes_stuck = 0; +my $t = 0; for(@allmidievents) { - my $t = tick2sec $_->[1]; + $t = tick2sec $_->[1]; my $track = $_->[3]; if($_->[0] eq 'note_on') { my $chan = $_->[4] + 1; $note_min = $_->[5] - if not defined $note_min or $_->[5] < $note_min; + if not defined $note_min or $_->[5] < $note_min and $chan != 10; $note_max = $_->[5] - if not defined $note_max or $_->[5] > $note_max; + if not defined $note_max or $_->[5] > $note_max and $chan != 10; if($midinotes{$chan}{$_->[5]}) { --$notes_stuck; @@ -460,6 +482,14 @@ for(@allmidievents) } } +for(@busybots_allocated) +{ + if($_->{done}) + { + busybot_cmd_bot_execute $_, $notetime + $t + $timeoffset3, @{$_->{done}}; + } +} + print STDERR "Range of notes: $note_min .. $note_max\n"; print STDERR "Safe transpose range: @{[$note_max - 19]} .. @{[$note_min + 13]}\n"; print STDERR "Unsafe transpose range: @{[$note_max - 27]} .. @{[$note_min + 18]}\n"; -- 2.39.2