Juce + Python

For the last five years I have been writing a computer training game for learning perfect pitch.

I started out on iOS/XCode/Obj-C and moved to Unity3D/C#-scripting.  From the get-go I have been hitting up against limitations of Unity3D -- it isn't designed for real-time audio, and it is constantly trying to get a square peg in a round hole.  For example, in my game microphone input is fed into a ring resonator and sent out with the headphones as sympathetic resonance. It's impossible to achieve a latency < 0.2s with Unity, as opposed to < 0.01s that I could achieve with iOS.

But I love the idea of cross-platform. One day I will be able to release this game, and to release it simultaneously on all platforms would be fantastic! I also want to use Python. I've looked at Kivy (cross-platform+Python), but it is not designed with audio engineering in mind.

I am hoping that I will be able to use Juce and a mix of Python (for the game logic), GLES2 (for high performance graphics) and C/C++ (for low-level audio processing). In fact I'm hoping that Juce's API may mean I need to do a minimal amount of GLES2 and C/C++.

I have already recoded my game-logic in Python; it is complex game logic that is not performance critical. Also I am constantly revising the logic, trying out new ideas. Hence Python is the perfect language for this. C#/C++/Obj-C family of languages just don't have the flexibility to accommodate for this rapid prototyping.

My question is: can I write the game logic in Python, and still distribute a standalone app on every platform?

I've learned that Python is itself written in C, and if you add its source-tree to your C/C++ project, and #include "Python.h" you can start up a Python environment and execute scripts:



    "from time import time,ctime\n"

    "print 'Today is',ctime(time())\n"


Then you need to worry about how to call script functions from C, and vice versa. But it all seems to be possible! Doc here: https://docs.python.org/2/extending/

I've looked through the forum history:  There appears to be PyJuce, but this seems to be dead in the water; I am pulling up threads between people that haven't been active on this site for over six years.

I think that allowing Python scripting would massively increase the power of this engine. A fusion of high-level and low-level coding.

Is anyone interested in making this happen?



PS I've set my IRC client to auto-join #juce on the FREENODE irc server; I will be sitting in, if anyone is interested to talk about these things.

I'd be interested in this too... keep C/C++ for low level intensive stuff for realtime audio and graphics and Python or other dynamic language for logic. 

yes, me too - great idea!

There's been some talk of integrating Lua as a scripting extension of JUCE apps. But haven't seen anything solid with regards to Python thats not from a number of years ago. The more I'm getting into JUCE, the more its making sense and my development time is getting faster. I would say to the OP that doing the game in JUCE only, esp if there is already code in C#, should not be too difficult.


it's absolutely possible to EMBED a python interpreter into you application and EXTEND that python interpreter with functionality from you Application. (Did this a few years back). Check out swig.org . swig is a tool that lets you generate binding for source code written in C/C++ to several languages (including python/C#/...). With swig, it should be doable to create a binding for JUCE - but that might be quite a lot of work. What one could do is to write a simpler (e.g. higher level) Interface in C++ and export that to python.

Also read http://stackoverflow.com/questions/3991418/internal-scripting-programming-language-allowed-in-an-iphone-app-store-app if you plan to release on iOS.

If the grapics of you game cannot be done with JUCE-Graphics (because it's 3D or a lot of 2D sprites/particles/etc.) I'd recomend to check out Cocos2d-x, Marmalade, Ogre3D, Unity3D. Anything that goes beyond a few simple sprites can become a lot of work quickly. You need might need Sprite-atlassing, Animations, Particle effects, ... And also a pipeline to get the graphics into your game. 3D is another bag of worms (Skeletal-Animation, Normal-Maps, Shadows, ...). So if you're doing this because of the sake of the game and not because you feel like writing a graphics engine: Use one that's out there!

Also note, that you could extend Unity3D via a native plugin that just does Audio I/O and processing. But you'd need a Pro license for that.

-- Benjamin

Boost provides another option for embedding Python: http://www.boost.org/doc/libs/1_57_0/libs/python/doc/

By the way give me a shout if you ever need any beta testers for your perfect pitch game. It's a good idea for a game.