My favorites ▼ | Sign in Support browsers that contribute to open source, try Firefox or Google Chrome. most
pixelsever
Multi-Screen Library for
Processing Project Home Downloads Wiki Issues Source Search Search within: All wiki pages Featured pages Current pages Deprecated pagesfor Updated Aug 31, 2009 by daniel.shiffman Labels: Featured,
Tutorial ProcessingTutorial Tutorial on how to use the MPE library with the
Processing IDE. Before you try this
tutorial, you probably want to read HowThisWorks. Step 1. Run the server.¶ Download and extract MPE server application Run the server via the command line. java -jar mpeServer.jar -debug1 -framerate30 -screens2 The server can be configured by changing the command line arguments. Step 2. Download and install the MPE library¶ Grab the library from the | download page 3. Convert a single-screen applet to a
multi-screen one! Let's say you have a | simple ball bouncing applet that runs at 320x240. We now want to make it run at 640x240 across two windows. (For testing, it's easiest to run two windows on one machine.) First, import the library: import mpe.client.*; Then create a client object: // A client object TCPClient client; In setup(), initialize the Client object. Here, a settings INI file is required. This file tells the client what its local dimensions are, as well as its location within the master dimensions. # indicates a comment and end all lines with a semi-colon (and no spaces!) Here is an example: # Client ID (0,1,2,etc.) id=0; # Server address (localhost for testing) server=localhost; # Server port port=9002; # What are the client window dimensions? localScreenSize=200,400; # Where is the client located in the master dimensions? localLocation=0,0; # What are the master dimensions? masterDimensions=400,400; # Turn to 0 to turn off all the console printing debug=1; Once you've created the INI file, you can make the client object in setup(): // make a new Client using an INI file // sketchPath() is used so that the INI file is local to the sketch client = new TCPClient(sketchPath("mpe.ini"), this); Once you've made the Client object, you should ask it for the size of your sketch. // the size is determined by the client's local width and height size(client.getLWidth(), client.getLHeight()); Finally, in setup(), you must make sure to tell the client to start(). It's generally best to do this as the last thing in setup. // Important, must start the client! client.start();
Processing's draw() loop is replaced by the frameEvent() callback. This function is triggered by the Client object whenever the server alerts the client that a new frame should be rendered. You must implement this function for the framework to function properly. //-------------------------------------- // Triggered by the client whenever a new frame should be rendered. // All synchronized drawing should be done here when in auto mode. void frameEvent(TCPClient c) { background(255); // move and draw all the balls for (int i = 0; i < balls.size(); i++) { Ball ball = (Ball)balls.get(i); ball.calc(); ball.draw(); } } Draw you can keep empty. //-------------------------------------- // Keep the motor running... draw() needs to be added in auto mode, even if // it is empty to keep things rolling. void draw() { } Note that if you are using the variables width or height in your sketch, you may need to change these to client.getMWidth(); if (x < 0 || x > client.getMWidth()) xdir *= -1; // Note the use of the master width! In addition, if you are using any random numbers or Perlin noise, you must make sure to seed them with a constant so that all client screens will pick the same sequence of randoms. randomSeed(1); // Seed random so all clients pick same sequence noiseSeed(1); Broadcasting Messages¶ You can also broadcast a message from one client to all clients. For example, if you want a mouse connected to one client to act as a mouse for the entire system, you will need to broadcast a message when the mouse is clicked. //-------------------------------------- // Adds a Ball to the stage at the position of the mouse click. void mousePressed() { // never include a ":" when broadcasting your message int x = mouseX + client.getXoffset(); int y = mouseY + client.getYoffset(); client.broadcast(x + "," + y); } Note the use of getXoffset() and getYoffset() to account for the mouse’s position within the master dimensions. The message is then received during a frameEvent(). Note that the message comes in as an array of Strings (the server accumulates these messages into an array.) // read any incoming messages if (c.messageAvailable()) { String[] msg = c.getDataMessage(); String[] xy = msg[0].split(","); float x = Integer.parseInt(xy[0]); float y = Integer.parseInt(xy[1]); balls.add(new Ball(x, y)); } Step 4. Ok, how the heck do I run this thing?¶ Going back to the bouncing ball example, we want to have two windows 320x240 each, together making a bigger window 640x240. The server should have masterDimensions=640x240 and each client will have local dimensions of 320x240. You should now go ahead and export your sketch to application, and make a copy of that application. You should then have two applications and two INI files. These would ultimately live on separate computers, but for now you can place them in separate folders. Note the application is identical, only the INI file is different! One INI file would look like this: id=0; localLocation=0,0; server=localhost; port=9002; localScreenSize=320,240; masterDimensions=640,240; And the other like this: id=1; localLocation=320,0; server=localhost; port=9002; localScreenSize=320,240; masterDimensions=640,240; You can download the example sketch from the downloads page: http://code.google.com/p/most
pixelsever/downloads/list Comment by zimmen, Sep 30, 2008 What i'd like to know is how you managed to get a huge video running in
processing! The default library isn't up to hd footage. Comment by xbilidade, Oct 01, 2008 I thing that code: // A client object Client client; Should be: // A client object UDPClient client; update the
tutorial Comment by s.benoit.studio, Nov 30, 2008 hi! I've got a problem on step 1: Where exactly have weto extract the server? My terminal doesn't find the .jar file when i run the command line; or doesn't permit me to launch it when i give an absolute path. :-( Got an idea? - Comment by traumasystems, Mar 04, 2009 Anybody got any idea how to run the server on a windows machine i've donwloaded Java and instaled it but what is the next step Comment by nabais.fernando, Apr 12, 2009 Hello all Great work and thanks for making it available. I´m experimenting with it, I have a prototype running but would like to be able to generalize it by accessing the masterdimensions from within the applet. The examples use client.getLWidth(), etc, but I can find any reference to other public methods (like masterDimensions, for example). Is there a reference somewhere? Thanks Comment by nabais.fernando, Apr 14, 2009 sorry, it´s when I post a question that I become clever :-) there´s the L, for local and M for Master (who would say ;-) Comment by sunilvallu, Dec 17, 2009 Has anyone tried using MPE for interactive work like Motion
tracking using (web cam)? need help with this. Comment by aashkashah3, Dec 17, 2009 can we run client program with little bit of changes from server program? Comment by tmargo, Apr 05, 2010 i seem to have it running OK since windows pop up & messages are being broadcast to each other, however nothing is actually being DRAWN on the canvas... i noticed the
tutorial says ball.draw() but the Ball source file only has a display() function. shouldn't that be ball.display() then? btw, what is this 'auto mode' you refer to? Thanks Comment by alejandrofloresm, Jul 20, 2010 I'm using OS X 10.6.4 and
Processing 1.1, if you downloaded the example sketch you have re-export the application in order to get it working :D Comment by borges.coelho, Yesterday (25 hours ago) I get it working fine by running the sketch in
Processing, but when exporting the app, it quits immediately after launching. The app folders have the .INI, any clues? Using OS X 10.5.8 ► Sign in to add a comment ©2010 Google - Terms - Privacy - Project Hosting Help Powered by Google Project Hosting