Is there a way to check what system a processing sketch is running on?

edited May 2016 in How To...

I'm developing some visuals for a project that will eventually be brought into a larger ecosystem and also be running on a Raspberry Pi. I am currently doing the development on my Mac.

So, is there a way to get what hardware the Processing sketch is running on so I can wrap certain Pi specific libraries such as "import processing.io.*;" conditionals so they only run when the sketch is running on the PI and not my Mac?

The reason is that I'd prefer not to have to comment out blocks of code before I can work on my machine and then uncomment these blocks before I commit to the project repo. Seems like a bit of a risk having to do this.

If there are other ways of accomplishing this workflow dev. on mac and production on pi with io requirements I'd love to know about them!

Cheers,

Answers

  • ... is there a way to get what hardware the Processing sketch is running on...

    final String OS = platformNames[platform];
    println(OS);
    exit();
    
  • Ah, awesome. Thanks!

    This is only part of what I am looking to do. I know that you can't have if statement outside of functions in processing...but, is there another way, or is it even possible to use the OS for a conditional? So something like i have below as workflow.

    final String OS = platformNames[platform];
    
    if(OS != "macosx"){ 
        import processing.io.*;
    }
    

    Thanks!

  • edited May 2016
    • Why can't you just import everything which is possibly needed, regardless the platform? :|
    • Do you really got any libraries not available depending on the platform the code is compiled for?
    • Dynamic ClassLoader is a very advanced topic in Java.
    • And in Processing's IDE (PDE) we don't even have access to the libraries' classpath.
    • It's all done behind the scenes by the PDE.
    • Unless we place them (".jar", ".class") inside sketchPath's "code/" subfolder.
  • If you don't mind the bad performance, try Python Mode out: :>

    OS = platformNames[this.platform]
    isMac = OS == 'macosx'
    print platformNames, ENTER, OS, isMac
    
    add_library('sound') if isMac else add_library('minim')
    print 'Minim is loaded? %r' % ('Minim' in globals())
    
    exit()
    
  • How about you create a launcher? So when you run the sketch you have to select the OS you are on and and then you open the PDF that corresponds with the selected OS?

    That means you would have two almost identical files though..

    Or if the problem is that one library is not available on a certain OS, you could maybe check for null pointer exception?

Sign In or Register to comment.