NOW SUPERCEDED BY BUILD FOR 3.2.0 RELEASE
This version will not work with the 3.2.0 release source.
UPDATED 2nd Feb 2020
Problems with gem files build are now sorted, and rugged does not have to be treated separately. Instead compile_extensions.rb can be run without modification
An error in the line
cp utils/ruby_help.tmpl ruby_help.h
has been corrected to
cp utils/ruby_help.tmpl utils/ruby_help.h
Further changes in the Sonic Pi source code which is currently undergoing some fairly radical changes means two changes have to be made to let it build using the method I have used below rather than tje cmake method under development.
These are covered in two files that need to be amended are described in this issue posted on the github site.
Since that issue was posted some further commits have moved the relevant line numbers, but you should be able to locate them without too much difficulty still.
the scope.cpp line number after commit #72cd59 is still 199, but the line to change in mainwindow.cpp has moved to line 1041
The original article follows, with the modifications listed here incorporated
At present the Raspbian Buster distribution which is necessary to run a Pi4 ships with a very old version of Sonic Pi (2.10). For those used to using version 3.0.1 on the earlier Rasbian Stretch distro on earlier Pi versions this is a frustration.
In time a new .deb file may be developed for Buster, and there has been correspondence elsewhere about the problems of this happening.
In the meantime, for those who are prepared to build Sonic Pi 3.2dev from source this is perfectly possible, and the performance of this version on a Pi4 makes it well worth the effort. However please note that this is a development version which does have some glitches still to be ironed out, and as such it is NOT a build that can be supported by Sam Aaron, (or indeed by myself), although there are probably those on this forum who may be able to help if necessary.
I have produced some instructions which will enable you to build Sonic Pi3.2dev on a pristine install of Buster release date 2019-07-10 with
sudo apt update
sudo apt upgrade
applied.
I built it on a 4Gb RAM version. The final build will certainly work on 1 and 2Gb machines, but on the former you may have to temporarily increase the swap file size. Seethis article for details. You can swap it back again afterwards.
The whole build process takes about 30 minutes to complete.
It is designed to coexist with the installed Sonic Pi version, and it probably best to leave this installed. If you remove it, you have to reinstall two packages to get the 3.2 version running.
Some of the instructions can merely be copied and pasted into a terminal window. However there are a couple of bits that need to be manually completed involving use of a text editor.
Start a terminal window in the Pi user home folder, then copy and paste in the section below, which will:
- install extra packages required
- create a src folder and download sonic pi source files into it.
- add osmid source files to the src folder
- build the m2o and o2m binaries in osmid
- install the binaries
- build the two erlang files from osc.erl and pi_server.erl
#now install extra packages needed to build Sonic Pi
sudo apt-get install -y \
g++ ruby ruby-dev pkg-config git build-essential libjack-jackd2-dev \
libsndfile1-dev libasound2-dev libavahi-client-dev libicu-dev \
libreadline6-dev libfftw3-dev libxt-dev libudev-dev cmake libboost-dev \
libqwt-qt5-dev libqt5scintilla2-dev libqt5svg5-dev qt5-qmake qt5-default \
qttools5-dev qttools5-dev-tools qtdeclarative5-dev libqt5webkit5-dev \
qtpositioning5-dev libqt5sensors5-dev libqt5opengl5-dev qtmultimedia5-dev libffi-dev \
curl python erlang-base libssl-dev libaubio5 supercollider-server
#create folder src in Pi home folder
mkdir -p ~/src
cd src
#install sonic-pi source (latest)
git clone https://github.com/samaaron/sonic-pi
#install source for osmid, and build m2o and o2m
git clone https://github.com/llloret/osmid.git || true
cd osmid
mkdir -p build
cd build
cmake ..
make
#add installation folder in Sonic Pi
mkdir -p ../../sonic-pi/app/server/native/osmid/
#copy over the two binary images
cp m2o ../../sonic-pi/app/server/native/osmid/
cp o2m ../../sonic-pi/app/server/native/osmid/
There is an existing bug in the source-files for SP concerning the pi_server.erl file. In commit dedc9ea6cfbf6e8c6d02e48196c5cb23c93e0b55 on 22nd October 2017 Erlang - tech scheduler to only listen on loopback network (This stops the Erlang process from triggering firewall warnings on Windows) Sam prevented the erlang schedular in listening to entries other than from the local host. This was to solve a problem with the Windows install. Unfortunately it also had the side effect of preventing Sonic Pi from sending OSC messages to external IP addresses. Of course, on a non windows matching this is not a problem, and you can revert this commit and rebuild the modified pi_server.erl file and it will then be able to send OSC messages to external IP addresses. The change required is in line 69 which reads
` {ok, Socket} = gen_udp:open(Port, [binary, {ip, loopback}]),`
change it to read
` {ok, Socket} = gen_udp:open(Port, [binary]),`
and resave the file.
Now is also a good time to alter the two files scope.cpp and mainwindow.cpp as detailed in update 3 described above
#build the two erlang beam files
cd ~/src/sonic-pi/app/server/erlang
erlc osc.erl
erlc pi_server.erl
#The rest of the build process is carried out in a terminal window from the qt folder
cd ~/src/sonic-pi/app/gui/qt
#compile some vendor gems
#note this also creates the folder ../../server/ruby/rb-native/2.5.0
../../server/ruby/bin/compile-extensions.rb
#you will notice several warnings during this process but that is normal
#it will also take some time to complete
#now start building the documentation
#first the translation files
../../server/ruby/bin/i18n-tool.rb -t
#prepare a fresh header for the help file compilation
cp utils/ruby_help.tmpl utils/ruby_help.h
#populate the header file with qt-doc.rb
../../server/ruby/bin/qt-doc.rb -o utils/ruby_help.h
#now complete the preparation of completed translation files
#listed in the SonicPi.pro file
/usr/bin/lrelease SonicPi.pro
#prepare the Makefile using qmake
/usr/bin/qmake SonicPi.pro
#do the compilation of sonic pi
make #this takes quite a bit of time
Hopefully at this stage you have completd a working Sonic Pi3.2dev
To test it, in your terminal window type
~/src/sonic-pi/bin/sonic-pi
You should see the sonic pi logo in the terminal window and a splash screen will open.
After about 20 seconds you should see the main Sonic Pi window opening.
for a clean exit right click the Sonic Pi icon in the taskbar and choose Close Window.
Note although the window will close immediately the app takes about 19 seconds seconds to completely close down, so don’t try to restart it immediately.
Further work, to add an icon to start Sonic Pi3.2 from the maim menu.
It is easy to add a second SOnic Pi icon to the application menu as follows:
from a terminal type:
sudo cp /usr/share/pixmaps/sonic-pi.png /usr/share/pixmaps/sonic-pi3.2.png
# edit the new desktop file using nano:
sudo nano /usr/share/applications/sonic-pi3.2.desktop
Change the contents of the editor window to the version shown below. Essentially adding 3.2 three times
[Desktop Entry]
Version=1.0
Type=Application
Exec=sonic-pi3.2
Icon=/usr/share/pixmaps/sonic-pi3.2.png
Terminal=false
Name=Sonic Pi 3.2
Comment=Learn programming and computer science while creating music
Categories=Application;Development;
Keywords=Music;Sound;Algorave;Live;Coding;Programming;Synthesizer
Type ctrl+X followed by Y return to exit, saving the file with its existing name
(Note I used a duplicate icon, in case the original Sonic Pi is uninstalled so tha the second icon remains.)
Now generate a launcher file to place in /usr/bin
paste the folliowng
cd /usr/bin
sudo nano sonic-pi3.2
#!/bin/sh
/home/pi/src/sonic-pi/bin/sonic-pi
Tyoe ctrrl+X then Y return to exit
Finally make the file executable:
sudo chmod +x /usr/bin/sonic-pi3.2
You should now find a Sonic Pi 3.2 icon in the Applications Menu Programming Section underneath the original Sonic Pi icon. Clicking it should launch Sonic Pi 3.;2dev
Note if you want to move the sonic-pi folder in the src somewhere else, having completed the build then you can do so. You just have to amend the path in the sonic-pi3.2 file in the section above to suit. (change the /home/pi/src/sonic-pi/bin/sonic-pi
to give an absolute path to the new location)
Some notes on the installation
This is a development version, and it has one or two known bugs/problems
The transparency slider in the Preferences panel is currently visible, but has no effect. IF it is not possible to get it working with a Pi, then it will be removed before the final version.
Even though it is ticked as enabled in the IO prefs section, OSC messages don’t work
until you disable and then re-enable the OSC Server
It is possible to run Sonic Pi using an externally setup jack server using QjackCtl.
This is of great use if you want to connect inputs from a sound card like PiSound,
which can also work with reduced latency by adjusting the connection parameters.
It can also let you connect the audio output of Qsynth or Helm synths
running on your Pi directly to Sonic Pi, even if you don’t have a sound card.
I will detail this later in a separate article.
Note Sonic Pi does NOT stop the current jackd when it quits, (in case you are using an external version).
Consequently you must issue killall jackd
if you have started Sonic Pi with the internal call to jackd BEFORE you can subseqeuntly use QjackCtl.
qjackctl IS already installed on Buster but is hidden on the Applications Menu.
To enable it, select Main Menu Editor from the Preferences Section, navigate to the Sound & Visual section, and tick QjaclCtl to enable it.
If you uninstall the original Sonic Pi (ver 2.10) (which I don’t recommend) then it will also remove ruby and supercollider-server packages.
In this case you will have to reinstall them using
sudo apt install ruby supercollider-server
for Sonic Pi3.2dev to work.
Although this install has been created on a Pi4, the SD card can be transferred to a Pi3B+where it will work quite happily. It should also build on this Pi model, although it may take a lot longer, and I suspect you may have to temporarily increase the swap file size as mentioned at the beginning of this post.
Occasionally things can go wrong and Sonic Pi doesn’t exit cleanly and clean up it various components. One way to do this is to reboot the machine. More easily in ` terminal:
killall m2o
killall o2m
killall beam.smp
killall scsynth
killall ruby
should clobber everything. (You will get not found messages for thse that are already closed)
Transporting Sonic Pi3.2dev to a different SD card
Having built Sonic Pi3.2 it is possible to slim down a copy the final folder, and then move this to another Raspbian Buster SD card. With the addition of three packages, and adding the desktop files this will then work there, without having to build it again. At a later date I will give fuller detains plus some scripts to automate the process.
I hope that this post will be useful. I would welcome feedback on its use, so that it can be amended if necessary.