Successful linux install plus Tidal coding on iPad (and most likely an Android device) with emacs

Hi All

I decided to share my almost "hands free" approach to installing Tidal on Ubuntu 20.04 box with the help of this wonderful community. I'm putting this post into the "Installation" section as it mostly deals with successful installation process with a minimal headache on a Linux Ubuntu system. This post is by no means meant to replace the official installation guidelines.

I share my brief experience on how to set up the configured system to work with iPad for coding Tidal with Emacs editor and also set up audio output from iPad speakers (or AirPods / bluetooth earphones/speakers).

I'm writing it from the perspective of a complete fresh Ubuntu system install so feel free to skip parts.

Lastly, most of the commands below are issued form the Terminal (aka shell). I tried to be more or less overly verbose with commands and some explanations for people who have minimal exposure of working with the Terminal.

Ubuntu 20.04 + Ubuntu Studio performance and audio packages install

The motivation for this combo is that you'll end up with a leaner system that is optimized for audio work and looks like a regular Ubuntu 20.04 install. Any other packages you're using can be installed on top of it.

  • Download Ubuntu 20.04 installer and install it onto your box (I selected the minimal install and no to 3rd party option to keep the system lean).

  • After the install, update the system sudo apt update && sudo apt upgrade -y and install Ubuntu Studio Installer package sudo apt install ubuntustudio-installer (accept real-time jack setting during the installation).

  • Run Ubuntu Studio installer sudo ubuntustudio-installer This gives you a choice to install various creativity related packages, low latency kernel and system tweaks and will install along side almost all dependencies needed to work with audio etc that I skipped during Ubuntu install in the first step (see ubuntustudio-installer and Ubuntu Studio audio features ).

I'm gearing my linux box towards audio work so I chose to install everything with audio, low latency, performance and carla in the name of given install options and left alone other packages. If you ever need any other offered non-audio related packages to install you can run the installer again to do so. A word of caution - refrain from installing gnome-branding package as it will turn your plain vanilla Ubuntu install into Ubuntu Studio distribution install. In my opinion, it will be easier to download and install Ubuntu Studio distro in the first place instead.

  • Reboot your computer once ubuntu studio install is complete.

Tidal install

  • Follow this instructions for the excellent minimal interaction approach written by the forum member cleary. Cleary provides installs with different editors - I chose tidalcycles + vscode. This will configure everything you need by simply clicking on programs' icons to launch them (ie SuperCollider and VSCode).

  • Once installation is complete you can test that everything is working - (1) start jack server via Ubuntu Studio Controls or QjackCtl, (2) start SuperCollider (3) start your chosen editor from the above step (VSCode in my case) and (4) run Tidal code to make a sound. Everything worked flawlessly for me (very happy).

Emacs + SSH install (to code on iPad)

