abc on Linux

James Allwright, January 2002

My original intention was that document would be an authoritative 'HOWTO' in the style of other Linux HOWTO documents. However, it has turned out to be less authoritative than I had hoped and for much of the detail you will still need to consult other HOWTO documents. Nevertheless, it may help you on the way to getting the most out of your Linux system.

There is an enormous amount of PC hardware available. Getting it working can be difficult whatever operating system you have. This document aims to cover the Linux-related problems you might encounter while using the abc music notation system on a GNU/Linux system. Because most of the abc programs convert abc notation to another file format, they tend to run without any problems. You are much more likely to run into problems when you want to hear your music or see it on-screen or printed out.

This document assumes you already know how to use abc notation and instead focuses on getting things up and running on your GNU/Linux system. If you need to know more about abc notation itself, you should consult the abc home page.

1. Getting abc Software for Linux

To make installing software easy, some Linux distributions supply programs in the form of a package which can be installed with a simple command. In Debian Linux, package files have the extension .deb and are unpacked using the command dpkg. In Red Hat Linux, package files have the extension .rpm and are unpacked using the command rpm. It is not recommended that you try installing a .rpm file on a Debian system or a .deb on a Red Hat system. However, some other Linux distributions are based on these two and use one of these packaging systems.

The traditional unix way of supplying a program for do-it-yourself installation is as source code in a compressed archive. This is uncompressed and a directory structure is retrieved from the archive. The source usually comes with a file called README or something similar containing further instructions. Typically typing make will compile the program and create an executable which you need to put in a directory on your path in order for it to become usable as a regular command.

Programs available:

2. Viewing PostScript on-screen

A number of programs convert abc to PostScript graphics files, which you will probably want to view on-screen. In order to do this, you will need to install X windows (graphical Windowing system), ghostscript (free PostScript interpreter) and GhostView (a graphical PostScript viewer). If you have not already set up X windows, consult: One problem you may find is that Ghostview uses the wrong paper size by default. In the U.S.A., 'U.S. letter' is the commonly used paper size, while in Europe and elsewhere, 'A4' is used. These are similar but different enough that this is a problem. My version of Ghostview allows you to change this from the menu with 'State' -> 'gv options', which creates a file .gv in your home directory. The program that you use to convert abc to PostScript also needs to know what paper size to use - see the documentation for that program for how to select whichever one you want.

3. Playing MIDI files

MIDI files can be created with abc2midi. To play these, you need to install a MIDI file player and make sure that it can talk to your sound card, which generally means you must install a kernel module for your MIDI/sound card. There are 3 ways a MIDI file can be played:
  1. Send the MIDI data to an external MIDI device (e.g. a MIDI keyboard), using a card that provides a MIDI interface. One of the first cards to offer this capability was the Roland MPU401 and many cards claim MPU401 compatibility.
  2. Send the MIDI data to a card that uses it to synthesize sound.
  3. Use a program that converts the MIDI data to sampled audio data and send that audi data to a suitable audio device. The Timidity program offers this capability.
Two popular programs for playing MIDI are playmidi and timidity.

In order to use a sound card, you need to install a kernel module or modules to handle it. Red Hat Linux provides a utility called sndconfig which may be able to do this automatically provided that it knows about your particular sound card. If this doesn't work, you will have to resort to installing the modules by hand, as described below.

First, you should check that you are using a relatively recent kernel (preferably 2.2 or newer). The command uname -a will report the kernel version. You then need to find out what address and interrupt your sound card uses. If your card follows the 'Plug and Play' scheme, you may find that the file /etc/isapnp.conf contains this information and the utility isapnp will probe your card for the same information. Here are 2 examples of how to set up sound:

  1. On my Debian system, I have an MPU401 compatible card using interrupt 9 and base address 330(hex). The card is connected by MIDI cables to an external tone generator. The following command executed as root will install a driver for my sound card:
    modprobe mpu401 irq=9 io=0x330
    
    Once that is installed, I can play a MIDI file 'test.mid' with
    playmidi -e test.mid
    
    If I shutdown Linux, I lose this configuration, so I want to arrange for the module to be loaded every time the system boots. To achieve this, I created the following file sound in directory /etc/modutils/.
    options mpu401 irq=9 io=0x330
    
    Then I ran update-modules which transfers the contents of this file to modules.conf.

    All this does is define the options that mpu401 takes. To load up the module on system startup, I added a file /etc/rc2.d/S21sound containing the line :

    modprobe mpu401
    
    I also found that playmidi could only be run by root because of permission problems. To solve this, I executed the following commands:
    chgrp audio /usr/bin/playmidi
    chmod 2755 /usr/bin/playmidi
    
    This puts playmidi executable in the same group as the sequencer device /dev/sequencer and make the executable run with those group permissions.
  2. On my Red Hat system with kernel 2.4.2, I have an OPL3-SAx card. The following commands will set this up and play a MIDI file:
    modprobe mpu401
    modprobe opl3sa2 io=0x370 mss_io=0x530 mpu_io=0x330 irq=5 dma=0 dma2=7
    modprobe opl3 io=0x388
    modprobe ad1848
    
    playmidi test.mid
    
    The list of modules to install came from the sound section of the kernel module documentation and the parameters were deduced from the contents of /etc/isapnp.conf.

The startup files on this system live in /etc/rc3.d and there is already a symbolic link called S85sound which points to /etc/init.d/sound. I created this file containing suitable modprobe instructions.

Your setup will almost certainly be different to mine, so don't expect the above commands to work for you. If you install the correct modules but with the wrong parameters, you will probably find that your sound card stays silent and offers no clue as to what went wrong. If you tinker with the scripts in /etc/rcN.d and get things horribly wrong, your system may not boot up correctly at all, leaving with the problem of how to recover! For this reason, running a script to install your sound drivers is a safer option than installing them on system startup.

Documents to consult:

In the HOWTO collection (stored in /usr/doc/HOWTO/en-txt/ on my Debian system) :

In the kernel source documentation (stored at /usr/src/kernel-source-2.2.17/Documentation on my Debian system) : Once you have succeeded in getting sound, you will want to configure your system to come up with the relevant modules installed. The file /etc/modules.conf or /etc/conf.modules control this, but the way these files are set up seems to be distribution dependant. You can get a description of the syntax with man modules.conf.

4. Printing music

In order to be able to print anything, you will need a printer for which a Linux driver exists. There are a very large number of different printers and drivers. The printing HOWTO document gives a list of which printers have Linux drivers and a more up-to-date list may be found on the web at:
http://www.linuxprinting.org/
My printer is a Lexmark 1000, which is not listed as having as driver in the HOWTO, but for which I was able to find a driver at the above website. I downloaded and compiled this driver.

To get printed output, I loaded a parallel port driver into the kernel with

modprobe parport
This drives the parallel port (/dev/lp0 in my case). I am then able to print by creating a script with the following command:
gs -q -sDEVICE=ppmraw -r300 -sPAPERSIZE=a4 -dNOPAUSE -dSAFER \
      -sOutputFile=- $1 | lm1100 - > /dev/lp0
The program lm1100 is the printer driver that I downloaded. The script invokes gs (the ghostscript interpreter) to generate PPM images, which are processed by the filter before being sent to the printer. $1 is the name of the file to be printed.

Ideally, I'd want to arrange things so that I could use lpr, the print spooling command. Red Hat Linux has a tool called 'printool' which sets this up, but which unfortunately doesn't know about my printer and driver.

Two important references for printing are the printing HOWTOs: