Commission Music

Commission Music
Bespoke Noise!!

Monday, 29 April 2013

A useful script

The best way to remember to do something when you're going to run some important program is to put in the program itself. Or at the very least, put it in a script that you use to invoke the program.

I have a few things I need to remember for the performance I'm preparing for. One has to do with a projector. I'm using a stylus to draw cloud shapes on my screen. And one way I can do this is to mirror my screen to a projector so the audience can see my GUI. However, doing this usually changes the geometry of my laptop screen, so that instead of extending all the way to the edges, there are empty black bars on either side of the used portion of my display. That's fine, except the stylus doesn't know and doesn't adjust. So to reach the far right edge of the drawn portion of the screen, I need to touch the far right edge of the drawn portion, which puts over a centimetre between the stylus tip and the arrow pointer. Suboptimal!

Ideally, I'd like to have any change in screen geometry trigger a script that changes the settings for for the stylus (and I have ideas about how that may or may not work, using upstart, xrandr and xsetwacom), but in the absence of that, I just want to launch a manual calibration program. If I launch the settings panel, there's a button on that that launches one. So the top part of my script checks if the calibration is different than normal and launches settings if it is.

The next things I need to remember are audio related. I need to kill pulseaudio. If my soundcard (a Fast Track Ultra) is attached, I need to change the amplitude settings internally so it doesn't send the input straight to the output. Then I need to start jack using it. Or if it's not attached, I need to start jack using a default device. Then, because it's useful, I should start up Jack Control, so I can do some routing, should I need it. (Note: in 12.04 if you start qjackctl after starting jackd, it doesn't work properly. This is fixed by 13.04.) Finally, I should see if SuperCollider is already running and if not, I should start it.

That's a bit too much to remember for a performance, so I wrote a script. The one thing I need to remember with this script is that if I want to kill jack, it won't die from Jack Control, so I'll need to do a kill -9 from the prompt. hopefully, this will not be an issue on stage.

This is my script:


# first check the screen

LINE=`xrandr -q | grep Screen`
WIDTH=`echo ${LINE} | awk '{ print $8 }'`
HEIGHT=`echo ${LINE} | awk '{ print $10 }' | awk -F"," '{ print $1 }'`

if  [[ ${WIDTH} != 1366 || ${HEIGHT} != 768 ]]
 gnome-control-center wacom
 echo normal resolution

# now setup the audio

pulseaudio --kill

# is the ultra attached?
if aplay -l | grep -qi ultra
 echo ultra
 #adjust amplitude
 for i in $(seq 8); do
         for j in $(seq 8); do
                 if [ "$i" != "$j" ]; then
                         amixer -c Ultra set "DIn$i - Out$j" 0% > /dev/null
                         amixer -c Ultra set "DIn$i - Out$j" 100% > /dev/null
                 amixer -c Ultra set "AIn$i - Out$j" 0% > /dev/null

 #for i in $(seq 4); do 
 # amixer -c Ultra set "Effects return $i" 0% > /dev/null 

 #start jack
 jackd -d alsa -d hw:Ultra &
 #start jack with default hardware
 jackd -d alsa -d hw:0 &

sleep 2

# jack control
qjackctl &

sleep 1

# is supercollider running?
if ps aux | grep -vi grep | grep -q scide
 echo already running
 scide test.scd &

No comments: