Permalink
Browse files

adding OscBundle event method

  • Loading branch information...
1 parent d6d9225 commit 63061a726b8b5a278cb1a1231b54fb576015afbe @sojamo committed Nov 19, 2015
View
@@ -2,10 +2,12 @@ target/
.classpath
.project
.settings/
+.externalToolBuilders/
distribution/
lib/
data/
TODO
NOTES
bin/
reference/
+materials/
View
@@ -2,3 +2,17 @@ oscp5
=====
An Open Sound Control (OSC) implementation for java and processing.org
+
+
+
+
+## <a name="issues"></a>Digital Object Identifiers
+
+In case you make use of OscP5 in your research publication, please use the DOI below as a reference.
+
+Digital Object Identifiers (DOI) are the backbone of the academic reference and metrics system which allows researchers writing software to make their work they share on GitHub citable by archiving one of their GitHub repositories and assigning a DOI with the data archiving tool Zenodo [(link)](https://guides.github.com/activities/citable-code/).
+
+
+[![DOI](https://zenodo.org/badge/11256/sojamo/oscp5.svg)](http://dx.doi.org/10.5281/zenodo.16308)
+
+Copyright 2004-2015 Andreas Schlegel
@@ -0,0 +1,39 @@
+import oscP5.*;
+import netP5.*;
+
+OscP5 osc;
+NetAddress addr;
+
+void setup() {
+ osc = new OscP5(this, 12000);
+ addr = new NetAddress("127.0.0.1", 12000);
+}
+
+
+void draw() {
+}
+
+void keyPressed() {
+ switch(key) {
+ case('1'):
+ osc.send(addr, "/test", 1, 2, 3);
+ break;
+ case('2'):
+ OscBundle bundle = new OscBundle();
+ bundle.add(new OscMessage("/m/1", 1));
+ bundle.add(new OscMessage("/m/2", 2));
+ osc.send(addr, bundle);
+ break;
+ }
+}
+
+void oscEvent(OscBundle theBundle) {
+ println("received a bundle", theBundle);
+ for (OscMessage m : theBundle.get()) {
+ oscEvent(m);
+ }
+}
+
+void oscEvent(OscMessage theMessage) {
+ println("received a message", theMessage);
+}
@@ -0,0 +1,39 @@
+import oscP5.*;
+import netP5.*;
+
+OscP5 osc;
+NetAddress addr;
+
+void setup() {
+ osc = new OscP5(this, 12000);
+ addr = new NetAddress("127.0.0.1", 12000);
+}
+
+
+void draw() {
+}
+
+void keyPressed() {
+ switch(key) {
+ case('1'):
+ osc.send(addr, "/test", 1, 2, 3);
+ break;
+ case('2'):
+ OscBundle bundle = new OscBundle();
+ bundle.add(new OscMessage("/m/1", 1));
+ bundle.add(new OscMessage("/m/2", 2));
+ osc.send(addr, bundle);
+ break;
+ }
+}
+
+void oscEvent(OscBundle theBundle) {
+ println("received a bundle", theBundle);
+ for (OscMessage m : theBundle.get()) {
+ oscEvent(m); /* forward each message inside the bundle to oscEvent(OscMessage) */
+ }
+}
+
+void oscEvent(OscMessage theMessage) {
+ println("received a message", theMessage);
+}
View
@@ -45,11 +45,11 @@
<property name="author" value="Andreas Schlegel"/>
<property name="copyright" value="(c) 2004-2015"/>
<property name="libraryName" value="oscP5"/>
- <property name="versionNumber" value="2.0.3"/>
+ <property name="versionNumber" value="2.0.4"/>
<property name="yourLink" value="http://www.sojamo.de" />
<property name="keywords" value="osc,networking" />
<property name="tested:platform" value="osx, windows, linux" />
- <property name="tested:processingVersion" value="2.2.1" />
+ <property name="tested:processingVersion" value="3.0.1" />
<property name="tested:dependencies" value="none" />
<property name="source:host" value="github" />
<property name="source:url" value="https://github.com/sojamo/oscp5" />
@@ -180,24 +180,24 @@
</copy>
<mkdir dir="${dist}/${libraryName}-${versionNumber}" />
- <mkdir dir="${dist}/${libraryName}-${versionNumber}/controlP5" />
- <mkdir dir="${dist}/${libraryName}-${versionNumber}/controlP5/src" />
- <mkdir dir="${dist}/${libraryName}-${versionNumber}/controlP5/examples" />
- <mkdir dir="${dist}/${libraryName}-${versionNumber}/controlP5/reference" />
- <mkdir dir="${dist}/${libraryName}-${versionNumber}/controlP5/library" />
+ <mkdir dir="${dist}/${libraryName}-${versionNumber}/oscP5" />
+ <mkdir dir="${dist}/${libraryName}-${versionNumber}/oscP5/src" />
+ <mkdir dir="${dist}/${libraryName}-${versionNumber}/oscP5/examples" />
+ <mkdir dir="${dist}/${libraryName}-${versionNumber}/oscP5/reference" />
+ <mkdir dir="${dist}/${libraryName}-${versionNumber}/oscP5/library" />
<mkdir dir="${dist}/tmp" />
<mkdir dir="${dist}/tmp/${libraryName}" />
- <copy todir="${dist}/${libraryName}-${versionNumber}/controlP5/src"><fileset dir="${dist}/src"/></copy>
- <copy todir="${dist}/${libraryName}-${versionNumber}/controlP5/examples"><fileset dir="${dist}/examples"/></copy>
- <copy todir="${dist}/${libraryName}-${versionNumber}/controlP5/reference"><fileset dir="${dist}/reference"/></copy>
- <copy todir="${dist}/${libraryName}-${versionNumber}/controlP5/library"><fileset dir="${dist}/library"/></copy>
+ <copy todir="${dist}/${libraryName}-${versionNumber}/oscP5/src"><fileset dir="${dist}/src"/></copy>
+ <copy todir="${dist}/${libraryName}-${versionNumber}/oscP5/examples"><fileset dir="${dist}/examples"/></copy>
+ <copy todir="${dist}/${libraryName}-${versionNumber}/oscP5/reference"><fileset dir="${dist}/reference"/></copy>
+ <copy todir="${dist}/${libraryName}-${versionNumber}/oscP5/library"><fileset dir="${dist}/library"/></copy>
<copyfile src="${resources}/install_instructions.txt" dest="${dist}/tmp/install_instructions.txt"/>
- <copyfile src="${resources}/library.properties" dest="${dist}/tmp/controlP5/library.properties"/>
+ <copyfile src="${resources}/library.properties" dest="${dist}/tmp/oscP5/library.properties"/>
<move todir="${dist}/tmp/${libraryName}">
- <fileset dir="${dist}/${libraryName}-${versionNumber}/controlP5" />
+ <fileset dir="${dist}/${libraryName}-${versionNumber}/oscP5" />
</move>
<!-- zip the distribution of the library -->
@@ -1,4 +1,4 @@
-How to install library ##library.name##
+How to install library oscP5
Install with the "Add Library..." tool
@@ -26,19 +26,19 @@ By default the following locations are used for your sketchbook folder:
For Windows users, the sketchbook folder is located inside
'My Documents'/Processing.
-The folder structure for library ##library.name## should be as follows:
+The folder structure for library oscP5 should be as follows:
Processing
libraries
- ##library.name##
+ oscP5
examples
library
- ##library.name##.jar
+ oscP5.jar
reference
src
Some folders like "examples" or "src" might be missing. After library
-##library.name## has been successfully installed, restart the Processing
+oscP5 has been successfully installed, restart the Processing
application.
View
@@ -0,0 +1,4 @@
+cd $HOME/Documents/workspace/oscP5/target/classes
+jar cf ../oscP5.jar .
+cp ../oscP5.jar $HOME/Documents/Processing3/libraries/oscP5/library
+echo "oscP5 compiled on $(date)"
@@ -1,20 +0,0 @@
-2013-10-29 Andreas Schlegel
-
- * src netP5.StringUtils.java:
- removed.
-
-2013-10-29 Andreas Schlegel
-
- * src netP5.*:
- massive rework on network protocol classes
-
-2013-07-21 Andreas Schlegel
-
- * src netP5.NetInfo.java:
- adding method getNetworkInterfaces() which returns a map of available network interfaces
- including name, inetaddress, or mac.
-
- * version 2.0.0
-
- * major renovation going on here, streamlining and cleaning up.
- This version is not backwards compatible with 0.9.9 and earlier.
@@ -10,22 +10,23 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
+ * Boston, MA 02111-1307 USA
*
- * @author ##author##
- * @modified ##date##
- * @version ##version##
+ * @author ##author##
+ * @modified ##date##
+ * @version ##version##
*/
package oscP5;
import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import netP5.Bytes;
@@ -37,9 +38,7 @@
public class OscBundle extends OscPacket {
protected static final int BUNDLE_HEADER_SIZE = 16;
-
protected static final byte[] BUNDLE_AS_BYTES = { 0x23 , 0x62 , 0x75 , 0x6E , 0x64 , 0x6C , 0x65 , 0x00 };
-
private int _myMessageSize = 0;
public OscBundle( ) {
@@ -48,6 +47,10 @@ public OscBundle( ) {
OscBundle( Map m ) {
_myMessageSize = parseBundle( m );
+ _myRef = m.get( "socket-ref" );
+ hostAddress = s( m.get( "socket-address" ) , null );
+ port = i( m.get( "socket-port" ) , 0 );
+ localPort = i( m.get( "local-port" ) , 0 );
}
public OscBundle add( OscMessage ... theOscMessages ) {
@@ -82,6 +85,17 @@ public int size( ) {
return _myMessageSize;
}
+ public OscMessage get( int theIndex ) {
+ if ( theIndex < 0 || theIndex >= size( ) ) {
+ return null;
+ }
+ return messages.get( theIndex );
+ }
+
+ public List< OscMessage > get( ) {
+ return messages;
+ }
+
/**
* TODO set the timetag of an osc bundle. timetags are used to synchronize events and execute
* events at a given time in the future or immediately. timetags can only be set for osc
@@ -115,4 +129,8 @@ public static long now( ) {
}
return myBytes;
}
+
+ public final String toString( ) {
+ return String.format( "OscBundle{hostAddress=%s, port=%s, messages=%s}" , hostAddress , port , size( ) );
+ }
}
Oops, something went wrong.

0 comments on commit 63061a7

Please sign in to comment.