package com.haxademic.demo.hardware.dmx;

import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.app.config.AppSettings;
import com.haxademic.core.draw.context.PG;
import com.haxademic.core.draw.image.ImageUtil;
import com.haxademic.core.hardware.dmx.DMXFixture.DMXMode;
import com.haxademic.core.hardware.dmx.editor.DMXEditor;
import com.haxademic.core.media.DemoAssets;

import processing.core.PGraphics;
import processing.video.Movie;

public class Demo_DmxEditor
extends PAppletHax {
	public static void main(String args[]) { arguments = args; PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }
	
	protected DMXEditor editor;
	protected PGraphics textureMap;
	protected PGraphics dmxUI;
	protected Movie video;
	
	protected void overridePropsFile() {
		p.appConfig.setProperty(AppSettings.WIDTH, 960);
		p.appConfig.setProperty(AppSettings.HEIGHT, 540);
	}

	public void setupFirstFrame() {
		textureMap = PG.newPG(960/2, 540/2);	// can be smaller, but should be same aspect ratio as pgUI
		video = DemoAssets.movieFractalCube();
		video.loop();
		dmxUI = PG.newPG(960, 540);
		editor = new DMXEditor("COM3", 9600, DMXMode.SINGLE_CHANNEL, "text/dmx/dmx-lights-editor.txt", dmxUI, textureMap, DemoAssets.textureNebula());
	}

	public void drawApp() {
		p.background(0, 127, 0);
		if(video.width > 20) ImageUtil.cropFillCopyImage(video, textureMap, true);	// Update light map texture 
		editor.update();															// Update DMXEditor
		p.image(dmxUI, 0, 0);														// Draw editor to screen
	}
}

@@ -413,16 +413,47 @@
 aphics;%0A
+import processing.core.PImage;%0A
 import p
@@ -754,16 +754,45 @@
  dmxUI;%0A
+%09protected PImage floorplan;%0A
 %09protect
@@ -987,16 +987,227 @@
 ame() %7B%0A
+%09%09// Create buffer for DMXEditor color sampling%0A%09%09// Can be smaller, but should be same aspect ratio as pgUI%0A%09%09// - Buffer is treated as the same size as GUI, but scaled up for speed of sampling smaller texture%0A
 %09%09textur
@@ -1240,67 +1240,190 @@
 /2);
+%0A%09
 %09// c
-an be smaller, but should be same aspect ratio as pgUI
+reate buffer for DMXEditor UI%0A%09%09dmxUI = PG.newPG(960, 540);%0A%09%09// load floorplan%0A%09%09floorplan = DemoAssets.textureNebula();%0A%09%09// create animation to map to floorplan & DMXEditor
 %0A%09%09v
@@ -1482,35 +1482,49 @@
 ;%0A%09%09
-dmxUI = PG.newPG(960, 540);
+// build editor with all buffers & images
 %0A%09%09e
@@ -1553,9 +1553,9 @@
 %22COM
-3
+4
 %22, 9
@@ -1640,34 +1640,17 @@
 ap, 
-DemoAssets.textureNebula()
+floorplan
 );%0A%09
@@ -1683,32 +1683,94 @@
 %7B%0A%09%09
-p.background(0, 127, 0);
+// clear background%0A%09%09p.background(0);%0A%09%09// copy lights animation to DMXEditor buffer 
 %0A%09%09i
@@ -1846,37 +1846,51 @@
 ue);
+ %0A%09
 %09// 
-U
+u
 pdate 
-light map textu
+& send lights to DMX hardwa
 re
- 
 %0A%09%09e
@@ -1908,104 +1908,59 @@
 e();
-%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09// Update DMXEditor%0A%09%09p.image(dmxUI, 0, 0);%09%09%09%09%09%09%09%09%09%09%09%09%09%09// Draw editor to screen
+%0A%09%09// Draw editor to screen%0A%09%09p.image(dmxUI, 0, 0);
 %0A%09%7D%0A

Add notes around DMXEditor demo