<<

MIDI with KNOW-HOW MAKINGConnecting a MIDI keyboard to your Linux system MUSIC

A MIDI keyboard is a useful extension to any audio workstation. Learn how to connect a MIDI instru- ment to your Linux sound studio through a MIDI interface device. BY JOHN MARTIN UNGAR

inux is growing increasingly competitive as an environ- ment for composing and playing electronic music. One Limportant feature of the New Music scene is an elec- tronic keyboard that outputs digital information in MIDI (Musical Instrument Digital Interface) format. The MIDI protocol supports communication between electronic musical instruments and computers. MIDI does not transfer sounds, but sound descrip- tions, such as “play a -sharp on a grand piano as a quarter note at 80 beats per minute.” This approach makes it easier to encode sound events in a far more compact way than would be possible with real sound data streams. At the same time, you can use any suitable MIDI sequencer and a MIDI keyboard to load mel- odies directly into your computer, where you can then change the notes and beat, transpose the key, or use different instru- ment sounds for the arrangement. To connect a MIDI instrument to your Linux computer, you’ll need an interface device that receives input from the instrument through a standard MIDI cable and passes in- formation in and out of the computer with a PC-friendly connection to an ordinary USB port. Several MIDI-to-USB interface devices are currently available. Unfortunately, like so many other commercial products on the market, these devices are not always ready for Linux in their default state. Luckily, the source community has responded with up- dates and other tools necessary for supporting MIDI devices. In this article, I’ll describe how to connect a MIDI instrument to your Linux sound studio through a MIDI interface device, the popular M-Audio MIDIS- PORT 1x1 USB/MIDI interface, which costs about US$ 49.95. For other devices, see the vendor doc- umentation for Linux configuration options. Interface Figure 1 shows the front and back of the M-Audio device. A MIDI instrument connects to the front of the device, and the MIDI data is then carried to and from the computer

MARCH 2008 ISSUE 88 51

051-055_music-studios.indd Abs1:51 16.01.2008 20:15:00 Uhr KNOW-HOW MIDI with Linux

Regardless of your distri- manually copy the file from the midis- bution, you will need a util- port-firmware-1.2 folder to the firmware ity called fxload to upload directory /usr/local/share/usb/maudio. the firmware to the MIDI in- The device is attached, but you still terface; your distribution’s can’t use it. To do so, you first must load package manager should the firmware to the MIDI box via USB. give you an install option. Previously, this task was handled by the On Debian and Ubuntu, hotplug , but modern distribu- simply double-click the pack- tions use the Hardware Abstraction age after downloading it and Layer (HAL) and the udev rules, which follow the instructions of the are located below /etc/ udev/Rules.d . The package manager. rules for your MIDI box are still missing, For openSUSE, download so let’s create them. the ezusbmidi package to With HAL and udev, the system takes your machine and launch about 60 seconds to find the new device YaST to install. and activate it with the use of the udev rule. Debian-based systems do this reli- Figure 1: The MIDISPORT 1x1 interface connects to MIDI Workaround ably, but you might need to give open- devices and then passes the information to the computer If any problems occur, you SUSE 10.2 a helping hand. The fxload through the USB port. can try a workaround. First, command tells udev to upload the firm- load the firmware onto your ware to the device. If this does not hap- through the USB port on the back. The system and unpack the archive. Then, pen automatically, you can perform the “1x1” in the name means that the device pop up a console, change to the new steps manually. To do so, pop up a con- has one MIDI In port and one MIDI Out directory created at the last step (midis- sole and load the firmware as follows: port. (The MIDI Out connection lets your port-firmware-1.2), and enter the follow- Linux system output MIDI instructions ing commands: to an external sound-generating device.) M-Audio makes interface models with nonumber up to eight inputs and outputs. $ ./configure To use the the M-Audio MIDI interface $ make with Linux, you’ll need to install new $ sudo su firmware. Debian users will prefer the # make install Figure 2: The main window in the Jack control program, DEB package [1]; users of Ubuntu 7.04 QJackCtl. need a separate version [2]. SUSE and This gives you the firm- openSUSE, Red Hat/Fedora, and Mand- ware, and you will have a udev rule to $ fxload -D /dev/bus/usb/USB-Bus riva can use the RPM packages [3]. match in /etc/udev/Rules.d, rule 42, /Device -v -s /usr/local/share/u Users with other distributions will need which will be called something like sb/maudio/MidiSportLoader.ihx -I version 1.2 of the source code [4]. 42-midisport-firmware.rules. /usr/local/share/usb/maudio/Mid The corresponding firmware scripts iSport1x1.ihx Listing 1: New Device are located in /usr/local/share/usb/mau- 01 nonumber dio and are identifiable by the file exten- Replace USB-Bus with the numeric iden- 02 Bus 002 Device 001: ID sion .ihx. tifier that lsusb shows you; in this exam- 0000:0000 Make sure that none of these scripts is ple, this is 001. In the same vein, use the 0 bytes. If so, the installation script has device number that is shown for Device 03 Bus 001 Device 002: ID caused an error and you will need to – 002, in this case. Then, open the KDE 0763:1011 Midiman 04 Bus 001 Device 001: ID Listing 2: Checking for Required Modules 0000:0000 01 nonumber audio 02 snd_usb_audio 88736 0 07 snd 65256 17 snd_usb_ Choosing a Keyboard 03 snd_usb_lib 21888 1 snd_usb_ audio,snd_hda_intel, To leverage the features offered by mod- audio snd_seq_oss,snd_hda_ ern, virtual instruments, I recommend a codec,snd_pcm_oss, 04 snd_pcm 89096 6 snd_usb_ keyboard with touch response, as well snd_mixer_oss,snd_seq,snd_ as additional after-touch that provides audio,snd_hda_intel, pcm, modulation options at the push of a but- snd_hda_codec,snd_pcm_oss snd_timer,snd_rawmidi,snd_ ton. Also, the keyboard should have a 05 snd_rawmidi 31392 seq_device, pitch bend wheel to change the key and 2 snd_usb_lib,snd_seq_midi another modulation wheel to change snd_hwdep the sound. 06 snd_hwdep 15240 1 snd_usb_ 08 usbhid 45088 0

