Skip to content

Commit

Permalink
initial add of source code (from r49149 in Subversion)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed May 4, 2011
1 parent 958dc55 commit 442a444
Show file tree
Hide file tree
Showing 19 changed files with 1,324 additions and 0 deletions.
98 changes: 98 additions & 0 deletions Makefile
@@ -0,0 +1,98 @@
.DELETE_ON_ERROR:

# NETLOGO is the directory containing the NetLogo install we are
# building against. if not specified, it defaults to two dirs up from
# this directory
ifeq ($(origin NETLOGO), undefined)
NETLOGO =../..
endif

# JAVA_HOME is the base of the java installation we will build with
ifeq ($(origin JAVA_HOME), undefined)
$(error JAVA_HOME must be defined.)
endif

ifeq ($(origin SCALA_JAR), undefined)
SCALA_JAR = $(NETLOGO)/lib/scala-library.jar
endif


JAVA = $(JAVA_HOME)/bin/java
JAVAC = $(JAVA_HOME)/bin/javac
JAVACARGS=-g -deprecation -Xlint:all -Xlint:-serial -Xlint:-fallthrough -Xlint:-path -encoding us-ascii -source 1.5 -target 1.5
JAR = $(JAVA_HOME)/bin/jar
SLASH = /
COLON = :


OS = $(shell uname)

ifneq (,$(findstring CYGWIN,$(OS)))
SLASH = \\
COLON = \;
endif

SRCDIR = src
CLASSDIR = classes
LIBDIR = lib
DOCDIR = doc

# the name of the extension
EXTENSION=sound

# a list of external jars the extension needs to build and ship with
EXTERNAL_JARS=

# a space separated list of directories to include in the tarball
DISTDIRS=

# a space separated list of files to include in the tarball
DISTFILES=soundbank-min.gm