I'm going to jump ahead and caution the following:

  • it requires a purchase of Blink Shell:Mosh & SSH Client app in Apple appstore (although you can compile and sign one yourself for free, as I understand, if you're up to it). Disclaimer - I'm not in anyway affiliated to this app or it's creator. I just happen to use it for a number of years already and find it very useful. Also, note user experience difference between mosh and ssh - mosh will not disconnect your session quickly if, for example, you switch to another app for a while.

  • your linux box and iPad need to be connected to the same local network (there's nothing to stop you to access you linux box from the remote locations and send the audio stream back but this is outside of scope here).

  • there's a small but noticeable audio lag between running the code and hearing it. But I don't find it a distraction.

  • the below should work (I didn't try) on Android devices - you'll just need to find a suitable ssh or mosh client app in Android store.

  • if you're using Vim already you probably don't need Emacs but I didn't try.

The main purpose for me to install Emacs is to be able to code Tidal (and just about anything else) on an iPad via ssh or mosh. Hence, the below install steps are for Emacs with no graphical interface or sound. Moreover, I use Spacemacs distro but will refer to it as Emacs for brevity.

Onward with install:
Install SSH server sudo apt install openssh-server -y
Install mosh if you plan to use it sudo apt install mosh -y
Install Emacs build dependencies sudo apt install -y gnutls-dev texinfo build-essential libncurses-dev autopoint debhelper dh-autoreconf dh-strip-nondeterminism libfile-stripnondeterminism-perl

then in the Terminal issue the following to download, compile and install Emacs
cd
git clone -b master git://git.sv.gnu.org/emacs.git
cd emacs/
./autogen.sh
./configure --without-sound --without-x
make -j5
check it's working
src/emacs --version
install it globally
sudo make install

install Spacemacs (you don't have to but I find it a good companion to Emacs)
cd
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
cd .emacs.d/
git checkout develop
run spacemacs
cd
emacs

The last command will launch Emacs. It will ask you what editor style you prefer - I chose Emacs instead of Vim and also chose to use full distribution instead of minimal.

Once Emacs finished self updating, close it (Ctrl-x Ctrl-c where Ctrl-x stands for holding the CTRL key while pressing 'x').

Add tidal layer (thanks to the forum member rbino for coding this)
cd && nano .spacemacs
scroll a bit down until you see dotspacemacs-configuration-layers line. Type tidalcycles on a new line directly underunder emacs-lisp (refrain from typing ;; in front it).
Save and close (Ctrl-x type y and hit enter).

At this point go ahead and see if tidal works in Emacs:
create a test file with tidal extension (for example cd && touch test.tidal)
start Jack server and SuperCollider then
emacs
hit (Alt-x) type tidal-mode select it and hit Enter button
hit Ctrl-x Ctrl-f, navigate and find test.tidal file in your home directory, select it and hit Enter to open it in Emacs
hit Alt-x type tidal-start-haskell select it and hit Enter to start Tidal.

Your Emacs screen should be now split in two horizontal windows. If you don't see any error output on the bottom window then you're ready to code Tidal in Emacs. If you see on the bottom window an error complaining about being unable to locate BootTidal.hs file to launch Tidal then to fix this do the following:

close Emacs and
cd && ~/.emacs.d/elpa/28.0/develop/
then cd into the tidal folder (as of the time I'm writing this post it will be the following command cd tidal-20191210.1647 ) and edit tidal.el file as below (we are going to set an alternative path to BootTidal.hs file)
nano tidal.el
scroll down and find the line starting with (defvar tidal-boot-script-path You'll need to uncomment the whole block of code belonging to this defvar function. Stop uncommenting just at the line starting with (defvar tidal-literate-p
type the following on the new line (setq tidal-boot-script-path "~/.cabal/share/x86_64-linux-ghc-8.6.5/tidal-1.4.9/BootTidal.hs")
Save and close file.

Start Emacs again to check if the error went away. It did for me and I was able to make sounds with Tidal in Emacs. Close Emacs.

Emacs + iPad "integration"

As mentioned above, I use Blink app on my iPad to ssh/mosh into my linux box. This "frees" me form the desk/monitor and I can code Tidal anywhere within the local wi-fi network I'm using. Plus the latest version of iPad OS lets me to connect a keyboard so I don't have to type on screen. Just about any iPad generation should work.

  • install Blink on your iPad (Blink lets you choose different themes and fonts - try Monokai theme and Fira Code as a font).
  • install byobu on your linux box sudo apt install byobu -y
  • find the ip address of your linux box. In the Terminal type ifconfig the output of this command will show the ip address assigned to your machine (ie 192.168.xx.xx where xx are the digits as per the output). If you don't have ifconfig installed Ubuntu will inform you what command to issue to install it.
  • open Blink on iPad and type ssh your_linux_box_user_name_here@192.168.xx.xx (if you decide to use mosh then replace ssh with mosh)
  • accept the keys to be added
  • now you should be connected to your lunux box and it should look like the Terminal window. Issue the following commands
    byobu and then
    emacs

You will see Emacs screen on your iPad. You can code sound in Tidal at this point from iPad but the audio output is still tied to the linux box.

To send audio to the iPad I use ffmpeg on the linux box and VLC for Mobile on the iPad to receive it (you'll need to install VLC app form the app store).

If you installed Ubuntu Studio packages then ffmpeg and all audio codecs are already installed for you. At the moment iOS only understands mp3 streaming so we'll use ffmpeg to capture and stream audio from your linux box to iPad in mp3 format.

Below assumes you have jack server and SuperCollider running already.

Find the ip address of your iPad in the Wi-Fi menu (it should be something like 192.168.yy.yy or similar)

Open VLC on iPad, click on Network --> Open Network Stream --> type rtp://192.168.yy.yy:3689 and click on the orange button Open Network Stream. Now your iPad is ready to receive the audio stream as sent by ffmpeg

On your linux box issue the following command in the new Terminal screen. Don't close this Terminal screen and let it be open unless you want close ffmpeg and terminate streaming.

ffmpeg -f jack -i hw:PCH,0 -acodec libmp3lame -q:a 3 -ac 2 -f rtp rtp://192.168.yy.yy:3689

where hw:PCH,0 is my linux sound card -q:a 3 is the mp3 variable bit rate setting for ffmpeg to use -ac 2 is to capture two channels, rtp is the stream protocol 192.168.yy.yy is the ip address of your iPad and 3689 is an arbitrary port.

Find your particular sound card harware address (something like hw:PCH,0) in Ubuntu Studio Controls under Audio Set-up / Jack Master Device drop down list.

Last step is to connect the system audio output to the hardware device for ffmpeg to capture it. Do this by running QjackCtl

Once QjackCtl window is open click on Connect button. A new window will open. In this window select/highlight both system on the left screen and hw on the right screen. Click on the Connect button. You can save this connection as a preset - click on Patchbay --> left hand side Add --> in Output Socket set to Audio, choose system in Client and add capture_1 and capture_2 Plugs. Click OK. Then right hand side Add --> Input Socket Type set to Audio, choose hw in Client (if you don't see it you need to start ffmpeg command as above and try again) and add input_1 and input_2 Plugs. Click OK. Then click Save; give it a name and save it. You can use this preset next time instead.

Go back to emacs on your iPad, start Tidal and code a sound. Hopefully you will hear sounds coming from your iPad. To use wireless earphones / speakers just connect them to your iPad.

If no sound is coming - try troubleshooting by ensuring that:
jack server and SuperCollider are running,
system and hw are connected in QjackCtl;
instead of system try connecting SuperCollider and hw;
you have the correct ip address for the iPad in both ffmpeg command line and VLC app;
you chose the correct hw device (your PC probably has more than one audio device);
your linux box and iPad are on the same local network;
ffmpeg comman is runnig in the Terminal.

One note on byobu (if you haven't used it before) - it lets you to open different Terminal windows in tabs by pressing F2 and cycle between them by pressing F4 or F3. That way you can run your linux box without a monitor and ssh from iPad into it to strart jack server, SuperCollider, ffmpeg and Emacs. You can also configure buyobu itself by pressing F9.

Happy Tidal coding.

10 Likes

Awesome! Will keep this handy... <3 thanks so much!!!!

Epic post!
I'm glad I was able to help, it should be fairly trivial to add an emacs editor role to my ansible setup - I plan to have a dig into that in the coming weeks (I've committed to not distracting myself too much from actually making music for a bit though) :smiley:

1 Like

Great! Glad to help.

Thanks! You helped me out al lot. I already had a set up with everything manually compiled but SuperCollider install was a bit shaky. I used Ansible installs somewhere else so I knew that it should a preferable way to go instead of the manual way. So I did a new install from scratch and it was that simple and took way less time also :slight_smile: . If you can add an Ansible role for Emacs/Spacemacs that will be cool. Emacs is a thing in itself to learn but as a shell text editor it's great.

1 Like

Very nice! While I think I'm done with configuration battles for a while, I could see a future where I want to ssh in from a tablet, so thanks!

This is great! Thank you for the detailed post.

I have a setup where I connect my Super Collider outputs to Darkice and then stream to my computer with Rocket Streaming Audio Server.

I usually see around 5 to 10 seconds of latency with this setup while streaming to the browser as mp3. I would love to improve this. What kind of latency are getting with ffmpeg?

My unscientific test gives me latency of around 3 seconds. That is ffmpeg to my iphone and then to a bluetooth speaker.