I recently had trouble talking from me desktop PC to my music-playing PC, running Giocoso. I'd launch a remote ssh session to the player PC, kick off some music playback …and the ssh connection would die, stopping the music playback as it did so. Very annoying if, say, you'd played 1.75 hours of a 2 hour opera: when the ssh session dies, the partial play is essentially regarded as never having happened, so you have to start from scratch next time you connect.
My first thought on fixing this was: screen. It's a utility you launch on the music-playing PC immediately after you've ssh'd into it from the desktop PC, and then within screen, you can launch Giocoso. If the ssh connection dies between desktop and player PCs, screen and anything launched from within it continues to run regardless. Brilliant! But, unfortunately, this is what launching Giocoso inside screen looks like:
Complete gibberish, of course! I mean, you can just about make out menu options and navigation aids and the thing will actually play music.. but it's obviously not ideal! It probably has something to do with the way Screen handles terminal emulation: I did try fiddling with the value of the TERM environment variable before launching Giocoso, but it really didn't make any difference.
So my second thought was tmux, which does the same sort of thing as Screen: provide an environment in which programs can be launched such that, should the network die, the running program doesn't.
So I tweaked my desktop PC's launcher for 'remote Giocoso'. It's application remained unchanged from before:
/usr/bin/uxterm
…that is, everything continues to run inside a local session of the 'uxterm' console program. What's different is the “arguments” that you pass to that uxterm session as it begins. Mine used to read:
-T 'Giocoso - A Digital Music Player' -xrm 'xterm*iconHint: /home/hjr/.local/share/giocoso3/art/giocosoico.xpm' -bg black -fg green -geometry 103x28+0+0 -fa 'Luxi Mono:style=Regular' -fs 12 -ti 340 -tn xterm-256color -e 'trap "" HUP; ssh -Y -t [email protected] /usr/bin/giocoso3.sh'
…which is “give the terminal a name and a thumbnail icon, set it to be black with green text, make it 103 columns wide and 28 rows high, positioning it in the top left of my desktop PC's monitor; set the font to something nice, and then ssh over to the music-player PC and launch Giocoso”. Looks messy, but it worked (or did if the network stayed up)!
The new “arguments” however now read as follows:
-T 'Giocoso - A Digital Music Player' -xrm 'xterm*iconHint: /home/hjr/.local/share/giocoso3/art/giocosoico.xpm' -bg black -fg green -geometry 103x28+0+0 -fa 'Luxi Mono:style=Regular' -fs 12 -ti 340 -tn xterm-256color -e "ssh -Y -t [email protected] \"tmux new-session -A -s giocoso '/usr/bin/giocoso3.sh'\""
Most of that starts off exactly as it used to. The new feature is that having ssh'd to the remote PC, it doesn't directly launch Giocoso, but launches tmux and creates a new session (called 'giocoso') and, within that session, runs the giocoso3.sh executable. This appears on my desktop PC almost exactly the same as it used to… except that I can now physically close the Giocoso window, thereby manually terminating the ssh session… and the music previously playing will continue playing without interruption. If my network dies of its own accord, the player PC will similarly continue playing without a murmur. Especially nice is that if I re-launch Giocoso on my desktop, it will automatically re-connect to the remote tmux session and display it exactly where I left it, album art and all.
The only slight fly in the ointment is that, by default, tmux likes to display a status bar at the bottom of the terminal window it's running in:
That glowing green bar at the bottom of the screen rather throws off my geometry calculations: Giocoso needs to run in a 103×28 terminal window… but if one of the vertical lines is taken up by tmux's status bar, Giocoso gets muddled:
None of the lines actually appear where they should and text over-writes them in places. The fix for this is relatively straightforward. One possible fix is to retain the status bar and just amend the “arguments” for my launcher to launch at 103×2*9* rather than 103×28. That's a client-side fix, of course. The fix I decided to adopt is a server-side one: on the remote PC, I create the file $HOME/.tmux.conf and type the following code into it:
set -g status off
Once a new tmux session starts, it picks up this new setting… and the result is:
The title bar of that terminal tells you that the session is running tmux… but now there's no bright green bar at the bottom of the screen. The status bar is off!
All of which means that no matter how dodgy my network connection to different parts of my home might be, I can be confident that Giocoso will play things through to completion, every time: no more getting 4.5 hours through Götterdämmerung and then having the rug pulled out from under me yet again! A future Giocoso installer may implement this tmux configuration tweak directly, though I haven't decided on it yet. Obviously: it only affects people who use Giocoso via a network/ssh connection, so it is maybe a bit niche to start making sweeping configuration changes to other programs at this point!