Intelligent Drum Machines Using Cartesian Genetic Programming Initial Essay Sample
A musician’s need to express their musical ideas in a way that is both acoustically pleasing and comfortable for whom ever is using it cannot always be communicated by themselves alone and often requires external assistance. This aid often comes in the form of an instrument, an interface channelling the thoughts and emotions from a user into their surrounding environment manifested into a physical medium, for example sound and light. This report will focus in on the acoustic exchange of these ideas and so will be restricted to the musical art form. The technology that is developed as a solution to this problem has been developed with two factors in mind; how it sounds and how easy it is for one to successfully express oneself with it, the later is important as it is assumed a user must be in comfort to successfully express their ideas. This criteria can be seen from the very beginnings of human musical history in the altering of drum sizes for variable pitch (figure 1), the use of multiple instruments at a time to implement polyphonic ideas and even the shaping of these instruments into easy to use tools for example a violin exhibiting a vibrating string with a quick and convenient excitation tool, the bow (figure 2).
Figure 1 taken fromFigure 2: taken from
These are all human creations allowing the manifestation of their internal musical ideas in the physical world. In more recent developments computers have been introduced including applications such as physical modelling, samplers, synthesizers and controllers for these systems of which any music technologist will be well acquainted with. These, much like the previous examples, have been produced to not only add to our bank or musical tools but to further increase the ease of the production of music removing the need to gather a full orchestra, practise the trumpet for 10 years or carry a drum kit around, as all these sounds can now be contained within a small laptop and controlled with a single keyboard. The downside of using computers, however, is that the music produced is often rigid sounding and robotic, much like the underlying systems that drive them. By using appropriate controllers the functionality of an acoustic instrument is mimicked in a device that can communicate with computers, controlling these sounds in a way that makes them sound more natural and realistic.
This is important because it is not always obvious what it is that we prefer about a real acoustic performance, and even if it was obvious it cannot be contained by a set of rules, only that we like it or we don’t like it. There is no formula that can generalise art. This is the fundamental problem with acquiring a pleasing and natural sound with electronic instruments and thus we still require a musician to control these systems to achieve the sound we desire. It should be noted that sound does not necessarily – and in fact at all for the purpose of this experiment – refer to the spectral make up of a sound but to the way in which it is musically shaped; for example a musician may define this shaping as what makes a musician sound “musical” or not. Human error brings colour to a performance in the subtle differences in note placement and volume making it sound “musical” and “natural”. The function of this report is to experiment with artificial intelligence in applying these subtitles to an existing drum track in the hope that it will enhance its musical shape, groove or feel without the external influence of a musician.
2. Literature Review
2.1 What Makes A Rhythm Groove
If the aim of this experiment is to musically enhance a rhythm then it follows that these enhancements should be defined. Music that exhibits this enhancement, for example a production sourced from a professional drummer, is often referred to as “groovy” in that it contains “groove”. For this reason in this report this humanistic quality will be referred to as groove throughout. As this experiment focuses on drum music, rhythms or “beats” it will be the rhythmic groove that is discussed .
“Groove – or swing – is a primordial aspect of music, more so for ingenious and functional kinds of music, such as dance- and folk music, than for art music. People appear to judge the amount of groove fast and effortlessly, although an objective or consistent definition is wanting. One possible definition of groove could be “suggestion to move to the pulse”” Madison, Guy (Institute of psychology, Uppsala university)  General consensus seems to relate “Groove” with swing, movement and the inconsistencies found in a human performance. Although difficult to define, the result of groove is altogether agreed in that it suggests to the listener a tempo or pulse, making the listener feel the need to tap their foot, nod their head or even dance. A short experiment was carried out to attempt a categorisation of the parameters which affect groove using a typical dance rhythm often referred to as a 4/4 beat or more colloquially “four on the floor”.
Consider the following two drum tracks exhibiting typical rhythms found in music today (figure 3 and 4). Both contain the same beat; retaining tempo, instruments and note placements however the latter has been performed by a musician rather than produced on a computer. It should be noted that although groove may vary with genre, due to its association with genres such as dance, jazz and folk music, a drummer who specialises in these genres was used. For the purpose of this experiment both recordings will be recorded in the MIDI domain and thus an electronic drum kit was used in the process of recording the musician. This also removes all timbral qualities added by the user, allowing the experiment to focus on purely musical qualities. The musician was given a click track to allow him to synchronise his performance; however no quantisation was applied thus the inconsistencies will give an idea as to what is adding this human quality. Figures 3 and 4 display a typical MIDI drum machine where the x-axis portrays time and the y-axis is instrument. The velocity of a note is shown by the intensity of colour: a dark red displays a note high in velocity and a light red displays a note low in velocity. This is shown more clearly in the note velocity charts below the note placement diagrams.
Figure 3: Computer performed rhythm
Figure 3: Human performed rhythm
By inspection, three main differences can be seen:
1.Note lengths are varied by a seemingly random factor
2.Note velocities are varied by a seemingly random factor. This variation although random displays a periodic nature as seen in higher velocity hi hats on the 3rd semi quaver of each beat. 3.Note placement displays an offset. This variation although seemingly random also displays a common offset for the 2nd and 4th semiquavers where they are delayed by a small fraction of the semiquaver integer. This factor is often referred to as “swing”
Note that this experiment is focusing in the musical aspects of what makes a rhythm groove and will not be taking into account timbral aspects of music. This does not mean to say that timbral qualities do not contribute towards the groove of a musical production.
2.2 Automatic Composition
Computers have developed to such an extent that it is now possible for them to not only produce and perform music but to assist its creation both in advance and in real time i.e. improvisation. MuSing for example, a rhythmic composition program, evolves drum patterns and is used as a compositional aid  while the genetic drummer uses similar techniques to produce an accompanying drum track designed for a live performance scenario . There are even programs which listen to real time audio and improvise along side a musician, for example Haile the robot drummer , a testament to modern day music technology. It is systems like these and the techniques used by them that are of interest in this report as they may give an indication of how to achieve a humanistic drum machine. Although these machines harness artificial intelligence (AI) to compose and improvise music, there is still a clear divide between the creation of music and the human enhancement of music, the later being the aim and focus of this experiment.
However if a computer can independently create art then there is no reason to rule out the addition of human qualities such as groove also. In general automatic musical composition involves defining a set of rules and restrictions within a system before allowing this system to make decisions, most likely with random or pseudo random process to select options. An example of this might include defining a major scale, restricting the program to euphonic notes only. By defining these rules a computer is able to compose without direct influence from a user while retaining some form of musical structure, a scale, metre or form. This technique lays down the basic structure of an algorithmic composition making automatic musical composition possible. The disadvantages of this system however are the static nature of an algorithm, in that changes in the rules that govern it must be pre defined, hard coded into the program often resulting in monotonous compositions or compositions of a fixed length.
If these rules are made less strict then the resulting sound is often Atonal and unmusical, which is unsurprising as no way of specifying fitness is available. This fitness is defined by how well it achieves its goal or how closely it resembles the desired solution and in the case of music how “good” it sounds. The difficulty in programming a computer to produce “good” music can easily be seen due to the subjective nature of music. Thus it can be seen that more complex systems are required to compose music on a more human level. Genetic software, unlike evolutionary algorithms, is dynamic in that it changes or evolves itself over time, mutating the inner workings and functionality of the program. The combination and routings of internal components are not defined but continually changed. These changes are continually guided by a fitness function specifying the goal. In the case of producing music or art, the fitness is often user defined as previously noted; there is no formula that can generalise art. This technique is commonly used and has been found more successful in simulating the humanistic traits found in music.
2.3 Genetic Programming
Genetic Programming (GP) is a branch of evolutionary programming that utilises the automatic evolution of computational structures (such as mathematical equations, computer programs, digital circuits, etc.) to solve problems. GP can be represented by a number of nodes or cells connected together in chain like structures. Data is passed through these nodes where by each node contains an operation appropriate for the data present. The software varies the routing of data between these nodes – i.e. the order in which they are performed on data – before comparing the resulting data often via user feedback. This automatic variation is referred to as mutation. The following diagrams (figure 5 and 6) give an example of this process:
Figure 5: First combination:
Figure 6: Second “mutated” combination
The fitness of each nodal combination or “chromosome” must then be deduced. The outputs of chromosomes 1 and 2 can then be compared to deduce the fittest solution where by the fittest model is selected and passed down to the next generation. Through this comparison influential nodes may be defined and kept, while less important nodes can be further varied to optimise the programs function. This is often achieved by “breeding” the chromosomes, combining components from each parent giving birth to a new combination. While only two combinations are initially proposed, in many genetic programs the population of chromosomes would be much greater posing a wider variety of solutions and possibly even a faster evolution rate. Parameters like these will directly affect the success of the program in how efficiently it solves the given problem. However, it should be noted that for different problems different rates are optimal. This mutation and comparison process is repeated continuously, hence the evolutionary aspect of this software .
A common example of the utilisation of GP is the travelling salesman problem portraying a salesman who must travel between numerous settlements in order to sell his merchandise. The problem in this is finding the shortest path for the salesman while ensuring all settlements are visited once. There is no general formula that can solve this problem and thus a trial and error experimental approach must be taken. GP is useful at this point as it itself uses a trial and error approach in the routing of data between operations. The operations could be defined as routes between settlements and the routing between them directly represents the order of routes taken by the salesman. The feedback in this problem is also easily defined as, unlike music and art, all we require is the smallest possible value. Thus by continually running this program and comparing the results, when a minimum is reached we have a solution . The branch of Genetic programming that will be used in this experiment will be Cartesian genetic programming (CGP), a C based program where by the functions used are represented by an array of numbers. CGP is particularly useful, as it has been designed with a black box mentality.
To clarify, a CGP program will take an arbitrary number of inputs and produce and arbitrary number of outputs. So long as the system has been altered to handle the desired data type and appropriate functions have been selected, the process of CGP does not require any adaptation from problem to problem hence its universally applicable nature and selection for this experiment. For example consider CGP applied to an arithmetical context whereby the data type would simply be numbers and the operations would include mathematical functions such as addition, multiplication and sinusoidal operators. CGP also allows the quality or rate of evolution to be customised by defining parameters in a .par file. This allows the alteration of population sizes, mutation rates, the range in which individual nodes can communicate with each other; levels back and the operators included. Figure 7:
CGPs intelligence is in its flexibility. The user or programmer gives CGP all the required resources and guides it without directly solving the problem. With minimal restraints it can often find creative and even surprising solutions whose method is only defined by what we see at the input and the output, how the program achieves this function is of no concern. Its evolutionary nature also means that it may never come up with the same solution twice, displaying almost human behaviour. For these reasons it has even been successfully used in the creation of art. Examples of this art can be seen below in figure 8 developed by Laurence Adam Zendric Ashmore 
More of these examples can be found at: http://www.emoware.org/evolutionary_art.asp
The art created, although abstract, rarely followed the same evolutionary patterns and most importantly of all was enjoyable for users to view. For this reason it is speculated that this almost human personality will lend itself to the altering of computer generated music tracks in the hope that it might add a human and natural feel or groove. The way in which this feel is added to an existing drum track is not defined nor is it known what we are aiming for, it simply utilises the user’s ability to define what they like or dislike to direct the evolution of this composition.
MIDI is a musical interfacing language that specifies the musical content of a real time or previously recorded composition. Musical content refers to the purely musical ideas as opposed to the timbre of the sounds used to convey these ideas. This can be summarised by the parameters pitch, velocity, length and placement of these notes relative to each other. A universal example of this might be musical notation on paper where by multiple musicians across the globe are performing the same music but with their own instruments and sounds. Musical notation (figure 9) does not contain the actual sound only the idea of it.
MIDI (figure 10) is exactly the same however is much more universal in that it can communicate not only with musicians but with computers, synthesisers and drum machines also.
The reason for this separation of musical and timbral qualities is purely for convenience, allowing the universal communication of modern day musical devices while optimising the speed and quality at which they communicate. In other words; modern day musical instruments have been modularised, separating the responsibilities of creating the music and creating the sound the music is played with into separate entities. Implementing this software with the MIDI interface automatically turns a purely experimental procedure into a potential musical instrument that may be used by real musicians and academics alike. The MIDI library being used will be the PortMIDI library due to its open source availability and popularity within the industry. PortMIDI is also written in C, a language completely compatible with numbers of which CGP can easily generate and interface with .
3. The Experiment
3.1 Proposition and Objectives
The proposition of this experiment is to utilise natural selection to evolve an existing drum tracks’ performance in order to achieve a more natural, organic and groovy composition. Cartesian genetic programming will utilise a dynamic system that can be used to produce a set of numbers whose values will control a set of parameters in a drum machine. These parameters have been deduced as groove enhancing thus the data from CGP will have a direct effect on the drum tracks groove. The development of these numbers will be automatically evolved to test an array of instances of our drum track and will be guided by a fitness function, a user who will define what they “like” and what they “dislike”. Like and dislike will be defined by whatever production sounds more natural, human and groovy to the user. This process will be repeated over a series of generations. Through this selection, fit chromosomes will be defined and evolved. The following diagram (figure 11) displays the main structure of this program.
The main objective is to evolve what might initially be a robotic and unpleasant sounding rhythmic composition into one that exhibits natural tendencies and variations i.e. displays a groove of which until now have only been possible by using real life musicians or meticulously editing drum tracks in audio editing software. Although this is possible by using real musicians to control electronic instruments, ideally this enhancement would not rely on a real musician and could be applied with a computer. If this is found successful the ultimate goal is to implement this groove evolution in a real time scenario creating what could be considered as an intelligent accompanying midi drum machine. This engine would play infinitely until told to stop by a user and would constantly evolve guided only by the user specified fitness of the compositions produced. Use of the midi domain will allow user specified samples and customisation of the performance. This ability would not only aid the composition and production of music but could also benefit musicians in performance, some of which might even stimulate new musical ideas.
3.2 Cartesian Genetic Programming and MIDI
In this experiment CGP will be used to produce a series of floating point numbers between 0 and 1 that will define the alteration of the groove enhancing parameters in an existing drum track. The drum track will be previously defined in a MIDI program and as follows (figure 12):
The groove enhancing parameters are as follows:
Offset refers to the amount every second semi quaver or 16th note is delayed. This delay is typical of “swing” traits found in many genres of music. This offset will vary not only from genre to genre or from musician to musician but is also dynamic within a real time performance or composition as no musician can remain completely in time. The amount of offset applied will be defined as a percentage, a float number from 0 to 1.
Velocity refers to the force at which a note is played. This should not be confused with volume, although velocity will often correlate directly with the volume of a sound it also effects the attack and timbre of a sound. This division between volume and velocity should be made clear as in modern electronic instruments the volume can be altered independently without affecting the timbre. Velocity will again be defined as a percentage of the full available velocity as a float number from 0 to 1.
Each note is assigned a place within the bar of music played. For example hi-hats are played every semi quaver or 16th note. Note length refers to the percentage of this assigned area that the note is actually played. This percentage will be defined as a float number between 0 and 1.
The offset will be defined for a whole bar while note velocity and note length will be defined for each semiquaver within a single crotchet individually. This choice has been made due to the repetitive nature of rhythmic compositions in for example jazz, electronic or popular drum compositions. Thus the MIDI groove enhancing parameters required from CGP can be summarised as follows:
•1 parameter which specifies the offset
•4 parameters which specify velocity of each hi hat in a crotchet beat
•1 parameter which specifies snare drum velocity
•1 parameter which specifies kick drum velocity
•4 parameters which specify note length of each hi hat in a crotchet beat
•1 parameter which specifies snare drum note length
•1 parameter which specifies kick drum note length
All of which can be summarised into 13 floating-point numbers between 0 and 1.
The numbers provided by CGP must not only be within an appropriate range in order to interface successfully with our MIDI drum machine but must also mutate appropriately. This means that the parameters that define the quality and speed of evolution of the CGP program must be optimised for this particular problem. There is no available information on this particular problem neither is there a formula that may be used to conclude this, so an experimental approach will be taken. To ensure compatibility both MIDI and CGP programs will be written in C programming language. This will allow both components to be contained in close proximity while retaining a convenient application medium.
3.3 General Approach and Plan
To ensure a successful experiment and completion before the deadline thorough planning is necessary . To begin with, the task at hand must be broken down and defined to allow inspection and execution of the project approach.
This will make foreseen problems visible minimising problems and delays during the experimentation process while allowing satisfactory time for research and all background reading required.
The project can be broken down into the following tasks:
•Gain familiarity with C programming language
•Gain familiarity with CGP
•Gain familiarity with PortMIDI
•Develop CGP for required parameters
•Develop simple drum machine reliant on proposed parameters
•Interface Drum Machine with CGP
•Optimise CGPs functionality
•Test program on users
The organisation of these tasks is equally important to ensure completion before the deadline. The following GANT chart is proposed (figure 15):
As can be drawn from the GANT chart (figure 15) much has been achieved already. Individual components have been constructed and the collaboration of both MIDI drum machine and CGP has already begun. Once this has been achieved it will be necessary to optimize the functionality of CGP before testing the product on users before completing the final write up.
 Miller J. F., Thomson P. Cartesian Genetic Programming. Proceedings of the 3rd European Conference on Genetic Programming. Springer LNCS 1802 (2000) 121-132.
 Koza, John R. “Genetic programming as a means for programming computers by natural selection.” Statistics and Computing 4(2) (1994): 87-112.
 Larranaga, Pedro, et al. “Genetic algorithms for the travelling salesman problem: A review of representations and operators.” Artificial Intelligence Review 13(2 )(1999): 129-170.
 David, B. Fogel. “Applying evolutionary programming to selected traveling salesman problems.” Cybernetics and systems 24(1) (1993): 27-36.
 Ashmore, Laurence, and J. Miller. “Evolutionary Art with Cartesian Genetic Programming.” Technical Online Report (2004).
 Wikipedia (2013) MIDI. [online] Site: http://en.wikipedia.org/wiki/MIDI [Accessed: 7 Feb 2013].
 Harding, Simon L., Julian F. Miller, and Wolfgang Banzhaf. “Self-modifying cartesian genetic programming.” Cartesian Genetic Programming (2011): 101-124.
 Costelloe, Dan, and Conor Ryan. “Genetic programming for subjective fitness function identification.” Genetic Programming (2004): 259-268.
 Senaratna, Nuwan I. “AUTOMATIC MUSIC COMPOSITION USING A TREE OF INTERACTING EMERGENT SYSTEMS.” (2006).
 Tokui, Nao, and Hitoshi Iba. “Music composition with interactive evolutionary computation.” Proceedings of the 3rd international conference on generative art. Vol. 17. No. 2. 2000.
 Geneffects, MuSing, Beat Maker Drum Software, Beat Machine Site: http://www.geneffects.com/musing/
 Martin Dostál, The Genetic Drummer, rhythmic accompaniment Site: http://dostal.inf.upol.cz/evm.html
 Georgia Tech, Haile, Robotic Drummer
 Johanson, Brad, and Riccardo Poli. “GP-music: An interactive genetic programming system for music generation with automated fitness raters.”Genetic Programming 1998: Proceedings of the Third Annual Conference. 1998.
 John A. Maurer, A history of Algorithmic Composition (1999) Site: https://ccrma.stanford.edu/~blackrse/algorithm.html
 Friberg, Anders, and Andreas Sundström. “Swing ratios and ensemble timing in jazz performance: Evidence for a common rhythmic pattern.” Music Perception19.3 (2002): 333-349.
 Wikipedia (2013), Groove (music) [online] Site: http://en.wikipedia.org/wiki/Groove_(music) [Accessed: 1 Feb 2013].
 Madison, Guy. “Different kinds of groove in jazz and dance music as indicated by listeners’ ratings.” Proceedings of the VII International Symposium on Systematic and Comparative Musicology and III International Conference on Cognitive Musicology. University of Jyväskylä, 2001.
 Miller J. F., Tempesti G. “Bio-inspired computing and Introduction to Bio-inspired Computing” Site: https://www.elec.york.ac.uk/internal_web/meng/yr4/modules/Bio_Inspired_Comp/bic.html [Accessed: 10 Jan 2013]
 A. Hunt, “Your Research Project: How to Manage It”. New York: Routledge, 2005.
Miller J. F., Thomson P. “Cartesian Genetic Programming”. Proceedings of the 3rd European Conference on Genetic Programming. Springer LNCS 1802 (2000) 121-132.
Mitchell Melanie. “An Introduction To Genetic Algorithms”. 1st ed. MIT press (1998).
Butler, Mark Jonathan. “Unlocking the groove: rhythm, meter, and musical design in electronic dance music”. Indiana University Press, (2006).
A. Hunt, “Your Research Project: How to Manage It”. New York: Routledge, 2005.