Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit bf75e01d2aad2d6d0b8b6b1d91451a34382b9a1d @ycros committed Nov 15, 2011
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/groovy" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/groovy" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: org.apache.commons:commons-math:2.2" level="project" />
+ <orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.6.3" level="project" />
+ <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.3" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.spockframework:spock-core:0.5-groovy-1.8" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.groovy:groovy-all:1.8.4" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit-dep:4.8.2" level="project" />
+ </component>
+</module>
+
117 pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.monome.pages</groupId>
+ <artifactId>pages-3</artifactId>
+ <version>1.0</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <version>1.3</version>
+
+ <executions>
+ <execution>
+ <configuration>
+ <providerSelection>1.7</providerSelection>
+ </configuration>
+ <goals>
+ <goal>generateStubs</goal>
+ <goal>compile</goal>
+ <goal>generateTestStubs</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.gmaven.runtime</groupId>
+ <artifactId>gmaven-runtime-1.7</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>org.monome.pages.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
+ <version>2.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.spockframework</groupId>
+ <artifactId>spock-core</artifactId>
+ <version>0.5-groovy-1.8</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.4</version>
+ </dependency>
+ </dependencies>
+
+</project>
@@ -0,0 +1,63 @@
+package org.monome.pages
+
+import org.monome.pages.time.MusicalDuration
+import org.monome.pages.time.MusicalScheduler
+import javax.sound.midi.MidiDevice
+import javax.sound.midi.spi.MidiDeviceProvider
+import javax.sound.midi.MidiSystem
+import com.sun.media.sound.RealTimeSequencerProvider
+import javax.sound.midi.MidiMessage
+import javax.sound.midi.ShortMessage
+import org.monome.pages.midi.MidiManager
+
+abstract class ScriptBase extends Script {
+
+ static {
+ Number.metaClass {
+ getTh {-> new MusicalDuration(1, delegate)}
+ getNd {-> delegate.th}
+ }
+ }
+
+ MusicalDuration md(num, den) {
+ new MusicalDuration(num, den)
+ }
+
+ def whole = 1.th
+ def half = 2.th
+ def qtr = 4.th
+
+ def mm = MidiManager.getInstance()
+
+ def every(MusicalDuration duration, Closure closure) {
+ MusicalScheduler.getInstance().schedule(duration, closure)
+ }
+
+ def noteon(int note, int velocity) {
+ mm.noteOn(note, velocity)
+ }
+
+ def noteoff(int note, int velocity) {
+ mm.noteOff(note, velocity)
+ }
+
+ def once(MusicalDuration delay, Closure closure) {
+ def first = true
+ def task = null
+ task = MusicalScheduler.getInstance().schedule(delay) {
+ if (first) {
+ first = false
+ } else {
+ closure.call()
+ task.stop()
+ }
+ }
+ }
+
+ def play(int note, int velocity, MusicalDuration duration) {
+ noteon(note, velocity)
+ once(duration) {
+ noteoff(note, velocity)
+ }
+ }
+}
@@ -0,0 +1,8 @@
+package junk;
+
+import java.util.List;
+
+public class Device {
+ public Page currentPage;
+ public List<Page> attachedPages;
+}
@@ -0,0 +1,23 @@
+package junk;
+
+import java.util.Map;
+
+public class DeviceRequirement {
+ Class<Device> deviceClass;
+ int amount;
+ Map<String, String> parameters;
+
+ public DeviceRequirement(Class<Device> deviceClass) {
+ this(deviceClass, null);
+ }
+
+ public DeviceRequirement(Class<Device> deviceClass, Map<String, String> parameters) {
+ this(deviceClass, 1, parameters);
+ }
+
+ public DeviceRequirement(Class<Device> deviceClass, int amount, Map<String, String> parameters) {
+ this.deviceClass = deviceClass;
+ this.amount = amount;
+ this.parameters = parameters;
+ }
+}
@@ -0,0 +1,14 @@
+package junk;
+
+import groovy.lang.Closure;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GridBuilder {
+ List<Closure> presses = new ArrayList<Closure>();
+
+ public void press(Closure closure) {
+ presses.add(closure);
+ }
+}
@@ -0,0 +1,14 @@
+package junk;
+
+import java.util.List;
+
+public abstract class Page {
+ private List<Device> devices;
+
+ public List<Device> getDevices() {
+ return devices;
+ }
+
+ protected abstract List<DeviceRequirement> getDeviceRequirements();
+
+}
@@ -0,0 +1,12 @@
+package junk;
+
+import groovy.lang.Closure;
+
+public class PageBuilder {
+ public GridBuilder grid(Closure closure) {
+ GridBuilder gridBuilder = new GridBuilder();
+ closure.setDelegate(gridBuilder);
+ closure.call();
+ return gridBuilder;
+ }
+}
@@ -0,0 +1,34 @@
+package junk
+
+import org.monome.pages.time.MusicalScheduler
+import org.monome.pages.time.MusicalLoop
+import org.monome.pages.time.MusicalDuration
+
+def musicalScheduler = new MusicalScheduler()
+def musicalLoop = new MusicalLoop(musicalScheduler)
+
+def md(num, den) {
+ new MusicalDuration(num, den)
+}
+
+Number.metaClass {
+ getTh {-> new MusicalDuration(1, delegate)}
+}
+
+whole = 1.th
+half = 2.th
+qtr = 4.th
+
+musicalScheduler.schedule(qtr) {
+ println "beep!"
+}
+
+musicalScheduler.schedule(whole) {
+ println "bam!"
+}
+
+musicalScheduler.schedule(half) {
+ println "bong!"
+}
+
+musicalLoop.run()
@@ -0,0 +1,40 @@
+package org.monome.pages;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyClassLoader;
+import groovy.util.GroovyScriptEngine;
+import groovy.util.ResourceException;
+import groovy.util.ScriptException;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.monome.pages.time.MusicalLoop;
+import sun.org.mozilla.javascript.internal.Script;
+
+import java.io.IOException;
+
+public class Main {
+
+ // TODO: refactor all the common stuff out into classes
+ public static void main(String[] args) {
+ String[] roots = new String[] { "/Users/ycros/tmp/" };
+ try {
+ CompilerConfiguration config = new CompilerConfiguration();
+ config.setScriptBaseClass(ScriptBase.class.getName());
+
+ GroovyClassLoader loader = new GroovyClassLoader(Main.class.getClassLoader(), config);
+
+ GroovyScriptEngine gse = new GroovyScriptEngine(roots, loader);
+ gse.setConfig(config);
+
+ Binding binding = new Binding();
+ gse.run("test.groovy", binding);
+
+ MusicalLoop.getInstance().run();
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ } catch (ResourceException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ } catch (ScriptException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit bf75e01

Please sign in to comment.