# HG changeset patch
# User Robert McIntyre <rlm@mit.edu>
# Date 1319774870 25200
# Node ID d10f4d4ff15a0a6d5749574d3125adf6d1e35fd3
# Parent  8a6b1684f53697ac8b90ae6201a9d87caf62ae1f
going to improve documentation

diff -r 8a6b1684f536 -r d10f4d4ff15a build.xml
--- a/build.xml	Thu Oct 27 02:27:02 2011 -0700
+++ b/build.xml	Thu Oct 27 21:07:50 2011 -0700
@@ -11,8 +11,6 @@
     <pathelement path="${lib}/lwjgl.jar"/>
     <pathelement path="${lib}/xuggle/xuggle-xuggler.jar"/>
     <pathelement path="${lib}/audio-send.jar"/>
-    
-    
   </path>
 
   <target name="prepare">
diff -r 8a6b1684f536 -r d10f4d4ff15a src/com/aurellem/capture/Capture.java
--- a/src/com/aurellem/capture/Capture.java	Thu Oct 27 02:27:02 2011 -0700
+++ b/src/com/aurellem/capture/Capture.java	Thu Oct 27 21:07:50 2011 -0700
@@ -2,34 +2,73 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.concurrent.Callable;
 
+import com.aurellem.capture.audio.MultiListener;
+import com.aurellem.capture.audio.WaveFileWriter;
 import com.aurellem.capture.video.AVIVideoRecorder;
 import com.aurellem.capture.video.AbstractVideoRecorder;
 import com.aurellem.capture.video.XuggleVideoRecorder;
 import com.jme3.app.Application;
-import com.jme3.math.ColorRGBA;
+import com.jme3.audio.AudioRenderer;
+import com.jme3.renderer.ViewPort;
+import com.jme3.scene.Spatial;
+import com.jme3.system.AppSettings;
 
 public class Capture {
 
-	public static void SimpleCaptureVideo(Application app, File file) throws IOException{
-		app.getViewPort().setClearFlags(true, true, true);
-		// this prevents pixels from staying in the render buffer between frames
-		// and messing the video up.  It's not a problem since Black is the default, and this 
-		// can be overridden by user code.
-		app.getViewPort().setBackgroundColor(ColorRGBA.Black);
-		
+	public static void captureVideo(final Application app, final File file) throws IOException{
+
+		final AbstractVideoRecorder videoRecorder;
 		// The XuggleVideoRecorder is better than the AVIVideoRecorder in every way
 		// except for ease of installation.  The excellent work by Werner Randelshofer
 		// is used as a fallback option.  Please visit http://www.xuggle.com/ to learn
 		// how to set up the XuggleVideoRecorder.
+
+		if (file.getCanonicalPath().endsWith(".avi")){
+			videoRecorder = new AVIVideoRecorder(file);}
+		else { videoRecorder = new XuggleVideoRecorder(file);}
+
+		Callable<Object> thunk = new Callable<Object>(){
+			public Object call(){
+
+				ViewPort viewPort = 
+						app.getRenderManager()
+						.createPostView("aurellem record", app.getCamera());
+
+				viewPort.setClearFlags(false, false, false);
+
+				// get GUI node stuff
+				for (Spatial s : app.getGuiViewPort().getScenes()){
+					viewPort.attachScene(s);
+				}
+
+				app.getStateManager().attach(videoRecorder);
+				viewPort.addProcessor(videoRecorder);
+				return null;
+			}
+		};
+		app.enqueue(thunk);
+	}
+
+	
+	public static void captureAudio(final Application app, final File file) throws IOException{
+		AppSettings settings = new AppSettings(true);
+		settings.setAudioRenderer("Send");
+		app.setSettings(settings);
+
+		Callable<Object> thunk = new Callable<Object>(){
+			public Object call(){
+				AudioRenderer ar = app.getAudioRenderer();
+				if (ar instanceof MultiListener){
+					MultiListener ml = (MultiListener)ar;
+					ml.registerSoundProcessor(new WaveFileWriter(file));
+				}
+				return null;
+			}
+		};
 		
-		AbstractVideoRecorder videoRecorder;
-		
-		if (file.getCanonicalPath().endsWith(".avi")){
-			 videoRecorder = new AVIVideoRecorder(file);}
-		else { videoRecorder = new XuggleVideoRecorder(file);}
-		
-		app.getStateManager().attach(videoRecorder);
-		app.getViewPort().addFinalProcessor(videoRecorder);
-	}	
+		app.enqueue(thunk);
+	}
+	
 }
