aplaymidi Command in Linux

Introduction to aplaymidi

In this guide, you'll discover the power of aplaymidi, a command-line tool in Linux for playing MIDI files. The aplaymidi command sends MIDI data to ALSA MIDI devices, making it invaluable for systemadmin tasks related to audio production and music composition on Linux systems. We'll cover the fundamental usage of aplaymidi, demonstrate how to play MIDI files, and explore some advanced options to enhance your control.

Understanding the aplaymidi Command-Line Utility

This section provides a comprehensive overview of the aplaymidi command, a versatile Linux utility designed for playing MIDI files. By leveraging aplaymidi, you can seamlessly transmit MIDI data to ALSA MIDI devices, making it an essential asset for systemadmin working in audio production and music creation on Linux systems.

Let's begin by examining the basic syntax of the aplaymidi command. To view a list of available MIDI devices on your system, execute the following command:

aplaymidi -l

Example output:

## aplaymidi -l
Port    Client name                       Port name
 14:0    Midi Through                      Midi Through Port-0
 20:0    TiMidity                          TiMidity port 0
 20:1    TiMidity                          TiMidity port 1

This command presents a list of the MIDI devices detectable by your system, including details such as their client name and port name. This information is crucial for identifying the specific MIDI device you wish to target for playback.

Now, let's proceed with playing a MIDI file using the aplaymidi command. Assuming you have a MIDI file named example.mid located in your ~/project directory, you can initiate playback with the following command:

aplaymidi -p 20:0 ~/project/example.mid

This command will transmit the MIDI data from the example.mid file to the MIDI device associated with the port name TiMidity port 0.

The -p option is used to specify the MIDI device port that should be used for playback. Refer to the output of the aplaymidi -l command to select the appropriate MIDI device for your needs.

Playing MIDI Files with aplaymidi: A Practical Guide

In this section, we'll provide step-by-step instructions on how to utilize the aplaymidi command to play MIDI files on your Linux system.

First, ensure you have a MIDI file ready. You can download a sample MIDI file or reuse the example.mid file from the previous section.

To initiate playback of a MIDI file using aplaymidi, execute the following command:

aplaymidi -p 20:0 ~/project/example.mid

Remember to replace ~/project/example.mid with the actual path to your MIDI file.

The -p 20:0 option designates the MIDI device port for playback. In this case, we're utilizing the "TiMidity port 0" device, identified in the preceding step.

You should now be able to hear the MIDI file playing through your system's audio output.

To play the MIDI file in the background, append the & operator to the command:

aplaymidi -p 20:0 ~/project/example.mid &

This allows you to continue working in the terminal while the MIDI file plays.

To stop playback, use the kill command in conjunction with the process ID (PID) of the aplaymidi process. First, determine the PID using the ps command:

ps aux | grep aplaymidi

This will display the PID of the running aplaymidi process. Then, use the kill command to terminate playback:

kill [PID]

Replace [PID] with the actual PID of the aplaymidi process.

Advanced Options for aplaymidi

In this final section, we will explore some of the more advanced options available within the aplaymidi command.

A valuable option is the ability to send MIDI data to multiple MIDI devices simultaneously. This is accomplished using the -p option with a comma-separated list of device ports. For instance, to send MIDI data to both "TiMidity port 0" and "TiMidity port 1", use the following command:

aplaymidi -p 20:0,20:1 ~/project/example.mid

This command will play the MIDI file through both MIDI devices concurrently.

Another advanced option is the ability to adjust the playback volume of the MIDI file. Utilize the -v option followed by a value between 0 and 127 to set the volume level. For example, to play the MIDI file at 75% volume, use:

aplaymidi -p 20:0 -v 95 ~/project/example.mid

You can also combine the volume option with the multiple device option to adjust the volume for each device individually:

aplaymidi -p 20:0,20:1 -v 95,127 ~/project/example.mid

In this example, the MIDI file will be played at 75% volume on the "TiMidity port 0" device and 100% volume on the "TiMidity port 1" device.

Finally, the --wait option keeps the aplaymidi process running until MIDI playback is complete. This is useful when ensuring the entire MIDI file plays before a script or program continues:

aplaymidi -p 20:0 --wait ~/project/example.mid

These advanced options allow you to fine-tune the MIDI playback experience and seamlessly integrate the aplaymidi command into your audio production or music creation workflows within your role as a systemadmin.

Conclusion

This guide introduced the aplaymidi command, a Linux tool for MIDI file playback. We covered displaying available MIDI devices and using aplaymidi to play MIDI files, specifying target devices. We explored playing MIDI files with aplaymidi, covering command structure and options for device selection. Finally, we examined advanced options like volume control and looping, enhancing your systemadmin capabilities.

400+ Linux Commands