]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/midi2cfg-ng.pl
use jumpers for a test
[xonotic/xonotic.git] / misc / tools / midi2cfg-ng.pl
index ea1b1e6d167bcf82a6cc1354766490d0d7a86a7c..3e178a24d3463aab4e021da807f0d16d541799f6 100755 (executable)
@@ -473,10 +473,19 @@ sub busybot_note_on_bot($$$$$$$)
        }
        ++$bot->{seen}{$k0}{$k1};
 
+       if(($bot->{lastuse} // -666) >= $time - $time_forgetfulness && $channel == $bot->{lastchannel})
+       {
+               $bot->{lastchannelsequence} += 1;
+       }
+       else
+       {
+               $bot->{lastchannelsequence} = 1;
+       }
        $bot->{lastuse} = $time;
        $bot->{lastchannel} = $channel;
-       $bot->{lastprogram} = $program;
-       $bot->{lastnote} = $note;
+
+#      print STDERR "$time $bot->{id} $channel:$note\n"
+#              if $channel == 11;
 
        return 1;
 }
@@ -521,7 +530,7 @@ sub botsort($$$$@)
                }
                sort
                {
-                       $a->[1] <=> $b->[1]
+                       $b->[1] <=> $a->[1]
                        or
                        ($a->[0]->{lastuse} // -666) <=> ($b->[0]->{lastuse} // -666)
                        or
@@ -530,18 +539,18 @@ sub botsort($$$$@)
                map
                {
                        my $q = 0;
-                       if(($_->{lastuse} // -666) >= $time - $time_forgetfulness)
+                       if($channel != 10) # percussion just should do round robin
                        {
-                               if($channel == $_->{lastchannel})
+                               if(($_->{lastuse} // -666) >= $time - $time_forgetfulness)
                                {
-                                       ++$q;
-                                       if($program == $_->{lastprogram})
+                                       if($channel == $_->{lastchannel})
                                        {
-                                               ++$q;
-                                               if($note == $_->{lastnote})
-                                               {
-                                                       ++$q;
-                                               }
+                                               $q += $_->{lastchannelsequence};
+                                       }
+                                       else
+                                       {
+                                               # better leave this one alone
+                                               $q -= $_->{lastchannelsequence};
                                        }
                                }
                        }
@@ -805,7 +814,7 @@ sub ConvertMIDI($$)
                        if($midinotes{$chan}{$_->[5]})
                        {
                                --$notes_stuck;
-                               busybot_note_off($t - SYS_TICRATE, $chan, $_->[5]);
+                               busybot_note_off($t - SYS_TICRATE - 0.001, $chan, $_->[5]);
                        }
                        busybot_note_on($t, $chan, $programs{$chan} || 1, $_->[5]);
                        ++$notes_stuck;
@@ -817,7 +826,7 @@ sub ConvertMIDI($$)
                        if($midinotes{$chan}{$_->[5]})
                        {
                                --$notes_stuck;
-                               busybot_note_off($t - SYS_TICRATE, $chan, $_->[5]);
+                               busybot_note_off($t - SYS_TICRATE - 0.001, $chan, $_->[5]);
                        }
                        $midinotes{$chan}{$_->[5]} = 0;
                }
@@ -848,7 +857,7 @@ sub ConvertMIDI($$)
                                        my $votehigh = 0;
                                        my $votelow = 0;
                                        my $votegood = 0;
-                                       for(@busybots_allocated)
+                                       for(@busybots_allocated, grep { $_->{count} > 0 } values %$busybots)
                                        {
                                                next # I won't play on this channel
                                                        if defined $_->{channels} and not $_->{channels}->{$channel};
@@ -984,6 +993,8 @@ for(;;)
                my @preallocate_new = map { $_->{classname} } @busybots_allocated;
                if(@preallocate_new == @preallocate)
                {
+                       print "sv_cmd bot_cmd reset\n";
+                       print "sv_cmd bot_cmd setbots @{[scalar @preallocate_new]}\n";
                        print "$precommands$commands";
                        exit 0;
                }