Skip to main content

popsicle is JUCE Python Bindings on top of cppyy

Project description

popsicle

popsicle

Popsicle is a project that aims to give JUCE (https://juce.com/) a broader audience by allowing it to be used from python. Thanks to cppyy (http://cppyy.readthedocs.io/en/latest/) it exposes the JUCE framework api in a pythonic way, and the way it enables to write apps in python is very much similar to the way of writing them in C++ but without the overweight of managing project build, configurations and IDE solutions.

Linux Builds Status macOS Builds Status Windows Builds Status PyPI - Status PyPI - License PyPI - Python Version PyPI - Downloads

Features

  • Easy and quick to iterate over a JUCE application, no need to setup a build environment.

  • The way it allows to write JUCE code is very similar to how you would write it in C++.

  • It allows to mix Python and C++, and even compile C++ code at runtime when needed.

  • It is fast, and when the speed of C++ is required, it is possible to write those parts in C++ directly.

Example usage

A single 80 lines script is better than thousand of words:

from popsicle import juce_gui_basics
from popsicle import juce, juce_multi, START_JUCE_APPLICATION


class MainContentComponent(juce_multi(juce.Component, juce.Timer)):
    def __init__(self):
        super().__init__((), ())

        self.setSize(600, 400)
        self.startTimerHz(60)

    def __del__(self):
        self.stopTimer()

    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)

    def timerCallback(self):
        if self.isVisible():
            self.repaint()


class MainWindow(juce.DocumentWindow):
    component = None

    def __init__(self):
        super().__init__(
            juce.JUCEApplication.getInstance().getApplicationName(),
            juce.Desktop.getInstance().getDefaultLookAndFeel()
                .findColour(juce.ResizableWindow.backgroundColourId),,
            juce.DocumentWindow.allButtons,
            True)

        self.component = MainContentComponent()

        self.setResizable(True, True)
        self.setContentNonOwned(self.component, True)
        self.centreWithSize(800, 600)
        self.setVisible(True)

    def __del__(self):
        if hasattr(self, "component"):
            self.component.__del__()
            self.component = None

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


class Application(juce.JUCEApplication):
    window = None

    def getApplicationName(self):
        return "JUCE-o-matic"

    def getApplicationVersion(self):
        return "1.0"

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

    def shutdown(self):
        if hasattr(self, "window"):
            self.window.__del__()
            self.window = None


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

As easy as that ! You will find more example on JUCE usage in the examples folder.

Example Applications

Some images of JUCE tutorials and other small apps ported to popsicle.

Animated Component (https://docs.juce.com/master/tutorial_animation.html)

https://github.com/kunitoki/popsicle/raw/master/images/animated_component.png

Audio Player with waveforms (https://docs.juce.com/master/tutorial_audio_thumbnail.html)

https://github.com/kunitoki/popsicle/raw/master/images/audio_player_waveform.png

Slider decibels (https://docs.juce.com/master/tutorial_synth_db_level_control.html)

https://github.com/kunitoki/popsicle/raw/master/images/slider_decibels.png

Slider values example (https://docs.juce.com/master/tutorial_slider_values.html)

https://github.com/kunitoki/popsicle/raw/master/images/slider_values_example.png

Wavetable oscillator (https://docs.juce.com/master/tutorial_wavetable_synth.html)

https://github.com/kunitoki/popsicle/raw/master/images/wavetable_oscillator.png

Responsive GUI layouts using FlexBox and Grid (https://docs.juce.com/master/tutorial_flex_box_grid.html)

https://github.com/kunitoki/popsicle/raw/master/images/layout_flexgrid.png

Advanced GUI layout techniques (https://docs.juce.com/master/tutorial_rectangle_advanced.html)

https://github.com/kunitoki/popsicle/raw/master/images/layout_rectangles.png

Table listbox (https://docs.juce.com/master/tutorial_table_list_box.html)

https://github.com/kunitoki/popsicle/raw/master/images/table_list_box.png

Super Simple Animated Graphics

https://github.com/kunitoki/popsicle/raw/master/images/juce_o_matic.png

Installation

Installing popsicle is as easy as pulling from pypi (osx only for now):

pip3 install popsicle

Make sure you have a recent pip if you are on BigSur intel.

Build From Source

Clone the repository recursively as JUCE is a submodule

git clone --recursive git@github.com:kunitoki/popsicle.git

Install python dependencies.

pip3 install "cppyy>=2.3.1"

Then it’s possible to package a wheel and install it (currently this is only tested on macOS and Linux):

# Cleanup the temporary folders
python3 setup.py clean --all

# Build the binary distribution
python3 setup.py bdist_wheel

# Install the local wheel
pip3 install dist/popsicle-*.whl

Eventually uploading to PyPI:

python3 -m twine upload --repository popsicle dist/popsicle-*.whl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

popsicle-0.0.10-pp38-pypy38_pp73-win_amd64.whl (5.1 MB view hashes)

Uploaded PyPy Windows x86-64

popsicle-0.0.10-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

popsicle-0.0.10-pp37-pypy37_pp73-win_amd64.whl (5.1 MB view hashes)

Uploaded PyPy Windows x86-64

popsicle-0.0.10-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

popsicle-0.0.10-cp310-cp310-win_amd64.whl (5.1 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

popsicle-0.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-cp310-cp310-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

popsicle-0.0.10-cp310-cp310-macosx_10_9_universal2.whl (10.5 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

popsicle-0.0.10-cp39-cp39-win_amd64.whl (5.1 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

popsicle-0.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-cp39-cp39-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

popsicle-0.0.10-cp39-cp39-macosx_10_9_universal2.whl (10.5 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

popsicle-0.0.10-cp38-cp38-win_amd64.whl (5.1 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

popsicle-0.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-cp38-cp38-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

popsicle-0.0.10-cp38-cp38-macosx_10_9_universal2.whl (10.5 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

popsicle-0.0.10-cp37-cp37m-win_amd64.whl (5.1 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

popsicle-0.0.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

popsicle-0.0.10-cp37-cp37m-macosx_10_9_x86_64.whl (10.5 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page