/*********************************************	Copyright © 2001 Jason Lamport.	All rights reserved.----------------------J_OMSNodeInfoList is an abstract base class forJ_OMSInputNodes and J_OMSOutputNodes*******************************************/package com.strangelight.v4control;import com.strangelight.*;import com.strangelight.salsa.*;import com.strangelight.mactoolbox.*;import com.apple.jdirect.*;import com.apple.mrj.jdirect.*;public class J_OMSDeviceH extends J_HandleStruct {	public J_OMSDeviceH(int h) { super(h); }}public final class J_OMSNodeInfoRec {	private static final class OFFSETS {		static final int name = 0;		static final int flags = 32;		static final int uniqueID = 34;		static final int ioRefNum = 36;		static final int deviceH = 38;	}		private static int unsigned( byte b ) {		return ( ( (int) b ) & 0x000000FF );	}		J_OMSNodeInfoRec( byte[] raw_bytes ) {		int deviceH;				name = ASCII.toString( raw_bytes, OFFSETS.name + 1 , (int) raw_bytes[OFFSETS.name] );		flags = (short) (			( raw_bytes[OFFSETS.flags] << 8 )			| unsigned( raw_bytes[OFFSETS.flags + 1] )		);		uniqueID = (short) (			( raw_bytes[OFFSETS.uniqueID] << 8 )			| unsigned( raw_bytes[OFFSETS.uniqueID + 1] )		);		ioRefNum = (short) (			( raw_bytes[OFFSETS.ioRefNum] << 8 )			| unsigned( raw_bytes[OFFSETS.ioRefNum + 1] )		);		j_deviceH = null;		/*			XXX		we may need the info later, but for now, just ignore it.		 */	}		public String toString() {		return(			"[J_OMSNodeInfoRec"			+ " name:\"" + name + "\""			+ " flags:" + flags			+ " uniqueID:" + uniqueID			+ " ioRefNum:" + ioRefNum			+ " ]"		);	}		public String 		get_name() 		{ return name; }	public short		get_flags() 	{ return flags; }	public short		get_uniqueID() 	{ return uniqueID; }	public short		get_ioRefNum() 	{ return ioRefNum; }	public J_OMSDeviceH	get_j_deviceH()	{ return j_deviceH; }	private String			name;	private short			flags;	private short			uniqueID;	private short			ioRefNum;	private J_OMSDeviceH	j_deviceH;}public abstract class J_OMSNodeInfoList 	extends J_HandleStruct	implements V4ControlLib_interface {	private static final class OFFSETS {		static final int numNodes = 0;		static final int info_array = 2;	}			private static final int SIZEOF_INFOREC = 42;		protected J_OMSNodeInfoList( int infoList_H ) {		//	D.bug(":"+);		super( infoList_H );		D.bug("infoList_H:"+infoList_H);		D.bug("handle:"+handle);		int num_nodes = this.getShortAt(OFFSETS.numNodes);		D.bug("num_nodes:" + num_nodes);		the_infoRecs = new J_OMSNodeInfoRec[ num_nodes ];		D.bug("this.getSize():"+ this.getSize() );		for ( int i = 0; i < num_nodes ; i++ ) {			the_infoRecs[i] = new J_OMSNodeInfoRec(				this.getBytesAt( 					OFFSETS.info_array + (i * SIZEOF_INFOREC), 					SIZEOF_INFOREC 				)			);		}	}		/**		get the index of the OMS node with the specified		uniqueID.		@param id	the uniqueID to search for		@return		the index of the node with the specified uniqueID,					or -1 if the uniqueID cannot be found	*/	public int index_of_uniqueID(short uniqueID) {		for (int i=0; i < the_infoRecs.length; i++) {			if ( the_infoRecs[i].get_uniqueID() == uniqueID ) {				return i;			}		}		return -1;	}		public J_OMSNodeInfoRec get_infoRec_by_id(short uniqueID) {		int i = index_of_uniqueID(uniqueID);		if ( i == -1 ) {			return null;		} else {			return the_infoRecs[i];		}	}		public J_OMSNodeInfoRec get_infoRec(int i) {		return the_infoRecs[i];	}		public J_OMSNodeInfoRec[] get_infoRecs() {		return the_infoRecs;	}					private J_OMSNodeInfoRec[]	the_infoRecs;	}/*************	excerpts from the OMS API docs:*************OMSNodeInfoList structure	Clients receive lists of MIDI sources and destinations in handles to	OMSNodeInfoList structures.typedef unsigned short OMSUniqueID;/* Bits of OMSNodeInfoRec.flags * /enum {	/* only for inputs; attribute of ALL merged sources * /	kAnyIsController	= 0x8000,	kAnySendsSync	= 0x4000,	kAnySendsMTC	= 0x2000,	kAnySendsClock	= 0x0200,	kAnySendsMMC	= 0x0080,	/* only for outputs; attribute of ALL merged outputs * /	kAnyReceivesSync	= 0x1000,	kAnyReceivesMTC	= 0x0800,	kAnyReceivesClock	= 0x0400,	kAnyReceivesMMC	= 0x0040,			/* general * /	kIsOutput		= 0x0100,	/* true when an output * /	kIsReal		= 0x0001	/* true when real, false when							virtual * /};typedef struct OMSNodeInfoRec {	OMSString		name;	unsigned short	flags;	OMSUniqueID		uniqueID;	unsigned short	ioRefNum;	OMSDeviceH		deviceH;} OMSNodeInfoRec;Field descriptionsname	The nodeÕs name.  If the node is a real input, multiple devices		in the studio setup may be treated as a single input node, in which case		the name will contain the real devicesÕ names, separated by commas, up		to the maximum length of the OMSString (OMS_STRING_LEN bytes).flags	A group of booleans, as described above.uniqueID	The nodeÕs unique permanent identifier.ioRefNum	The nodeÕs refNum used for sending MIDI to an output, or			identifying the source of a clientÕs incoming MIDI data.deviceH		For real outputsÑor the first of multiple merged real			inputsÑa handle to an OMSDevice structure or null otherwise. 			The OMSDevice structure is described below.  May be null.typedef struct OMSNodeInfoList {	short			numNodes;	OMSNodeInfoRec	info[1];	/* variable-length * /} OMSNodeInfoList, ** OMSNodeInfoListH;If a client saves references to nodes in files, it should store theuniqueID field, which is the nodeÕs permanent identifierFor a client to send to an output node, it uses the ioRefNum, which canbe different each time the client runs. MIDI packets the client receivesfrom input nodes contain the ioRefNum of the source node. A clientwishing to use a special ioRefNum to signify Òinvalid refNumÓ may useOMSInvalidRefNum (-1).CAUTION: Your client must be aware of the possibility of deviceH beingnull.****/