Category Archives: FOSS

Arranging Music on Linux

For arranging or producing music then the Mac OS X is normally the “go to” platform. Even relatively simple or basic applications like GarageBand can provide great output for not a lot of effort. Replicating the same environment with FOSS under Linux is a bit of a challenge but it can be done. Personally, I have two main requirements:

  1. Arrange music for a group with the end result being some printed sheet music. It’s useful if I have a MIDI output as well to make sure that the arrangement sounds sensible.
  2. Arrange music for my wind synth, add some accompaniment / backing and allow me to play along with it.

Both of these cases need one more of the following tools:

  1. Create sheet music / printed output
  2. A way of generating a backing track
  3. An environment like GarageBand to pull it all together
  4. Some means of creating the sound and allows external MIDI input ( e.g from my wind synth or a keyboard )

( I’ve described how I got MIDI up and running on Linux and some of the tools below in an earlier post )

Creating Sheet Music

I’ve been using LilyPond for arranging sheet music for a number of years. It’s slightly unusual in that it uses a text based input rather than a graphical interface but I’ve found it to be very effective. There’s a very good description page on their website, with examples of how it works. An extract from that page:

LilyPond is a compiled system: it is run on a text file describing the music. The resulting output is viewed on-screen or printed. In some ways, LilyPond is more similar to a programming language than graphical score editing software.

You do not write music by dragging notes from a graphical toolbar and placing them on a dynamically refreshing score; you write music by typing text. This text is interpreted (or โ€œcompiledโ€) by LilyPond, which produces beautifully engraved sheet music.

It’s not the easiest program to get started on but it’s worth persevering as the output is excellent and easily as good as commercial offerings like Finale.

Frescobaldi is a very useful front end tool for LilyPond. It’s effectively an IDE with an editor pane ( with syntax highlighting ), an output preview and a message window. I was initially a bit sceptical but I’ve found that it very much speeds up the writing process.

However LilyPond has two small problems for me:

  1. Some of my arrangements are jazzy pieces for the wind synth and there’s no option to output the MIDI in “swing time“.
  2. There doesn’t seem to be an easy way of implementing the “Da capo” musical construct and no way of getting the correct MIDI output. This is particularly annoying because it’s a common enough musical idiom.

Both of these problems can be solved by using a different arranging program, e.g. MuseScore. The problem I’ve found with these is that the interface is usually graphical and results in far too much clicking and dragging to arrange the music. Additionally there’s no easy way of importing LilyPond scores into MuseScore so I’ve yet to fully solve these problems. To work around the two problems above I currently generate the basic music data in LilyPond, import the MIDI file into MuseScore and do the final arrangement there but it’s not ideal.

Backing Tracks

In this case a backing track is just a set of chords and/or rhythm parts to accompany the main solo part. Apple’s GarageBand has these built in as part of the program but there are other separate programs available as well, Band-in-a-box being one of the well known ones.

Finding a FOSS alternative was a bit tricky but I came across MMA – Musical MIDI Accompaniment which does the job very nicely. Again it’s not the easiest thing to get started on but there are tutorials on the site that explain the basics so that you can get up and running quite quickly.

One problem that I found was in trying to find a suitable backing track from the many that are available. There is a documentation browser for each of the presets but there’s no substitute for actually listening to the music. To make things easier I wrote a simple script that generates some basic C chords for every preset and creates a series of wav files that I can browse. Ideally there needs to be some way of combining these wav files with the written documentation to make it a little more user friendly but that’s probably a different project ๐Ÿ™‚

Digital Audio Workstation

A Digital Audio Workstation ( DAW ) is essentially a piece of software for manipulating audio files. The full story is of course much more complex than that but my use of a DAW is quite simple. There quite a few FOSS DAW programs but, after reading a few reviews, I ended up with LMMS which comfortably meets my needs at the moment. LMMS has a number of instruments built in but I usually use the Soundfont player ( Fluidsynth ) with a sound file that matches the General MIDI Specification, usually the default that comes with Fluidsynth.

My general workflow is:

  1. Import the MIDI generated from LilyPond
  2. Import the MIDI generated from MMA
  3. Add some backing rhythm using LMMS’s beat generator
  4. Add an extra solo instrument that’s controlled from a MIDI input, e.g. the wind synth

MIDI Output

The DAW will obviously produce sound output directly but a different approach could be to output a MIDI file and then use that to produce the final result. For live performances it’s arguably it’s easier to use a MIDI file with a soft synth or an external MIDI sound module rather than a laptop running a full DAW.

There are two steps here. Firstly the MIDI file needs to be exported from LMMS. This functionality was missing for some time but is now available in version 1.2 onwards. It’s pretty good because it exports any built in beat tracks as well as the instrument tracks. There is one drawback in that the MIDI instruments are not set so all exported tracks will default to channel 0, instrument 0. I can sort of understand this because the instruments used internally may not correspond in any way to the General MIDI Spec. However this does mean that the MIDI file will need to be edited to add the relevant program change events to each track.