52 ISSUE 88 MARCH 2008

051-055_music-studios.indd Abs1:52 16.01.2008 20:15:04 Uhr MIDI with Linux KNOW-HOW

tency refers to the QJackCtl, the Qt-based GUI. Both pack- wait time between ages are provided by any standard distri- triggering and pro- bution and can be installed easily with cessing a signal. YaST or Synaptic. In music and Immediately after the install, Jack is sound generation, ready for use. Before you launch Jack for too much latency the first time, check to see whether the will cause clicks kernel has all the required modules. To and dropouts, and do so, pop up a console and enter lsmod in recording, it | grep usb. will cause an un- The output should look something like acceptable lack of Listing 2; otherwise, you will need to synchronization in load the USB sound module before you signal processing. continue. To do so, enter the command The kernel is re- modprobe snd_usb_audio. Then type sponsible for these lsmod | grep usb again. Having the snd_ Figure 3: The Jack setup menu with critical settings. delays on Linux; seq module is important. If this module however, a solu- does not appear in the list, type mod- Desktop Settings program and change to tion has been available since the intro- probe snd_seq to load it. Sound and Multimedia | Sound system | duction of kernel version 2.6, and ver- Hardware. Now you will see your device sion 2.6.10 even introduced a working Starting Jack or at least be able to enable it in Select low-latency variant. Ubuntu Studio [6] To start the Jack front end, click Applica- MIDI device. Note that Debian and and JAD [7] pre-install the kernel, but tions | Multimedia | Music in your KDE Ubuntu do not have their usb/maudio you can build your own low-latency menu and select QJackCtl. The spartan directories below /usr/local/share, but kernel for any other distribution. main window provided by the front end below /usr/share instead. The Jack sound server cuts into the appears (Figure 2). If you click Start im- Advanced Linux Sound Architecture mediately, you will probably see an error Connecting the Keyboard (ALSA) at a low level to handle high- message because the default settings Attaching any keyboard to the 1x1 inter- bandwidth audio streams at maximum are not normally correct. Thus, it makes face is possible; any old organ with a speed. Whether the sound streams come more sense to select the Setup menu MIDI port will do, but you can just as from the analog converter on your sound (Figure 3). easily hitch up to a modern keyboard or card, an editor, effects, or virtual instru- To begin, enable the parameters Real- synthesizer from your live equipment. ments makes no difference. Jack lets you time, No Memory Lock, H/W Monitor, For my experiments, I used a fairly an- send data both to ALSA’s pcm_out and and H/W Meter, as well as Verbose mes- cient Yamaha PSR 400 and was happy any other program that can generate a sages output. In the Interface drop-down enough with it. Jack-in port. This gives users the frame- box, select the hw:0 option and, above Like the MIDI interface, the keyboard work for an extremely flexible and ex- that, accept the settings as Driver: alsa. must have at least one MIDI In and one tensible modular software system. Be- Pressing OK saves the settings; now quit MIDI Out port. Connect the two with the cause Jack latches into the system at a Jack and restart it. appropriate connectors of the MIDI inter- low level, you need root privileges to Next, you can move on to wiring the face device. (Note that the signal going launch the system, which also applies system. In the multimedia section, out of the keyboard is going in to the in- to any application that uses Jack. launch the ZynAddSubFX synthesizer. If terface, and the signal going out of the the synthesizer is not installed yet, use interface device is going in to the key- Installing Jack your package manager to install it. Then, board.) Using the USB lead, connect the For basic MIDI studio operations, you in the Jack control window, open Patch- box to your computer. only need the Jack daemon and bay (Figure 4). Now the system should show the new To enable input, device. Popping up a console and enter- click Add to the ing lsusb lets you check this. If every- right of Input thing is wired up correctly, the output Sockets/Plugs . In should be similar to Listing 1. the Type dialog that appears, se- Meet Jack lect MIDI and then After your PC has identified the interface select the MIDI as a USB device, you can start using the interface below keyboard. To do so, you will need the Client. Clicking Jack [5] sound server. Add Plug adds the Jack is a low-latency system that is Figure 4: QJackCtl Patchbay is where the connected audio applica- MIDI interface to ideal for a trouble-free sound system. La- tions are patched. the list of avail-

MARCH 2008 ISSUE 88 53

051-055_music-studios.indd Abs1:53 16.01.2008 20:15:04 Uhr KNOW-HOW MIDI with Linux

Figure 5: The spartan welcome window of the Seq24 sequencer gives users space to create new patterns.

able plugs. Pressing OK confirms your ods/Buffers in the selection; then, quit the dialog. Now Jack setup pane; your keyboard is available as an input note that this Figure 6: Create the individual components of your song in the device. In the same way, you can enable could affect your Seq24 Pattern Editor. output on the other side of the Patchbay sound quality. window with ZynAddSubFX as your round sequencer Seq24 for these tests. MIDI input. Working with the Sequencer To set up the sequencer, use your distri- Connecting the two plugs is the last To make MIDI music, you need what is bution’s package manager. step. To do so, select the Input Socket known as a sequencer. The sequencer If the Jack front end is not running, and the Output Socket and click Connect records the melodies you play on your then launch QJackCtl before you launch then Activate. Clicking the control keyboard, helps you edit them, and out- the Seq24 sequencer at the console by (x) button closes the Patchbay window. puts the results via the attached instru- entering /usr/bin/seq24. At first, you Now you have wired up your key- ments. The choice of sequencers on only get an empty main window (Figure board and synthesizer with Jack and you Linux is not particularly opulent, espe- 5) filled with rows and columns. Right- can be creative – load a sound into cially considering that the most popular clicking a free field and selecting New to ZynAddSubFX and play! open source sequencers – Rosegarden open what is known as the Pattern Edi- If the sound is scratchy, has drop-outs, and Muse – cause considerable trouble tor (Figure 6) lets you create sequences or is very late, change the values for without a low-latency kernel. On the and loops. Sample Rate, Frames/Period , and Peri- other hand, this complication makes the Creating and editing the individual choice easier – I went for the simple, all- sound bits of your composition is done MIDI Tools MIDI channels are numbered 0 through 15 or 1 through 16 depending on the convention the vendor follows. Assum- ing you have 16 instruments, or at least that many digital sound generators and effects capable of receiving MIDI signals on different channels, you can send a sound stream to an instrument on any of these channels. Normally you can freely assign sound generators to any MIDI channel. General MIDI [8] restricts this freedom for the sake of standardiz- ing instruments. For example, the drum track is always MIDI channel 10. The open source software synthesizers ZynAddSubFX and Hydrogen are equally suitable for interpreting incom- ing MIDI signals. A third useful tool is the software wavetable synthesizer Ti- Midity++ [9], which converts MIDI files to sound that is then output via Jack and ALSA; your distribution should include the instrument. Also, you might want to download the Freepats package [10] to Figure 7: Seq24 lets you play your pattern via a connected synthesizer – ZynAddSubFX in get your wavetable synthesizer playing. this case.

54 ISSUE 88 MARCH 2008

051-055_music-studios.indd Abs1:54 16.01.2008 20:15:06 Uhr MIDI with Linux KNOW-HOW

