Skip to content

Commit

Permalink
committing the new API. Streamy now takes
Browse files Browse the repository at this point in the history
instrument velocity tone duration

Sift.pl now provides those, as well.
  • Loading branch information
blucia0a committed Mar 24, 2012
1 parent 3f25552 commit 52e9ca8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 51 deletions.
18 changes: 11 additions & 7 deletions Sift.pl
Expand Up @@ -5,7 +5,7 @@

my $num_clients = 0;
my %clientMap;
my %Map;
my %toneMap;

while(<>){

Expand Down Expand Up @@ -36,13 +36,15 @@ ()
my $ip = shift;
my $port = shift;
my $direction = shift;
my $dir = 0;
if($direction eq 'send'){ $dir = 0; }else{ $dir = 1; }

if( $direction eq 'send' ){
print "".$clientMap{$ip}." ".$port." 0\n";
}
if( $direction eq 'recv' ){
print "".$clientMap{$ip}." ".$port." 1\n";
}
my $velocity = int((1.0 - ($port / 65536))*127);
my $tone = $toneMap{$clientMap{$ip}} * ($dir+1);
my $duration = int(rand(500000)) + 500000;

#API is "instrument velocity tone duration"
print "".$clientMap{$ip}." $velocity $tone $duration\n";

}

Expand All @@ -53,11 +55,13 @@ ()

if( !exists $clientMap{$srcip} ){
$clientMap{$srcip} = $num_clients++;
$toneMap{$clientMap{$srcip}} = int(rand(20)) + 25;
#print "New client: $srcip\n"
}

if( !exists $clientMap{$dstip} ){
$clientMap{$dstip} = $num_clients++;
$toneMap{$clientMap{$dstip}} = int(rand(20)) + 25;
#print "New client: $dstip\n"
}

Expand Down
87 changes: 43 additions & 44 deletions Streamy.c
Expand Up @@ -24,9 +24,9 @@ enum {
int voice = 0;

typedef struct _cmd{
int hostNum;
int port;
int dir;
int velocity;
int tone;
unsigned duration;
bool full;
} cmd;

Expand Down Expand Up @@ -70,45 +70,42 @@ void * sequence_play(void *p){
while(1){
pthread_mutex_lock(&(pps->lock));
if(pps->cmdBuf->full){
curCmd.hostNum = pps->cmdBuf->hostNum;
curCmd.port = pps->cmdBuf->port;
curCmd.dir = pps->cmdBuf->dir;
curCmd.velocity = pps->cmdBuf->velocity;
curCmd.tone = pps->cmdBuf->tone;
curCmd.duration = pps->cmdBuf->duration;
pps->cmdBuf->full = false;
pthread_mutex_unlock(&(pps->lock));
break;
}
pthread_mutex_unlock(&(pps->lock));
}

int level = (int)((((float)(65536 - curCmd.port))/65536.0f) * 127.0f);
for(int i = 0; i < pps->numSegments; i++){
int tone = curCmd.tone;
int level = curCmd.velocity;

int tone = pps->tone[i] * (1 + curCmd.dir);
MIDIPacketList packetList;
MIDIPacketList packetList;

/*On*/
packetList.numPackets = 1;
packetList.packet[0].length = 3;
packetList.packet[0].data[0] = 0x90; // note ON
packetList.packet[0].data[1] = tone; // C
packetList.packet[0].data[2] = level; // velocity
packetList.packet[0].timeStamp = 0;
MIDISend(pps->portRef,pps->endpoint,&packetList);
/*On*/
packetList.numPackets = 1;
packetList.packet[0].length = 3;
packetList.packet[0].data[0] = 0x90; // note ON
packetList.packet[0].data[1] = tone; // C
packetList.packet[0].data[2] = level; // velocity
packetList.packet[0].timeStamp = 0;
MIDISend(pps->portRef,pps->endpoint,&packetList);

usleep( pps->duration[i] );

/*Off*/
packetList.numPackets = 1;
packetList.packet[0].length = 3;
packetList.packet[0].data[0] = kMIDINoteOff; // note ON
packetList.packet[0].data[1] = tone; // C
packetList.packet[0].data[2] = level; // velocity
packetList.packet[0].timeStamp = 0;
MIDISend(pps->portRef,pps->endpoint,&packetList);
usleep( curCmd.duration );

/*Off*/
packetList.numPackets = 1;
packetList.packet[0].length = 3;
packetList.packet[0].data[0] = kMIDINoteOff; // note ON
packetList.packet[0].data[1] = tone; // C
packetList.packet[0].data[2] = level; // velocity
packetList.packet[0].timeStamp = 0;
MIDISend(pps->portRef,pps->endpoint,&packetList);

usleep( pps->period[i] );

}

}

Expand Down Expand Up @@ -153,7 +150,7 @@ int main(int argc, char *argv[])

for(int i = 0; i < NUM_SYNTHS; i++){

MIDIEndpointRef e= MIDIGetDestination(i);
MIDIEndpointRef e = MIDIGetDestination(i);

int numsegs;
numsegs = 1;
Expand Down Expand Up @@ -181,24 +178,26 @@ int main(int argc, char *argv[])

while(1){

int host;
int port;
int dir;
scanf("%d %d %d",&host,&port,&dir);
fprintf(stderr,"h=%u p=%u d=%u\n",host,port,dir);
int instrument;
int velocity;
int tone;
int duration;
scanf("%d %d %d %d",&instrument,&velocity,&tone,&duration);
fprintf(stderr,"%d %d %d %d\n",instrument,velocity,tone,duration);

instrument = instrument % NUM_SYNTHS;

host = host % NUM_SYNTHS;
pthread_mutex_lock(&(sourceParams[host]->lock));
if( sourceParams[host]->cmdBuf->full == false ){
pthread_mutex_lock(&(sourceParams[instrument]->lock));
if( sourceParams[instrument]->cmdBuf->full == false ){

/*full is false, so it is ok to put a command in*/
sourceParams[host]->cmdBuf->hostNum = host;
sourceParams[host]->cmdBuf->port = port;
sourceParams[host]->cmdBuf->dir = dir;
sourceParams[host]->cmdBuf->full = true;
sourceParams[instrument]->cmdBuf->velocity = velocity;
sourceParams[instrument]->cmdBuf->tone = tone;
sourceParams[instrument]->cmdBuf->duration = duration;
sourceParams[instrument]->cmdBuf->full = true;

}
pthread_mutex_unlock(&(sourceParams[host]->lock));
pthread_mutex_unlock(&(sourceParams[instrument]->lock));


}
Expand Down

0 comments on commit 52e9ca8

Please sign in to comment.