|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.sciss.net.OSCPacket
de.sciss.net.OSCBundle
public class OSCBundle
Implementation of the OSC-Bundle which assembles several OSC-Packets under the same timetag. See opensoundcontrol.org/spec-1_0 for the specification of the bundle format.
The bundle time can be calculated in
different ways: specifying a long
which represents the milliseconds since
1 jan 1970 as returned by System.currentTimeMillis()
,
produces the required network time tag
as required by the OSC specification.
Alternatively, using a float
for a relative time offset in seconds can
be used when running SuperCollider in offline
mode. Third, there is a version that calculates
a sample accurate time tag. However, scsynth
doesn't process bundles with this accuracy, so
it's kind of useless.
To assemble a bundle, you create a new instance of
OSCBundle
, call addPacket
one or several times, then write the contents of
the bundle to a ByteBuffer
using the
method encode
. The byte buffer can then
be written to a DatagramChannel
. Here is an example:
OSCBundle bndl; DatagramChannel dch = null; final ByteBuffer buf = ByteBuffer.allocateDirect( 1024 ); final SocketAddress addr = new InetSocketAddress( "localhost", 57110 ); final long serverLatency = 50; final long now = System.currentTimeMillis() + serverLatency; try { dch = DatagramChannel.open(); dch.configureBlocking( true ); bndl = new OSCBundle( now ); bndl.addPacket( new OSCMessage( "/s_new", new Object[] { "default", new Integer( 1001 ), new Integer( 1 ), new Integer( 0 ), "out", new Integer( 0 ), "freq", new Float( 666 ), "amp", new Float( 0.1f )})); bndl.encode( buf ); buf.flip(); dch.send( buf, addr ); buf.clear(); bndl = new OSCBundle( now + 2000 ); // two seconds later bndl.addPacket( new OSCMessage( "/n_free", new Object[] { new Integer( 1001 )})); bndl.encode( buf ); buf.flip(); dch.send( buf, addr ); } catch( IOException e2 ) { System.err.println( e2.getLocalizedMessage() ); } finally { if( dch != null ) { try { dch.close(); } catch( IOException e4 ) {}; } }Note that this example uses the old way of sending messages. A easier way is to create an
OSCTransmitter
which
handles the byte buffer for you. See the OSCReceiver
doc
for an example using a dedicated transmitter.
OSCReceiver
Field Summary | |
---|---|
protected List |
collPackets
|
static long |
NOW
The special timetag value to indicate that the bundle be processed as soon as possible |
static String |
TAG
This is the initial string of an OSC bundle datagram |
Constructor Summary | |
---|---|
OSCBundle()
Creates a new empty OSCBundle with timetag set to "immediately". |
|
OSCBundle(double when)
Creates a new empty OSCBundle with timetag specified by 'when' which is seconds relative to start of session. |
|
OSCBundle(long when)
Creates a new empty OSCBundle with timetag specified by 'when' which is milliseconds since 1 jan 1970 as returned by System.currentTimeMillis(). |
|
OSCBundle(long absMillisOffset,
long sampleFrames,
int sampleRate)
Creates a new empty OSCBundle with timetag specified by a sample frame offset and an absolute time in milliseconds since 1 jan 1970 as returned by System.currentTimeMillis() |
Method Summary | |
---|---|
void |
addPacket(OSCPacket p)
Adds a new OSCPacket to the tail
of the bundle. |
OSCPacket |
getPacket(int idx)
Gets the OSCPacket at the provided
index which must be between 0 inclusive
and getPacketCount() exclusive. |
int |
getPacketCount()
Returns the number of packets currently assembled in this bundle. |
long |
getTimeTag()
Returns the raw format time tag of the bundle |
void |
removePacket(int idx)
Removes the specified packet |
void |
setTimeTagAbsMillis(long when)
Sets the bundle's timetag specified by a long which is milliseconds since 1 jan 1970 as returned by System.currentTimeMillis() . |
void |
setTimeTagRaw(long raw)
|
void |
setTimeTagRelSecs(double when)
Sets the bundle's timetag specified by a double which is seconds relative to start of session. |
void |
setTimeTagSamples(long absMillisOffset,
long sampleFrames,
int sampleRate)
Sets the bundle's timetag as a combination of system absolute time and sample offset. |
Methods inherited from class de.sciss.net.OSCPacket |
---|
decode, encode, encode, getSize, getSize, printHexOn, printTextOn |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String TAG
public static final long NOW
protected final List collPackets
Constructor Detail |
---|
public OSCBundle()
public OSCBundle(long when)
when
- absolute time tag for the bundleSystem.currentTimeMillis()
public OSCBundle(double when)
when
- relative time tag for the bundlepublic OSCBundle(long absMillisOffset, long sampleFrames, int sampleRate)
System.currentTimeMillis()
absMillisOffset
- time offset as returned by System.currentTimeMillis
sampleFrames
- this offset is added to the milli second offset.sampleRate
- used in conjunction with sampleFrames
to
calculate the time offset.Method Detail |
---|
public void addPacket(OSCPacket p)
OSCPacket
to the tail
of the bundle. Passing null
is
allowed in which case no action
is performed.
p
- the packet to add to the tail of the bundlepublic OSCPacket getPacket(int idx)
OSCPacket
at the provided
index which must be between 0 inclusive
and getPacketCount()
exclusive.
If bundles are nested, each nested
bundle will count as one packet of course.
idx
- index of the packet to get
idx
public int getPacketCount()
public void removePacket(int idx)
idx
- the index of the packet to removepublic void setTimeTagAbsMillis(long when)
System.currentTimeMillis()
.
This is converted into an absolute time
offset since 1 jan 1900 as required by
the OSC specs.
when
- absolute time tag for the bundleSystem.currentTimeMillis()
public void setTimeTagRaw(long raw)
public void setTimeTagRelSecs(double when)
when
- relative time tag for the bundlepublic void setTimeTagSamples(long absMillisOffset, long sampleFrames, int sampleRate)
absMillisOffset
- time offset as returned by System.currentTimeMillis
sampleFrames
- this offset is added to the milli second offset.sampleRate
- used in conjunction with sampleFrames
to
calculate the time offset.public long getTimeTag()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |