Skip to main content

SuperCollider kernel for Jupyter

Project description

Supercollider Jupyter Kernel

This kernel allows running SuperCollider Code in a Jupyter environment.

Demo Notebook

Installation

Please make sure one has installed SuperCollider and Python 3 with pip.

  • To install the kernel for Jupyter execute

    pip3 install --upgrade sc-kernel
    

    This will also install Jupyter Lab if it is not already installed on the system.

  • Start a new Jupyter Lab instance by executing jupyter lab in a console.

  • Click on the SuperCollider icon

If one has not installed SuperCollider in the default location, one has to set a environment variable called SCLANG_PATH which points to the sclang executable.

To uninstall the kernel execute

jupyter kernelspec uninstall sc_kernel

As a Docker container

It is also possible to run sc-kernel in a Docker container, although a sound output is not possible in this case. Assuming you have cloned the repository and opened a terminal in its directory.

# build container - takes some time b/c we build supercollider
docker build -t sc_kernel .
# run container
# -v mounts the current directory to the container
# -p passes the container port to our host
docker run -v ${PWD}:/home/sc_kernel -p 8888:8888 sc_kernel

Usage

Contrary to ScIDE each document will run in its own interpreter and not in a shared one. This is the default behavior of Jupyter but maybe this will be changed at a later point.

Currently it is only possible to use the default config - if you encounter missing classes it is probably caused that they are not available in the default config.

Stop sound

Currently the Cmd + . command is not binded. Instead create a new cell with a single dot

.

and execute this cell. This will transform the command to CommandPeriod.run; which is what is actually called on the Cmd + . press in the IDE.

Recording

sc_kernel provides an easy way to record audio to the local directory and store it embedded in the notebook so one can transfer the notebook into a website which has the audio files included.

The audio is stored in FLAC with 16 bit resolution.

The provided function record takes 2 arguments:

  • Duration in seconds
  • Filename which will be used for the recording, using the path of the notebook as base path.

Assuming one has started the server, simply execute

Ndef(\sine, {
    var sig = SinOsc.ar(LFDNoise0.kr(1.0!2).exprange(100, 400));
    sig = sig * \amp.kr(0.2);
    sig;
}).play;

record.(4.0);

Recording

Plotting

sc_kernel also provides a way to embed images of SuperCollider windows into the Jupyter document. First create a window that you want to embed into the document

w = {SinOsc.ar(2.0)}.plot(1.0);

After the plotting is finished by the server we can now simply save an image of the window to a file and also embed the image into the document via a SuperCollider helper method which is available.

plot.(w);

Plotting magic

The image will be saved relative the directory where jupyter lab was executed. The optional second argument can be the filename.

Note that {}.plot does not return a Window but a Plotter, but sc_kernel accesses the window of a Plotter automatically.

For plotting e.g. the server meter you need to pass the proper window, so

a = s.meter;
// a is a ServerMeter

// new cell
plot.(a.window, "meter.png");

Autocomplete

Simply push Tab to see available autocompletions. This is currently limited to scan for available classes.

Documentation

To display the documentation of a Class, simply prepend a ? to it and execute it, e.g.

?SinOsc

You can also hit shift <tab> iff the cursor is behind a class to trigger the inline documentation.

Inline documentation

Real Time Collaboration

Jupyter Lab allows for real time collaboration in which multiple users can write in the same document from different computers by visiting the Jupyter server via their browser. Each user can write and execute sclang statements on your local sclang interpreter and the cursors of each user is shown to everyone.

This allows for interactive, shared sessions which can be an interesting live coding sessions.

Be aware that this can be a security threat as it allows for other people from within the network to execute arbitrary sclang commands on your computer

To start such a session you can spin Jupyter Lab via

jupyter lab --ip 0.0.0.0 --collaborative --NotebookApp.token='sclang'

where the NotebookApp.token is the necessary password to login - set it to '' if no password is wanted.

Check out the documentation on Jupyter Lab about Real Time Collaboration.

Development

Any PR is welcome! Please state the changes in an Issue. To contribute, please

  • Fork the repository and clone it to a local directory

  • Create a virtual environment and install the dev dependencies in it with

    pip3 install -e ".[dev]"
    
  • If one wants to add the kernel to an existing Jupyter installation one can execute

    jupyter kernelspec install sc_kernel
    

    and run jupyter lab from within the cloned directory as we need to have access to sc_kernel.

  • Run ./run_tests.sh and make a PR :) Use black sc_kernel test to format the source code.

Maintainers

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

sc_kernel-0.5.0.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sc_kernel-0.5.0-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

Details for the file sc_kernel-0.5.0.tar.gz.

File metadata

  • Download URL: sc_kernel-0.5.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sc_kernel-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a3dbe1aec3bed35f7ab7ff6b450cb4ea094b12251c3ad0627fd64eef05eca7d1
MD5 de6898a7a12aebd5cc385fc0bf0ca397
BLAKE2b-256 07d4087cfb11edf5eb6e59b5a8abcc541cdcd04e7bffc8e1a45d1c773b3bfa09

See more details on using hashes here.

File details

Details for the file sc_kernel-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: sc_kernel-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 43.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sc_kernel-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3debab846134c9175b157c9d28037fcf8dc2ce2e500b1f96cb630d4ea912c980
MD5 b224768e30585dd5254ab44d5460d3d5
BLAKE2b-256 7208620606d77db65c42870e6fc366d2c2efbd1256f971035c80e4f96ef8b0a0

See more details on using hashes here.

Supported by

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