// you can use SwingOSC to
// perform virtually any operations in the java
// language.
// note: it's often easier to use the [JavaObject] class
n = NetAddr( "127.0.0.1", 57111 );
try { n.connect }; // if running on TCP!
n.sendMsg( "/local", \myBool, '[', "/new", "java.lang.Boolean", "true", ']')
n.sendMsg( "/print", \myBool )
n.sendMsg( "/print", '[', "/local", \currentDate, '[', "/methodr", '[', "/method", "java.text.DateFormat", \getDateInstance, ']', \format, '[', "/new", "java.util.Date", ']', ']', ']' );
n.sendMsg( "/print", '[', "/local", \yourHomeFolder, '[', "/new", "java.io.File", '[', "/method", "java.lang.System", \getProperty, "user.home", ']', ']', ']' );
n.sendMsg( "/print", '[', "/local", \howManyFilesInYourFolder, '[', "/method", "java.lang.reflect.Array", \getLength, '[', "/method", \yourHomeFolder, \list, ']', ']', ']');
See why it can be dangerous to run SwingOSC in an open network?
...By the way, what SwingOSC version are we using?
(
// Note: OSCpathResponder( n.addr, ... ) doesn't work
// for a reason beyond my knowledge
OSCpathResponder( nil, [ '/info', \version ], { arg time, resp, msg;
("SwingOSC server is version" + msg[ 2 ]).postln;
resp.remove;
}).add;
n.sendMsg( "/query", \version, '[', "/field", "de.sciss.swingosc.SwingOSC", \VERSION, ']' );
)
Explanation
"/methodr", '[', "/method", "java.text.DateFormat", \getDateInstance, ']', \format,
'[', "/new", "java.util.Date", ']'
- The command "/methodr" has been added recently to allow you to call methods on method results (i.e. java objects) directly without having to create an object reference variable first. While "/method" requires a reference name as the first argument, "/methodr" requires a java object as directly returned from "/method" or "/new". Note here how "/method" is used to work on the reference name of a java class ("java.text.DateFormat") instead of the class object itself!
- If this looks confusing, think of the difference of (set) and (setq) in LISP for example.
- in a future version, methods "/setr" and "/getr" might accompany "/set" and "/get" in a similar fashion.
'[', "/method", "java.lang.reflect.Array", \getLength, '[', "/method", \yourHomeFolder, \list, ']', ']'
- this looks a bit awkward. The reason is that java is a bit tricky when it comes to "primitives" such as boolean, int, but also arrays. one might think that '[', "/fieldr", '[', "/method", \yourHomeFolder, \list, ']', \length, ']' should work, but the array stored in \list doesn't really have a \length field.
"/query", \version, '[', "/field", "de.sciss.swingosc.SwingOSC", \VERSION, ']'
- The command "/query" will reply to the sender with an "/info" message, whose first argument is the first argument of the query. this can be freely chosen and is merely for routing the reply message at the client. Typically you will use a self-explaning symbol as \version in the example since we are querying the version. The second argument to "/query" is a java object to be returned; again we can use a nested OSC message to return a field value or a result from a method call. "/field", just as "/method", can be used either with a object identifier as generated by added "/local" or "/global", or by specifying a class name string in case you wish to read a static (class) field. To operate on java objects directly, use "/fieldr".
// last mod: 30-jul-07 sciss