GenComp: An Environment for Graphic Creation and Representation of Music Generated with Genetic Algorithms

FERNANDO IAZZETTA

Laboratório de Linguagens Sonoras
Programa de Comunicação e Semiótica - PUC-SP
Rua Monte Alegre, 984 - Prédio Bandeira de Melo - 4º andar - Sala 416
05014-010 - São Paulo - SP - Brazil
e-mail: iazzetta@exatas.pucsp.br


Abstract: GenComp is a Macintosh application developed in the MAX environment. It uses Genetic Algorithms to generate music compositions which are based on graphic representation of different music parameters. In GenComp, the composer uses the mouse to draw a series of curves which control the behavior of the music to be generated. GenComp takes these curves as general values which will govern the composition. Moreover, these curves work as a graphic score which can be followed by the user during playback.

Introduction


This work describes a method of generating algorithm music composition based on graphic scores. The idea is to allow the composer to define the behavior of different parameters of a composition by drawing curves which would represent this behavior. The program makes use of a powerful technique for searching optimal solutions in a large problem-space called Genetic Algorithms (GAs) (Holland, 1975; Goldberg, 1989; Koza, 1992). For this purpose, we have created a program called GenComp which implements GAs in a MAX environment for Macintosh (Puckett & Zicarelli, 1990). In this case, using MAX is a comprehensible choice since it provides a very flexible environment for music programming and easily configurable graphic interfaces.

GenComp provides a graphic interface where the composer can define the behavior of six music parameters (density, tension, velocity, duration, distribution, and tempo) by drawing curves with the mouse. These curves are used both as a score and as the parameters which the program will use for generating the music. After the composer draws all the curves the GAs create and evaluate successive "generations" of the same piece until it finds a solution which best fits the parameters represented by the curves. Then, GenComp is able to play the composition through up to sixteen user configurable MIDI channels, and the user can follow the graphic score during the playback.

Genetic Algorithms



There is a large class of problems for which it is hard to formalize an efficient solution in terms of traditional algorithms. In most problem-solving processes involving a large problem-space, the search for a potential optimal solution can be highly improved with the use of GAs. GAs are stochastic optimization algorithms whose search methods are based on the metaphor of natural selection. A GA performs a multi-directional search through a population of potential solutions by allowing the exchange of information among individuals in this population.

The vocabulary of GAs is borrowed from genetics and evolution theory. The process which is used can be summarized as follows:
1) First, it is necessary to create a genetic representation of potential solutions. Usually it is done by representing the individuals as binary strings.
2) Then, it must create an initial population of potential solutions.
3) The individuals of each population are evaluated by a "fitness function" which measures how good they are.
4) Genetic operators modify the composition of the population generating a new population to be evaluated.

Figure 1: Flowchart of a Genetic Algorithm

The Implementation of GenComp


In the last few years GAs have been used in different types of music applications, such as sound synthesis (Fujinaga & Vantomme, 1994; Horner, Beauchamp, & Haken, 1993; Horner, Cheung, & Beauchamp, 1995), algorithmic composition (Horner & Goldberg, 1991; Jacob, 1995), rhythmic generation (Horowitz, 1994), and interactive music generation (Biles, 1994; Biles & Eign, 1995).

GenComp is a program which aids the composer to create small pieces of music by using a graphic interface. The music generation is treated as an optimization problem: the composer describes the behavior of a few parameters in a composition and the program uses this information as a goal. By using GAs, GenComp tries to find a particular piece which best fits the parameters given by the composer. We have already been working in a very similar compositional approach using another powerful optimization tool called simulated annealing (Iazzetta & kon, 1995).

The pieces created in GenComp are 100 bars long, and each bar is composed of up to sixteen note-events. Each of these sixteen note-events consists of four elements: MIDI-note, MIDI-velocity, duration, and start-time. The meaning of the first two elements is obvious. Duration is given in relation to the duration of the bar (since it can vary according to the tempo of the piece) and can rage from 1/16 to twice the duration of the bar itself. The start-time is the off-set of a particular note in relation to the beginning of the bar. The range is 0 to 15, and each unit represents 1/16 of the bar's duration.

