}
}
private void resortClients()
{
final NodeWatcher nw;
int off = 0;
OSCBundle bndl;
Group g;
boolean haveGrpTrig = false;
Client mc;
int srcChan;
meterTimer.stop();
if( resp != null ) resp.remove();
bndl = new OSCBundle();
meterBangBndl = null;
for( int i = 0; i < collActiveClients.size(); i++ ) {
mc = (Client) collActiveClients.get( i );
for( int j = 0; j < mc.synths.length; j++ ) {
if( mc.synths[ j ] != null ) {
bndl.addPacket( mc.synths[ j ].freeMsg() );
mc.synths[ j ] = null;
}
}
mc.setOffset( off );
off += mc.cNum;
}
if( bus != null ) {
bus.free();
bus = null;
}
numCtrlChans = off;
if( bndl.getPacketCount() > 0 ) {
try {
if( server.isRunning() ) server.sendBundle( bndl );
}
catch( IOException e1 ) {
numCtrlChans = 0;
printError( "resortClients", e1 );
}
}
numTask = 0;
try {
if( (server != null) && (numCtrlChans > 0) ) {
nw = NodeWatcher.newFrom( server );
bndl = new OSCBundle();
bus = Bus.control( server, numCtrlChans );
if( bus != null ) {
meterBangBndl = new OSCBundle();
meterBangBndl.addPacket( new OSCMessage( "/c_getn", new Object[] {
new Integer( bus.getIndex() ), new Integer( bus.getNumChannels() )}));
for( int i = 0; i < collActiveClients.size(); i++ ) {
mc = (Client) collActiveClients.get( i );
if( mc.task ) numTask++;
if( mc.g != null ) {
g = mc.g;
meterBangBndl.addPacket( new OSCMessage( "/n_set", new Object[] {
new Integer( g.getNodeID() ), "t_trig", new Integer( 1 )}));
} else {
if( grp == null ) {
grp = Group.basicNew( server );
grp.setName( "MeterManager" );
bndl.addPacket( grp.newMsg( server.getDefaultGroup(), kAddToTail ));
nw.register( grp );
}
g = grp;
if( !haveGrpTrig ) {
meterBangBndl.addPacket( new OSCMessage( "/n_set", new Object[] {
new Integer( g.getNodeID() ), "t_trig", new Integer( 1 )}));
haveGrpTrig = true;
}
}
for( int j = 0, m = bus.getIndex() + mc.cOffset; j < mc.synths.length; j++, m += 2 ) {
srcChan = mc.channels[ j ];
if( srcChan >= 0 ) {
mc.synths[ j ] = Synth.basicNew( "eisk-meter", server );
bndl.addPacket( mc.synths[ j ].newMsg( g, new String[] {
"i_aInBs", "i_kOtBs" }, new float[] {
srcChan, m }, kAddToTail ));
if( !mc.task ) {
bndl.addPacket( mc.synths[ j ].runMsg( false ));
}
nw.register( mc.synths[ j ]);
}
}
}
if( bndl.getPacketCount() > 0 ) {
try {