Package: sc-kernel
Supercollider Jupyter KernelThis kernel allows runningSuperColliderCode in aJupyterenvironment.InstallationPlease make sure one has installedSuperColliderandPython 3 with pip.To install the kernel for Jupyter executepip3install--upgradesc-kernelThis will also installJupyter Labif it is not already installed on the system.Start a new Jupyter Lab instance by executingjupyter labin a console.Click on the SuperCollider iconIf one has not installed SuperCollider in the default location, one has to set a environment variable
calledSCLANG_PATHwhich points to the sclang executable.To uninstall the kernel executejupyterkernelspecuninstallsc_kernelAs a Docker containerIt 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 supercolliderdockerbuild-tsc_kernel.# run container# -v mounts the current directory to the container# -p passes the container port to our hostdockerrun-v${PWD}:/home/sc_kernel-p8888:8888sc_kernelUsageContrary 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 soundCurrently theCmd + .command is not binded. Instead create a new cell with a single dot.and execute this cell. This will transform the command toCommandPeriod.run;which is what is actually called on theCmd + .press in the IDE.Recordingsc_kernelprovides 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 functionrecordtakes 2 arguments:Duration in secondsFilename which will be used for the recording, using the path of the notebook as base path.Assuming one has started the server, simply executeNdef(\sine,{varsig=SinOsc.ar(LFDNoise0.kr(1.0!2).exprange(100,400));sig=sig*\amp.kr(0.2);sig;}).play;record.(4.0);Plottingsc_kernelalso provides a way to embed images of SuperCollider windows into the Jupyter document.
First create a window that you want to embed into the documentw={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);The image will be saved relative the directory wherejupyter labwas executed.
The optional second argument can be the filename.Note that{}.plotdoes not return aWindowbut aPlotter, butsc_kernelaccesses the window of aPlotterautomatically.For plotting e.g. the server meter you need to pass the proper window, soa=s.meter;// a is a ServerMeter// new cellplot.(a.window,"meter.png");AutocompleteSimply pushTabto see available autocompletions.
This is currently limited to scan for available classes.DocumentationTo display the documentation of a Class, simply prepend a?to it and execute it, e.g.?SinOscYou can also hitshift <tab>iff the cursor is behind a class to trigger the inline documentation.Real Time CollaborationJupyter 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 computerTo start such a session you can spin Jupyter Lab viajupyterlab--ip0.0.0.0--collaborative--NotebookApp.token='sclang'where theNotebookApp.tokenis the necessary password to login - set it to''if no password is wanted.Check out thedocumentation on Jupyter LababoutReal Time Collaboration.DevelopmentAny PR is welcome! Please state the changes in an Issue.
To contribute, pleaseFork the repository and clone it to a local directoryCreate a virtual environment and install the dev dependencies
in it withpip3install-e".[dev]"If one wants to add the kernel to an existing Jupyter installation one can executejupyterkernelspecinstallsc_kerneland runjupyter labfrom within the cloned directory as
we need to have access tosc_kernel.Run./run_tests.shand make a PR :)
Useblack sc_kernel testto format the source code.MaintainersDennis Scheiba