From 0f770551cebca90c92b7a39b0e0135a445af51f9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Mar 2008 02:28:22 +0000 Subject: merging in pdj-0.8.4.tar.gz from http://www.le-son666.com/software/pdj/ svn path=/trunk/externals/loaders/pdj/; revision=9624 --- src/java/com/cycling74/max/MaxObject.java | 4 +- .../com/cycling74/max/MaxRuntimeException.java | 8 +- src/java/com/cycling74/max/MaxSystem.java | 2 +- src/java/com/cycling74/msp/AudioFileBuffer.java | 2 +- src/java/com/cycling74/net/TcpReceiver.java | 89 ++++++++++++++++++ src/java/com/cycling74/net/TcpSender.java | 103 +++++++++++++++++++++ src/java/com/cycling74/net/UdpReceiver.java | 84 +++++++++++++++++ src/java/com/cycling74/net/UdpSender.java | 84 +++++++++++++++++ src/java/com/e1/pdj/JikesCompiler.java | 1 - src/java/com/e1/pdj/PDJSystem.java | 20 ++-- src/java/pdj_test_class.java | 3 +- 11 files changed, 379 insertions(+), 21 deletions(-) create mode 100644 src/java/com/cycling74/net/TcpReceiver.java create mode 100644 src/java/com/cycling74/net/TcpSender.java create mode 100644 src/java/com/cycling74/net/UdpReceiver.java create mode 100644 src/java/com/cycling74/net/UdpSender.java (limited to 'src/java') diff --git a/src/java/com/cycling74/max/MaxObject.java b/src/java/com/cycling74/max/MaxObject.java index 3d07d49..15f2a16 100644 --- a/src/java/com/cycling74/max/MaxObject.java +++ b/src/java/com/cycling74/max/MaxObject.java @@ -806,7 +806,7 @@ public class MaxObject { } /** - * Tries to instanciate a MaxObject. + * Tries to instantiate a MaxObject. * @param name fq java name * @param _pdobj_ptr C pointer to pd object * @param args objects arguments @@ -844,7 +844,7 @@ public class MaxObject { pushPdjPointer(_pdobj_ptr); - // instanciate the object + // instantiate the object if ( args.length > 0 ) { try { Object argValue[] = new Object[1]; diff --git a/src/java/com/cycling74/max/MaxRuntimeException.java b/src/java/com/cycling74/max/MaxRuntimeException.java index 9909a5c..8043aa9 100644 --- a/src/java/com/cycling74/max/MaxRuntimeException.java +++ b/src/java/com/cycling74/max/MaxRuntimeException.java @@ -5,11 +5,15 @@ package com.cycling74.max; */ public class MaxRuntimeException extends RuntimeException { + public MaxRuntimeException() { + } + public MaxRuntimeException(String msg) { super(msg); } - public MaxRuntimeException() { - } + public MaxRuntimeException(Exception e) { + super(e); + } } diff --git a/src/java/com/cycling74/max/MaxSystem.java b/src/java/com/cycling74/max/MaxSystem.java index 3a29540..dd8fe48 100644 --- a/src/java/com/cycling74/max/MaxSystem.java +++ b/src/java/com/cycling74/max/MaxSystem.java @@ -171,7 +171,7 @@ public class MaxSystem { } // constants - public static String MXJ_VERSION = "pdj 0.8.3"; + public static String MXJ_VERSION = "pdj 0.8.4"; public static final int PATH_STYLE_COLON = 2; public static final int PATH_STYLE_MAX = 0; diff --git a/src/java/com/cycling74/msp/AudioFileBuffer.java b/src/java/com/cycling74/msp/AudioFileBuffer.java index b2e76f3..eebffa1 100644 --- a/src/java/com/cycling74/msp/AudioFileBuffer.java +++ b/src/java/com/cycling74/msp/AudioFileBuffer.java @@ -12,7 +12,7 @@ import javax.sound.sampled.UnsupportedAudioFileException; import com.cycling74.max.MessageReceiver; /** - * Work in progress, target: 0.8.4 + * Work in progress, target: 0.8.5 */ class AudioFileBuffer { diff --git a/src/java/com/cycling74/net/TcpReceiver.java b/src/java/com/cycling74/net/TcpReceiver.java new file mode 100644 index 0000000..f449517 --- /dev/null +++ b/src/java/com/cycling74/net/TcpReceiver.java @@ -0,0 +1,89 @@ +package com.cycling74.net; + +import java.lang.reflect.Method; +import java.net.DatagramPacket; +import java.net.DatagramSocket; + +import com.cycling74.max.Atom; +import com.cycling74.max.MaxRuntimeException; +import com.cycling74.max.MaxSystem; + +/** + * This portion of code is scheduled for pdj-0.8.5 + * IT IS NOT FUNCTIONAL + */ +public class TcpReceiver implements Runnable { + DatagramSocket receiver; + DatagramPacket packet; + + Method callback = null; + Object instance; + + String debugString = null; + int port; + boolean runnable = true; + + public void close() { + if ( receiver == null ) + return; + runnable = false; + receiver.close(); + } + + public int getPort() { + return port; + } + + public void setActive(boolean active) { + if ( active == false ) { + runnable = true; + new Thread(this).start(); + } else { + close(); + } + + } + + public void setCallback(Object caller, String methodName) { + try { + callback = caller.getClass().getDeclaredMethod(methodName, new Class[] { Atom.class }); + instance = caller; + } catch (Exception e) { + throw new MaxRuntimeException(e); + } + } + + public void setPort(int port) { + setActive(false); + this.port = port; + } + + public void setDebugString(String debugString) { + this.debugString = debugString; + } + + public void run() { + DatagramPacket packet = new DatagramPacket(new byte[4096], 4096); + Object callerArgs[] = new Object[1]; + + try { + while(runnable) { + receiver.receive(packet); + String msg = new String(packet.getData(), 0, packet.getLength()); + if ( debugString != null ) + MaxSystem.post(debugString + " " + msg); + callerArgs[0] = Atom.parse(msg); + try { + callback.invoke(instance, callerArgs); + } catch( Exception e ) { + e.printStackTrace(); + } + } + } catch (Exception e) { + if ( runnable != false) { + runnable = false; + throw new MaxRuntimeException(e); + } + } + } +} diff --git a/src/java/com/cycling74/net/TcpSender.java b/src/java/com/cycling74/net/TcpSender.java new file mode 100644 index 0000000..2ba0f67 --- /dev/null +++ b/src/java/com/cycling74/net/TcpSender.java @@ -0,0 +1,103 @@ +package com.cycling74.net; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetSocketAddress; + +import com.cycling74.max.Atom; +import com.cycling74.max.MaxRuntimeException; + +/** + * This portion of code is scheduled for pdj-0.8.5 + * IT IS NOT FUNCTIONAL + */ +public class TcpSender { + DatagramSocket sender; + DatagramPacket packet; + String address = null; + int port = -1; + + public TcpSender() { + } + + public TcpSender(String address, int port) { + this.address= address; + this.port = port; + } + + public void send(Atom args[]) { + if ( sender == null ) + initsocket(); + + byte buff[] = Atom.toOneString(args).getBytes(); + packet.setData(buff, 0, buff.length); + try { + sender.send(packet); + } catch (IOException e) { + throw new MaxRuntimeException(e); + } + } + + public void send(int i) { + if ( sender == null ) + initsocket(); + + byte buff[] = Integer.toString(i).getBytes(); + packet.setData(buff, 0, buff.length); + try { + sender.send(packet); + } catch (IOException e) { + throw new MaxRuntimeException(e); + } + } + + public void send(float f) { + if ( sender == null ) + initsocket(); + + byte buff[] = Float.toString(f).getBytes(); + packet.setData(buff, 0, buff.length); + try { + sender.send(packet); + } catch (IOException e) { + throw new MaxRuntimeException(e); + } + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + if ( sender != null ) { + sender = null; + sender.close(); + } + this.address = address; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + if ( sender != null ) { + sender = null; + sender.close(); + } + this.port = port; + } + + private synchronized void initsocket() { + if ( sender != null ) + return; + try { + sender = new DatagramSocket(); + sender.connect(new InetSocketAddress(address, port)); + packet = new DatagramPacket(new byte[0], 0); + } catch (Exception e) { + throw new MaxRuntimeException(e); + } + } +} diff --git a/src/java/com/cycling74/net/UdpReceiver.java b/src/java/com/cycling74/net/UdpReceiver.java new file mode 100644 index 0000000..fd47e25 --- /dev/null +++ b/src/java/com/cycling74/net/UdpReceiver.java @@ -0,0 +1,84 @@ +package com.cycling74.net; + +import java.net.DatagramPacket; +import java.net.DatagramSocket; + +import com.cycling74.max.Atom; +import com.cycling74.max.MaxRuntimeException; +import com.cycling74.max.MaxSystem; +import com.cycling74.max.Callback; + +/** + * This portion of code is scheduled for pdj-0.8.5 + * IT IS NOT FUNCTIONAL + */ +public class UdpReceiver implements Runnable { + DatagramSocket receiver; + DatagramPacket packet; + + Callback callback; + + String debugString = null; + int port; + boolean runnable = true; + + public void close() { + if ( receiver == null ) + return; + runnable = false; + receiver.close(); + } + + public int getPort() { + return port; + } + + public void setActive(boolean active) { + if ( active == false ) { + runnable = true; + new Thread(this).start(); + } else { + close(); + } + + } + + public void setCallback(Object caller, String methodName) { + callback = new Callback(caller, methodName); + } + + public void setPort(int port) { + setActive(false); + this.port = port; + } + + public void setDebugString(String debugString) { + this.debugString = debugString; + } + + public void run() { + DatagramPacket packet = new DatagramPacket(new byte[4096], 4096); + Object callerArgs[] = new Object[1]; + + try { + while(runnable) { + receiver.receive(packet); + String msg = new String(packet.getData(), 0, packet.getLength()); + if ( debugString != null ) + MaxSystem.post(debugString + " " + msg); + callerArgs[0] = Atom.parse(msg); + + /* try { + callback.invoke(instance, callerArgs); + } catch( Exception e ) { + e.printStackTrace(); + } */ + } + } catch (Exception e) { + if ( runnable != false) { + runnable = false; + throw new MaxRuntimeException(e); + } + } + } +} diff --git a/src/java/com/cycling74/net/UdpSender.java b/src/java/com/cycling74/net/UdpSender.java new file mode 100644 index 0000000..6ef7e34 --- /dev/null +++ b/src/java/com/cycling74/net/UdpSender.java @@ -0,0 +1,84 @@ +package com.cycling74.net; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; + +import com.cycling74.max.Atom; +import com.cycling74.max.MaxRuntimeException; + +/** + * This portion of code is scheduled for pdj-0.8.5 + * IT IS NOT FUNCTIONAL + */ +public class UdpSender { + InetAddress inetAddress; + DatagramSocket sender; + boolean init; + + String address = null; + int port = -1; + + public UdpSender() { + } + + public UdpSender(String address, int port) { + this.address = address; + this.port = port; + initsocket(); + } + + public void send(Atom args[]) { + send(Atom.toOneString(args).getBytes()); + } + + public void send(int i) { + send(Integer.toString(i).getBytes()); + } + + public void send(float f) { + send(Float.toString(f).getBytes()); + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + initsocket(); + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + initsocket(); + } + + synchronized void initsocket() { + try { + sender = null; + inetAddress = InetAddress.getByName(address); + sender = new DatagramSocket(); + } catch (Exception e) { + throw new MaxRuntimeException(e); + } + } + + void send(byte buff[]) { + if ( sender == null ) + throw new MaxRuntimeException("UdpSender is not initialized"); + + try { + DatagramPacket packet = new DatagramPacket(buff, buff.length, inetAddress, port); + sender.send(packet); + } catch (IOException e) { + throw new MaxRuntimeException(e); + } + + } +} diff --git a/src/java/com/e1/pdj/JikesCompiler.java b/src/java/com/e1/pdj/JikesCompiler.java index f9337b2..041a4f7 100644 --- a/src/java/com/e1/pdj/JikesCompiler.java +++ b/src/java/com/e1/pdj/JikesCompiler.java @@ -1,6 +1,5 @@ package com.e1.pdj; -import java.io.*; import com.cycling74.max.MaxSystem; public class JikesCompiler extends GenericCompiler { diff --git a/src/java/com/e1/pdj/PDJSystem.java b/src/java/com/e1/pdj/PDJSystem.java index 3d30a53..1fd50d2 100644 --- a/src/java/com/e1/pdj/PDJSystem.java +++ b/src/java/com/e1/pdj/PDJSystem.java @@ -7,6 +7,7 @@ import java.awt.Frame; import java.awt.Toolkit; import java.io.*; +import java.awt.GraphicsEnvironment; /** * Startup class for pdj. */ @@ -50,7 +51,7 @@ public class PDJSystem { // this is a hack to be sure that statics of MaxSystem are loaded // before everything Class cls = MaxSystem.class; - + String osname = System.getProperty("os.name"); if ( osname.indexOf("Linux") != -1 ) { @@ -71,20 +72,13 @@ public class PDJSystem { if ( osname.indexOf("OS X") != -1 ) { // maps PD object as a JVM native library - try { - Runtime.getRuntime().load(pdjHome + "/pdj.pd_darwin"); - } catch (UnsatisfiedLinkError e ) { - Runtime.getRuntime().load(pdjHome + "/pdj.pd_imac"); - } + Runtime.getRuntime().load(pdjHome + "/pdj.d_fat"); loaded = 1; - - // this will initialize the AWT component in another thread - new Thread(new Runnable() { - public void run() { - Class clz = Component.class; - } - }).start(); + if ( System.getenv("PDJ_USE_AWT") != null ) { + GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); + Toolkit.getDefaultToolkit(); + } GenericCompiler.rtJar = "/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar:"; return; diff --git a/src/java/pdj_test_class.java b/src/java/pdj_test_class.java index ff6f756..61cf804 100644 --- a/src/java/pdj_test_class.java +++ b/src/java/pdj_test_class.java @@ -9,6 +9,7 @@ public class pdj_test_class extends MaxObject implements Executable { clock = new MaxClock(this); declareAttribute("patate"); + declareIO(2,2); } public pdj_test_class(Atom args[]) { @@ -49,7 +50,7 @@ public class pdj_test_class extends MaxObject implements Executable { } protected void inlet(float f) { - post("le float " + f); + post("le float " + f + "inlet " + getInlet()); } void wer(Atom[] atom) { -- cgit v1.2.1