diff -r 8a6b1684f536 -r d10f4d4ff15a src/com/aurellem/capture/hello/AdvancedAudio.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/aurellem/capture/hello/AdvancedAudio.java	Thu Oct 27 21:07:50 2011 -0700
@@ -0,0 +1,158 @@
+package com.aurellem.capture.hello;
+
+import java.io.File;
+
+import com.aurellem.capture.IsoTimer;
+import com.aurellem.capture.audio.MultiListener;
+import com.aurellem.capture.audio.WaveFileWriter;
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+import com.jme3.audio.Listener;
+import com.jme3.input.controls.ActionListener;
+import com.jme3.input.controls.MouseButtonTrigger;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Quaternion;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.shape.Box;
+import com.jme3.system.AppSettings;
+
+
+/**
+ * 
+ * 
+ * 
+ * @author Robert McIntyre
+ *
+ */
+
+public class AdvancedAudio extends SimpleApplication {
+	  
+
+  
+  public static void main(String[] args) {
+
+	 // Logger.getLogger("com.jme3").setLevel(Level.OFF);
+	  
+	AdvancedAudio app = new AdvancedAudio();
+	AppSettings settings = new AppSettings(true);
+	
+	settings.setAudioRenderer("Send");
+	app.setSettings(settings);
+	app.setShowSettings(false);
+	app.start();
+	app.setPauseOnLostFocus(false);
+  }
+
+  
+  
+  private AudioNode audio_gun;
+  private AudioNode audio_nature;
+  private Geometry player;
+  private Listener auxListener = new Listener(); 
+  public File data1 = new File("/home/r/tmp/data1.wav");
+  public File data2 = new File("/home/r/tmp/data2.wav");
+  public File data3 = new File("/home/r/tmp/data3.wav");
+   
+  private File makeTarget(int n){
+	  	return new File("/home/r/tmp/assload-" + n + ".wav");
+  }
+  
+  
+  @Override
+  public void simpleInitApp() {
+	this.setTimer(new IsoTimer(60));
+	
+	
+	if (this.audioRenderer instanceof MultiListener){
+		MultiListener rf = (MultiListener)this.audioRenderer;
+		
+		for (int n = 0; n < 0; n++){
+			Listener zzz = new Listener();
+			rf.addListener(zzz);
+			rf.registerSoundProcessor(
+						zzz, new WaveFileWriter(makeTarget(n)));
+		}
+		Listener listener3 = new Listener();
+		rf.addListener(auxListener);
+		rf.addListener(listener3);
+		rf.registerSoundProcessor(new WaveFileWriter(data1));
+		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
+		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
+	}
+    flyCam.setMoveSpeed(40);
+    
+    /** just a blue box floating in space */
+    Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
+    player = new Geometry("Player", box1);
+    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
+    mat1.setColor("Color", ColorRGBA.Blue);
+    player.setMaterial(mat1);
+    rootNode.attachChild(player);
+    
+    /** custom init methods, see below */
+    initKeys();
+    initAudio();
+	
+	this.audioRenderer.playSource(audio_gun);
+
+	
+
+  }
+
+  /** We create two audio nodes. */ 
+  private void initAudio() {
+	//audioRenderer.setEnvironment(Environment.Cavern);
+    /* gun shot sound is to be triggered by a mouse click. */
+	audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false);
+	//audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
+    audio_gun.setLooping(false);
+    audio_gun.setVolume(2);
+    audio_gun.setPositional(true);
+
+
+    /* nature sound - keeps playing in a loop. */
+    audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false);
+    audio_nature.setLooping(true);
+    audio_nature.setPositional(true);
+    audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
+    audio_nature.setVolume(3);
+    audio_nature.updateGeometricState();
+  }
+
+  /** Declaring the "Shoot" action, and
+   *  mapping it to a trigger (mouse click). */
+  private void initKeys() {
+    inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
+    inputManager.addListener(actionListener, "Shoot");
+  }
+
+  /** Defining the "Shoot" action: Play a gun sound. */
+  private ActionListener actionListener = new ActionListener() {
+    @Override
+    public void onAction(String name, boolean keyPressed, float tpf) {
+      if (name.equals("Shoot") && !keyPressed) {
+        audioRenderer.playSource(audio_gun); // play once!
+      }
+    }
+  };
+
+  /** Move the listener with the camera - for 3D audio. */
+  @Override
+  public void simpleUpdate(float tpf) {
+	Vector3f loc = cam.getLocation();
+	Quaternion rot = cam.getRotation();
+    listener.setLocation(loc);
+    listener.setRotation(rot);
+    auxListener.setLocation(loc);
+    auxListener.setRotation(rot);
+    if (audio_gun.getStatus() == AudioNode.Status.Stopped){
+    	System.out.println("I'm Stopped!");
+    	this.requestClose(false);
+    }
+    	
+    	
+  }
+
+}
diff -r 8a6b1684f536 -r d10f4d4ff15a src/com/aurellem/capture/hello/BasicAVRecord.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/aurellem/capture/hello/BasicAVRecord.java	Thu Oct 27 21:07:50 2011 -0700
@@ -0,0 +1,76 @@
+package com.aurellem.capture.hello;
+
+import java.io.File;
+import java.io.IOException;
+
+import jme3test.helloworld.HelloAudio;
+import jme3test.helloworld.HelloJME3;
+import jme3test.niftygui.TestNiftyExamples;
+import jme3test.water.TestPostWater;
+
+import com.aurellem.capture.Capture;
+import com.aurellem.capture.IsoTimer;
+import com.jme3.app.SimpleApplication;
+
+
+/**
+ * 
+ * Demonstrates how to use basic Audio/Video capture with a jMonkeyEngine 
+ * application.
+ * 
+ * @author Robert McIntyre
+ *
+ */
+
+public class BasicAVRecord {
+	
+	public static void basicVideo() throws IOException{
+		File video = File.createTempFile("HelloJME3", ".avi");
+		System.out.println("Saving video to: " + video.getCanonicalPath());
+		SimpleApplication app = new HelloJME3();
+		app.setTimer(new IsoTimer(60));
+		
+		Capture.captureVideo(app, video);
+		app.start();
+	}
+	
+	public static void basicVideoGUI() throws IOException {
+		File video = File.createTempFile("GUI", ".avi");
+		System.out.println("Saving video to: " + video.getCanonicalPath());
+		SimpleApplication app = new TestNiftyExamples();
+		app.setTimer(new IsoTimer(60));
+		
+		Capture.captureVideo(app, video);
+		app.start();
+	}
+	
+	public static void basicAudio() throws IOException{
+		File audio = File.createTempFile("BasicAudio", ".wav");
+		System.out.println("Saving audio to: " + audio.getCanonicalPath());
+		SimpleApplication app = new HelloAudio();
+		app.setTimer(new IsoTimer(60));
+		
+		// you will not hear the audio while it is being captured.
+		Capture.captureAudio(app, audio);
+		
+		app.start();
+	}
+	
+	public static void basicAudioVideo() throws IOException{
+		File video = new File("/home/r/tmp/basicVideo.avi");
+		File audio = new File("/home/r/tmp/basicAudio.wav");
+		
+		SimpleApplication app = new TestPostWater();
+		app.setTimer(new IsoTimer(60));
+		
+		Capture.captureVideo(app, video);
+		Capture.captureAudio(app, audio);
+		
+		app.start();
+	}
+	
+	
+	public static void main(String[] ignore) throws IOException{
+		basicAudio();
+		}
+}
diff -r 8a6b1684f536 -r d10f4d4ff15a src/com/aurellem/capture/hello/HelloAudio.java
--- a/src/com/aurellem/capture/hello/HelloAudio.java	Thu Oct 27 02:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-package com.aurellem.capture.hello;
-
-import java.io.File;
-
-import com.aurellem.capture.IsoTimer;
-import com.aurellem.capture.audio.MultiListener;
-import com.aurellem.capture.audio.WaveFileWriter;
-import com.jme3.app.SimpleApplication;
-import com.jme3.audio.AudioNode;
-import com.jme3.audio.Listener;
-import com.jme3.input.controls.ActionListener;
-import com.jme3.input.controls.MouseButtonTrigger;
-import com.jme3.material.Material;
-import com.jme3.math.ColorRGBA;
-import com.jme3.math.Quaternion;
-import com.jme3.math.Vector3f;
-import com.jme3.scene.Geometry;
-import com.jme3.scene.shape.Box;
-import com.jme3.system.AppSettings;
-
-/** Sample 11 - playing 3D audio. */
-public class HelloAudio extends SimpleApplication {
-	  
-
-  
-  public static void main(String[] args) {
-
-	 // Logger.getLogger("com.jme3").setLevel(Level.OFF);
-	  
-	HelloAudio app = new HelloAudio();
-	AppSettings settings = new AppSettings(true);
-	
-	//settings.setAudioRenderer("Send");
-	app.setSettings(settings);
-	app.setShowSettings(false);
-	app.start();
-	app.setPauseOnLostFocus(false);
-  }
-
-  
-  
-  private AudioNode audio_gun;
-  private AudioNode audio_nature;
-  private Geometry player;
-  private Listener auxListener = new Listener(); 
-  public File data1 = new File("/home/r/tmp/data1.wav");
-  public File data2 = new File("/home/r/tmp/data2.wav");
-  public File data3 = new File("/home/r/tmp/data3.wav");
-   
-  private File makeTarget(int n){
-	  	return new File("/home/r/tmp/assload-" + n + ".wav");
-  }
-  
-  
-  @Override
-  public void simpleInitApp() {
-	this.setTimer(new IsoTimer(60));
-	
-	
-	if (this.audioRenderer instanceof MultiListener){
-		MultiListener rf = (MultiListener)this.audioRenderer;
-		
-		for (int n = 0; n < 0; n++){
-			Listener zzz = new Listener();
-			rf.addListener(zzz);
-			rf.registerSoundProcessor(
-						zzz, new WaveFileWriter(makeTarget(n)));
-		}
-		Listener listener3 = new Listener();
-		rf.addListener(auxListener);
-		rf.addListener(listener3);
-		rf.registerSoundProcessor(new WaveFileWriter(data1));
-		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
-		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
-	}
-    flyCam.setMoveSpeed(40);
-    
-    /** just a blue box floating in space */
-    Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
-    player = new Geometry("Player", box1);
-    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
-    mat1.setColor("Color", ColorRGBA.Blue);
-    player.setMaterial(mat1);
-    rootNode.attachChild(player);
-    
-    /** custom init methods, see below */
-    initKeys();
-    initAudio();
-	
-	this.audioRenderer.playSource(audio_gun);
-
-	
-
-  }
-
-  /** We create two audio nodes. */ 
-  private void initAudio() {
-	//audioRenderer.setEnvironment(Environment.Cavern);
-    /* gun shot sound is to be triggered by a mouse click. */
-	audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false);
-	//audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
-    audio_gun.setLooping(false);
-    audio_gun.setVolume(2);
-    audio_gun.setPositional(true);
-
-
-    /* nature sound - keeps playing in a loop. */
-    audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false);
-    audio_nature.setLooping(true);
-    audio_nature.setPositional(true);
-    audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
-    audio_nature.setVolume(3);
-    audio_nature.updateGeometricState();
-  }
-
-  /** Declaring the "Shoot" action, and
-   *  mapping it to a trigger (mouse click). */
-  private void initKeys() {
-    inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
-    inputManager.addListener(actionListener, "Shoot");
-  }
-
-  /** Defining the "Shoot" action: Play a gun sound. */
-  private ActionListener actionListener = new ActionListener() {
-    @Override
-    public void onAction(String name, boolean keyPressed, float tpf) {
-      if (name.equals("Shoot") && !keyPressed) {
-        audioRenderer.playSource(audio_gun); // play once!
-      }
-    }
-  };
-
-  /** Move the listener with the camera - for 3D audio. */
-  @Override
-  public void simpleUpdate(float tpf) {
-	Vector3f loc = cam.getLocation();
-	Quaternion rot = cam.getRotation();
-    listener.setLocation(loc);
-    listener.setRotation(rot);
-    auxListener.setLocation(loc);
-    auxListener.setRotation(rot);
-    if (audio_gun.getStatus() == AudioNode.Status.Stopped){
-    	System.out.println("I'm Stopped!");
-    	this.requestClose(false);
-    }
-    	
-    	
-  }
-
-}
diff -r 8a6b1684f536 -r d10f4d4ff15a src/com/aurellem/capture/hello/HelloVideo.java
--- a/src/com/aurellem/capture/hello/HelloVideo.java	Thu Oct 27 02:27:02 2011 -0700
+++ b/src/com/aurellem/capture/hello/HelloVideo.java	Thu Oct 27 21:07:50 2011 -0700
@@ -48,7 +48,7 @@
     	}catch (IOException e) {
     		e.printStackTrace();}
     		*/
-    	try {Capture.SimpleCaptureVideo(this, movingVideo);} 
+    	try {Capture.captureVideo(this, movingVideo);} 
     	catch (IOException e) {e.printStackTrace();}
 		
     }