Skip to content
Browse files

SIFT WILL TAKE YOUR COMMANDS NOW

  • Loading branch information...
1 parent f875257 commit 964d9d996e359553bd285341a918976aa921766f @blucia0a committed Apr 7, 2012
Showing with 65 additions and 12 deletions.
  1. +65 −12 Sift.pl
View
77 Sift.pl
@@ -5,7 +5,8 @@
my $num_clients = 0;
my %clientMap;
-my %toneMap;
+
+my %noteSets;
if ($#ARGV != 0) {
die("Usage: Sift.pl [config file]");
@@ -14,11 +15,34 @@
# Read in the config file.
my $filename = shift @ARGV;
open FILE, "<" . $filename or die $!;
-my @config = <FILE>;
+while(<FILE>){
+
+ chomp;
+ next if /#/;
+ next if $_ eq "";
+ if( /default/i ){
+
+ my @notes = split /\s+/;
+ shift @notes;
+ push @{$noteSets{'default'}}, @notes;
+
+ }elsif( /instrument/i ){
+
+ my @notes = split /\s+/;
+ my $iNum = shift @notes;
+ $iNum =~ s/instrument//i;
+ push @{$noteSets{$iNum}}, @notes;
+
+ }else{
+
+ warn "Weird line in config file: \"$_\". Ignoring it.\n";
+
+ }
+
+}
close(FILE);
-my @possibleNotes = split(/\s+/, $config[0]);
-my @specialInstrumentToneIndexes = split(/\s+/, $config[1]);
+#my @possibleNotes = split /\s+/, $config[0];
while(<>){
@@ -67,8 +91,17 @@ ()
my $velocity = 117;
- my $toneIndex = $specialInstrumentToneIndexes[$instrument];
- my $tone = $possibleNotes[$toneIndex] + ($dir * 12);
+
+ my $tone = 33;
+ if( exists $noteSets{ $instrument } ){
+
+ $tone = $noteSets{ $instrument }->[int( rand( $#{$noteSets{ $instrument }} ) )];
+
+ }else{
+
+ $tone = $noteSets{ 'default' }->[int( rand( $#{$noteSets{ 'default' }} ) )];
+
+ }
my $duration = int(rand(1000000)) + 500000;
@@ -85,29 +118,49 @@ ()
if($direction eq 'send'){ $dir = 0; }else{ $dir = 1; }
my $velocity = int((1.0 - ($port / 65536))*127);
- my $tone = $toneMap{$clientMap{$ip}} + ($dir * 12);
+
+ my $instrument = $clientMap{$ip};
+ my $tone = 33;
+ if( exists $noteSets{ $instrument } ){
+
+ $tone = $noteSets{ $instrument }->[int( rand( $#{$noteSets{ $instrument }} ) )];
+
+ }else{
+
+ $tone = $noteSets{ 'default' }->[int( rand( $#{$noteSets{ 'default' }} ) )];
+
+ }
+
my $duration = int(rand(1000000)) + 500000;
#API is "instrument velocity tone duration"
- print "".$clientMap{$ip}." $velocity $duration $tone,35,42\n";
+ print "".$clientMap{$ip}." $velocity $duration $tone\n";
}
+sub directionTransform(){
+ my $noteSpec = shift;
+
+ if( $noteSpec =~ /,/ ){
+ my @notes = split /,/, $noteSpec;
+ $_ = $_ + 12 for @notes;
+ return join ',',@notes;
+ }else{
+ return $noteSpec + 12;
+ }
+}
+
sub addClientIfNew(){
my $srcip = shift;
my $dstip = shift;
if( !exists $clientMap{$srcip} ){
$clientMap{$srcip} = $num_clients++;
- $toneMap{ $clientMap{$srcip} } = $possibleNotes[int(rand(14))];
- #print "New client: $srcip\n"
}
if( !exists $clientMap{$dstip} ){
$clientMap{$dstip} = $num_clients++;
- $toneMap{$clientMap{$dstip}} = $possibleNotes[int(rand(14))];
- #print "New client: $dstip\n"
}
}

0 comments on commit 964d9d9

Please sign in to comment.
Something went wrong with that request. Please try again.