To edit the file I’ve used a program called seq24. However it’s quite a manual process and, at the moment, I haven’t really found an ideal solution especially one that I could use on my old Thinkpad laptop. Maybe this is the next coding project ๐Ÿ™‚

Secondly the MIDI will need to be played and routed to the relevant MIDI device. There are a number of options for this:

There’s a command line program called ‘aplaymidi’ which will play a MIDI file to a MIDI output port:

aplaymidi -l ( get a list of available MIDI ports )
aplaymidi --port=xx.x file.mid ( plays file to the defined port )

( Seq24 can also play MIDI files but it’s more aimed at playing MIDI loops rather than single tracks. )

Raspberry Pi as a Music Server

Version 1 of the Raspberry Pi computer was rather underpowered for use as even the most basic desktop machine. However it was ideal as an “always on” computer especially for streaming video or audio. A number of OS distributions sprang up all aimed at using the Pi as a home theatre device, usually with custom user interfaces. However I really only wanted to stream audio and I preferred to control the output from, say a phone, rather than having a dedicated screen. Fortunately most of these home theatre distros use Music Player Daemon (MPD) as the basic engine and will add their own custom UI over the top. MPD itself is a server and there are a number of clients for all platforms. This post describes how I set up and operate my MPD based music server.

Hardware & OS

The main part of the hardware is a version 1 Raspberry Pi. As I didn’t intend using a screen then I used the “Lite” version of Raspbian without the desktop. It’s powered using an old USB phone charger into the micro-USB socket on the Pi.

The on board audio is not really suitable for anything serious so I bought a Hi-Fi Berry DAC which just plugged into the expansion pins. For around ยฃ30 this gave a massive improvement in sound output. There were a few steps to getting it configured:

1. Add the following modules to /etc/modules:

snd_soc_bcm2708
bcm2708_dmaengine
snd_soc_pcm5102a
snd_soc_hifiberry_dac

2. In /boot/config.txt add the following lines to enable the I2C, disable the on board audio and enable the Hifi Berry

dtparam=i2c_arm=on
dtparam=audio=off
dtoverlay=hifiberry-dac

3. Finally create a /etc/asound.conf similar to:

pcm.!default  { type hw card 0 }
ctl.!default { type hw card 0 }

Basic Music Player Daemon

MPD and its command line local command line client can be installed from the standard repositories:

sudo apt-get install mpd
sudo apt-get install mpc

When I did this I got verion 0.19.0 which is a little behind the latest version ( 0.20.18 ) and I should really download, build and install the latest version at some point.

To set up MPD I generally followed the instructions in these two blog posts ( 1, 2 ). It’s pretty straightforward and the only configuration needed is to change these lines in /etc/mpd.conf to match your set up:

  • music_directory “/change/this/to/where/your/music/will/be”
  • playlist_directory “/change/this/to/where/your/playlists/will/be”
  • bind_to_address “any”

Storage

To store the music I used an old 500 Mbyte SATA drive via a cheap SATA<->USB interface attached to one of the Pi’s USB ports. This is a useful guide to mounting USB drives into the Pi’s file systems. I also added “utf8” to the list of options in the line in /etc/fstab otherwise non-English characters are not supported in file names.

Client Interfaces

There are a number of client interfaces depending on which platform you use. There’s a suggested list on the MPD site but generally I use:

Both are FOSS, licenced under GPL v3.

CD Ripping and Adding Music

Once MPD is up and running then obviously we need some music to play ๐Ÿ™‚ There are two steps here:

Ripping CDs

Ripping CDs can be a bit painful on Linux. However I use Rhythmbox as a music player and it has a pretty good built-in ripping facility. I use FLAC as the output format to get a balance between file size and sound quality. The output format and file naming convention can be found in the “Music” tab of the “preferences dialog ( left ). I’ve had no problems with this method. An alternative that I’ve used in the past with some success is “abcde“. This is command line based and not easy to get started with although it does give good results. The web page has links to some tutorials and it’s well worth following these the first time through.

Copying Files to the Pi

Once the files are ripped then they need to be copied to the Pi. I set up the file sharing on the Pi so that the USB disk is accessible over my internal network and files can just be dragged and dropped across. There’s a useful article on how to set up file sharing using Samba and I generally followed these instructions. Note that I made the share publicly available within my home network but this may not be suitable for everybody. In my experience setting up Samba passwords can get complicated so you may need to research a little wider if the instructions in the article don’t work.

Final Note

If you want some music to just test the set up without ripping CDs then I recommend “The Open Goldberg Variations” which is an entirely free version of Bach’s Golberg Variations for piano.