The information about each bar consists of a string of 64 numbers (16 note-events * 4 elements) and these strings are stored in a MAX object called 'coll'. Thus, the coll object stores 64,000 numbers that represent a potential music solution which will be evaluated and transformed by the GAs.

The structure of GenComp has three main parts: 1) the User-Interface Window, where the composer draws the curves which will be used as parameters for generating the piece; 2) the Genetic Operators, which will evaluate and transform successive populations of note-events in order to reach a near optimal solution; 3) the Player, which plays the pieces generated by the program through up to 16 MIDI-channels. These three parts can run at the same time. It means that it is possible to listen to the music while the program generates a new population of note-events, so that one can follow the evolution of a certain piece towards a goal by listening to successive music generations. Also, the composer can follow the curves he has drawn while listening to the piece and compare the aural results with the graphics on the computer's screen.


The User-Interface Window



GenComp's User-Interface Window is used to input the parameter which will generate the music and to control the playback. The composer uses the mouse to draw eight curves in six tables vertically aligned in the computer's screen. Each point on the curves determines the values for each of the 100 bars of the piece. The curves in each of the six tables refer to different parameters, as follow:
Table 1 - Density: each point on this curve defines how many notes should happen at each bar, ranging from 0 (completely silent) to 16 notes;
Table 2 - Tension: defines the harmonic tension among all the melodic and harmonic intervals which occur in a bar. The tension is calculated according to the distance from one note to the other in the harmonic series. These values are stored in a MAX object called table and can be modified by the user, allowing different possibilities;
Table 3 - Velocity: is defined by two curves (minimum and maximum velocity) which determine the MIDI-velocity range for the notes at each bar;
Table 4 - Duration: is also defined by two curves (minimum and maximum duration) which determine how long or how short the notes should be in each bar;
Table 5 - Distribution: this curve works as an index which represents how the notes are distributed in a bar. If the curve is low, the notes tend to be grouped in the form of a chord; if the curve is high, the notes tend to be evenly spread through the bar;

Table 6 - Tempo: allows the composer to determine tempo changes in relation to previously defined basic metronome. Each point in the curve represents a deviation from -50% to + 50% from the basic metronome. This parameter does not affect the genetic processing and is used only for playback.

Figure 2 shows the user interface. The composer draws each of the eighth curves in the drawing box. After drawing each curve the user clics the button that particular curve refers to and the program automatically fills correspondent table with a colored curve. The information of each curve is stored so it can be recalled even after quitting the program. The 'Redraw Curves' button redraws the last eight stored curves.

The playback function is controlled by the Play, Pause, and Stop buttons. When play is activated, the current music solution is played again and again until the user activates the Pause or the Stop buttons. The speed of the playback is set in the 'Basic Metro' box. The value in this box represents the duration in milliseconds for each bar of the piece.

The 'MIDI Setup' button opens a new window where the user can route the 16 voices to up to 16 different MIDI-channels. This window allows the definition of a MIDI program for each channel using up to 2 MIDI ports. This gives a very flexible configuration for MIDI playback. The store button can store and retrieve 3 different MIDI setups.

On the top of table column there is a cursor and a counter which indicates the playback progression and bar number. Thus, during playback it is possible to follow the music progression in relation to the curves which function as a graphic score.

Figure 2: GenComp's User-Interface Window


The Genetic Operators



In GenComp, GAs are used to generate a piece of music whose characteristics fit the graphic description given by the composer. For this purpose it is necessary to create a starting population of note-events which will be iteratively processed in order to reach a satisfactory solution. This starting population is itself a potential solution which will be evaluated by the algorithm. It consists of a collection of MIDI data randomly generated by the program. Activating the genetic operators button at the user interface window will make the program start the search for the music which best fits the parameters given by the composer.

