Skip to main content

Live music coding inspired by Sonic Pi

Project description

POCKETROCKIT - A rocket in your pocket that rocks!

Original project page: https://projects.om-office.de/frans/pocketrockit.git

Write a music track in Python and play it while you write it (as you might know it from Sonic Pi, but written in Python (sonic.py was not available on PyPi, though)).

Write melodies, create rythm patterns, define endless simultaneously playing instruments, all in a .. well .. simple Python syntax.

Installation

[<PYTHON> -m] pip[3] install [--upgrade] pocketrockit

Usage

Workflow is not quite mature yet, so here is the short version for now.

Create and enter a separate folder and provide required SoundFont files (configurable later, hard-coded for now).

Pocketrockt expects two SoundFont files: instrumental.sf2 and drums.sf2. You can download and move/rename any file that works for you, and you can also just create symlinks (this is what I do).

This is just an example:

mkdir mytracks
cd mytracks
ln -s /usr/share/soundfonts/FluidR3_GM.sf2 instrumental.sf2
wget https://musical-artifacts.com/artifacts/2744/JV_1080_Drums.sf2
ln -s JV_1080_Drums.sf2 drums.sf2

The file FluidR3_GM.sf2 was shipped with FluidSynth for me, and I got JV_1080_Drums.sf2 from here.

Create a file myfirsttrack.py with the following content:

#!/usr/bin/env python3

from pocketrockit import Env, midiseq, player, track

@track
def my_first_track(env: Env):

    @player
    def metronome():
        yield from midiseq("x x x x", channel=128, note=37)

    @player
    def melody1():
        yield from midiseq(
            "| .                .                 .                (II I)      "
            "| (II  VI<)        (IV< VI< . II<)   .                (II I)      "
            "| (II  VI<)        (IV< VI< . II<)   .                (II III)    "
            "| (IV  . III IV)   (. IV . II)       (III . II III)   (. III . I) "
            ,
            key="A5", channel=13)

Now - keeping the editor open for later use - execute this file. You can either make it executable and run it directly or you run python3 instead:

chmod +x myfirsttrack.py
./myfirsttrack.py

# or

python3 myfirsttrack.py

Development & Contribution

pip3 install -U poetry pre-commit
git clone --recurse-submodules https://projects.om-office.de/frans/pocketrockit.git
cd pocketrockit
pre-commit install
# if you need a specific version of Python inside your dev environment
poetry env use ~/.pyenv/versions/3.10.4/bin/python3
poetry install

After modifications, this way a newly built wheel can be checked and installed:

poetry build
poetry run twine check dist/pocketrockit-0.0.25-py3-none-any.whl
python3 -m pip install --user --upgrade dist/pocketrockit-0.0.25-py3-none-any.whl

Stuff to read / Sources

SoundFonts

flatpak install flathub com.polyphone_soundfonts.polyphone flatpak run com.polyphone_soundfonts.polyphone instrumental.sf2

Music stuff

Drum patterns

Tech stuff

Notation

Similar projects

Troubles

ALSA lib conf.c:4555:(snd_config_update_r) Cannot access file /usr/local/share/alsa/alsa.conf
ALSA lib seq.c:935:(snd_seq_open_noupdate) Unknown SEQ default
sudo mkdir /usr/local/share/alsa
sudo ln -s /usr/share/alsa/alsa.conf /usr/local/share/alsa/alsa.conf

Project details


Download files

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

Source Distribution

pocketrockit-0.0.30.tar.gz (23.2 kB view hashes)

Uploaded Source

Built Distribution

pocketrockit-0.0.30-py3-none-any.whl (23.6 kB view hashes)

Uploaded Python 3

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