Sonic Pi: accessing the cutting edge

github-logo-80pxsonic-pi-web-logoPLEASE NOTE. As Sam Aaron, the developer of Sonic Pi points out in a comment, following this article will show you how to load a development version of Sonic Pi. As the name implies IT MAY CHANGE. DO NOT expect the way a development version works to remain the same, or even for new features in to to be included in the next release version.  By all means try out the new ideas under development, but do NOT rely on them. Only work produced with a release version of Sonic Pi is totally safe.

UPDATE New build instructions for the Windows version have recently been added to the sonic-p[i git site. These are detailed and should enable you to build Sonic Pi on your PC. So far tested on Windows 10, but should work on 8.1 and Windows 7.

If you are a regular user of Sonic Pi, then you probably become impatient from time to time for the next release to become available.  Each time this happens, new goodies become available and the program is enhanced several ways. Well the good news is that you don’t have to. Sonic Pi is an Open Source program, and as such the code used to produce the application is freely available and is held on a site called GitHub. This is a site widely used by software developers because it enables you to provide version control of your project. All changes are logged and documented and it is possible to reverse things when they go wrong and back track and also to let other people take a copy of your work, amend it, and offer the amendments back to you, where you can accept or reject them, and in this way several people can collaborate on the development of a project. If you look at the info page in Sonic Pi, you will see that there is a core team of four developers, including Sam Aaron, each of whom has contributed significantly to the development of Sonic Pi. Even lesser mortals like yours truly have helped (in my case by picking up typos and small slips). I do not purport in any way to be an expert on the use of github, but I am happy with what is required to enable you to download the source code and build your own working application of the latest version.

If you have never done this, then you will probably find the initial experience rather daunting. This article will take you through the process for the Raspberry Pi, although you can also do it (with modifications) on MacOS, Windows and Linux, depending on the platform for which you wish to build your own copy of Sonic Pi.

To start with, you need a Raspberry Pi, running a copy of Raspbian (Wheezy). If you are using the latest release (from December 24th 2014), then this will already contain the current release of Sonic Pi ver 2.2 What we will do is to add the latest development version (approaching release 2.3). Don’t worry, the two can coexist quite happily together, although you can only run one of them at a time! First we will take a look at where the source code is, and see how to download it onto your Pi. The code is available at

https://github.com/samaaron/sonic-pi A screenshot of a recent visit to this page is shown below

sonicPiGitHub

If you visit the site then what you see will be similar to this, but will differ, as the contents displayed change over time. The page can be a bit confusing until you learn your way around it. Fortunately, if we just want to build the latest Sonic-Pi version you can do everything from the command line. It is not easy to use the webpage from Sonic Pi directly. If you can view it on a desktop machine or laptop then you may care to try one or two of the following for interest.

If you click on the line that says nnnn commits then this will give you a list of the most recent changes that have been “committed” or added to Sonic-Pi by Sam Aaron. You can return to the page above by clicking on the sonic-pi link beside samaaron/

If you click  on the link issues you can see the concerns and problems that other users have flagged up with Sonic-Pi. Again return by clicking the sonic-pi link.

If you click on the words Pull Requests you can see a list of proposed alterations by other users, waiting for Sam Aaron to either accept or reject them. If the former case they will be added as commits.

On the right hand side there is is an https:// link which we will use from the command line to download a copy of the source code.

Open a terminal window on your Raspberry Pi. If you have an old Model B version with only 256Mb of RAM you can still build Sonic Pi on it but it will take a bit longer, and you will also probably have to reduce the memory allocated to the GPU unit to give it enough memory for the compile process to complete. You do this using sudo raspi-config, selecting no 8 Advanced Options from the menu then A3 Memory Split and set it to 32. Select OK. You can also if you wish apply some moderate overclocking to your Pi which will improve performance using option 7. I suggest the Medium Setting. After changing either or both of these setting you will need to take the Reboot option to bring them into force.

Now decide where you would like your new cutting edge Sonic Pi to be located. The code will be downloaded into a folder named sonic-pi, located where you issue the next command. (I just put mine into the Pi user home directory). Make sure that your Pi is connected to the internet via ethernet or wi-fi.

Type git clone https://github.com/samaaron/sonic-pi.git

This will download an up-to-date cloned copy of the Sonic-Pi source code into a folder sonic-pi The process took about 1min 20 secs on my Pi, with a fast ethernet link.

Now you need to add the dependencies that Sonic Pi requires to build successfully.

First you need to use the following command to make sure that your list of package sources is up to date. sudo apt-get update

You can also bring all existing packages up to date using sudo apt-get upgrade

Now to install the dependencies use the command:

(Type the following all on one line. Do NOT press return half way)
sudo apt-get install supercollider ruby1.9.3 libqscintilla2-8 libqscintilla2-dev qt4-dev-tools cmake ruby-dev libffi-dev

You will probably find that a couple of these are already installed and you will be asked to confirm that you wish to install the rest. It may take some time for these to be downloaded and installed.

Now we begin to build the new app in earnest:

cd sonic pi
ls

You will see the contents of the top level of the sonic-pi distribution. The file INSTALL.md contains the installation instructions, although more briefly than I am describing them here, and also includes detail of how to install on MacOS or on a PC. To take a quick look you can type
nano INSTALL.md
Use the down and up arrow keys to scroll around the file and use ctrl-C to exit. If you have inadvertently altered the file just say N when it asks if you want to save any changes.

There are three sub directories which contain the code. The etc directory contains a documentation directory together with the built in examples, samples and synth definitions. The app folder contains the source files. Switch to the following directory
cd app/server/bin
This is the sub-directory from which we will compile some ruby extensions used by sonic-pi. Type
./compile-extensions.rb
Leave this to run and have a cup of tea. It will take some time to complete. Don’t worry if nothing seems to be happening for periods of time. Also don’t worry about warnings printed on the screen. Problems have only occurred if it stops with an error flagged. The whole process took about 16.5 minutes on my 256Mb RAM model B. Thankfully this part of the process only has to be done infrequently as these extensions are not changed as frequently as the rest of the application which is built in a separate process. Now type

cd ../../gui/qt
ls

You should see a section of files including rp-build-app which we will use to build the final application. If you don’t see this check that you are in the directory
~/sonic-pi/app/gui/qt (assuming your sonic-pi folder is situated directly in the Pi user home directory).
Type

./rp-build-app

Again this will take some time. Don’t worry about inactivity on the screen, or about printed warnings. Both are normal. You should only worry if an error is generated. This process took just under 11 minutes on my 256Mb Model B.
Congratulations! You have just successfully built the latest version of Sonic-Pi. To use it now do the following.
type startx
When the graphical environment has started, open a terminal window.  Navigate to ~/sonic-pi/app/gui/qt by typing
cd ~/sonic-pi/app/gui/qt
ls

You should se a range of files including rp-app-bin
To run Sonic Pi type

./rp-app-bin &
and press return  (The & launches the file and returns)

You should see the Sonic-Pi splash screen (saying currently version 2.3…the next one!!) and after several seconds the main Sonic-Pi window.   Your new version will coexist quite happily with the released version.  Of course you can only run one of them at a time. Also note they share the same preference and current workspace contents. All of these are stored in the hidden folder .sonic-pi stored in the user home directory.

Updating your cutting edge copy
If you notice that further work has been done on Sonic-Pi and you want to update your cutting edge copy, you quit the application if it is running, and return to a terminal window. (To maximise memory you can exit the graphics environment and work from there. Return to the log on directory (where you should be able to see your sonic-pi directory using the ls command. Enter this directory by typing
cd sonic-pi
Bring it up to date using the command git pull (with your pi connected to the internet).  You will see the update taking place on the screen.  Once it has finished, you can type
cd app/gui/qt
and run the program
./rp-build-app   again to rebuild Sonic-Pi incorporating the changes. Once in a while you might have to rebuild the extensions again if they are altered, but that is not very often. In that case, before running the above you also include:
Switch to the following directory
cd app/server/bin
This is the sub-directory from which we will compile some ruby extensions used by sonic-pi. Type
./compile-extensions.rb

Other Plaforms
If you have a Mac, then in principle the process is very similar. If you look at the INSTALL.md file the details are listed there. It IS a bit more complex, because you have also to build some other bits used in the process, and you have e to modify a couple of files to fit your own installation.  However the plus side is that the final build of extensions and of the app is much quicker on a Mac because you will have a much more powerful processor than in the modest Raspberry Pi.  I find that I can do a complete “git pull” and “build” in under a couple of minutes on this platform. I have not tried on a PC, but I would suspect it would be similar. I have also an installation on Ubuntu, and that is also quite quick to update.

Once you are comfortable with building Sonic Pi from github you might like to look further at how this works. Who knows you might even try to add your own offerings to the process of developing Sonic Pi for the benefit of the community. There are some good references to using github which will aid you in the process.

Advertisements

4 thoughts on “Sonic Pi: accessing the cutting edge

  1. It’s always great to see people trying out the latest development version and it’s something I heartily recommend to those interested in Sonic Pi’s development process. However, working with the latest from GitHub doesn’t come without risks. Firstly, whilst I try and keep the dev version stable and bug free – it’s got a good chance of being more unstable and have more bugs than the latest release. Also (and this is perhaps more important) features in the dev version are constantly changing and are *not* ever guaranteed to make it into the next stable release. The dev version is where I play around with new ideas – some of which work and some don’t.

    So, if you’re happy with some more instability and features changing/being removed without any prior warning – please do play around with the dev version!

  2. Pingback: Sonic Pi: accessing the cutting edge | broeze

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s