JAVAFILES = $(wildcard $(SRCDIR)/*.java)
CLASSFILES = $(patsubst $(SRCDIR)/%.java,$(CLASSDIR)/%.class,$(JAVAFILES))

empty=
space:=$(empty) $(empty)
NLJAR=$(NETLOGO)$(SLASH)NetLogo.jar
CLASSPATH=$(NLJAR)$(COLON)$(subst $(space),$(COLON),$(EXTERNAL_JARS))$(COLON)$(USERCLASSPATH)

BUILDPREFIX=build
BUILDDIR=$(BUILDPREFIX)/$(EXTENSION)
INSTALL=install


$(EXTENSION).jar: $(JAVAFILES) $(NLJAR) $(EXTERNAL_JARS) manifest.txt Makefile
mkdir -p $(CLASSDIR)
$(JAVAC) $(JAVACARGS) -classpath $(CLASSPATH)$(COLON)$(SCALA_JAR) -d $(CLASSDIR) $(JAVAFILES)
$(JAR) cmf manifest.txt $(EXTENSION).jar -C $(CLASSDIR) .

.PHONY: clean
clean:
rm -rf $(CLASSDIR)
rm -f $(EXTENSION).jar
rm -rf $(BUILDPREFIX)
rm -f $(EXTENSION).tgz

.PHONY: prerelease
prerelease: $(EXTENSION).jar docs lib
mkdir -p $(BUILDDIR)
$(foreach jar, $(EXTERNAL_JARS), cp $(jar) $(BUILDDIR);)
$(foreach distfile, $(DISTFILES), cp $(distfile) $(BUILDDIR);)
$(foreach distdir, $(DISTDIRS), cp -r $(distdir) $(BUILDDIR);)
if [ -d $(DOCDIR) ]; then cp -r $(DOCDIR) $(BUILDDIR); fi
if [ -d $(LIBDIR) ]; then cp -r $(LIBDIR) $(BUILDDIR); fi
if [ -d $(SRCDIR) ]; then cp -r $(SRCDIR) $(BUILDDIR); fi
if [ -f README.txt ]; then cp -r README.txt $(BUILDDIR); fi
cp $(EXTENSION).jar $(BUILDDIR)
cp Makefile config.mk manifest.txt $(BUILDDIR)
if test -n "$$(find . -maxdepth 1 -name '*.nlogo' -print -quit)" ; then cp *.nlogo $(BUILDDIR); fi
if test -n "$$(find . -maxdepth 1 -name '*.nlogo3d' -print -quit)" ; then cp *.nlogo3d $(BUILDDIR); fi
(cd $(BUILDPREFIX); /usr/bin/find . -name CVS -print0 | xargs -0 rm -rf)
(cd $(BUILDPREFIX); /usr/bin/find . -name .svn -print0 | xargs -0 rm -rf)

$(EXTENSION).tgz: prerelease
tar czfC $@ $(BUILDPREFIX) $(EXTENSION)

$(EXTENSION).zip: prerelease
cd $(BUILDPREFIX); zip -r ../$(EXTENSION).zip $(EXTENSION)
4 changes: 4 additions & 0 deletions manifest.txt
@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Extension-Name: sound
Class-Manager: org.nlogo.extensions.sound.SoundExtension
NetLogo-Extension-API-Version: 5.0
Binary file added soundbank-min.gm
Binary file not shown.
34 changes: 34 additions & 0 deletions src/Dump.java
@@ -0,0 +1,34 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound ;

/**
* Returns debug information about the state of the synthesizer.
**/
public class Dump
implements org.nlogo.api.Reporter
{
public String getAgentClassString()
{
return "OTP" ;
}

public org.nlogo.api.Syntax getSyntax()
{
return org.nlogo.api.Syntax.reporterSyntax(
org.nlogo.api.Syntax.TYPE_STRING
);
}

public boolean getSwitchesBoolean() { return false; }

public org.nlogo.api.Reporter newInstance( String name )
{
return new Dump() ;
}

public Object report( org.nlogo.api.Argument args[] , org.nlogo.api.Context context )
{
return SoundExtension.dump();
}
}
38 changes: 38 additions & 0 deletions src/ListDrums.java
@@ -0,0 +1,38 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound ;

import org.nlogo.api.LogoList;

/**
* NetLogo command returns the names of all the available drums.
**/
public class ListDrums
implements org.nlogo.api.Reporter
{
public String getAgentClassString()
{
return "OTP" ;
}

public org.nlogo.api.Syntax getSyntax()
{
return org.nlogo.api.Syntax.reporterSyntax( org.nlogo.api.Syntax.TYPE_LIST ) ;
}

public boolean getSwitchesBoolean()
{
return false;
}

public org.nlogo.api.Reporter newInstance( String name )
{
return new ListDrums() ;
}

public Object report( org.nlogo.api.Argument args[] , org.nlogo.api.Context context )
throws org.nlogo.api.ExtensionException , org.nlogo.api.LogoException
{
return LogoList.fromJava( SoundExtension.DRUM_NAMES );
}
}
38 changes: 38 additions & 0 deletions src/ListInstruments.java
@@ -0,0 +1,38 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound;

import org.nlogo.api.LogoList;

/**
* NetLogo command returns the names of all the available instruments.
**/
public class ListInstruments
implements org.nlogo.api.Reporter
{
public String getAgentClassString()
{
return "OTP";
}

public org.nlogo.api.Syntax getSyntax()
{
return org.nlogo.api.Syntax.reporterSyntax( org.nlogo.api.Syntax.TYPE_LIST );
}

public boolean getSwitchesBoolean()
{
return false;
}

public org.nlogo.api.Reporter newInstance( String name )
{
return new ListInstruments();
}

public Object report( org.nlogo.api.Argument args[] , org.nlogo.api.Context context )
throws org.nlogo.api.ExtensionException , org.nlogo.api.LogoException
{
return LogoList.fromJava( SoundExtension.INSTRUMENT_NAMES );
}
}
60 changes: 60 additions & 0 deletions src/LoopSound.java
@@ -0,0 +1,60 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound ;

import java.net.URL ;

/**
* NetLogo command loops a sound file
**/
public class LoopSound
implements org.nlogo.api.Command
{
public String getAgentClassString()
{
return "OTP" ;
}

public org.nlogo.api.Syntax getSyntax()
{
int[] right =
{
org.nlogo.api.Syntax.TYPE_STRING,
};
return org.nlogo.api.Syntax.commandSyntax( right ) ;
}

public boolean getSwitchesBoolean()
{
return false;
}

public org.nlogo.api.Command newInstance( String name )
{
return new LoopSound() ;
}


public void perform( org.nlogo.api.Argument args[] , org.nlogo.api.Context context )
throws org.nlogo.api.ExtensionException , org.nlogo.api.LogoException
{
try {
String soundpath = args[ 0 ].getString() ;
URL soundurl ;
soundpath = context.attachCurrentDirectory( soundpath ) ;
try {
soundurl = new URL( context.attachCurrentDirectory( soundpath ) ) ;
}
catch( java.net.MalformedURLException ex )
{
soundurl = new URL("file", "", soundpath ) ;
}
SoundExtension.loopSound( soundurl ) ;
}
catch( java.net.MalformedURLException ex )
{
throw new org.nlogo.api.ExtensionException
( "Unable to open sound sample: " + ex.getMessage() ) ;
}
}
}
43 changes: 43 additions & 0 deletions src/PlayDrum.java
@@ -0,0 +1,43 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound ;

/**
* NetLogo command plays a drum.
**/
public class PlayDrum
implements org.nlogo.api.Command
{
public String getAgentClassString()
{
return "OTP" ;
}

public org.nlogo.api.Syntax getSyntax()
{
int[] right =
{
org.nlogo.api.Syntax.TYPE_STRING,
org.nlogo.api.Syntax.TYPE_NUMBER
};
return org.nlogo.api.Syntax.commandSyntax( right ) ;
}

public boolean getSwitchesBoolean()
{
return false;
}

public org.nlogo.api.Command newInstance( String name )
{
return new PlayDrum() ;
}

public void perform( org.nlogo.api.Argument args[], org.nlogo.api.Context context )
throws org.nlogo.api.ExtensionException , org.nlogo.api.LogoException
{
int drum = SoundExtension.getDrum( args[ 0 ].getString() );
int velocity = args[ 1 ].getIntValue();
SoundExtension.playDrum( drum, velocity );
}
}
51 changes: 51 additions & 0 deletions src/PlayNote.java
@@ -0,0 +1,51 @@
/** (c) 2004-2011 Uri Wilensky. See README.txt for terms of use. **/

package org.nlogo.extensions.sound ;

/**
* NetLogo command plays a note for a specified duration.
**/
public class PlayNote
implements org.nlogo.api.Command
{
public String getAgentClassString()
{
return "OTP" ;
}

public org.nlogo.api.Syntax getSyntax()
{
int[] right =
{
org.nlogo.api.Syntax.TYPE_STRING,
org.nlogo.api.Syntax.TYPE_NUMBER,
org.nlogo.api.Syntax.TYPE_NUMBER,
org.nlogo.api.Syntax.TYPE_NUMBER
};
return org.nlogo.api.Syntax.commandSyntax( right ) ;
}

public boolean getSwitchesBoolean()
{
return false;
}

public org.nlogo.api.Command newInstance( String name )
{
return new PlayNote() ;
}


public void perform( org.nlogo.api.Argument args[] , org.nlogo.api.Context context )
throws org.nlogo.api.ExtensionException , org.nlogo.api.LogoException
{
int instrument = SoundExtension.getInstrument( args[ 0 ].getString() );
int note = args[ 1 ].getIntValue();
int velocity = args[ 2 ].getIntValue();

// convert duration from seconds to milliseconds
int duration = Math.round( (float) args[ 3 ].getDoubleValue() * (float) 1000.0 );

SoundExtension.playNote( instrument, note, velocity, duration );
}
}

0 comments on commit 442a444

Please sign in to comment.