Juce Python Bindings

Anyone interested in juce bindings with minimal effort ?

from juce_bindings import juce, START_JUCE_APPLICATION


class MainComponent(juce.Component):
    def paint(self, g):
        g.fillAll(juce.Colours.black)

        random = juce.Random.getSystemRandom()
        rect = juce.Rectangle[int](0, 0, 20, 20)
 
        for _ in range(100):
            g.setColour(juce.Colour(
                random.nextInt(256),
                random.nextInt(256),
                random.nextInt(256)))
 
            rect.setCentre(random.nextInt(self.getWidth()), random.nextInt(self.getHeight()))
            g.drawRect(rect)


class MainWindow(juce.DocumentWindow):
    def __init__(self):
        super().__init__(
            juce.JUCEApplication.getInstance().getApplicationName(),
            juce.Colours.red, 
            juce.DocumentWindow.allButtons,
            True)

        self.component = MainComponent()

        self.setResizable(True, True)
        self.setContentNonOwned(self.component, True)
        self.centreWithSize(400, 300)
        self.setVisible(True)

    def __del__(self):
        del self.component

    def closeButtonPressed(self):
        juce.JUCEApplication.getInstance().systemRequestedQuit()


class Application(juce.JUCEApplication):
    def getApplicationName(self):
        return "Super JUCE-o-matic"

    def getApplicationVersion(self):
        return "1.0"

    def initialise(self, commandLine):
        self.window = MainWindow()

    def shutdown(self):
        if hasattr(self, "window") and self.window:
            self.window.setVisible(False)
            del self.window


if __name__ == "__main__":
    START_JUCE_APPLICATION(Application)

4 Likes

This looks interesting, please reveal more!

i will for sure, once i have everything in place. the actual bindings code is just 20 lines of code, using the current juce headers. i will look into creating actual non interactive bindings that can be deployed as wheels.

1 Like

I’ve opened up the repo for the juce python bindings. It’s in early alpha stage but it’s possible already do a lot of cool things. I will improve the packaging for all the supported platforms and publish the wheels as soon as i can. For now, you will need to build it yourself, so you can enjoy it here:

In the near future, it will be as easy as doing:

pip install popsicle

cheers !

7 Likes

Very interesting!

Also I edited the post title, hope that’s OK.