The genetic operators consist of two parts: the evaluating function, and the transforming operators. GenComp evaluates the data of each bar by comparing this data with the parameters set by the composer. There are six independent evaluations, one for each parameter defined in the user interface window. For each bar the program analyses the density, harmonic tension, velocity, note duration, and note distribution, and compares the results with the value of the respective curve corresponding to that particular bar. If the difference between the evaluated parameter and the value set by the curve is small, the bar tends to be kept unchanged in future generations. On another hand, if this difference is big, the bar tends be transformed by the genetic operators. After been evaluated, the genetic operators change the data in that bar.

There are three genetic operators: crossover, selection, mutation. These operators transform numeric data in binary strings in order to start the genetic transformations. For example, the note-event 40 95 50 4 (note, velocity, duration, offset) will be represented by the following bit strings: 0101000 1011111 0110010 0100.

Crossover operates over the MIDI-notes and velocities by choosing pairs of notes or velocities which occur in that bar and mixing their binary configuration to form a new element. Consider, for example, MIDI-notes 59 and 40. Their binary representations are 0111011 and 0101000. The crossover operator could take part of the genetic (binary) information of each note to generate a new one: 0101011, or MIDI-note 43, for example.

Selection takes new elements created by the crossover operators to replace old ones. The replacement rates for each bar are dynamically established in function of how far that bar is from the established parameters. That means: the more a bar fits the values defined by the curves, the less current note-events will be exchanged for new ones.

Mutation operators introduce random changes in the binary strings. Their function is to introduce newness in the current piece of music by changing the genetic information. For example, if the velocity of a note-event is 73, or 1001001, and the mutation operator shifts the fourth bit from 0 to 1, the new string is 1000001, or 65. Mutation operator must be carefully used: high mutation rates applied to near optimal solution can lower the fitness of further generations, while very low rates can lead to a high number of iterations before the system can find a satisfactory solution.

After these three operators are applied, the current music solution is updated with the new note-events to form a new generation. Again, this new generation will be evaluated and processed by genetic operators. In most cases, starting from a completely random generation of note-events, GenComp is able to find a satisfactory result in about 100 hundred iterations. GenComp takes approximately 1.2 second to evaluate, process and update each bar, so a new generation appears each 2 minutes (100 bars * 1.2 second).

The Player


The player module takes the information about note-events stored in the MAX coll object and maps it in MIDI format to be played. A small built-in MAX patch uses a Markov chain to set each note to one of the sixteen available voices in the program. This Markov chain is set in a way that low pitches with high duration tend to be routed to lower voices while high pitches and short duration tend to be routed to higher voices. Intermediary values are accordingly distributed through intermediary voices. This helps the composer to setup MIDI channels, as well as the timber for each voice. For example, voice 1 and 2 could use a timber which can produce long sounds and works well for lower sounds, like strings, while voice 16 could use percussion-like sounds, since it will be mostly playing short sounds.

The controls of player functions are on the User-Interface Window and consist of standard Play, Pause, and Stop buttons and a box for setting the playback tempo.

Results and Further Developments


Many different experiments have been made with GenComp. In most cases, the program is able to generate pieces of music which satisfactorily meets the parameters set by the curves after 80 to 100 generations. It takes approximately three hours to produce these iterations. We are currently working on the genetic operators in order to enhance this performance. Moreover, a further version of GenComp will have a new table to control the MIDI-note range at each bar in the piece.

As usual in computer generated music the results are also very dependent on the composer's ability in using the software. Moreover, an important part in the compositional process relays on the composer's choices concerning the timber combination used for playback. By now, we have created a few pieces using GenComp with very satisfactory results.

Conclusion



The main goal in this research was the development of a tool for generating a graphic representation of music pieces. This graphic representation has two purposes. The first is to come up with a score which could represent some relationship among different parameters in a composition which are hard to delineate by using traditional notation. The curves drawn in GenComp's User-Interface Window provide a simultaneous and very clear visualization of the six different parameters. The cursor at the top of the curves helps the user to follow the score during playback. The second purpose is to provide an intuitive tool for music composition. GenComp allows the composer to practice the manipulation of different compositional parameters in order to create very complex music structures.

Acknowledgments


Part of this research was developed while I was visiting the CNMAT (Center for New Music and Audio Technologies) at the University of California, Berkeley. This research was made possible by a grant from CNPq, Brazil.

References