Sc_kernel - SuperCollider / sclang kernel for Jupyter

Jupyter is an environment which allows to use a repl in a browser. This allows for rich text source code which can embedd videos, images, LaTeX code as well as audio. Jupyter is heavily used in Data Science and Machine Learning and is also known via the proprietary fork Google Colab.
I heard sagas that old SuperCollider versions supported rich text as source code - now it is back :slight_smile:

I started coding this in 2020 and used it since to create some course materials for websites but decided to give this a proper release by anouncing it here. Have in mind that this is still a beta (currently @ v0.4.0), any contributions are welcome.

Stepping into the Jupyter ecosystem allows to use e.g. Jupyter Book or use its real time collaboration features (see below).

Installation

Assuming you have python with pip installed as well as SuperCollider (of course) it is as easy as

pip3 install --upgrade sc_kernel

You may want to take a look at venv to keep your python environment clean.

Right now I am unsure if this will work under Windows - I don’t have a machine to test the delicate piping of the sclang process, any help via a PR is welcome here :slight_smile:

I only tested this with macOS (intel) and Ubuntu 22.04

Quickstart

To start a Jupyter lab server simply call

jupyter lab

and create a new SuperCollider notebook.

If everything worked out one can execute sclang commands in the browser now.
As Jupyter is already cell oriented there is no need to create surrounding ( ) brackets anymore!
To execute a cell simply hit <shift> + <return>.
Anything that is printed in sync by the command will be displayed below the cell, making it clear what each command returned.

So what is not printing printing in-sync? Tdef, Routine or s.boot are running async - if these fails you are a bit out of luck currently in sc_kernel as you won’t be seeing any error messages of them (I still don’t know how to handle async printing in a good way, any recommendations are welcome!)

Before we continue: The infamous <cmd> + . command is not available here! To stop any sound simply enter a .

image

Features

I added some “magic functions” one is used to from the Python notebooks. These are simply functions which are prepended to each script cell call.
Check out the documentation for more extensive info about these features

Real time collaboration

Allows to share/sync/execute code over the network - each participant can join via a browser and can execute commands. The cursor of each participant is displayed as well.
This can allow for some cool shared live coding experiments!

sharing

Recording audio

Embedd a short snippet of your server audio directly into the notebook

Embedding plots

Autocomplete

Still WIP - completes class names (if they are longer than 3 chars) when hitting <tab> asking the interpreter for matching classes.

I want to embedd method auto-completion here as well, probably for v0.5.0.

Documentation

Display the raw schelp file of a class by prepending a ? to the class

Also works by hitting <shift> + <tab> when the cursor is behind an existing class.

For v0.5.0 I maybe want to mimic displaying the help file via an inspector.

4 Likes

Because of limitations in the kinds of HTML that VSCode can display, I think the SCDoc documentation has to be rendered slightly differently vs how it’s rendered now in order to be visible there. I recall this is mostly related to how links are written (I believe everything needs to be relative? I can’t recall exactly). If you do any work on this problem, it would definitely be shareable with the SuperCollider language server and VSCode support.

And, with that in mind, I’m happy to make changes to the SuperCollider language server if it would help with the Jupyter support? In particular, the LSC has pretty full support for auto-completion, and other introspection kinds of activities, and it probably wouldn’t be hard to write an adapter to Jupyter for this functionality.

1 Like

Integrating your language server would be awesome and is probably not too hard (?) since there is a Language Server integration for JupyterLab, see

How do you handle the communication between the language server and the interpreter? Doesn’t the LSP rely on TCP communication (which sc lacks?) or can you manage it via stdin/stdout or via OSC? Maybe we can discuss it @ Create LSP Branch · Issue #21 · capital-G/sc_kernel · GitHub ? :slight_smile: