Skip to content

Commit

Permalink
adding OscBundle event method
Browse files Browse the repository at this point in the history
  • Loading branch information
sojamo committed Nov 19, 2015
1 parent d6d9225 commit 63061a7
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 282 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ target/
.classpath
.project
.settings/
.externalToolBuilders/
distribution/
lib/
data/
TODO
NOTES
bin/
reference/
materials/
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions examples/basics-without-comments/oscP5bundle/oscP5bundle.pde
Original file line number Diff line number Diff line change
@@ -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);
}
39 changes: 39 additions & 0 deletions examples/basics/oscP5bundle/oscP5bundle.pde
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 13 additions & 13 deletions resources/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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 -->
Expand Down
10 changes: 5 additions & 5 deletions resources/install_instructions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
How to install library ##library.name##
How to install library oscP5


Install with the "Add Library..." tool
Expand Down Expand Up @@ -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.


Expand Down
4 changes: 4 additions & 0 deletions resources/jar.sh
Original file line number Diff line number Diff line change
@@ -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)"
20 changes: 0 additions & 20 deletions src/main/java/netP5/changelog.txt

This file was deleted.

32 changes: 25 additions & 7 deletions src/main/java/oscP5/OscBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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( ) {
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -115,4 +129,8 @@ public byte[] getBytes( ) {
}
return myBytes;
}

public final String toString( ) {
return String.format( "OscBundle{hostAddress=%s, port=%s, messages=%s}" , hostAddress , port , size( ) );
}
}
Loading

0 comments on commit 63061a7

Please sign in to comment.