From bd86769f9840b1dd92a0fd759b8e66c3a2f1ddf5 Mon Sep 17 00:00:00 2001 From: Michael Forrest Date: Sun, 25 Jan 2009 19:53:32 +0000 Subject: [PATCH] lots and lots of changes --- src/animata/AnimataPlayback.java | 53 +++----- src/animata/Animator.java | 1 + src/animata/Camera.java | 119 ++++++++++++++++++ src/animata/Clock.java | 77 ++++++++++++ src/animata/Controller.java | 12 ++ src/animata/GrimoniumInput.java | 33 +++++ src/animata/LayerView.java | 2 +- src/animata/NoteParser.java | 10 +- src/animata/RandomCameraPanner.java | 36 ++++++ src/animata/Scene.java | 38 +++++- src/animata/controls/BoneTempoKeyRanges.java | 6 +- src/animata/controls/BoneTempoKeys.java | 12 +- src/animata/controls/CameraPosition.java | 45 +++++++ src/animata/controls/CameraShake.java | 22 ++++ src/animata/controls/ClockBobber.java | 32 +++++ .../{ => controls}/ControlFactory.java | 10 +- src/animata/controls/NoteBone.java | 39 +++--- src/animata/controls/NoteRangeBone.java | 35 ++++-- src/animata/model/Layer.java | 12 +- src/test/TestScene.java | 3 + 20 files changed, 500 insertions(+), 97 deletions(-) create mode 100644 src/animata/Camera.java create mode 100644 src/animata/Clock.java create mode 100644 src/animata/GrimoniumInput.java create mode 100644 src/animata/RandomCameraPanner.java create mode 100644 src/animata/controls/CameraPosition.java create mode 100644 src/animata/controls/CameraShake.java create mode 100644 src/animata/controls/ClockBobber.java rename src/animata/{ => controls}/ControlFactory.java (76%) diff --git a/src/animata/AnimataPlayback.java b/src/animata/AnimataPlayback.java index 43d200d..5dc0878 100644 --- a/src/animata/AnimataPlayback.java +++ b/src/animata/AnimataPlayback.java @@ -6,38 +6,11 @@ import processing.xml.XMLElement; import rwmidi.MidiInput; import rwmidi.RWMidi; +import animata.controls.ClockBobber; import animata.model.Layer; public class AnimataPlayback { - public class Camera { - public float x; - public float y; - public float z; - public float targetX; - public float targetY; - public float targetZ; - public Camera(PApplet applet) { - x = applet.width/2.0f; - y = applet.height/2.0f; - z = 1500;//(applet.height/2.0f) / PApplet.tan(PApplet.PI*60.0f / 360.0f); - targetX = applet.width/2.0f; - targetY = applet.height/2.0f; - targetZ = 0f; - } - 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 static final float timeDivision = 42f; public static float gravity = 0; private static boolean debug; @@ -45,8 +18,9 @@ public void panYBy(float delta) { private Layer root; private LayerView layersView; private Controller controller; - private Camera camera; + public Camera camera; private MidiInput in; + public static Clock clock; public AnimataPlayback(PApplet applet, String nmtFile){ setup(applet); @@ -62,8 +36,12 @@ private void setup(PApplet applet) { this.applet.hint(PApplet.ENABLE_OPENGL_2X_SMOOTH); root = new Layer(); in = RWMidi.getInputDevice("IAC Bus 1 Apple Computer, Inc.").createInput(); + clock = new Clock("IAC Bus 2"); + new ClockBobber(clock); + new RandomCameraPanner(clock, this); Controller.init(applet,root,this); controller = Controller.getInstance(); + new GrimoniumInput(applet,root,controller,7111); } public void initOSC(int port){ new OSCInput(applet,root,controller,port); @@ -82,20 +60,23 @@ public void loadSet(String xml){ XMLElement[] layers = scene.getChildren("layer"); for (int i = 0; i < layers.length; i++) { XMLElement element = layers[i]; - addScene(element.getStringAttribute("nmt")); - new Scene(element,in); + Layer layer = addScene(element.getStringAttribute("nmt")); + layer.visible = true; + layer.alpha = 1; + new Scene(element,in,applet,layer); } + layersView = new LayerView(root, applet); } - public void addScene(String xml){ - addScene(xml, root); + public Layer addScene(String xml){ + return addScene(xml, root); } - public void addScene(String xml, Layer parent){ + public Layer addScene(String xml, Layer parent){ String folder = new File(xml).getParent(); if(folder == null) folder = "."; XMLElement element = new XMLElement(applet, xml); - parent.addLayers(element.getChildren("layer"), folder); - layersView = new LayerView(root, applet); + return parent.addLayer(folder, element);//element.getChildren("layer"), folder); + } public void draw(){ applet.camera(camera.x, camera.y, camera.z, camera.targetX, camera.targetY,camera.targetZ, 0f, 1f, 0f); diff --git a/src/animata/Animator.java b/src/animata/Animator.java index 6be94ad..521320a 100644 --- a/src/animata/Animator.java +++ b/src/animata/Animator.java @@ -62,6 +62,7 @@ public void complete() { } public void stop() { + frame = 1; // engine.deleteObserver(this); } diff --git a/src/animata/Camera.java b/src/animata/Camera.java new file mode 100644 index 0000000..ad201fb --- /dev/null +++ b/src/animata/Camera.java @@ -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() + ""; + } + public void shake() { + shaker.shake(); + + } +} \ No newline at end of file diff --git a/src/animata/Clock.java b/src/animata/Clock.java new file mode 100644 index 0000000..1253cfd --- /dev/null +++ b/src/animata/Clock.java @@ -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; + } + } + + +} diff --git a/src/animata/Controller.java b/src/animata/Controller.java index a08395f..209f92e 100644 --- a/src/animata/Controller.java +++ b/src/animata/Controller.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import processing.core.PApplet; +import animata.controls.CameraPosition; import animata.model.Layer; import animata.model.Skeleton; import animata.model.Skeleton.Bone; @@ -11,6 +12,7 @@ public class Controller { private static Controller instance; private final AnimataPlayback animataPlayback; + public String currentSong; public Controller(PApplet applet, Layer root, AnimataPlayback animataPlayback) { this.animataPlayback = animataPlayback; @@ -67,4 +69,14 @@ public static void init(PApplet applet, Layer root, AnimataPlayback animataPlayb } + public void moveCameraTo(CameraPosition p, int frames) { + animataPlayback.camera.moveTo(p.x, p.y,p.z, frames); + + } + + public void shakeCamera() { + animataPlayback.camera.shake(); + + } + } diff --git a/src/animata/GrimoniumInput.java b/src/animata/GrimoniumInput.java new file mode 100644 index 0000000..64d823b --- /dev/null +++ b/src/animata/GrimoniumInput.java @@ -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; + } +} diff --git a/src/animata/LayerView.java b/src/animata/LayerView.java index 2e1b30f..78513ea 100644 --- a/src/animata/LayerView.java +++ b/src/animata/LayerView.java @@ -28,7 +28,7 @@ private void addChildLayers(ArrayList layers) { } public void draw() { - if(!layer.visible) return; + //if(!layer.visible) return; applet.pushMatrix(); doTransformation(); applet.pushMatrix(); diff --git a/src/animata/NoteParser.java b/src/animata/NoteParser.java index d0d2632..057d931 100644 --- a/src/animata/NoteParser.java +++ b/src/animata/NoteParser.java @@ -28,13 +28,19 @@ public static Integer getNote(XMLElement xml) throws BadNoteFormatException{ return getNote(noteName); } - public static Integer getNote(String noteName) throws BadNoteFormatException{ + public static Integer getNote(String noteName){ try { return Integer.parseInt(noteName); - } catch (NumberFormatException e) { + } catch (NumberFormatException e) {} + + try { return convertStringToNoteNumber(noteName); + } catch (BadNoteFormatException e) { + e.printStackTrace(); } + System.out.println("Note xml - error parsing " + noteName); + return null; } /* * C0 = 0 diff --git a/src/animata/RandomCameraPanner.java b/src/animata/RandomCameraPanner.java new file mode 100644 index 0000000..c7d0256 --- /dev/null +++ b/src/animata/RandomCameraPanner.java @@ -0,0 +1,36 @@ +package animata; + +import java.util.ArrayList; +import java.util.Observable; +import java.util.Observer; + +import animata.controls.CameraPosition; + +public class RandomCameraPanner implements Observer{ + + private static RandomCameraPanner instance; + + public RandomCameraPanner(Clock clock, AnimataPlayback animataPlayback) { + clock.addObserver(this); + instance = this; + } + + public void update(Observable o, Object arg) { + if(arg == Clock.BAR) moveToRandomPosition(); + + } + + private void moveToRandomPosition() { + if(Math.random() >.125) return; + definitelyMoveCameraToRandomPosition(); + } + + public void definitelyMoveCameraToRandomPosition() { + ArrayList positions = CameraPosition.getCurrentSongPositions(); + int index = (int)(Math.random() * positions.size()); + Controller.getInstance().moveCameraTo(positions.get(index), 100); + } + public static void moveNow(){ + instance.definitelyMoveCameraToRandomPosition(); + } +} diff --git a/src/animata/Scene.java b/src/animata/Scene.java index adf7dfe..3ed02be 100644 --- a/src/animata/Scene.java +++ b/src/animata/Scene.java @@ -1,20 +1,49 @@ package animata; +import java.awt.event.KeyEvent; +import java.util.Observable; +import java.util.Observer; + +import processing.core.PApplet; import processing.xml.XMLElement; import rwmidi.MidiInput; import animata.controls.Control; +import animata.controls.ControlFactory; +import animata.model.Layer; -public class Scene { +public class Scene implements Observer { + private static final float OFF_CAMERA = -3000; private Control[] controls; private MidiInput in; + private char toggle; + private final PApplet applet; + private String id; + private Layer layer; + private Animator animator; - public Scene(XMLElement element, MidiInput in) { + public Scene(XMLElement element, MidiInput in, PApplet applet, Layer layer) { this.in = in; + this.applet = applet; + this.id = element.getStringAttribute("id"); + this.layer = layer; + toggle = element.getStringAttribute("toggle","¤").charAt(0); + if(toggle != '¤') setupToggle(); addControls(element.getChildren()); + animator = new Animator(OFF_CAMERA,this); } + private void setupToggle() { + applet.registerKeyEvent(this); + layer.y = OFF_CAMERA; + } + public void keyEvent(KeyEvent key){ + if(key.getKeyChar() == toggle && key.getID() == KeyEvent.KEY_PRESSED ){ + System.out.println("revealing " + id); + animator.set(animator.currentValue < 0 ? 0 : OFF_CAMERA, 50); + } + } private void addControls(XMLElement[] elements) { controls = new Control[elements.length]; for (int i = 0; i < elements.length; i++) { @@ -24,4 +53,9 @@ private void addControls(XMLElement[] elements) { } } + public void update(Observable o, Object arg) { + layer.y = animator.currentValue; + if(animator.currentValue == 0) Controller.getInstance().shakeCamera(); + } + } diff --git a/src/animata/controls/BoneTempoKeyRanges.java b/src/animata/controls/BoneTempoKeyRanges.java index dc5e90b..67d9876 100644 --- a/src/animata/controls/BoneTempoKeyRanges.java +++ b/src/animata/controls/BoneTempoKeyRanges.java @@ -15,11 +15,7 @@ public class BoneTempoKeyRanges extends Control { private int step; public BoneTempoKeyRanges(XMLElement element, MidiInput in) { super(element, in); - try { - low = NoteParser.getNote(element.getStringAttribute("low", "1")); - } catch (BadNoteFormatException e) { - System.out.println(e.getMessage()); - } + low = NoteParser.getNote(element.getStringAttribute("low", "1")); channel = element.getIntAttribute("channel", 16) - 1; step = element.getIntAttribute("step"); boneRoot = element.getStringAttribute("bone"); diff --git a/src/animata/controls/BoneTempoKeys.java b/src/animata/controls/BoneTempoKeys.java index b894481..e397ac5 100644 --- a/src/animata/controls/BoneTempoKeys.java +++ b/src/animata/controls/BoneTempoKeys.java @@ -26,19 +26,15 @@ public BoneTempoKeys(MidiInput in, int low, int high, String bone, float tempo, public BoneTempoKeys(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()); - } + low = NoteParser.getNote(element.getStringAttribute("low", "1")); + high = NoteParser.getNote(element.getStringAttribute("high", "100")); bone = element.getStringAttribute("bone"); tempo = element.getFloatAttribute("tempo"); Controller.getInstance().setBoneTempo(bone, 0f); } public void noteOnReceived(Note n) { - if(n.getChannel()!= channel) return; + if (n.getChannel() != channel) return; int pitch = n.getPitch(); if (pitch < low) return; if (pitch > high) return; @@ -50,7 +46,7 @@ public void noteOnReceived(Note n) { } public void noteOffReceived(Note n) { - if(n.getChannel()!= channel) return; + if (n.getChannel() != channel) return; int pitch = n.getPitch(); if (pitch < low) return; if (pitch > high) return; diff --git a/src/animata/controls/CameraPosition.java b/src/animata/controls/CameraPosition.java new file mode 100644 index 0000000..2d70cd5 --- /dev/null +++ b/src/animata/controls/CameraPosition.java @@ -0,0 +1,45 @@ +package animata.controls; + +import java.util.ArrayList; +import java.util.Hashtable; + +import animata.Controller; + + + +import processing.xml.XMLElement; +import rwmidi.MidiInput; + +public class CameraPosition extends Control { + static Hashtable> songs = new Hashtable>(); + public float x; + public float y; + public float z; + private String song; + public static ArrayList allPositions = new ArrayList(); + + public CameraPosition(XMLElement element, MidiInput in) { + super(element, in); + song = element.getParent().getStringAttribute("id"); + + x = element.getFloatAttribute("x"); + y = element.getFloatAttribute("y"); + z = element.getFloatAttribute("z"); + + allPositions.add(this); + addToCorrectArrayList(); + } + + private void addToCorrectArrayList() { + if(songs.get(song) == null) songs.put(song, new ArrayList()); + ArrayList list = songs.get(song); + list.add(this); + } + + public static ArrayList getCurrentSongPositions() { + return songs.get(Controller.getInstance().currentSong); + } + + + +} diff --git a/src/animata/controls/CameraShake.java b/src/animata/controls/CameraShake.java new file mode 100644 index 0000000..293984f --- /dev/null +++ b/src/animata/controls/CameraShake.java @@ -0,0 +1,22 @@ +package animata.controls; + +import animata.Controller; +import animata.NoteParser; +import processing.xml.XMLElement; +import rwmidi.MidiInput; +import rwmidi.Note; + +public class CameraShake extends Control { + + private Integer note; + + public CameraShake(XMLElement element, MidiInput in) { + super(element,in); + note = NoteParser.getNote(element.getStringAttribute("note")); + } + public void noteOnReceived(Note n){ + if(n.getChannel()!=channel) return; + if(n.getPitch()!=note) return; + Controller.getInstance().shakeCamera(); + } +} diff --git a/src/animata/controls/ClockBobber.java b/src/animata/controls/ClockBobber.java new file mode 100644 index 0000000..e8b0474 --- /dev/null +++ b/src/animata/controls/ClockBobber.java @@ -0,0 +1,32 @@ +package animata.controls; + +import java.util.Observable; +import java.util.Observer; + +import animata.Animator; +import animata.Clock; +import animata.Controller; + +public class ClockBobber implements Observer { + + private Animator animator; + + public ClockBobber(Clock clock) { + System.out.println("new clock bobber"); + clock.addObserver(this); + animator = new Animator(0,this); + } + + public void update(Observable o, Object arg) { + if(arg == Clock.CROTCHET){ + animator.currentValue = 0; + animator.set((float)Math.PI,30); + } + if(o == animator) updateAnimation(); + } + + private void updateAnimation() { + Controller.getInstance().animateBone("crotchet", 1 - (float)Math.sin(animator.currentValue)); + } + +} diff --git a/src/animata/ControlFactory.java b/src/animata/controls/ControlFactory.java similarity index 76% rename from src/animata/ControlFactory.java rename to src/animata/controls/ControlFactory.java index 81bfdd6..9e206ec 100644 --- a/src/animata/ControlFactory.java +++ b/src/animata/controls/ControlFactory.java @@ -1,12 +1,7 @@ -package animata; +package animata.controls; 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 { @@ -18,7 +13,8 @@ public static Control createControl(XMLElement element, MidiInput in) { 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); return new Control(element, in); } diff --git a/src/animata/controls/NoteBone.java b/src/animata/controls/NoteBone.java index f85a61d..12da3f4 100644 --- a/src/animata/controls/NoteBone.java +++ b/src/animata/controls/NoteBone.java @@ -8,7 +8,6 @@ import rwmidi.Note; import animata.Animator; import animata.NoteParser; -import animata.NoteParser.BadNoteFormatException; public class NoteBone extends Control implements Observer { @@ -22,36 +21,36 @@ public class NoteBone extends Control implements Observer { public NoteBone(XMLElement element, MidiInput in) { super(element, in); bone = element.getStringAttribute("bone"); - on = element.getFloatAttribute("on",0); - off = element.getFloatAttribute("off",1f); - try { - note = NoteParser.getNote(element.getStringAttribute("note")); - } catch (BadNoteFormatException e) { - e.printStackTrace(); - } - animator = new animata.Animator(off,this); - System.out.println("Created notebone for bone " + bone + " note=" +note); + on = element.getFloatAttribute("on", 0); + off = element.getFloatAttribute("off", 1f); + note = NoteParser.getNote(element.getStringAttribute("note")); + + animator = new animata.Animator(off, this); + System.out.println("Created notebone for bone " + bone + " note=" + note); } - public NoteBone(MidiInput in, int channel, String bone, float on, float off, int note){ + + public NoteBone(MidiInput in, int channel, String bone, float on, float off, int note) { super(channel, in); this.on = on; this.off = off; this.note = note; this.bone = bone; // TODO: can I unrepeat this without a silly small method? - animator = new animata.Animator(off,this); + animator = new animata.Animator(off, this); } - public void noteOnReceived(Note n){ - if(n.getChannel() != channel) return; - if(n.getPitch() != note) return; - animator.set(on,3); + public void noteOnReceived(Note n) { + if (n.getChannel() != channel) return; + if (n.getPitch() != note) return; + animator.set(on, 3); } - public void noteOffReceived(Note n){ - if(n.getChannel() != channel) return; - if(n.getPitch() != note) return; - animator.set(off,10); + + public void noteOffReceived(Note n) { + if (n.getChannel() != channel) return; + if (n.getPitch() != note) return; + animator.set(off, 10); } + public void update(Observable o, Object arg) { controller.animateBone(bone, animator.currentValue); } diff --git a/src/animata/controls/NoteRangeBone.java b/src/animata/controls/NoteRangeBone.java index e21981f..454896b 100644 --- a/src/animata/controls/NoteRangeBone.java +++ b/src/animata/controls/NoteRangeBone.java @@ -1,5 +1,9 @@ package animata.controls; +import java.util.Observable; +import java.util.Observer; + +import animata.Animator; import animata.Controller; import animata.NoteParser; import animata.NoteParser.BadNoteFormatException; @@ -7,30 +11,35 @@ import rwmidi.MidiInput; import rwmidi.Note; -public class NoteRangeBone extends Control { +public class NoteRangeBone extends Control implements Observer { private String bone; private float range; private int low; private int high; + private Animator animator; public NoteRangeBone(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()); - } + low = NoteParser.getNote(element.getStringAttribute("low", "1")); + high = NoteParser.getNote(element.getStringAttribute("high", "100")); + bone = element.getStringAttribute("bone"); range = (float) high - low; + animator = new animata.Animator(low, this); } - public void noteOnReceived(Note n){ - if(n.getChannel() != channel) return; + + public void noteOnReceived(Note n) { + if (n.getChannel() != channel) return; int pitch = n.getPitch(); - if(pitch < low ) return; - if(pitch > high) return; - float length = 1f - ((float)((pitch - low)) / range); - Controller.getInstance().animateBone(bone, length); + if (pitch < low) return; + if (pitch > high) return; + float length = 1f - ((float) ((pitch - low)) / range); + animator.set(length, 4); + } + + public void update(Observable o, Object arg) { + Controller.getInstance().animateBone(bone, animator.currentValue); + } } diff --git a/src/animata/model/Layer.java b/src/animata/model/Layer.java index 78ace9f..4953d34 100644 --- a/src/animata/model/Layer.java +++ b/src/animata/model/Layer.java @@ -66,8 +66,8 @@ private void setupAttributes(XMLElement element) { x = element.getFloatAttribute("x"); y = element.getFloatAttribute("y"); z = - element.getFloatAttribute("z"); - alpha = element.getFloatAttribute("alpha"); - scale = element.getFloatAttribute("scale"); + alpha = element.getFloatAttribute("alpha",1); + scale = element.getFloatAttribute("scale",1); visible = element.getIntAttribute("vis") == 1; } @@ -82,10 +82,16 @@ private void setupLayerContents(XMLElement element, String folder) { public void addLayers(XMLElement[] children, String folder) { for (int i = 0; i < children.length; i++) { XMLElement element = children[i]; - layers.add(new Layer(element,folder)); + addLayer(folder, element); } } + public Layer addLayer(String folder, XMLElement element) { + Layer layer = new Layer(element,folder); + layers.add(layer); + return layer; + } + public void simulate() { if(skeleton != null) skeleton.simulate(40); for (Layer layer : layers) { diff --git a/src/test/TestScene.java b/src/test/TestScene.java index 7d28365..ba1ba0e 100644 --- a/src/test/TestScene.java +++ b/src/test/TestScene.java @@ -24,6 +24,9 @@ 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);