Linux MIDI: A Brief Survey, Part 4

Looking ahead to the next generation of MIDI music-making software, including Improv, Q-Midi and Csound.

In this installment of our tour of Linux MIDI software, we look at some experimental MIDI music-making environments. I've divided this class of software into command-line and GUI-based applications. Regardless of interface, the user is expected to employ a more than average amount of brainpower to get the best results from this software. With that warning in mind, let's first look at some language-based environments designed for the experimental MIDI musician.

Improv

Craig Stuart Sapp's Improv is designed for an interactive performance-oriented environment for experimentally minded MIDI musicians. The system currently is available as a package that includes a library of C++ classes optimized for MIDI I/O and a set of examples demonstrating the functions and capabilities of those classes.

Improv controls real-time MIDI communication between a host computer and an external synthesizer. In a typical program, the computer receives MIDI input from the synthesizer, immediately alters that input in some preprogrammed manner and sends the altered data stream to the specified MIDI output port. Some Improv examples have the computer produce a MIDI output stream that can be altered by the external keyboard, creating interesting possibilities for a musical "dialog" with the program.

The following small program inverts the note-numbers of a MIDI keyboard, 0-127. Thus, if a player plays the series of pitches C-D-E, two whole steps upwards, the Improv program converts the series to C-Bb-Ab, two whole steps downwards, at the same time. With MIDI Thru enabled, the normal and altered lines produce sound simultaneously. The code is from the set of examples provided in the Improv package. For brevity's sake, I've edited Craig's comments, but the entire listing is available on-line here.


// An Improv program that inverts the incoming MIDI note numbers.
//

// Header for synthesizer I/O programming

#include "synthImprov.h" 

/*------------- beginning of improvization algorithms ------------*/

/*-  ------------- maintenance algorithms ------------------------*/

// description -- Put a description of the program and how to use it here.

void description(void) {
   cout << "plays music backwards" << endl;
} 

// initialization -- Put items here which need to be initialized at the 
// beginning of the program.

void initialization(void) { }

// finishup -- Put items here which need to be taken care of when the 
// program is finished.

void finishup(void) { }

/*-------------------- main loop algorithms -----------------------------*/

// mainloopalgorithms -- this function is called by the improv interface
//   continuously while the program is running.  The global variable t_time
//   which stores the current time is set just before this function is
//   called and remains constant while in this functions.

MidiMessage m;
void mainloopalgorithms(void) { 
   while (synth.getNoteCount() > 0) {
      m = synth.extractNote();
      synth.send(m.p0(), 127 - m.p1(), m.p2());
   }
}

/*-------------------- triggered algorithms -----------------------------*/

// keyboardchar -- Put commands here which will be executed when a key is 
// pressed on the computer keyboard.

void keyboardchar(int key) { }

/*------------------ end improvization algorithms -----------------------*/

The main loop of this example performs a simple inversion of the incoming MIDI note number and sends the result to the MIDI output port. The example is fairly trivial, but its significance lies in its real-time action, by which the inversion occurs at apparently the same time as the input.

The henontune example is one of my favorite demonstrations of Improv's capabilities. When henontune is run, it produces a melody generated by the Henon chaos mapping function. Incoming MIDI note-on and velocity values control the parameters of the mapping function, resulting in a new note stream that becomes cyclic, enters a chaotic sequence or simply stops. The code listing for henontune is too lengthy to print here, but it can be read on-line here.

Improv can be used to create your own MIDI programming environment, including non-real-time applications. The program's author has provided control processes not only for typical MIDI synthesizers but also for the Radio Baton and the Adams Stick. The package's documentation is excellent and tells you all you need to know in order to create your own Improv programs.

jMusic

One of these days, I will dedicate a column to the numerous interesting music applications made with the Java programming language, one of which is the excellent jMusic audio/MIDI programming environment. Like Improv, the jMusic package provides a library of classes as well as a set of useful examples to demonstrate the library functions and capabilities. jMusic's API also lends the graphics power of Java to its resources, giving the programmer the opportunity to create attractive GUIs for his music coding endeavors.

An impressive amount of work has gone into jMusic development. The resulting environment is a powerful cross-platform resource for music composition, analysis and non-real-time performance. jMusic can be used to create real-time MIDI note streams or it can produce standard MIDI files. You can employ JavaSound for conversion to audio output, or you can use the MidiShare environment to provide jMusic with flexible MIDI I/O for routing output to external synthesizers, including softsynths.