easily modify the signals any time later – for example, to change the key. To modify signals, first click on one of the bars representing the key and dura- tion of the note. Once the bar has turned orange, you can move it or press the Delete key to delete. This lets you create and modify the individual patterns in your song. Create a Song To put your patterns together and create a song, launch the Song Editor by click- ing the pencil icon in the bottom right- Figure 8: An example of an arrangement with Seq24. hand side of the main Seq24 window. In the left column of the Song Editor, you in the Pattern Editor. Type a name for audio control. The Master Conditional will see an overview of existing patterns, the pattern in the first field at the top left button only passes control to the se- and the timeline for your song is at the – for example, Intro, Bridge, or Refrain. quencer if there is no other master. top in bars (Figure 8). Then, use the two arrows to set the The Live Mode and Song Mode options Holding the right mouse button down number of beats to the bar, or simply let you specify whether you will manipu- while also pressing the left mouse but- use the default, 4/4 . The next field to the late the pattern while you are inputting ton places a pattern on the timeline and right lets you define the length of the it or would like to play a complete ar- removes the pattern from the list. pattern in bars. rangement that you have created with Holding down the left mouse button When you are done, click the slightly the Song Editor, without the ability to moves a pattern in the timeline. Clicking cryptic button with the three MIDI con- change it. Pressing OK confirms your the third icon from the left in the icon nectors and select an instrument to out- selection. bar outputs your composition as an infi- put the MIDI events. Using the MIDI In the bottom right-hand side of the nite loop. icon on the far right, select the MIDI Pattern Editor, you will find a small icon Making music with your Linux PC channel that you will be using to output with the function Records incoming midi- really can be this simple – so have fun the signals. In the next row, set the reso- data. In the main Seq24 window, enable composing! I lution for the pattern. The default, 1/ 16, the button and click the green triangle. tells the sequencer to drag any notes that This somewhat roundabout approach INFO are not located exactly on a sixteenth of lets you record MIDI events from the [1] Debian package for MIDISPORT: a bar to the sixteenth automatically to keyboard. To stop recording, click the http:// packages. debian. org/ unstable/ assure precise values. Also, you can set red square to the left. sound/ midisport-firmwaremc/ the key and adjust the major and minor Playing Back Sequences [2] Ubuntu package for MIDISPORT: setting here. http:// packages. ubuntu. com/ feisty/ To tap in a sequence, choose one of Selecting ZynAddSubFX in the Pattern misc/ midisport-firmware two options. The first is to use the ma- Editor’s Select Output Bus menu lets you [3] RPM package for MIDISPORT: trix in the Pattern Editor to add tones. hear what you have played. The synthe- http:// rpm. pbone. net/ index. php3/ stat/ First, press the right mouse button to sizer must be enabled with the sound 26/ dist/ 7/ size/ 71557/ name/ change the cursor to a pen, and press the program loaded for this to work (Figure ezusbmidi-2002_11_17-1. src. rpm left mouse button to insert events into 7). Again, in the bottom right-hand side [4] MIDISPORT firmware: the matrix. Then you can hold down the of the Pattern Editor, click the left button http:// usb-midi-fw. sourceforge. net/ left mouse button on any event to move with the function Sequence dumps data [5] Information on Jack: it or select the event and press the Delete to midi-bus. This tells the sequencer to http:// www. jacklab. org/ key to delete it. send the recorded MIDI data to the at- [6] Ubuntu Studio: The more intuitive approach is to use tached sound generator so you can hear http:// ubuntustudio. org the attached keyboard as your input de- the sounds. [7] Jacklab Audio Distribution: vice. To do so, close the Pattern Editor, If the application fails to produce http:// distrowatch. com/ table. click File | Options in the main window, sound output, check your Jack Control php?distribution=jacklab and open the MIDI Input tab. patch field: Is the synthesizer audio out- [8] General MIDI (Wikipedia): http:// en. Select a MIDI interface or instrument put connected to the ALSA system? If wikipedia. org/ wiki/ General_MIDI and change back to the Jack tab. not, change the setting. [9] TiMidity++: http:// freshmeat. net/ Enabling the Jack Transport and Jack projects/ timidity/ Master settings tells the sequencer to use Modify Signals [10] Freepats packages: Jack to organize the data streams and Because MIDI signals are simple control http:// freepats. opensrc. org Seq24 as the master program for Jack signals and not audio events, you can

MARCH 2008 ISSUE 88 55

051-055_music-studios.indd Abs1:55 16.01.2008 20:15:09 Uhr