Skip to content

Commit

Permalink
animated transitions
Browse files Browse the repository at this point in the history
forwarded osc messages
added debug mode
fixed bug with initial bone conditions from file
  • Loading branch information
michaelforrest committed Jan 22, 2009
1 parent 5b1e1c1 commit 4fb8ba0
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 56 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<classpathentry kind="lib" path="/Applications/Processing.app/Contents/Resources/Java/libraries/oscP5/library/oscP5.jar"/>
<classpathentry kind="lib" path="/Applications/Processing.app/Contents/Resources/Java/libraries/opengl/library/opengl.jar"/>
<classpathentry kind="lib" path="/Applications/Processing.app/Contents/Resources/Java/libraries/rwmidi/library/rwmidi.jar"/>
<classpathentry kind="lib" path="/Users/michaelforrest/Documents/Processing/libraries/MicroKontrol/library/MicroKontrol.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
72 changes: 72 additions & 0 deletions src/animata/Animata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package animata;

import oscP5.OscMessage;
import oscP5.OscP5;
import processing.core.PApplet;
import netP5.NetAddress;
import netP5.NetInfo;

public class Animata {

public static NetAddress net;
public static OscP5 oscP5;

public static void startOSC(PApplet applet) {
net = new NetAddress(NetInfo.getHostAddress(), 7110);
oscP5 = new OscP5(applet, 12000);
PApplet.println("Sending Animata stuff to " + net.address());
}


private static boolean checkInitialised() {
if (net == null) {
//PApplet.println("need to call init() with valid settings on Animata");
return false;
}
return true;
}

public static void zoomCamera(Float delta) {
if (!checkInitialised()) return;
OscMessage message = new OscMessage("/cameradeltazoom");
message.add(delta);
oscP5.send(message, net);
System.out.println("message:" + message + " to " + net);
}

public static void panLayer(Float deltaX) {
if (!checkInitialised()) return;
OscMessage message = new OscMessage("/cameradeltapan");
message.add(deltaX);
message.add(0.0f);
oscP5.send(message, net);
System.out.println("message:" + message + " to " + net);
}

public static void setBone(String name, Float n) {
if (!checkInitialised()) return;
OscMessage message = new OscMessage("/anibone");
message.add(name);
message.add((float) n);
PApplet.println("trying to send to " + net.address() + " = " + n + " to bone " + name);
oscP5.send(message, net);
}

public static void setAlpha(String layer, float value) {
if(!checkInitialised()) return;
OscMessage message = new OscMessage("/layeralpha");
message.add(layer);
message.add(value);
oscP5.send(message, net);
}

public static void setBoneTempo(String bone, Float tempo) {
if(!checkInitialised()) return;
OscMessage message = new OscMessage("/bonetempo");
message.add(bone);
message.add((float) tempo);
PApplet.println("trying to send to " + net.address() + " = " + tempo + " to bone " + bone);
oscP5.send(message, net);
}

}
16 changes: 16 additions & 0 deletions src/animata/AnimataPlayback.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ public void panXBy(float delta) {
x += delta;
targetX += delta;
}
public void panYBy(float delta) {
y += delta;
targetY += delta;
}
}
public static final float timeDivision = 42f;
public static float gravity = 0;
private static boolean debug;
private PApplet applet;
private Layer root;
private LayerView layersView;
Expand All @@ -52,6 +57,7 @@ public AnimataPlayback(PApplet applet){
}
private void setup(PApplet applet) {
this.applet = applet;
Animator.init(applet);
camera = new Camera(applet);
this.applet.hint(PApplet.ENABLE_OPENGL_2X_SMOOTH);
root = new Layer();
Expand Down Expand Up @@ -106,5 +112,15 @@ public void zoomCamera(float delta) {
public void panCameraX(float delta) {
camera.panXBy(delta);
}
public void panCameraY(float delta){
camera.panYBy(delta);
}
public void debug() {
debug = true;

}
public static boolean debugging() {
return debug;
}

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

import java.util.Observable;
import java.util.Observer;

import processing.core.PApplet;

public class Animator extends Observable implements Observer {


private static Engine engine;
float targetValue;
float initialValue;
float difference;
float frameIncrement;
public float currentValue = 0;
float frame = 0;
boolean isComplete = false;

public Animator(float startValue, Observer target) {
engine.addObserver(this);
initialValue = currentValue = startValue;
addObserver(target);
}

public void set(float value, int _frames) {
targetValue = value;
initialValue = currentValue;
difference = (value - initialValue);
frameIncrement = 1 / (float) _frames;
isComplete = false;
frame = 0;
frame += frameIncrement;
}

public float getValue() {
return currentValue;
}

public void update(Observable o, Object arg) {
// Just gonna assume it's always nextFrame.
if (frame >= 1 || frame == 0) return;
frame += frameIncrement;
currentValue = initialValue + (difference * easeOutQuad(frame));
changed();
if (frame >= 1) complete();
}

void changed() {
setChanged();
notifyObservers(NEXT_FRAME);
}

public boolean isComplete() {
return isComplete;
}

public void complete() {
currentValue = targetValue;
isComplete = true;
notifyObservers("complete");
}

public void stop() {
// engine.deleteObserver(this);
}

float easeOutQuad(float t) {
return -1 * (t /= 1) * (t - 2);
}

public static void init(PApplet applet) {
engine = new Engine(applet);

};
public static final String NEXT_FRAME = "nextFrame";
public static class Engine extends Observable{

public Engine(PApplet applet) {
applet.registerDraw(this);
}
public void draw() {
setChanged();
notifyObservers(NEXT_FRAME);
}

}

}
9 changes: 6 additions & 3 deletions src/animata/ControlFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import processing.xml.XMLElement;
import rwmidi.MidiInput;
import animata.controls.BoneTempoKeyRanges;
import animata.controls.BoneTempoKeys;
import animata.controls.Control;
import animata.controls.NoteBone;
import animata.controls.NoteRangeBone;

public class ControlFactory {

Expand All @@ -12,9 +15,9 @@ public static Control createControl(XMLElement element, MidiInput in) {
if(name.equals("notebone")) return new NoteBone(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);
// if(name.equals("bonetempokeys")) return new BoneTempoKeys(element);
// if(name.equals("bonetempokeyranges")) return new BoneTempoKeyRanges(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);

return new Control(element, in);

Expand Down
4 changes: 4 additions & 0 deletions src/animata/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public boolean setBoneTempo(String name, Float tempo) {
for (Bone bone : bones) {
bone.setTempo(tempo);
}
// TODO: extract interface for Animata calls
Animata.setBoneTempo(name, tempo);
return true;
}

Expand All @@ -51,6 +53,8 @@ public boolean animateBone(String name, float scale) {
for (Bone bone : bones) {
bone.setScale(scale);
}
// TODO: extract interface for Animata calls
Animata.setBone(name, scale);
return true;
}

Expand Down
21 changes: 17 additions & 4 deletions src/animata/LayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import processing.core.PApplet;
import animata.model.Layer;
import animata.model.Skeleton.Bone;
import animata.model.Skeleton.Joint;

public class LayerView extends ViewBase {

Expand All @@ -30,21 +32,32 @@ public void draw() {
applet.pushMatrix();
doTransformation();
applet.pushMatrix();
drawMesh();
if(mesh!= null) mesh.draw();
if(AnimataPlayback.debugging()) drawDebugStuff();
drawChildLayers();
applet.popMatrix();

applet.popMatrix();
}
private void drawDebugStuff() {
if(layer.skeleton == null) return;
for(Joint joint : layer.skeleton.joints){
applet.fill(0xFFFFFF00);
applet.ellipse(joint.x, joint.y, 5, 5);
}
applet.stroke(0x99FF00FF);
applet.strokeWeight(5);
for(Bone bone : layer.skeleton.bones){
applet.line(bone.j1.x, bone.j1.y, bone.j0.x, bone.j0.y);
}
}

private void drawChildLayers() {
for (LayerView layerView : layers) {
layerView.draw();
}
}

private void drawMesh() {
if(mesh!= null) mesh.draw();
}

// this is like the calcTransformationMatrix method from the original, but called during draw
private void doTransformation() {
Expand Down
1 change: 1 addition & 0 deletions src/animata/MeshView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public MeshView(PApplet applet, Layer layer) {
this.layer = layer;
}
public void draw() {
applet.noStroke();
drawFaces(layer.mesh.faces);
// applet.textFont(font);
// applet.fill(0);
Expand Down
39 changes: 39 additions & 0 deletions src/animata/controls/BoneTempoKeyRanges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package animata.controls;

import processing.xml.XMLElement;
import rwmidi.MidiInput;
import animata.NoteParser;
import animata.NoteParser.BadNoteFormatException;

public class BoneTempoKeyRanges extends Control {
private Integer low;
private Integer high;
private int bonecount;
private float tempo;
private BoneTempoKeys[] ranges;
private String boneRoot;
public BoneTempoKeyRanges(XMLElement element, MidiInput in) {
super(element, in);
try {
low = NoteParser.getNote(element.getStringAttribute("low", "1"));
high = NoteParser.getNote(element.getStringAttribute("high", "100"));
} catch (BadNoteFormatException e) {
System.out.println(e.getMessage());
}
channel = element.getIntAttribute("channel", 16) - 1;
boneRoot = element.getStringAttribute("bone");
tempo = element.getFloatAttribute("tempo", 1);
bonecount = element.getIntAttribute("bonecount",1);
addRanges();
}

private void addRanges() {
ranges = new BoneTempoKeys[bonecount];
float step = (((float)high)-((float)low))/((float)bonecount);
for (int i = 0; i < bonecount; i++) {
int rangeLow = low + (int)(i*step);
System.out.println("added range low=" + rangeLow + " step was " + step);
ranges[i] = new BoneTempoKeys(in, rangeLow, rangeLow + (int)step, boneRoot+i, tempo, channel);
}
}
}
Loading

0 comments on commit 4fb8ba0

Please sign in to comment.