Commit 51944aae authored by Philip Levis's avatar Philip Levis
Browse files

Fix a few spacings, a few minor bugs. Clean up some code.

parent 7eba0056
......@@ -53,7 +53,8 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
}
protected void onDraw(UI ui, PGraphics pg) {
try { pg.pushMatrix();
try {
pg.pushMatrix();
drawBuilding(pg);
drawFlyers(pg);
pg.popMatrix();
......@@ -176,7 +177,7 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
* Flyer that has been selected in the physical layout tool.
*/
private void computeFlyerLightsAndWings() {
flyerHighlighter.highlight();
//flyerHighlighter.highlight();
}
/** Draws the Packard stairwell: the walls, the ceiling pipes, and
......
......@@ -115,7 +115,7 @@ void initializeUI(LXStudio lx, LXStudio.UI ui) {
public void onUIReady(LXStudio lx, LXStudio.UI ui) {
System.out.println("Creating UI.");
FlightGui.this.flyerHighlighter = new FlyerHighlighter(lx, flyerConfigurations);
FlightGui.this.flyerHighlighter = new FlyerHighlighter(lx, flyerConfigurations, model);
lx.addEffect(flyerHighlighter);
configureUI(lx, ui);
}
......@@ -164,10 +164,30 @@ void configureUI(LXStudio lx, LXStudio.UI ui) {
ui.addLayer(viewContext);
ui.addLayer(new UIFlyerConfiguration(ui));
ui.addLayer(new UIPatternMixer(lx, ui));
ui.addLayer(new UIManager(lx, ui));
}
@Override
public void draw() {
List<FlyerModel> flyers = model.getFlyers();
LXChannel channel = lx.engine.mixer.getDefaultChannel();
List<LXPattern> patterns = channel.patterns;
for (LXPattern pattern: patterns) {
try {
FlightPattern fp = (FlightPattern)pattern;
// Copy the skew out of the pattern into the model
for (FlyerModel flyer: flyers) {
WingModel left = (WingModel)flyer.getLeftWing();
WingModel right = (WingModel)flyer.getRightWing();
left.setSkew(fp.getSkew(left));
right.setSkew(fp.getSkew(right));
}
break;
} catch (ClassCastException ex) {
System.err.println("There is a non-FlightPattern in the pattern list.");
ex.printStackTrace();
}
}
//background(#222222);
// The actual model and such are drawn in their own
// draw methods, e.g. UIFlightDisplay.onDraw.
......
......@@ -300,17 +300,27 @@ class UIFlyerConfiguration extends UIWindow {
class UIPatternMixer extends UIWindow {
final static int WIDTH = 400;
final static int HEIGHT = 200;
final static int WIDTH = 600;
final static int HEIGHT = 180;
final static int BORDER = 4;
UIPatternMixer(LX thislx, UI ui) {
super(ui, "MIXER",
WIDTH, FlightGui.this.height - (HEIGHT + BORDER),
300, FlightGui.this.height - (HEIGHT + BORDER),
WIDTH, HEIGHT);
System.out.println("thislx " + thislx);
System.out.println("thislx.engine " + thislx.engine);
System.out.println("thislx.engine.mixer " + thislx.engine.mixer);
new UIMixer(ui, thislx, 0, 0, HEIGHT).addToContainer(this);
}
}
class UIManager extends UIWindow {
final static int WIDTH = 300;
final static int HEIGHT = 300;
final static int BORDER = 4;
UIManager(LX thislx, UI ui) {
super(ui, "Patterns",
0, 0,
WIDTH, HEIGHT);
new UIPatternList(ui, 0, 0, WIDTH, HEIGHT, thislx.engine.mixer.getDefaultChannel()).addToContainer(this);
}
}
......@@ -44,20 +44,23 @@ abstract class FlightEngine {
// Automation variables
final FFAutomationClip[] automation = new FFAutomationClip[NUM_AUTOMATION];
final ArrayList<LXPattern> patterns;
/** CONSTRUCTOR **/
FlightEngine(String projectPath, FlightModel model, LXStudio lx) {
FlightEngine(String projectPath, FlightModel model, LXStudio lx) {
this.projectPath = projectPath;
io = new IO(projectPath);
this.io = new IO(projectPath);
this.model = model;
this.lx = lx;
this.patterns = new ArrayList<LXPattern>();
/** All engine configuration **/
configureGeneratorOutput();
configureChannels();
configureAutomation();
/** For testing **/
lx.engine.addLoopTask(new FadeTest(lx));
//lx.engine.addLoopTask(new FadeTest(lx));
// io.saveConfigFile(model.getFlyerConfigs(), Config.FLYER_CONFIG_FILE);
// String testPlaylistFilename = "data/playlist.json";
......@@ -95,8 +98,10 @@ abstract class FlightEngine {
/* Configures channels */
private void configureChannels() {
for (int i = 0; i < NUM_CHANNELS; ++i) {
LXChannel channel = lx.engine.mixer.addChannel(i, getPatternArrayForChannels());
addPatterns(this.patterns);
int numChannels = Math.min(this.patterns.size(), NUM_CHANNELS);
for (int i = 0; i < numChannels; ++i) {
LXChannel channel = lx.engine.mixer.addChannel(i, new LXPattern[] {this.patterns.get(i)});
//setupChannel(channel, true);
if (i == 0) {
channel.fader.setValue(1);
......
......@@ -15,9 +15,11 @@ class FlyerHighlighter extends Effect {
final QuadraticEnvelope strobe = new QuadraticEnvelope(100, 0, 1000);
final DiscreteParameter flyerIndex;
final BooleanParameter showBlanks = new BooleanParameter("BLANKS", false);
FlyerHighlighter(LX lx, FlyerConfig[] configs) {
final FlightModel model;
FlyerHighlighter(LX lx, FlyerConfig[] configs, FlightModel model) {
super(lx);
this.model = model;
flyerConfigurations = configs;
flyerIndex = new DiscreteParameter("FLYER", flyerConfigurations.length);
......@@ -31,7 +33,6 @@ class FlyerHighlighter extends Effect {
// }
// });
addModulator(strobe).start();
addLayer(new HighlightLayer());
}
// REVIEW(mcslee): automatically receive these changes from our
......@@ -57,15 +58,15 @@ class FlyerHighlighter extends Effect {
}
void reloadModel() {
Model m = new Model(flyerConfigurations);
lx.setModel(m.getFlightModel());
lx.getModel().bang();
}
void trigger() {
strobe.trigger();
}
void highlight() {
@Override
public void run(double deltaMs, double enabledAmount) {
// REVIEW(mcslee): looks redunant with HighlightLayer below?
if (isEnabled()) {
for (LightSamplePointModel point : getFlyerLightPoints()) {
......@@ -79,37 +80,4 @@ class FlyerHighlighter extends Effect {
}
}
}
// REVIEW(mcslee): this doesn't do anything
// public void run(double deltaMs) {}
@Override
public void run(double deltaMs, double enabledAmount) {
// REVIEW(mcslee): this is where your effect logic should be
}
// REVIEW(mcslee): not sure there's any reason for a layer here, put this logic in
// the run(double deltaMs, double foo)
class HighlightLayer extends LXLayer {
HighlightLayer() {
super(FlyerHighlighter.this.lx);
}
@Override
public void run(double deltaMs) {
if (isEnabled()) {
for (LightSamplePointModel point : getFlyerLightPoints()) {
int oldColor = getColor(point);
float val = strobe.getValuef();
int highlightColor = LX.hsb(0, 0, val);
int newColor = LXColor.blend(oldColor,
highlightColor,
LXColor.Blend.ADD);
FlyerHighlighter.this.setColor(point, newColor);
}
}
}
}
}
import heronarts.lx.LX;
import heronarts.lx.pattern.LXModelPattern;
import heronarts.lx.model.LXPoint;
abstract class Pattern extends LXModelPattern<FlightModel> {
abstract class FlightPattern extends LXModelPattern<FlightModel> {
protected int[] skews = null;
Pattern(LX lx) {
FlightPattern(LX lx) {
super(lx);
// this.addLayer(new LXLayer(lx, new LXDeviceComponent(lx, "skew")));
skews = ((FlightModel) lx.getModel()).getAllWingsSkew();
......
import java.util.List;
import heronarts.lx.LX;
import heronarts.lx.modulator.SinLFO;
import heronarts.lx.parameter.BoundedParameter;
// array of wing positions akin to colors[]
class FadeTest extends Pattern {
final BoundedParameter speed = new BoundedParameter("SPEE", 11000, 100000, 1000);
final SinLFO color = new SinLFO(0, 360, speed);
FadeTest(LX lx) {
super(lx);
addParameter(speed);
addModulator(color).start();
}
@Override
public void run(double deltaMs) {
float hue = color.getValuef();
int val = lx.hsb(hue, 100, 100);
int skew = (int)((hue - 180f) / 2);
for (Wing wing: model.getAllWings()) {
wing.setSkew(skew);
}
for (LightSamplePointModel bodyPoint : model.getAllBodyLights()) {
setColor(bodyPoint, LX.hsb(0, 0, 20));
}
for (LightSamplePointModel wingPoint : model.getAllWingsLights()) {
setColor(wingPoint, LX.hsb(hue, 100, 100));
}
}
}
class BlackPinkTest extends Pattern {
int FLYER_MOD = 75;
final BoundedParameter period = new BoundedParameter("RATE", 10000, 10000, 18000);
final SinLFO flyerIndex = new SinLFO(0, FLYER_MOD, period);
BlackPinkTest(LX lx) {
super(lx);
addParameter(period);
addModulator(flyerIndex).start();
}
@Override
public void run(double deltaMs) {
List<LightSamplePointModel> allLights = model.getAllLights();
for (LightSamplePointModel lightPoint : allLights) {
if (lightPoint.getBodyIndex() == (int) flyerIndex.getValue()) {
setColor(lightPoint, LX.hsb(330, 70, 70));
} else {
setColor(lightPoint, LX.hsb(0, 0, 20));
}
}
for (WingModel wing : model.getAllWings()) {
if (wing.getFlyerIndex() == (int) flyerIndex.getValue()) {
setSkew(wing, 180);
} else {
setSkew(wing, 0);
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment