MusicBeam
MusicBeam copied to clipboard
Projector Simulator
Implements #59
Proposed Changes
- Add ProjectorSimulator class
- Tool that allows for quick effects prototyping
- Extends PApplet; runs on its own thread
- Runs on debugMode
- Modify Stage class to support ProjectorSimulator
- Add, init, and start ProjectorSimulator sim field
- Arrange draw() to accommodate image export to ProjectorSimulator
- Update sim field in draw()
@LuisMQuinones this is pretty amazing!
I just had a first look and ran it. I noticed that the simulator only shows part of the stage. I attached a screenshot:
I'll have a deeper look into the code now. I think we should add a keyboard shortcut to en- and disable the debug mode. Maybe some other people want to play with it. Not everyone has a project at hand when they want to test the software.
Ok, I think i found the problem. I created a very simplified version of your approach:
public class ProjectorSimulator extends PApplet{
private PImage projImg;
private int hires_factor = 2;
public ProjectorSimulator(){
super();
}
public void settings() {
pixelDensity(displayDensity());
size(800, 600, P3D);
}
public void setup(){
projImg = createImage(800,600,ARGB);
}
public void setImage(PImage img){
projImg = img;
}
public void draw(){
background(0);
drawBeams();
}
private void drawBeams(){
blendMode(ADD);
strokeWeight(hires_factor);
projImg.loadPixels();
color[] pixels = projImg.pixels;
translate(0, 0, -500);
for(int i=0; i < pixels.length; i+=hires_factor){
color pixel = pixels[i];
if(pixel != color(0)){
stroke(pixel);
int x = (i % (projImg.width * hires_factor)) / hires_factor;
int y = (i / (projImg.width * hires_factor)) / hires_factor;
line(projImg.width/hires_factor, 0, 0, x, y, 500);
}
}
}
}
Now the problem is that projImg.width is does not return the correct result for retina (hi-res) displays. projImg.pixels on the other hand does contain this information.
So the array on my MacBook has 8002 * 6002 pixel. Not 800*600.
Thank you! I really appreciate it. I'm still a student, so I'm still a little shy sharing my ideas and code.
As far as a keyboard shortcut, my suggestion is the '`' key. It is used to open the console in games like CS: GO and other valve games. My concern for enabling and disabling debugMode is starting and properly killing threads.
On the retina fix; I looked at the javadocs for PImage, and using projImg.pixelWidth and projOmg.pixelHeight instead of proj.width and proj.height should fix the problem. That, along with initializing hires_factor to pixelDensity, should fix the problem. It should be a quick fix, and I'll have the commit up shortly.
How's performance? I think creating a new PImage object every draw cycle (in Stage) is taxing. I tried finding a way to get the PApplet's pgrahics object, but I couldn't get it working. One trick i did to help with performance is to not draw a light beam for every pixel, so it keeps the number of items being drawn to a minimum. That helped a lot.
@LuisMQuinones no reason to be shy here, I wrote this when I was a student too ;) Also my Java is.... well lets say I don't do much Java these days.
Ok, how do we continue. I would suggest you update your PR to support retina properly. I would probably for now also omit the rotation features.
Hide the feature behind the debug flag for now. We can figure out how to trigger debug mode in a separate PR.
Oh and yes, rendering less pixel is totally fine. Especially on a retina there so many pixel ;)
I don't quite understand, "I would probably for now also omit the rotation features. Hide the feature behind the debug flag for now. "
In the current build, the tool is only launched if the debugMode flag is true. User's can: - Move the camera along theta in spherical coordinates with 'a' and 'd' - Move the camera distance with 'w' and 's' - Move the camera along phi in spherical coordinates 'q' and 'e' - Move the point of reference (in 2D) with the arrow keys So the tool itself( and the window) doesn't launch if the debug flag is off.
Do you want the tool to open regardless if it's in debugMode? Do you want the tool to open, but the navigations features are turned off until the debugMode flag is true?
I know it will help people visualize the effects better if the tool opens up alongside the stage window, but my concern would be too many windows to handle for the user.
As my understanding, this is what you when launching the app regularly: The controller, the projector simulator (without navigation and controls), and the stage at fullscreen at startup?
The simple fix in the last commit should fix the retina issues. I don't have a retina display myself to test it out. @codingjoe let me know if the commit fixes the retina issues
Bump message. It's been a week since I've made the latest commit.
@codingjoe Did you look at the changes that I've made? I've made the changes you wanted, reformat the rest of the code to Google Java Style Guide standards, and documented/commented the class, fields, and methods.
I think the rotation feature and its associated camera system is a big part of the tool, but I'll voice my concern when this PR is merged, and I post my opinion on the issue thread.
Hi @LuisMQuinones sorry for the late response. I was super busy at work. Ok, so I didn't review the code yet, but I tested it. It still doesn't seem to work correctly for retina displays. I still only see half the effect.

Oh btw, I am trying to find a sponsor in MA for you ;)
@LuisMQuinones I found some hardware for you :) just send me your shipping address to [email protected]