Merge remote-tracking branch 'upstream/master'

This commit is contained in:
codeanticode
2014-11-15 14:27:06 -07:00
20 changed files with 429 additions and 1994 deletions
+5
View File
@@ -7928,4 +7928,9 @@ public class PGraphics extends PImage implements PConstants {
public boolean isGL() { // ignore
return false;
}
public boolean is2X() {
return pixelFactor == 2;
}
}
+23 -33
View File
@@ -4,7 +4,7 @@ import java.awt.*;
public class PGraphicsRetina2D extends PGraphicsJava2D {
PImage retina;
// PImage retina;
// int retinaWidth;
// int retinaHeight;
@@ -14,21 +14,21 @@ public class PGraphicsRetina2D extends PGraphicsJava2D {
// INTERNAL
public PGraphicsRetina2D() {
retina = new PImage();
retina.format = RGB;
}
// public PGraphicsRetina2D() {
// retina = new PImage();
// retina.format = RGB;
// }
@Override
public void setParent(PApplet parent) {
super.setParent(parent);
retina.parent = parent;
}
// @Override
// public void setParent(PApplet parent) {
// super.setParent(parent);
// retina.parent = parent;
// }
@Override
protected void allocate() {
// @Override
// protected void allocate() {
// parent.setIgnoreRepaint(true);
// g2 = (Graphics2D) parent.getGraphics();
@@ -80,7 +80,7 @@ public class PGraphicsRetina2D extends PGraphicsJava2D {
g2 = (Graphics2D) image.getGraphics();
}
*/
}
// }
//////////////////////////////////////////////////////////////
@@ -88,38 +88,22 @@ public class PGraphicsRetina2D extends PGraphicsJava2D {
// FRAME
@Override
public boolean canDraw() {
return parent.getGraphicsConfiguration() != null;
}
// @Override
// public boolean canDraw() {
// return parent.getGraphicsConfiguration() != null;
// }
@Override
public void beginDraw() {
// g2 = (Graphics2D) parent.getGraphics();
GraphicsConfiguration gc = parent.getGraphicsConfiguration();
// if (false) {
// if (image == null || ((VolatileImage) image).validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
// image = gc.createCompatibleVolatileImage(width*2, height*2);
// }
// } else {
if (image == null) {
retina.width = width * 2;
retina.height = height * 2;
image = gc.createCompatibleImage(retina.width, retina.height);
// System.out.println("image type is " + image);
}
// }
g2 = (Graphics2D) image.getGraphics();
// g2.scale(2, 2);
// if (bimage == null ||
// bimage.getWidth() != width ||
// bimage.getHeight() != height) {
// PApplet.debug("PGraphicsJava2D creating new image");
// bimage = gc.createCompatibleImage(width, height);
checkSettings();
resetMatrix(); // reset model matrix
@@ -652,4 +636,10 @@ public class PGraphicsRetina2D extends PGraphicsJava2D {
return super.save(filename);
}
}
@Override
public boolean is2X() {
return true;
}
}
File diff suppressed because it is too large Load Diff
+9 -1
View File
@@ -48,6 +48,8 @@ public interface PSurface {
public Frame initFrame(PApplet sketch, Color backgroundColor,
int deviceIndex, boolean fullScreen, boolean spanDisplays);
//
/** Set the window (and dock, or whatever necessary) title. */
public void setTitle(String title);
@@ -57,6 +59,8 @@ public interface PSurface {
/** Set true if we want to resize things (default is not resizable) */
public void setResizable(boolean resizable);
//
public void placeWindow(int[] location);
public void placeWindow(int[] location, int[] editorLocation);
@@ -67,6 +71,8 @@ public interface PSurface {
// Sketch is running from the PDE, set up messaging back to the PDE
public void setupExternalMessages();
//
/** Start the animation thread */
public void startThread();
@@ -87,6 +93,8 @@ public interface PSurface {
public boolean isStopped();
//
// sets displayWidth/Height inside PApplet
//public void checkDisplaySize();
@@ -98,7 +106,7 @@ public interface PSurface {
// receive key and mouse events
public void requestFocus();
// finish rendering to the screen
// finish rendering to the screen (called by PApplet)
public void blit();
//
+1 -1
View File
@@ -786,7 +786,7 @@ public class PSurfaceAWT implements PSurface {
// Formerly this was broken into separate versions based on offscreen or
// not, but we may as well create a compatible image; it won't hurt, right?
graphics.image = gc.createCompatibleImage(wide, high);
System.out.println(graphics.image);
// System.out.println(graphics.image);
//throw new RuntimeException("implement me, see readme.md");
sketchWidth = sketch.width = wide;
+6 -1
View File
@@ -2,6 +2,8 @@
X detect CMYK JPEG images and return null
X https://community.oracle.com/thread/1272045?start=0&tstart=0
_ remove sketch path hack from PApplet
python has to use launch() instead of open()
map() is bad for Python (and JavaScript?)
@@ -11,6 +13,9 @@ _ https://github.com/processing/processing/issues/2924
_ why doesn't p5 punt when loadFont() is used on an otf?
_ is this a GL problem?
_ show warning when display spanning is turned off
_ defaults read com.apple.spaces spans-displays
data
X fix XML.getString() with a default when no attrs are present at all
X was causing a NullPointerException
@@ -36,7 +41,7 @@ X https://github.com/processing/processing/issues/2641
X remove isGL(), is2D(), is3D(), displayable() from PApplet
X these were auto-imported from PGraphics
X remove pause variable from PApplet (was not documented)
_ remove sketch path hack from PApplet
X added copy() to PImage (to work like get(), ala PVector)
pulls
X Fix check in loadShader()
-10
View File
@@ -1,10 +0,0 @@
Copyright (c) 2002-2006, C. Ramakrishnan / Illposed Software
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
• Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
• Neither the name of the Illposed Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-190
View File
@@ -1,190 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import com.illposed.osc.utility.OSCJavaToByteArrayConverter;
/**
* A bundle represents a collection of OSC packets
* (either messages or other bundles)
* and has a time-tag which can be used by a scheduler to execute
* a bundle in the future,
* instead of immediately.
* {@link OSCMessage}s are executed immediately.
*
* Bundles should be used if you want to send multiple messages to be executed
* atomically together, or you want to schedule one or more messages to be
* executed in the future.
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCBundle extends OSCPacket {
/**
* 2208988800 seconds -- includes 17 leap years
*/
public static final BigInteger SECONDS_FROM_1900_TO_1970 =
new BigInteger("2208988800");
/**
* The Java representation of an OSC timestamp with the semantics of
* "immediately".
*/
public static final Date TIMESTAMP_IMMEDIATE = new Date(0);
private Date timestamp;
private List<OSCPacket> packets;
/**
* Create a new empty OSCBundle with a timestamp of immediately.
* You can add packets to the bundle with addPacket()
*/
public OSCBundle() {
this(TIMESTAMP_IMMEDIATE);
}
/**
* Create an OSCBundle with the specified timestamp.
* @param timestamp the time to execute the bundle
*/
public OSCBundle(Date timestamp) {
this((Collection<OSCPacket>) null, timestamp);
}
// deprecated since version 1.0, March 2012
/**
* Creates an OSCBundle made up of the given packets
* with a timestamp of now.
* @param packets array of OSCPackets to initialize this object with
* @deprecated
*/
public OSCBundle(OSCPacket[] packets) {
this(packets, TIMESTAMP_IMMEDIATE);
}
/**
* Creates an OSCBundle made up of the given packets
* with a timestamp of now.
* @param packets array of OSCPackets to initialize this object with
*/
public OSCBundle(Collection<OSCPacket> packets) {
this(packets, TIMESTAMP_IMMEDIATE);
}
// deprecated since version 1.0, March 2012
/**
* Creates an OSCBundle, specifying the packets and timestamp.
* @param packets the packets that make up the bundle
* @param timestamp the time to execute the bundle
* @deprecated
*/
public OSCBundle(OSCPacket[] packets, Date timestamp) {
this((packets == null)
? new LinkedList<OSCPacket>()
: Arrays.asList(packets),
timestamp);
}
/**
* Create an OSCBundle, specifying the packets and timestamp.
* @param packets the packets that make up the bundle
* @param timestamp the time to execute the bundle
*/
public OSCBundle(Collection<OSCPacket> packets, Date timestamp) {
if (null == packets) {
this.packets = new LinkedList<OSCPacket>();
} else {
this.packets = new ArrayList<OSCPacket>(packets);
}
this.timestamp = timestamp;
init();
}
/**
* Return the time the bundle will execute.
* @return a Date
*/
public Date getTimestamp() {
return timestamp;
}
/**
* Set the time the bundle will execute.
* @param timestamp Date
*/
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
/**
* Add a packet to the list of packets in this bundle.
* @param packet OSCMessage or OSCBundle
*/
public void addPacket(OSCPacket packet) {
packets.add(packet);
}
/**
* Get the packets contained in this bundle.
* @return the packets contained in this bundle.
*/
public OSCPacket[] getPackets() {
OSCPacket[] packetArray = new OSCPacket[packets.size()];
packets.toArray(packetArray);
return packetArray;
}
/**
* Convert the time-tag (a Java Date) into the OSC byte stream.
* Used Internally.
*/
protected void computeTimeTagByteArray(OSCJavaToByteArrayConverter stream) {
if ((null == timestamp) || (timestamp == TIMESTAMP_IMMEDIATE)) {
stream.write(0);
stream.write(1);
return;
}
long millisecs = timestamp.getTime();
long secsSince1970 = millisecs / 1000;
long secs = secsSince1970 + SECONDS_FROM_1900_TO_1970.longValue();
// this line was cribbed from jakarta commons-net's NTP TimeStamp code
long fraction = ((millisecs % 1000) * 0x100000000L) / 1000;
stream.write((int) secs);
stream.write((int) fraction);
}
/**
* Compute the OSC byte stream representation of the bundle.
* Used Internally.
* @param stream OscPacketByteArrayConverter
*/
protected byte[] computeByteArray(OSCJavaToByteArrayConverter stream) {
stream.write("#bundle");
computeTimeTagByteArray(stream);
byte[] packetBytes;
for (OSCPacket pkg : packets) {
packetBytes = pkg.getByteArray();
stream.write(packetBytes.length);
stream.write(packetBytes);
}
return stream.toByteArray();
}
}
@@ -1,28 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.util.Date;
/**
* Interface for things that listen for incoming OSC Messages
*
* @author Chandrasekhar Ramakrishnan
*/
public interface OSCListener {
/**
* Accept an incoming OSCMessage
* @param time The time this message is to be executed.
* <code>null</code> means execute now
* @param message The message to execute.
*/
public void acceptMessage(Date time, OSCMessage message);
}
-150
View File
@@ -1,150 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import com.illposed.osc.utility.OSCJavaToByteArrayConverter;
/**
* An simple (non-bundle) OSC message.
*
* An OSC message is made up of an address (the receiver of the message)
* and arguments (the content of the message).
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCMessage extends OSCPacket {
private String address;
private List<Object> arguments;
/**
* Creates an empty OSC Message.
* In order to send this OSC message,
* you need to set the address and optionally some arguments.
*/
public OSCMessage() {
arguments = new LinkedList<Object>();
}
/**
* Creates an OSCMessage with an address already initialized.
* @param address the recipient of this OSC message
*/
public OSCMessage(String address) {
this(address, (Collection<Object>) null);
}
// deprecated since version 1.0, March 2012
/**
* Creates an OSCMessage with an address and arguments already initialized.
* @param address the recipient of this OSC message
* @param arguments the data sent to the receiver
* @deprecated
*/
public OSCMessage(String address, Object[] arguments) {
this.address = address;
if (arguments == null) {
this.arguments = new LinkedList<Object>();
} else {
this.arguments = new ArrayList<Object>(arguments.length);
this.arguments.addAll(Arrays.asList(arguments));
}
init();
}
/**
* Creates an OSCMessage with an address
* and arguments already initialized.
* @param address the recipient of this OSC message
* @param arguments the data sent to the receiver
*/
public OSCMessage(String address, Collection<Object> arguments) {
this.address = address;
if (arguments == null) {
this.arguments = new LinkedList<Object>();
} else {
this.arguments = new ArrayList<Object>(arguments);
}
init();
}
/**
* The receiver of this message.
* @return the receiver of this OSC Message
*/
public String getAddress() {
return address;
}
/**
* Set the address of this message.
* @param address the receiver of the message
*/
public void setAddress(String address) {
this.address = address;
}
/**
* Add an argument to the list of arguments.
* @param argument a Float, String, Integer, BigInteger, Boolean
* or an array of these
*/
public void addArgument(Object argument) {
arguments.add(argument);
}
/**
* The arguments of this message.
* @return the arguments to this message
*/
public Object[] getArguments() {
return arguments.toArray();
}
/**
* Convert the address into a byte array.
* Used internally only.
*/
protected void computeAddressByteArray(OSCJavaToByteArrayConverter stream) {
stream.write(address);
}
/**
* Convert the arguments into a byte array.
* Used internally only.
*/
protected void computeArgumentsByteArray(OSCJavaToByteArrayConverter stream) {
stream.write(',');
if (null == arguments) {
return;
}
stream.writeTypes(arguments);
for (Object argument : arguments) {
stream.write(argument);
}
}
/**
* Convert the message into a byte array.
* Used internally only.
*/
protected byte[] computeByteArray(OSCJavaToByteArrayConverter stream) {
computeAddressByteArray(stream);
computeArgumentsByteArray(stream);
return stream.toByteArray();
}
}
-72
View File
@@ -1,72 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import com.illposed.osc.utility.OSCJavaToByteArrayConverter;
/**
* OSCPacket is the abstract superclass for the various
* kinds of OSC Messages.
*
* The actual packets are:
* <ul>
* <li>{@link OSCMessage}: simple OSC messages
* <li>{@link OSCBundle}: OSC messages with timestamps
* and/or made up of multiple messages
* </ul>
*
* This implementation is based on
* <a href="http://www.emergent.de/Goodies/">Markus Gaelli</a> and
* Iannis Zannos' OSC implementation in Squeak Smalltalk.
*/
public abstract class OSCPacket {
private boolean isByteArrayComputed;
private byte[] byteArray;
/**
* Default constructor for the abstract class
*/
public OSCPacket() {
}
/**
* Generate a representation of this packet conforming to the
* the OSC byte stream specification. Used Internally.
*/
protected byte[] computeByteArray() {
OSCJavaToByteArrayConverter stream = new OSCJavaToByteArrayConverter();
return computeByteArray(stream);
}
/**
* Subclasses should implement this method to product a byte array
* formatted according to the OSC specification.
* @param stream OscPacketByteArrayConverter
*/
protected abstract byte[] computeByteArray(OSCJavaToByteArrayConverter stream);
/**
* Return the OSC byte stream for this packet.
* @return byte[]
*/
public byte[] getByteArray() {
if (!isByteArrayComputed) {
byteArray = computeByteArray();
}
return byteArray;
}
/**
* Run any post construction initialization. (By default, do nothing.)
*/
protected void init() {
}
}
-84
View File
@@ -1,84 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.net.DatagramSocket;
/**
* OSCPort is an abstract superclass, to send OSC messages,
* use {@link OSCPortOut}.
* To listen for OSC messages, use {@link OSCPortIn}.
*
* @author Chandrasekhar Ramakrishnan
*/
public abstract class OSCPort {
private DatagramSocket socket;
private int port;
public static final int DEFAULT_SC_OSC_PORT = 57110;
public static final int DEFAULT_SC_LANG_OSC_PORT = 57120;
protected OSCPort(DatagramSocket socket, int port) {
this.socket = socket;
this.port = port;
}
/**
* The port that the SuperCollider <b>synth</b> engine
* usually listens to.
* @see #DEFAULT_SC_OSC_PORT
*/
public static int defaultSCOSCPort() {
return DEFAULT_SC_OSC_PORT;
}
/**
* The port that the SuperCollider <b>language</b> engine
* usually listens to.
* @see #DEFAULT_SC_LANG_OSC_PORT
*/
public static int defaultSCLangOSCPort() {
return DEFAULT_SC_LANG_OSC_PORT;
}
/**
* Returns the socket associated with this port.
* @return this ports socket
*/
protected DatagramSocket getSocket() {
return socket;
}
/**
* Returns the port number associated with this port.
* @return this ports number
*/
protected int getPort() {
return port;
}
/**
* Close the socket if this hasn't already happened.
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
super.finalize();
socket.close();
}
/**
* Close the socket and free-up resources.
* It is recommended that clients call this when they are done with the
* port.
*/
public void close() {
socket.close();
}
}
-128
View File
@@ -1,128 +0,0 @@
/*
* Copyright (C) 2004-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.io.IOException;
import java.net.SocketException;
import com.illposed.osc.utility.OSCByteArrayToJavaConverter;
import com.illposed.osc.utility.OSCPacketDispatcher;
/**
* OSCPortIn is the class that listens for OSC messages.
*
* An example based on
* {@link com.illposed.osc.OSCPortTest#testReceiving()}:
* <pre>
receiver = new OSCPortIn(OSCPort.DEFAULT_SC_OSC_PORT());
OSCListener listener = new OSCListener() {
public void acceptMessage(java.util.Date time, OSCMessage message) {
System.out.println("Message received!");
}
};
receiver.addListener("/message/receiving", listener);
receiver.startListening();
* </pre>
*
* Then, using a program such as SuperCollider or sendOSC, send a message
* to this computer, port {@link #DEFAULT_SC_OSC_PORT},
* with the address "/message/receiving".
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCPortIn extends OSCPort implements Runnable {
// state for listening
private boolean listening;
private OSCByteArrayToJavaConverter converter
= new OSCByteArrayToJavaConverter();
private OSCPacketDispatcher dispatcher = new OSCPacketDispatcher();
/**
* Create an OSCPort that listens on the specified port.
* @param port UDP port to listen on.
* @throws SocketException
*/
public OSCPortIn(int port) throws SocketException {
super(new DatagramSocket(port), port);
}
/**
* Buffers were 1500 bytes in size, but were
* increased to 1536, as this is a common MTU.
*/
private static final int BUFFER_SIZE = 1536;
/**
* Run the loop that listens for OSC on a socket until
* {@link #isListening()} becomes false.
* @see java.lang.Runnable#run()
*/
public void run() {
byte[] buffer = new byte[BUFFER_SIZE];
DatagramPacket packet = new DatagramPacket(buffer, BUFFER_SIZE);
DatagramSocket socket = getSocket();
while (listening) {
try {
try {
socket.receive(packet);
} catch (SocketException ex) {
if (listening) {
throw ex;
} else {
// if we closed the socket while receiving data,
// the exception is expected/normal, so we hide it
continue;
}
}
OSCPacket oscPacket = converter.convert(buffer,
packet.getLength());
dispatcher.dispatchPacket(oscPacket);
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* Start listening for incoming OSCPackets
*/
public void startListening() {
listening = true;
Thread thread = new Thread(this);
thread.start();
}
/**
* Stop listening for incoming OSCPackets
*/
public void stopListening() {
listening = false;
}
/**
* Am I listening for packets?
*/
public boolean isListening() {
return listening;
}
/**
* Register the listener for incoming OSCPackets addressed to an Address
* @param anAddress the address to listen for. The address can be specified as a regex, e.g., "/m.*e/receiving"
* @param listener the object to invoke when a message comes in
*/
public void addListener(String anAddress, OSCListener listener) {
dispatcher.addListener(anAddress, listener);
}
}
-84
View File
@@ -1,84 +0,0 @@
/*
* Copyright (C) 2004-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
/**
* OSCPortOut is the class that sends OSC messages
* to a specific address and port.
*
* To send an OSC message, call send().
*
* An example based on
* {@link com.illposed.osc.OSCPortTest#testMessageWithArgs()}:
* <pre>
OSCPort sender = new OSCPort();
Object args[] = new Object[2];
args[0] = new Integer(3);
args[1] = "hello";
OSCMessage msg = new OSCMessage("/sayhello", args);
try {
sender.send(msg);
} catch (Exception e) {
showError("Couldn't send");
}
* </pre>
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCPortOut extends OSCPort {
private InetAddress address;
/**
* Create an OSCPort that sends to address:port.
* @param address the UDP address to send to
* @param port the UDP port to send to
*/
public OSCPortOut(InetAddress address, int port)
throws SocketException
{
super(new DatagramSocket(), port);
this.address = address;
}
/**
* Create an OSCPort that sends to address,
* using the standard SuperCollider port.
* @param address the UDP address to send to
*/
public OSCPortOut(InetAddress address) throws SocketException {
this(address, DEFAULT_SC_OSC_PORT);
}
/**
* Create an OSCPort that sends to "localhost",
* on the standard SuperCollider port.
*/
public OSCPortOut() throws UnknownHostException, SocketException {
this(InetAddress.getLocalHost(), DEFAULT_SC_OSC_PORT);
}
/**
* Send an OSC packet (message or bundle) to the receiver we are bound to.
* @param aPacket the bundle or message to send
*/
public void send(OSCPacket aPacket) throws IOException {
byte[] byteArray = aPacket.getByteArray();
DatagramPacket packet =
new DatagramPacket(byteArray, byteArray.length, address, getPort());
getSocket().send(packet);
}
}
@@ -1,351 +0,0 @@
/*
* Copyright (C) 2004-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc.utility;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.illposed.osc.OSCBundle;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPacket;
/**
* Utility class to convert a byte array,
* conforming to the OSC byte stream format,
* into Java objects.
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCByteArrayToJavaConverter {
private byte[] bytes;
private int bytesLength;
private int streamPosition;
/**
* Creates a helper object for converting from a byte array
* to an {@link OSCPacket} object.
*/
public OSCByteArrayToJavaConverter() {
}
/**
* Converts a byte array into an {@link OSCPacket}
* (either an {@link OSCMessage} or {@link OSCBundle}).
*/
public OSCPacket convert(byte[] byteArray, int bytesLength) {
this.bytes = byteArray;
this.bytesLength = bytesLength;
this.streamPosition = 0;
if (isBundle()) {
return convertBundle();
} else {
return convertMessage();
}
}
/**
* Is my byte array a bundle?
* @return true if it the byte array is a bundle, false o.w.
*/
private boolean isBundle() {
// only need the first 7 to check if it is a bundle
String bytesAsString = new String(bytes, 0, 7);
return bytesAsString.startsWith("#bundle");
}
/**
* Converts the byte array to a bundle.
* Assumes that the byte array is a bundle.
* @return a bundle containing the data specified in the byte stream
*/
private OSCBundle convertBundle() {
// skip the "#bundle " stuff
streamPosition = 8;
Date timestamp = readTimeTag();
OSCBundle bundle = new OSCBundle(timestamp);
OSCByteArrayToJavaConverter myConverter
= new OSCByteArrayToJavaConverter();
while (streamPosition < bytesLength) {
// recursively read through the stream and convert packets you find
int packetLength = ((Integer) readInteger()).intValue();
byte[] packetBytes = new byte[packetLength];
for (int i = 0; i < packetLength; i++) {
packetBytes[i] = bytes[streamPosition++];
}
OSCPacket packet = myConverter.convert(packetBytes, packetLength);
bundle.addPacket(packet);
}
return bundle;
}
/**
* Converts the byte array to a simple message.
* Assumes that the byte array is a message.
* @return a message containing the data specified in the byte stream
*/
private OSCMessage convertMessage() {
OSCMessage message = new OSCMessage();
message.setAddress(readString());
List<Character> types = readTypes();
if (null == types) {
// we are done
return message;
}
moveToFourByteBoundry();
for (int i = 0; i < types.size(); ++i) {
if ('[' == types.get(i).charValue()) {
// we're looking at an array -- read it in
message.addArgument(readArray(types, ++i).toArray());
// then increment i to the end of the array
while (types.get(i).charValue() != ']') {
i++;
}
} else {
message.addArgument(readArgument(types.get(i)));
}
}
return message;
}
/**
* Reads a string from the byte stream.
* @return the next string in the byte stream
*/
private String readString() {
int strLen = lengthOfCurrentString();
char[] stringChars = new char[strLen];
for (int i = 0; i < strLen; i++) {
stringChars[i] = (char) bytes[streamPosition++];
}
moveToFourByteBoundry();
return new String(stringChars);
}
/**
* Reads the types of the arguments from the byte stream.
* @return a char array with the types of the arguments
*/
private List<Character> readTypes() {
// the next byte should be a ','
if (bytes[streamPosition] != 0x2C) {
return null;
}
streamPosition++;
// find out how long the list of types is
int typesLen = lengthOfCurrentString();
if (0 == typesLen) {
return null;
}
// read in the types
List<Character> typesChars = new ArrayList<Character>(typesLen);
for (int i = 0; i < typesLen; i++) {
typesChars.add((char) bytes[streamPosition++]);
}
return typesChars;
}
/**
* Reads an object of the type specified by the type char.
* @param type type of the argument to read
* @return a Java representation of the argument
*/
private Object readArgument(char type) {
switch (type) {
case 'i' :
return readInteger();
case 'h' :
return readBigInteger();
case 'f' :
return readFloat();
case 'd' :
return readDouble();
case 's' :
return readString();
case 'c' :
return readChar();
case 'T' :
return Boolean.TRUE;
case 'F' :
return Boolean.FALSE;
case 't' :
return readTimeTag();
default:
return null;
}
}
/**
* Reads a char from the byte stream.
* @return a {@link Character}
*/
private Object readChar() {
return new Character((char) bytes[streamPosition++]);
}
/**
* Reads a double from the byte stream.
* This just reads a float.
* @return a {@link Double}
*/
private Object readDouble() {
return readFloat();
}
/**
* Reads a float from the byte stream.
* @return a {@link Float}
*/
private Object readFloat() {
byte[] floatBytes = new byte[4];
floatBytes[0] = bytes[streamPosition++];
floatBytes[1] = bytes[streamPosition++];
floatBytes[2] = bytes[streamPosition++];
floatBytes[3] = bytes[streamPosition++];
// int floatBits =
// (floatBytes[0] << 24)
// | (floatBytes[1] << 16)
// | (floatBytes[2] << 8)
// | (floatBytes[3]);
BigInteger floatBits = new BigInteger(floatBytes);
return new Float(Float.intBitsToFloat(floatBits.intValue()));
}
/**
* Reads a Big Integer (64 bit integer) from the byte stream.
* @return a {@link BigInteger}
*/
private Object readBigInteger() {
byte[] longintBytes = new byte[8];
longintBytes[0] = bytes[streamPosition++];
longintBytes[1] = bytes[streamPosition++];
longintBytes[2] = bytes[streamPosition++];
longintBytes[3] = bytes[streamPosition++];
longintBytes[4] = bytes[streamPosition++];
longintBytes[5] = bytes[streamPosition++];
longintBytes[6] = bytes[streamPosition++];
longintBytes[7] = bytes[streamPosition++];
return new BigInteger(longintBytes);
}
/**
* Reads an Integer (32 bit integer) from the byte stream.
* @return an {@link Integer}
*/
private Object readInteger() {
byte[] intBytes = new byte[4];
intBytes[0] = bytes[streamPosition++];
intBytes[1] = bytes[streamPosition++];
intBytes[2] = bytes[streamPosition++];
intBytes[3] = bytes[streamPosition++];
BigInteger intBits = new BigInteger(intBytes);
return Integer.valueOf(intBits.intValue());
}
/**
* Reads the time tag and convert it to a Java Date object.
* A timestamp is a 64 bit number representing the time in NTP format.
* The first 32 bits are seconds since 1900, the second 32 bits are
* fractions of a second.
* @return a {@link Date}
*/
private Date readTimeTag() {
byte[] secondBytes = new byte[8];
byte[] fractionBytes = new byte[8];
for (int i = 0; i < 4; i++) {
// clear the higher order 4 bytes
secondBytes[i] = 0; fractionBytes[i] = 0;
}
// while reading in the seconds & fraction, check if
// this timetag has immediate semantics
boolean isImmediate = true;
for (int i = 4; i < 8; i++) {
secondBytes[i] = bytes[streamPosition++];
if (secondBytes[i] > 0) {
isImmediate = false;
}
}
for (int i = 4; i < 8; i++) {
fractionBytes[i] = bytes[streamPosition++];
if (i < 7) {
if (fractionBytes[i] > 0) {
isImmediate = false;
}
} else {
if (fractionBytes[i] > 1) {
isImmediate = false;
}
}
}
if (isImmediate) {
return OSCBundle.TIMESTAMP_IMMEDIATE;
}
BigInteger secsSince1900 = new BigInteger(secondBytes);
long secsSince1970 = secsSince1900.longValue()
- OSCBundle.SECONDS_FROM_1900_TO_1970.longValue();
// no point maintaining times in the distant past
if (secsSince1970 < 0) {
secsSince1970 = 0;
}
long fraction = (new BigInteger(fractionBytes).longValue());
// this line was cribbed from jakarta commons-net's NTP TimeStamp code
fraction = (fraction * 1000) / 0x100000000L;
// I do not know where, but I'm losing 1ms somewhere...
fraction = (fraction > 0) ? fraction + 1 : 0;
long millisecs = (secsSince1970 * 1000) + fraction;
return new Date(millisecs);
}
/**
* Reads an array from the byte stream.
* @param types
* @param pos at which position to start reading
* @return the array that was read
*/
private List<Object> readArray(List<Character> types, int pos) {
int arrayLen = 0;
while (types.get(pos + arrayLen).charValue() != ']') {
arrayLen++;
}
List<Object> array = new ArrayList<Object>(arrayLen);
for (int j = 0; j < arrayLen; j++) {
array.add(readArgument(types.get(pos + j)));
}
return array;
}
/**
* Get the length of the string currently in the byte stream.
*/
private int lengthOfCurrentString() {
int i = 0;
while (bytes[streamPosition + i] != 0) {
i++;
}
return i;
}
/**
* Move to the next byte with an index in the byte array
* which is dividable by four.
*/
private void moveToFourByteBoundry() {
// If i am already at a 4 byte boundry, I need to move to the next one
int mod = streamPosition % 4;
streamPosition += (4 - mod);
}
}
@@ -1,340 +0,0 @@
/*
* Copyright (C) 2003-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc.utility;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.util.Collection;
/**
* OSCJavaToByteArrayConverter is a helper class that translates
* from Java types to their byte stream representations according to
* the OSC spec.
*
* The implementation is based on
* <a href=" http://www.emergent.de/">Markus Gaelli</a> and
* Iannis Zannos' OSC implementation in Squeak.
*
* This version includes bug fixes and improvements from
* Martin Kaltenbrunner and Alex Potsides.
*
* @author Chandrasekhar Ramakrishnan
* @author Martin Kaltenbrunner
* @author Alex Potsides
*/
public class OSCJavaToByteArrayConverter {
private ByteArrayOutputStream stream = new ByteArrayOutputStream();
private byte[] intBytes = new byte[4];
private byte[] longintBytes = new byte[8];
public OSCJavaToByteArrayConverter() {
}
/**
* Line up the Big end of the bytes to a 4 byte boundary.
* @return byte[]
* @param bytes byte[]
*/
private byte[] alignBigEndToFourByteBoundry(byte[] bytes) {
int mod = bytes.length % 4;
// if the remainder == 0 then return the bytes otherwise pad the bytes
// to lineup correctly
if (mod == 0) {
return bytes;
}
int pad = 4 - mod;
byte[] newBytes = new byte[pad + bytes.length];
// for (int i = 0; i < pad; i++)
// newBytes[i] = 0;
// for (int i = 0; i < bytes.length; i++)
// newBytes[pad + i] = bytes[i];
System.arraycopy(bytes, 0, newBytes, pad, bytes.length);
return newBytes;
}
/**
* Pad the stream to have a size divisible by 4.
*/
public void appendNullCharToAlignStream() {
int mod = stream.size() % 4;
int pad = 4 - mod;
for (int i = 0; i < pad; i++) {
stream.write(0);
}
}
/**
* Convert the contents of the output stream to a byte array.
* @return the byte array containing the byte stream
*/
public byte[] toByteArray() {
return stream.toByteArray();
}
/**
* Write bytes into the byte stream.
* @param bytes bytes to be written
*/
public void write(byte[] bytes) {
writeUnderHandler(bytes);
}
/**
* Write an integer into the byte stream.
* @param i the integer to be written
*/
public void write(int i) {
writeInteger32ToByteArray(i);
}
/**
* Write a float into the byte stream.
* @param f floating point number to be written
*/
public void write(Float f) {
writeInteger32ToByteArray(Float.floatToIntBits(f.floatValue()));
}
/**
* @param i the integer to be written
*/
public void write(Integer i) {
writeInteger32ToByteArray(i.intValue());
}
/**
* @param i the integer to be written
*/
public void write(BigInteger i) {
writeInteger64ToByteArray(i.longValue());
}
/**
* Write a string into the byte stream.
* @param aString the string to be written
*/
public void write(String aString) {
/*
XXX to be revised ...
int stringLength = aString.length();
// this is a deprecated method -- should use get char and convert
// the chars to bytes
// aString.getBytes(0, stringLength, stringBytes, 0);
aString.getChars(0, stringLength, stringChars, 0);
// pad out to align on 4 byte boundry
int mod = stringLength % 4;
int pad = 4 - mod;
for (int i = 0; i < pad; i++)
stringChars[stringLength++] = 0;
// convert the chars into bytes and write them out
for (int i = 0; i < stringLength; i++) {
stringBytes[i] = (byte) (stringChars[i] & 0x00FF);
}
stream.write(stringBytes, 0, stringLength);
*/
byte[] stringBytes = aString.getBytes();
// pad out to align on 4 byte boundry
int mod = aString.length() % 4;
int pad = 4 - mod;
byte[] newBytes = new byte[pad + stringBytes.length];
System.arraycopy(stringBytes, 0, newBytes, 0, stringBytes.length);
try {
stream.write(newBytes);
} catch (IOException e) {
throw new RuntimeException("You're screwed:"
+ " IOException writing to a ByteArrayOutputStream", e);
}
}
/**
* Write a char into the byte stream.
* @param c the character to be written
*/
public void write(char c) {
stream.write(c);
}
/**
* Write an object into the byte stream.
* @param anObject one of Float, String, Integer, BigInteger, or array of
* these.
*/
public void write(Object anObject) {
// Can't do switch on class
if (null == anObject) {
} else if (anObject instanceof Object[]) {
Object[] theArray = (Object[]) anObject;
for (int i = 0; i < theArray.length; ++i) {
write(theArray[i]);
}
} else if (anObject instanceof Float) {
write((Float) anObject);
} else if (anObject instanceof String) {
write((String) anObject);
} else if (anObject instanceof Integer) {
write((Integer) anObject);
} else if (anObject instanceof BigInteger) {
write((BigInteger) anObject);
}
}
/**
* Write the type tag for the type represented by the class
* @param c Class of a Java object in the arguments
*/
public void writeType(Class c) {
// A big ol' case statement -- what's polymorphism mean, again?
// I really wish I could extend the base classes!
// use the appropriate flags to tell SuperCollider what kind of
// thing it is looking at
if (Integer.class.equals(c)) {
stream.write('i');
} else if (java.math.BigInteger.class.equals(c)) {
stream.write('h');
} else if (Float.class.equals(c)) {
stream.write('f');
} else if (Double.class.equals(c)) {
stream.write('d');
} else if (String.class.equals(c)) {
stream.write('s');
} else if (Character.class.equals(c)) {
stream.write('c');
}
}
/**
* Write the types for an array element in the arguments.
* @param array array of base Objects
*/
public void writeTypesArray(Object[] array) {
// A big ol' case statement in a for loop -- what's polymorphism mean,
// again?
// I really wish I could extend the base classes!
for (int i = 0; i < array.length; i++) {
if (array[i] == null) {
} else if (Boolean.TRUE.equals(array[i])) {
// Create a way to deal with Boolean type objects
stream.write('T');
} else if (Boolean.FALSE.equals(array[i])) {
stream.write('F');
} else {
// this is an object -- write the type for the class
writeType(array[i].getClass());
}
}
}
/**
* Write types for the arguments.
* @param types the arguments to an OSCMessage
*/
public void writeTypes(Collection<Object> types) {
// A big ol' case statement in a for loop -- what's polymorphism mean,
// again?
// I really wish I could extend the base classes!
for (Object type : types) {
if (null == type) {
continue;
}
// if the array at i is a type of array write a [
// This is used for nested arguments
if (type.getClass().isArray()) {
stream.write('[');
// fill the [] with the SuperCollider types corresponding to
// the object (e.g., Object of type String needs -s).
writeTypesArray((Object[]) type);
// close the array
stream.write(']');
continue;
}
// Create a way to deal with Boolean type objects
if (Boolean.TRUE.equals(type)) {
stream.write('T');
continue;
}
if (Boolean.FALSE.equals(type)) {
stream.write('F');
continue;
}
// go through the array and write the superCollider types as shown
// in the above method.
// The classes derived here are used as the arg to the above method.
writeType(type.getClass());
}
// align the stream with padded bytes
appendNullCharToAlignStream();
}
/**
* Write bytes to the stream, catching IOExceptions and converting them to
* RuntimeExceptions.
* @param bytes byte[]
*/
private void writeUnderHandler(byte[] bytes) {
try {
stream.write(alignBigEndToFourByteBoundry(bytes));
} catch (IOException e) {
throw new RuntimeException("You're screwed:"
+ " IOException writing to a ByteArrayOutputStream");
}
}
/**
* Write a 32 bit integer to the byte array without allocating memory.
* @param value a 32 bit integer.
*/
private void writeInteger32ToByteArray(int value) {
//byte[] intBytes = new byte[4];
//I allocated the this buffer globally so the GC has less work
intBytes[3] = (byte)value; value >>>= 8;
intBytes[2] = (byte)value; value >>>= 8;
intBytes[1] = (byte)value; value >>>= 8;
intBytes[0] = (byte)value;
try {
stream.write(intBytes);
} catch (IOException ex) {
throw new RuntimeException("You're screwed:"
+ " IOException writing to a ByteArrayOutputStream", ex);
}
}
/**
* Write a 64 bit integer to the byte array without allocating memory.
* @param value a 64 bit integer.
*/
private void writeInteger64ToByteArray(long value) {
longintBytes[7] = (byte)value; value >>>= 8;
longintBytes[6] = (byte)value; value >>>= 8;
longintBytes[5] = (byte)value; value >>>= 8;
longintBytes[4] = (byte)value; value >>>= 8;
longintBytes[3] = (byte)value; value >>>= 8;
longintBytes[2] = (byte)value; value >>>= 8;
longintBytes[1] = (byte)value; value >>>= 8;
longintBytes[0] = (byte)value;
try {
stream.write(longintBytes);
} catch (IOException ex) {
throw new RuntimeException("You're screwed:"
+ " IOException writing to a ByteArrayOutputStream", ex);
}
}
}
@@ -1,77 +0,0 @@
/*
* Copyright (C) 2003, C. Ramakrishnan / Auracle.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc.utility;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import com.illposed.osc.OSCBundle;
import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPacket;
/**
* Dispatches OSCMessages to registered listeners.
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCPacketDispatcher {
private Map<String, OSCListener> addressToListener
= new HashMap<String, OSCListener>();
/**
*
*/
public OSCPacketDispatcher() {
}
public void addListener(String address, OSCListener listener) {
addressToListener.put(address, listener);
}
public void dispatchPacket(OSCPacket packet) {
if (packet instanceof OSCBundle) {
dispatchBundle((OSCBundle) packet);
} else {
dispatchMessage((OSCMessage) packet);
}
}
public void dispatchPacket(OSCPacket packet, Date timestamp) {
if (packet instanceof OSCBundle) {
dispatchBundle((OSCBundle) packet);
} else {
dispatchMessage((OSCMessage) packet, timestamp);
}
}
private void dispatchBundle(OSCBundle bundle) {
Date timestamp = bundle.getTimestamp();
OSCPacket[] packets = bundle.getPackets();
for (OSCPacket packet : packets) {
dispatchPacket(packet, timestamp);
}
}
private void dispatchMessage(OSCMessage message) {
dispatchMessage(message, null);
}
private void dispatchMessage(OSCMessage message, Date time) {
for (Entry<String, OSCListener> addrList : addressToListener.entrySet()) {
if (message.getAddress().matches(addrList.getKey())) {
addrList.getValue().acceptMessage(time, message);
}
}
}
}
@@ -1,53 +0,0 @@
package galsasson.mode.tweak;
import java.net.InetAddress;
import java.util.ArrayList;
import com.illposed.osc.*;
public class OSCSender {
public static void sendFloat(int index, float val, int port) throws Exception
{
OSCPortOut sender = new OSCPortOut(InetAddress.getByName("localhost"), port);
ArrayList<Object> args = new ArrayList<Object>();
args.add(Integer.valueOf(index));
args.add(Float.valueOf(val));
OSCMessage msg = new OSCMessage("/tm_change_float", args);
try {
sender.send(msg);
} catch (Exception e) {
System.out.println("TweakMode: error sending new value of float " + index);
}
}
public static void sendInt(int index, int val, int port) throws Exception
{
OSCPortOut sender = new OSCPortOut(InetAddress.getByName("localhost"), port);
ArrayList<Object> args = new ArrayList<Object>();
args.add(Integer.valueOf(index));
args.add(Integer.valueOf(val));
OSCMessage msg = new OSCMessage("/tm_change_int", args);
try {
sender.send(msg);
} catch (Exception e) {
System.out.println("TweakMode: error sending new value of int " + index);
System.out.println(e.toString());
}
}
public static void sendLong(int index, long val, int port) throws Exception
{
OSCPortOut sender = new OSCPortOut(InetAddress.getByName("localhost"), port);
ArrayList<Object> args = new ArrayList<Object>();
args.add(Integer.valueOf(index));
args.add(Long.valueOf(val));
OSCMessage msg = new OSCMessage("/tm_change_long", args);
try {
sender.send(msg);
} catch (Exception e) {
System.out.println("TweakMode: error sending new value of long " + index);
System.out.println(e.toString());
}
}
}
+67 -102
View File
@@ -1,17 +1,13 @@
package galsasson.mode.tweak;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SketchParser
{
public ArrayList<ColorControlBox> colorBoxes[];
public ArrayList<Handle> allHandles[];
public class SketchParser {
public ArrayList<ColorControlBox>[] colorBoxes;
public ArrayList<Handle>[] allHandles;
int intVarCount;
int floatVarCount;
@@ -21,10 +17,10 @@ public class SketchParser
boolean requiresComment;
ArrayList<ColorMode> colorModes;
ArrayList<Range> scientificNotations[];
ArrayList<Range>[] scientificNotations;
public SketchParser(String[] codeTabs, boolean requiresComment)
{
public SketchParser(String[] codeTabs, boolean requiresComment) {
this.codeTabs = codeTabs;
this.requiresComment = requiresComment;
intVarCount=0;
@@ -49,8 +45,8 @@ public class SketchParser
handleMultipleColorModes();
}
public void addAllNumbers()
{
public void addAllNumbers() {
allHandles = new ArrayList[codeTabs.length];
addAllDecimalNumbers();
addAllHexNumbers();
@@ -60,25 +56,23 @@ public class SketchParser
}
}
/**
* Get a list of all the numbers in this sketch
* @return
* list of all numbers in the sketch (excluding hexadecimals)
*/
private void addAllDecimalNumbers()
{
/* for every number found:
* save its type (int/float), name, value and position in code.
*/
private void addAllDecimalNumbers() {
// for every number found:
// save its type (int/float), name, value and position in code.
Pattern p = Pattern.compile("[\\[\\{<>(),\\t\\s\\+\\-\\/\\*^%!|&=?:~]\\d+\\.?\\d*");
for (int i=0; i<codeTabs.length; i++)
{
for (int i = 0; i < codeTabs.length; i++) {
allHandles[i] = new ArrayList<Handle>();
String c = codeTabs[i];
Matcher m = p.matcher(c);
while (m.find())
{
while (m.find()) {
boolean forceFloat = false;
int start = m.start()+1;
int end = m.end();
@@ -536,8 +530,8 @@ public class SketchParser
}
}
public ArrayList<Range>[] getAllScientificNotations()
{
public ArrayList<Range>[] getAllScientificNotations() {
ArrayList<Range> notations[] = new ArrayList[codeTabs.length];
Pattern p = Pattern.compile("[+\\-]?(?:0|[1-9]\\d*)(?:\\.\\d*)?[eE][+\\-]?\\d+");
@@ -554,20 +548,17 @@ public class SketchParser
}
public static boolean containsTweakComment(String[] codeTabs)
{
public static boolean containsTweakComment(String[] codeTabs) {
for (String tab : codeTabs) {
if (hasTweakComment(tab)) {
return true;
}
}
return false;
}
public static boolean lineHasTweakComment(int pos, String code)
{
static public boolean lineHasTweakComment(int pos, String code) {
int lineEnd = getEndOfLine(pos, code);
if (lineEnd < 0) {
return false;
@@ -576,62 +567,48 @@ public class SketchParser
String line = code.substring(pos, lineEnd);
return hasTweakComment(line);
}
private static boolean hasTweakComment(String code)
{
static private boolean hasTweakComment(String code) {
Pattern p = Pattern.compile("\\/\\/.*tweak", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(code);
if (m.find()) {
return true;
}
return false;
return m.find();
}
private boolean isNegativeSign(int pos, String code)
{
static private boolean isNegativeSign(int pos, String code) {
// go back and look for ,{[(=?+-/*%<>:&|^!~
for (int i=pos; i>=0; i--)
{
for (int i = pos; i >= 0; i--) {
char c = code.charAt(i);
if (c == ' ' || c == '\t') {
continue;
}
if (c==',' || c=='{' || c=='[' || c=='(' ||
c=='=' || c=='?' || c=='+' || c=='-' ||
c=='/' || c=='*' || c=='%' || c=='<' ||
c=='>' || c==':' || c=='&' || c=='|' ||
c=='^' || c=='!' || c=='~') {
return true;
}
else {
return false;
if (c != ' ' && c != '\t') {
return (c==',' || c=='{' || c=='[' || c=='(' ||
c=='=' || c=='?' || c=='+' || c=='-' ||
c=='/' || c=='*' || c=='%' || c=='<' ||
c=='>' || c==':' || c=='&' || c=='|' ||
c=='^' || c=='!' || c=='~');
}
}
return false;
}
private int getNumDigitsAfterPoint(String number)
{
static private int getNumDigitsAfterPoint(String number) {
Pattern p = Pattern.compile("\\.[0-9]+");
Matcher m = p.matcher(number);
if (m.find()) {
return m.end() - m.start() - 1;
}
else {
return 0;
}
return 0;
}
private int countLines(String str)
{
static private int countLines(String str) {
String[] lines = str.split("\r\n|\n\r|\n|\r");
return lines.length;
}
/**
* Are we inside a string? (TODO: ignore comments in the code)
* @param pos
@@ -640,12 +617,10 @@ public class SketchParser
* the code
* @return
*/
private boolean isInsideString(int pos, String code)
{
static private boolean isInsideString(int pos, String code) {
int quoteNum = 0; // count '"'
for (int c = pos; c>=0 && code.charAt(c) != '\n'; c--)
{
for (int c = pos; c>=0 && code.charAt(c) != '\n'; c--) {
if (code.charAt(c) == '"') {
quoteNum++;
}
@@ -665,8 +640,7 @@ public class SketchParser
* @return
* true if the position 'pos' is in global scope in the code 'code'
*/
private boolean isGlobal(int pos, String code)
{
static private boolean isGlobal(int pos, String code) {
int curlyScope = 0; // count '{-}'
for (int c=pos; c>=0; c--)
@@ -711,8 +685,7 @@ public class SketchParser
return false;
};
private boolean isInComment(int pos, String code)
{
static private boolean isInComment(int pos, String code) {
// look for one line comment
int lineStart = getStartOfLine(pos, code);
if (lineStart < 0) {
@@ -723,17 +696,16 @@ public class SketchParser
}
// TODO: look for block comments
return false;
}
public static int getEndOfLine(int pos, String code)
{
static private int getEndOfLine(int pos, String code) {
return code.indexOf("\n", pos);
}
public static int getStartOfLine(int pos, String code)
{
static private int getStartOfLine(int pos, String code) {
while (pos >= 0) {
if (code.charAt(pos) == '\n') {
return pos+1;
@@ -744,14 +716,14 @@ public class SketchParser
return 0;
}
/** returns the object of the function starting at 'pos'
*
* @param pos
* @param code
* @return
*/
private String getObject(int pos, String code)
{
static private String getObject(int pos, String code) {
boolean readObject = false;
String obj = "this";
@@ -772,30 +744,28 @@ public class SketchParser
obj = code.charAt(pos) + obj;
}
}
return obj;
}
public static int getSetupStart(String code)
{
Pattern p = Pattern.compile("void[\\s\\t\\r\\n]*setup[\\s\\t]*\\(\\)[\\s\\t\\r\\n]*\\{");
Matcher m = p.matcher(code);
if (m.find()) {
return m.end();
}
return -1;
}
// static private int getSetupStart(String code) {
// Pattern p = Pattern.compile("void[\\s\\t\\r\\n]*setup[\\s\\t]*\\(\\)[\\s\\t\\r\\n]*\\{");
// Matcher m = p.matcher(code);
//
// if (m.find()) {
// return m.end();
// }
//
// return -1;
// }
private String replaceString(String str, int start, int end, String put)
{
return str.substring(0, start) + put + str.substring(end, str.length());
}
// private String replaceString(String str, int start, int end, String put) {
// return str.substring(0, start) + put + str.substring(end, str.length());
// }
class Range
{
class Range {
int start;
int end;
@@ -804,13 +774,8 @@ public class SketchParser
end = e;
}
public boolean contains(int v)
{
if (v>=start && v<end) {
return true;
}
return false;
public boolean contains(int v) {
return v >= start && v < end;
}
}
}
+2 -2
View File
@@ -55,6 +55,8 @@ X sketches should only write to the console of their editor window
X https://github.com/processing/processing/issues/153
X https://github.com/processing/processing/issues/2858
X https://github.com/processing/processing/pull/2827
X extend translations and update German language
X https://github.com/processing/processing/pull/2949
pulls (net)
X NullPointerException message when Server writes to a disconnected client
@@ -66,8 +68,6 @@ X https://github.com/processing/processing/pull/2588
_ Add support for localizing contributions
_ https://github.com/processing/processing/pull/2833
_ Fix renaming from RGB to Rgb.java and others
_ https://github.com/processing/processing/pull/2825
_ check on pull for mnemonics
_ https://github.com/processing/processing/pull/2382