Skip to content

Commit

Permalink
before working on new controls
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelforrest committed Jun 21, 2009
1 parent 35f7a9c commit 5e68145
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/Violinist/Violinist.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

211 changes: 211 additions & 0 deletions examples/Violinist/data/violin.nmt

Large diffs are not rendered by default.

Binary file added examples/Violinist/data/violin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/Violinist/data/violin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<layers>
<layer id="forest" nmt="violin.nmt"/>
</layers>

2 changes: 1 addition & 1 deletion src/animata/Animata.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void zoomCamera(Float delta) {
OscMessage message = new OscMessage("/cameradeltazoom");
message.add(delta);
oscP5.send(message, net);
// System.out.println("message:" + message + " to " + net);
//System.out.println("message:" + message.toString() + delta + " to " + net);
}

public static void panLayer(Float deltaX) {
Expand Down
6 changes: 4 additions & 2 deletions src/animata/AnimataPlayback.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import rwmidi.MidiInput;
import rwmidi.RWMidi;
import animata.controls.ClockBobber;
import animata.controls.LayerToggle;
import animata.model.Layer;
import animata.views.LayerView;

Expand All @@ -33,8 +34,9 @@ public AnimataPlayback(PApplet applet){
private void setup(PApplet applet) {
this.applet = applet;
Animator.init(applet);
LayerToggle.init(applet);
camera = new Camera(applet);
this.applet.hint(PApplet.ENABLE_OPENGL_2X_SMOOTH);

root = new Layer();
in = RWMidi.getInputDevice("IAC Bus 1 <MIn:0> Apple Computer, Inc.").createInput();
clock = new Clock("IAC Bus 2");
Expand Down Expand Up @@ -81,7 +83,7 @@ public Layer addScene(String xml, Layer parent){
}
public void draw(){
applet.camera(camera.x, camera.y, camera.z, camera.targetX, camera.targetY,camera.targetZ, 0f, 1f, 0f);
//root.simulate();
root.simulate();
applet.textureMode(PApplet.NORMAL);
applet.noStroke();
applet.fill(0,0);
Expand Down
1 change: 1 addition & 0 deletions src/animata/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public boolean setBoneTempo(String name, Float tempo) {
public boolean animateBone(String name, float scale) {
ArrayList<Bone> bones = Skeleton.findBones(name);
for (Bone bone : bones) {
//System.out.println("Scaling a bone to " + scale);
bone.setScale(scale);
}
// TODO: extract interface for Animata calls
Expand Down
41 changes: 41 additions & 0 deletions src/animata/FootController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package animata;

import rwmidi.Controller;
import rwmidi.MidiInput;
import rwmidi.RWMidi;
import microkontrol.controls.Button;

public class FootController {
public class FootSwitch {
private int cc;
public FootSwitch(int cc) {
this.cc = cc;
// all on channel 16
in.plug(this, "controllerChangeReceived",15);
}
public void controllerChangeReceived(Controller controller){
if(controller.getCC() == cc) button.press();
}
public Button button = new Button();

}

private static FootController instance;
public static FootSwitch[] footSwitches;
protected MidiInput in;
public FootController(String inputName) {
in = RWMidi.getInputDevice(inputName).createInput();
int[] ccs = {115,114,116,101,100};
footSwitches = new FootSwitch[ccs.length];
for (int i = 0; i < ccs.length; i++) {
int cc = ccs[i];
footSwitches[i] = new FootSwitch(cc);

}
}

public static FootController getInstance(){
if(instance == null) instance = new FootController("MIDI IN <MIn:3> KORG INC.");
return instance;
}
}
2 changes: 2 additions & 0 deletions src/animata/controls/ControlFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ public class ControlFactory {
public static Control createControl(XMLElement element, MidiInput in) {
String name = element.getName();
if(name.equals("notebone")) return new NoteBone(element, in);
if(name.equals("layeralpha")) return new LayerFader(element,in);
// if(name.equals("faderbone")) return new FaderBone(element);
// if(name.equals("freqbone")) return new FreqBone(element);
if(name.equals("noterangebone")) return new NoteRangeBone(element,in);
if(name.equals("bonetempokeys")) return new BoneTempoKeys(element,in);
if(name.equals("bonetempokeyranges")) return new BoneTempoKeyRanges(element, in);
if(name.equals("camera")) return new CameraPosition(element, in);
if(name.equals("camerashake")) return new CameraShake(element,in);
if(name.equals("layertoggle")) return new LayerToggle(element, in);
return new Control(element, in);

}
Expand Down
25 changes: 25 additions & 0 deletions src/animata/controls/LayerFader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package animata.controls;

import microkontrol.MicroKontrol;
import microkontrol.controls.FaderListener;
import processing.xml.XMLElement;
import rwmidi.MidiInput;
import animata.model.Layer;

public class LayerFader extends Control implements FaderListener {

private String layer;

public LayerFader(XMLElement element, MidiInput in) {
super(element, in);
layer = element.getStringAttribute("layer");
MicroKontrol.getInstance().faders[element.getIntAttribute("fader")].listen(this);
Layer.setAlpha(layer,0f);
}

public void moved(Float value) {
Layer.setAlpha(layer,value);

}

}
37 changes: 37 additions & 0 deletions src/animata/controls/LayerToggle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package animata.controls;

import java.awt.event.KeyEvent;

import animata.model.Layer;

import processing.core.PApplet;
import processing.xml.XMLElement;
import rwmidi.MidiInput;

public class LayerToggle extends Control {

private static PApplet applet;

private String layer;

private char toggle;

public LayerToggle(XMLElement element, MidiInput in) {
super(element,in);
toggle = element.getStringAttribute("key").charAt(0);
layer = element.getStringAttribute("layer");
applet.registerKeyEvent(this);
Layer.setVisibility(layer, false); // TODO confirm this is desirable default behaviour
}
public void keyEvent(KeyEvent key){
if(key.getKeyChar() == toggle && key.getID() == KeyEvent.KEY_PRESSED ){
System.out.println("toggling " + layer);
Layer.toggle(layer);
}
}
public static void init(PApplet theApplet) {
applet = theApplet;

}

}
21 changes: 21 additions & 0 deletions src/animata/model/Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ public PImage getImage(PApplet applet) {
public float scale = 1;
public boolean visible = true;

private static ArrayList<Layer> allLayers = new ArrayList<Layer>();

public Layer() {
}

public Layer(XMLElement element, String folder) {
setupAttributes(element);
addChildLayersIfPresent(element, folder);
allLayers.add(this);
}

private void addChildLayersIfPresent(XMLElement element, String folder) {
Expand Down Expand Up @@ -93,12 +96,30 @@ public Layer addLayer(String folder, XMLElement element) {
}

public void simulate() {
if(!visible || alpha == 0) return;
if(skeleton != null) skeleton.simulate(40);
for (Layer layer : layers) {
layer.simulate();
}

}

public static void toggle(String name) {
for(Layer layer : allLayers){
if(layer.name != null && layer.name.equals(name)) layer.visible = !layer.visible;
}
}
public static void setVisibility(String name, boolean visible){
for(Layer layer : allLayers){
if(layer.name != null && layer.name.equals(name)) layer.visible = visible;
}
}

public static void setAlpha(String name, Float value) {
for(Layer layer : allLayers){
if(layer.name != null && layer.name.equals(name)) layer.alpha = value;
}

}

}
4 changes: 3 additions & 1 deletion src/animata/views/LayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ private void addChildLayers(ArrayList<Layer> layers) {
}

public void draw() {
//if(!layer.visible) return;
if(!layer.visible || layer.alpha == 0) return;
if(layer.alpha != 1) applet.tint(layer.alpha * 255);
applet.pushMatrix();
doTransformation();
applet.pushMatrix();
Expand All @@ -40,6 +41,7 @@ public void draw() {
applet.popMatrix();

applet.popMatrix();
if(layer.alpha != 1) applet.tint(255);
}
private void drawDebugStuff() {
if(layer.skeleton == null) return;
Expand Down
49 changes: 49 additions & 0 deletions src/test/CrazyLandscape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package test;

import microkontrol.MicroKontrol;
import microkontrol.controls.Button;
import processing.core.PApplet;
import animata.Animata;
import animata.AnimataPlayback;
import animata.FootController;

public class CrazyLandscape extends PApplet {
private AnimataPlayback playback;
private MicroKontrol mk;

public void setup() {
size(950, 614, OPENGL);
MicroKontrol.init(this);
Animata.startOSC(this);
playback = new AnimataPlayback(this);

playback.loadSet("set.xml");
//playback.debug();
mk = MicroKontrol.getInstance();
FootController.getInstance().footSwitches[0].button.listen(Button.PRESSED, this, "doSomething");
}
public void doSomething(){
System.out.println("Pressed the switch!");
}
public void draw() {
if (keyPressed) {
if (keyCode == DOWN) playback.panCameraY(10);
if (keyCode == UP) playback.panCameraY(-10);
if (keyCode == LEFT) playback.panCameraX(-10);
if (keyCode == RIGHT) playback.panCameraX(10);
if( key == 'c') System.out.println("HASHS" + playback.camera);
}
playback.panCameraX(mk.joystick.getX() * 30);
playback.zoomCamera(mk.joystick.getY() * 30);
background(255);

playback.draw();

}

public static void main(String[] args) {
PApplet.main(new String[] { "--bgcolor=#c0c0c0", "TestScene" });

}

}
9 changes: 7 additions & 2 deletions src/test/TestScene.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package test;

import microkontrol.MicroKontrol;
import microkontrol.controls.Button;
import processing.core.PApplet;
import animata.Animata;
import animata.AnimataPlayback;
import animata.FootController;

public class TestScene extends PApplet {
private AnimataPlayback playback;
private MicroKontrol mk;

public void setup() {
size(950, 614, OPENGL);
MicroKontrol.init(this);
Animata.startOSC(this);
playback = new AnimataPlayback(this);

playback.loadSet("set.xml");
playback.debug();
MicroKontrol.init(this);
mk = MicroKontrol.getInstance();
FootController.getInstance().footSwitches[0].button.listen(Button.PRESSED, this, "doSomething");
}
public void doSomething(){
System.out.println("Pressed the switch!");
}

public void draw() {
if (keyPressed) {
if (keyCode == DOWN) playback.panCameraY(10);
Expand Down

0 comments on commit 5e68145

Please sign in to comment.