View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

Autoboot into emacs -sclang

Home   How To   Code Pool   Public Library   Theory   Events
For sound installations or other applications of SuperCollider, it may be useful to have your computer boot into Emacs sclang-mode, start your patch, and then later on being able to log on (remotely) to the computer and edit and or change the things that are running (i.e. executing more sclang-code).

It is possible to set this up on a Linux computer, using the Grub bootmanager to boot into a special runlevel, a startup script to start emacs/sclang and most importantly a little program called screen, which allows you to have a shell, that you can exit (but any programs that are running will keep running) and resume later on, even after having logged out and in again.

Setting this up, requires a bunch of little tweaks, in order to ensure that things are executed by the right user and the right paths are used, so here is a little HOWTO of how to do it.

GRUB
In GRUB you have to add an entry to boot into the runlevel you want.
To the file /boot/grub/menu.lst you have to add a line, similar to one of the others (for the kernel you want to boot), and add at the end the number of the runlevel you are going to use:

e.g.:
kernel          /boot/vmlinuz-2.6.14-1-multimedia-386 root=/dev/hda2 ro 3


if you are using runlevel 3.

Runlevel
Runlevels are basically a series of scripts that will be executed when booting or halting the system. On Debian systems, you will find these in directories called /etc/rcN.d where "N" is the number of the runlevel. Choose one of the runlevels that aren't really used (2 is used by Debian as a default, 6 is usually connected to shutting down), and adapt that runlevel.
In the directory you have to place all the symlinks for scripts that need to be executed and you can take away the ones you don't need (for example the one starting the graphical interface).
To start screen, emacs and sc, make a symlink like:

ln -s /home/me/mystartupscript.sh S99sclangpatch


Startup script

The script should look like this:

echo "starting sclang script"
cd /dev
/sbin/MAKEDEV console
echo "made devices"
chmod 666 /dev/console
route add -net default gw 129.102.145.254
cd /home/nescivi/
su nescivi -c "/usr/bin/jackd -R -dalsa -dhw:0 -r44100 -p256 -n2 &"
su nescivi -c "/usr/bin/screen -c /home/nescivi/.screenrc"
echo "sending command"
su nescivi -c "/usr/bin/screen -X screen -t supercollider 1 bash startemacs.sh"
echo "command sent"


In steps:


I am not sure whether the MAKEDEV line is needed. The "chmod 666" is needed, as otherwise the console is not writeable for the user that will execute the programs:

cd /dev
/sbin/MAKEDEV console
chmod 666 /dev/console



For some reason on my setup the route was not stored on shutdown, so I needed to add this on every boot:

route add -net default gw 129.102.145.254



Change to the home directory of the user (in my case "nescivi"):
cd /home/nescivi/


As the user (su nescivi) start JACK:

su nescivi -c "/usr/bin/jackd -R -dalsa -dhw:0 -r44100 -p256 -n2 &"


Start screen with startup file ".screenrc" (see below):
su nescivi -c "/usr/bin/screen -c /home/nescivi/.screenrc"


Tell screen to execute the script "startemacs.sh":
su nescivi -c "/usr/bin/screen -X screen -t supercollider 1 bash startemacs.sh"


.screenrc

should look like this:
startup_message off
console off
bash
detach


It will open a screen, without startup message, and detach the screen immediately afterwards.

startemacs.sh

In this file you have to set a couple of paths, so libraries can be found. And you have to start emacs with the startup file of the user, as that is where you'll probably have put the special sclang-commands.

LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

export PATH LD_LIBRARY_PATH PKG_CONFIG_PATH

emacs -u nescivi -sclang


.sclang.sc

emacs -sclang will automatically start sclang and execute anything that is in /home/nescivi/.sclang.sc, so that is where you tell sclang to load the document with your actual patch; for example:

// set some server options for a different setup
// hook up jack ports to audio channels
"SC_JACK_DEFAULT_INPUTS".setenv(
	"alsa_pcm:capture_1,"
	"alsa_pcm:capture_2,"
	"alsa_pcm:capture_3,"
	"alsa_pcm:capture_4,"
	"alsa_pcm:capture_5,"
	"alsa_pcm:capture_6,"
	"alsa_pcm:capture_7,"
	"alsa_pcm:capture_8");

"SC_JACK_DEFAULT_OUTPUTS".setenv(
	"alsa_pcm:playback_1,"
	"alsa_pcm:playback_2,"
	"alsa_pcm:playback_3,"
	"alsa_pcm:playback_4,"
	"alsa_pcm:playback_5,"
	"alsa_pcm:playback_6,"
	"alsa_pcm:playback_7,"
	"alsa_pcm:playback_8"
);


Server.default = s = Server.local; 
s.options
.numAudioBusChannels_(256)
.numInputBusChannels_(8)
.numOutputBusChannels_(8)
.memSize_(8192 * 4);


fork { 
	0.1.wait; 
	s.quit;
	0.5.wait; 	
	s.boot;
	1.wait;
	
	s.doWhenBooted( {
		{  "/home/nescivi/SuperCollider/startMyCoolPatch.scd".load }.defer;
		});
};

// EOF



Other tweaks
If you do not want to attach a keyboard and mouse to the computer, it may be necessary to make a change in the BIOS of the computer, to ensure that the computer doesn't halt when there is no keyboard found. Look for an option concerning "halt on any errors" or the like, and make sure it will not.

Testing
Of course, you should test the startup sequence a couple of times, to see if it is really doing all that you need it to do...

And it runs...
Now the whole thing should be running as desired and you can login to the computer after it has booted. Type

screen -r


to resume the screen session and you get back in to the emacs session.

To detach from the screen again you have to type <CTRL>-a d.

Proper shutdown...

You may want to properly stop some services, upon shutting down the computer.

In the file
/etc/acpi/events/powerbtn

you can put this:

event=button[ /]power
action=init 0


So that upon pressing the power button, the system will go to runlevel 0, which means executing all shutdown scripts.

You have to add a symlink to your shutdown script in /etc/rc0.d, with a name like K00mycoolscript
and make sure that the script you point to is executable (permissions!).



nescivi, June 2006 - May 2008

Links to this Page