-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bde5be
commit bd86769
Showing
20 changed files
with
500 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ public void complete() { | |
} | ||
|
||
public void stop() { | ||
frame = 1; | ||
// engine.deleteObserver(this); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package animata; | ||
|
||
import java.util.Observable; | ||
import java.util.Observer; | ||
|
||
import processing.core.PApplet; | ||
|
||
public class Camera implements Observer { | ||
private static final int CAMERA_DISTANCE = 500; | ||
public class CameraShaker implements Observer { | ||
private static final float X_RANGE = (float) Math.PI * 5; | ||
private Animator animator; | ||
public float y = 0; | ||
public float x = 0; | ||
|
||
CameraShaker(){ | ||
this.animator = new Animator(0,this); | ||
} | ||
|
||
public void update(Observable o, Object arg) { | ||
float v = sinWithDecay(animator.currentValue); | ||
this.y = v; | ||
updateWithShake(); | ||
} | ||
|
||
|
||
private float sinWithDecay(float v) { | ||
return (float) Math.sin(v) * 1/(v/X_RANGE); | ||
} | ||
|
||
public void shake() { | ||
animator.currentValue = 0; | ||
animator.set(X_RANGE, 20); | ||
} | ||
} | ||
// TODO: find a good standard Java vector class! This is shocking now. | ||
public float x; | ||
public float y; | ||
public float z; | ||
public float targetX; | ||
public float targetY; | ||
public float targetZ; | ||
private Animator animator; | ||
private float endX; | ||
private float endY; | ||
private float endZ; | ||
private float startX; | ||
private float startY; | ||
private float startZ; | ||
private CameraShaker shaker; | ||
|
||
|
||
|
||
public Camera(PApplet applet) { | ||
x = applet.width/2.0f; | ||
y = applet.height/2.0f; | ||
z = CAMERA_DISTANCE;//(applet.height/2.0f) / PApplet.tan(PApplet.PI*60.0f / 360.0f); | ||
targetX = applet.width/2.0f; | ||
targetY = applet.height/2.0f; | ||
targetZ = 0f; | ||
shaker = new CameraShaker(); | ||
animator = new Animator(0,this); | ||
} | ||
private void adjustCameraForShake() { | ||
y += shaker.y; | ||
|
||
} | ||
public void zoomBy(float delta) { | ||
z+=delta; | ||
targetZ += delta; | ||
|
||
} | ||
public void panXBy(float delta) { | ||
x += delta; | ||
targetX += delta; | ||
} | ||
|
||
public void panYBy(float delta) { | ||
y += delta; | ||
targetY += delta; | ||
} | ||
public void update(Observable o, Object arg) { | ||
updateFromAnimator(); | ||
updateWithShake(); | ||
} | ||
private void updateWithShake() { | ||
if(animator.currentValue != 1 && animator.currentValue != 0 ) return; | ||
y += shaker.y; | ||
targetY += shaker.y; | ||
|
||
} | ||
private void updateFromAnimator() { | ||
float v = animator.currentValue; | ||
x = startX + (endX-startX) * v; | ||
y = startY + (endY-startY) * v; | ||
z = startZ + (endZ-startZ) * v; | ||
targetX = x; | ||
targetY = y; | ||
targetZ = z - CAMERA_DISTANCE; | ||
} | ||
public void moveTo(float x, float y, float z, int frames){ | ||
startX = this.x; | ||
startY = this.y; | ||
startZ = this.z; | ||
endX = x; | ||
endY = y; | ||
endZ = z; | ||
animator.currentValue = 0; | ||
animator.set(1, frames); | ||
} | ||
@Override | ||
public String toString() { | ||
return super.toString() + "<camera x=\"" + x +"\" y=\"" + y +"\" z=\"" + z +"\" />"; | ||
} | ||
public void shake() { | ||
shaker.shake(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package animata; | ||
|
||
import java.util.Observable; | ||
|
||
import javax.sound.midi.*; | ||
|
||
|
||
public class Clock extends Observable implements Receiver { | ||
|
||
public static final Integer TICK = 0; | ||
public static final Integer CROTCHET = 1; | ||
public static final Integer BAR = 2; | ||
private MidiDevice in; | ||
private int tick = 0; | ||
|
||
public Clock(String deviceName) { | ||
in = getMidiDevice(deviceName); | ||
if (!in.isOpen()) try { | ||
in.open(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Transmitter transmitter; | ||
try { | ||
transmitter = in.getTransmitter(); | ||
transmitter.setReceiver(this); | ||
System.out.println("successfully created clock"); | ||
} catch (MidiUnavailableException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private MidiDevice getMidiDevice(String deviceName) { | ||
javax.sound.midi.MidiDevice.Info infos[] = MidiSystem.getMidiDeviceInfo(); | ||
for (javax.sound.midi.MidiDevice.Info info : infos) { | ||
System.out.println("info: " + info.getName()); | ||
if (info.getName().matches(deviceName + ".*")) { | ||
try { | ||
|
||
return MidiSystem.getMidiDevice(info); | ||
} catch (MidiUnavailableException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
System.out.println("Error - couldn't find " + deviceName); | ||
return null; | ||
} | ||
|
||
public void close() { | ||
in.close(); | ||
} | ||
|
||
public void send(MidiMessage message, long timestamp) { | ||
if(message.getStatus() == ShortMessage.START) tick = 0; | ||
if(message.getStatus() != ShortMessage.TIMING_CLOCK) return; | ||
setChanged(); | ||
notifyObservers(TICK); | ||
|
||
if(tick == 0){ | ||
setChanged(); | ||
notifyObservers(BAR); | ||
} | ||
|
||
if(tick % 24 == 0){ | ||
setChanged(); | ||
notifyObservers(CROTCHET); | ||
} | ||
|
||
tick ++; | ||
if(tick>=96) { | ||
tick = 0; | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package animata; | ||
|
||
import oscP5.OscMessage; | ||
import oscP5.OscP5; | ||
import processing.core.PApplet; | ||
import animata.model.Layer; | ||
|
||
public class GrimoniumInput { | ||
private Controller controller; | ||
|
||
public GrimoniumInput(PApplet applet, Layer root, Controller controller, int port) { | ||
this.controller = controller; | ||
new OscP5(this, port); | ||
|
||
} | ||
public void oscEvent(OscMessage message) { | ||
boolean result = run(message); | ||
if (!result) { | ||
System.out.println("failed to respond to message " + message.addrPattern()); | ||
message.print(); | ||
} | ||
} | ||
private boolean run(OscMessage message) { | ||
String type = message.addrPattern(); | ||
if(type.equals("/visualschanged")) return visualsChanged(message); | ||
return false; | ||
} | ||
private boolean visualsChanged(OscMessage message) { | ||
controller.currentSong = (String) message.arguments()[0]; | ||
RandomCameraPanner.moveNow(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.