The following example from the jMusic on-line tutorial demonstrates a basic program that creates a standard MIDI file as its output. The example is trivial, containing exactly one note, but it does indicate how a typical jMusic program is organized.


// First, access the jMusic classes:

import jm.JMC;
import jm.music.data.*;
import jm.util.*;

/*
 * This is the simplest jMusic program of all.
 * The equivalent to a programming language's 'Hello World'
 */

public final class Bing implements JMC{

    public static void main(String[] args){

       	//create a middle C minim (half note)
        Note n = new Note(C4, MINIM);

        //create a phrase
        Phrase phr = new Phrase();

        //put the note inside the phrase
        phr.addNote(n);

        //pack the phrase into a part
        Part p = new Part();
        p.addPhrase(phr);

        //pack the part into a score titled 'Bing'
        Score s = new Score("Bing");
        s.addPart(p);

       //write the score as a MIDI file to disk
       Write.midi(s, "Bing.mid");

   }

}

Compiling this code with javac Bing.java results in a file named Bing.class. Running java Bing produces a Type 1 standard MIDI file that then can be played by any MIDI player or sequencer, including TiMidity, playmidi, MusE and Rosegarden4. The jMusic tutorial includes the following version of this program prepared for eventual output to an audio file in Sun's AU format. jMusic applications typically first create a MIDI stream that either is output as a standard MIDI file or is handed off to JavaSound for translation to audio.


import jm.JMC;
import jm.music.data.*;
import jm.util.*;
import jm.audio.*;

public final class SonOfBing implements JMC{

	public static void main(String[] args){

	Score score = new Score(new Part(new Phrase(new Note(C4, MINIM))));
	Write.midi(score);
	Instrument inst = new SawtoothInst(44100);
	Write.au(score, inst);

	}

}

Compiling this code with javac SonOfBing.java produces the SonOfBing.class file. Running java SonOfBing opens dialogs for saving first the MIDI output and then the AU file.

The next example is a more elaborate program written by jMusic developer Andrew Brown. The program is called NIAM--N Is After M--named in homage to the famous M music software written by David Zicarelli. Again, the code listing is too lengthy for inclusion here, but the source may be obtained from the Applications page of the jMusic Web site (see Resources). The screenshot in Figure 1 nicely shows off jMusic's GUI capabilities.

Figure 1. NIAM at Play

Up to four parts may be defined with separate settings for all parameters seen in Figure 1. Output can be saved as a MIDI file, and despite its non-real-time nature and its simple appearance. NIAM is a powerful little program. Many other jMusic-based applications can be found on the jMusic Web site, showing off capabilities such as melody generation by way of cellular automata, music theory assistance and converting standard music notation to a MIDI file.

jMusic's developers have gone to some pains to provide copious documentation and tutorial material for the new user. The jMusic Web site also provides pointers to general information about Java and its music and sound features, and it offers guidance to other relevant materials on computer music and related topics. If you already know Java, you should be able to jump right in to using jMusic, but with the excellent help available from its Web site even Java novices quickly will be write their own jMusic tools and applications.

______________________

Similis sum folio de quo ludunt venti.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Will Part 5 be available soon

jhansonxi's picture

Will Part 5 be available soon?

Which card should I buy?

Atle Weibell's picture

Hi,

Thanks for great articles! I have a USB Midisport 2x2, but it doesn't seem to be easy to setup in linux. I need a new sound card anyway, so I'll buy one with MIDI support as well. In an earlier comment, it was mentioned that not all vendors provide specifications. Who are the good guys? Which cards should I consider for MIDI and audio? :)

regards, aw

I just got a midisport 1x1 go

nick rout's picture

I just got a midisport 1x1 going last night on my laptop. The way to do it is described here:

http://usb-midi-fw.sourceforge.net/

I made my son laugh this morning - I went to wake him up and told him I had learned some new pieces on the electric piano last night. I dashed back to the music room, hit play in kmid and a beautiful Bach sonata thundered out. As I usually struggle with anything beyond "Twinkle Twinkle" he was impressed !

Rosegarden had compiled while I slept and we then successfully used the piano to input a couple of scales into Rosegarden turned them into notation, played them back as a trumpet on the computer.

So your midisport will work!

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix