CinBalada: A multiagent rhythm factory

CinBalada is a system for automatic creation of polyphonic rhythmic performances by mixing elements from different musical styles. This system is based on agents that act as musicians playing percussion instruments in a drum circle. Each agent has to choose from a database the rhythm pattern of its instrument that satisfies the “rhythmic role” assigned to him in order to produce a collectivelyconsistent rhythmic performance. A rhythmic role is a concept that we proposed here with the objective of representing culture-specific rules for creation of polyphonic performances.


INTRODUCTION
Purely percussive music has its origins in the beginning of music itself but it is still a form of expression found nowadays in many traditional musical cultures around the world: the ensemble taiko drumming, in Japan; the Pungmul, in Korea; samba batucadas and maracatu, in Brazil; and the music produced in many tribes of Africa.In each of these musical cultures, percussion instruments are combined together in different ways, according to culturespecific rules, producing a polyrhythmic performance that carries the identity of that culture.
In a more contemporary form of expression, percussionists of different musical cultures engage in FTWO EKTENGU, where percussive music emerges in a collective improvised way.As described by percussionist Mickey Hart [12]: őThe main objective [in a drum circle] is to share rhythm and get in tune with each other and themselves".As a result "a new voice, a collective voice, emerges from the group as they drum togetherOE.These percussive jam sessions have great potential to produce PQXGN music, in the sense that the music produced does not match one particular cultural identity but it mixes elements of different cultures.
The research here presented was inspired by these intercultural encounters.We wished to create a computer tool to generate polyphonic percussive music by the combination of elements from different cultures.Instead of focusing in one particular culture, we aimed at mixing different cultures by using parameterized methods, in order to make the tool useful for experimentation with rhythms.Human composers could use it to test different ideas of percussive arrangements, for example.
A second goal of our research (directly linked to the first one) was to study ways of representing the culture-specific rules that govern human percussive performances.Moreover, we wished to study how these rules could be combined, in order to produce intercultural percussive music.This goal is obviously based on the assumption already present that new music can be produced in drum circles by the EQODKPCVKQP of elements of diverse cultures.
The result of our research was the creation of the CinBalada 1 system, in which intelligent agents simulate percussionists playing in a drum circle.To represent part of the cultural-specific knowledge, the system is based on pre-recorded rhythmic patterns classified by its instrument and by its original culture.Beyond the rhythmic patterns themselves, we assumed that the different cultures also employ different rules to combine the rhythms together in polyphonic contexts.So, we proposed the concept of TJ[VJOKE TQNG as a means of representing the rules that QPG specific culture uses when playing rhythmic patterns of QPG particular instrument (or group of similar instruments).At a lower abstraction level, we studied mathematical measures of combination between rhythms to be used to model the rhythmic roles' rules.
In the next section, we introduce the requirements of the CinBalada rhythm generation system.Then we present the state of the art in systems for rhythm generation.The following section reviews rhythm representation and evaluation techniques employed.Then, we explain the higher-level architecture of the CinBalada.The results are then discussed, based on an experiment for evaluation of the system.Conclusions and future work are presented in the last section.

REQUIREMENTS
As we observed in the last section, the scenario that inspired this research is that of an improvised intercultural rhythmic group performance, where musicians only play percussion instruments.Experienced musicians that take part in a meeting like this can soon adjust themselves to the rest of the group, usually keeping the resulting collective performance esthetically attractive.We wanted to apply a similar idea in a computer system for polyphonic rhythm generation.
Thus the first and most important step in this research was to try to understand what knowledge is involved in the generation of a rhythmic group performance.This involves getting a better understanding of the rhythmic dimension in music, particularly how to TGRTGUGPV and how and EQODKPG rhythmic patterns.
Therefore, the main musicological goal of this research is to KPXGUVKICVG RQUUKDNG CPUYGTU HQT VJG HQNNQYKPI SWGUVKQPU related to polyphonic rhythmic performances: • How to play just one percussion instrument in a musical (or human-like) way?
• What features a human perceives in a rhythmic pattern and how to calculate them?
• What rules of combination can be used by the musicians to produce a group performance?
• How the knowledge above can be organized to model culture-specific rules?As a result of this investigation, the second step of this research was to develop a sort of factory, workshop or laboratory for experimentation with rhythms, which could be used by musicians to explore new combinations of polyphonic/polyrhythmic music material to be used in compositions and arrangements.With this scenario in mind, we established the following requirements: (i) Musical quality.The system must be able to produce music that is pleasant to humans.
(ii) Rhythmic polyphony.The system must produce music that reproduces multiple percussionists playing together in a drum circle.Free combination of percussion instruments should be allowesd.
(iii) High-level parameterization.Users (that we assume to be musicians) must be able to tailor the system's outcomes in an intuitive way.Some of the parameters must be models of cultural elements to allow the user to mix different styles.
(iv) Diversity of outcomes.The system must produce different musical outcomes for different parameters.Small variations are also desired between outputs created with the same set of parameters.
(v) Response time.After having the parameters set, the system must produce its output in short time, so that the user can quickly try new parameters, if he wants to.A few seconds is assumed to be a good response time.
In the following section, we analyze previous works in automatic rhythm generation comparing them with the goals described in this section.

AUTOMATIC RHYTHMIC COMPOSITION
In this work, we assume automatic composition systems as those that are able to solve the problem of combining musical elements (e.g., notes, phrases or chords) into a more complete musical part, which may be a full composition or just a melodic line, for instance.
The literature describes many systems matching this definition [23].Although systems focusing pitchbased composition are by far the most common, there has been a growth in the number of systems focusing on the generation of purely percussive music in the last years.We will call them "percussive composition systems" in the rest of this paper.This classification does not include systems that compose rhythmic sequences not bound to any particular percussion instrument but intended to aid musicians in the composition of musical parts for other instruments, as [21] and [5].
A great number of techniques can be employed in automatic composition.In the composition of percussive music it is not different -we have found percussive composition systems developed with the following techniques: genetic algorithms, intelligent agents, CA automata, and a purely musicological approach.
In the following subsections, we analyze systems for percussive composition of all these different techniques.The first two techniques have many representatives and will be presented in specific subsections, while a third subsection will explain the rest of the systems.The fourth subsection compares the systems.

GENETIC ALGORITHMS
In a general description, a system based on a genetic algorithm evolutes populations of rhythmic patterns using operators to transform them and a fitness function to evaluate their esthetical quality.After a number of generations, the system provides the remaining rhythmic patterns as output.The six systems for percussive composition that we found can be divided according to the technique used for building its fitness function: neural networks [4] [25], interactive user evaluation [13][24] [34] and critical damped oscillator [41].
One thing that is common to systems that used neural networks is that were both intended to reproduce one or more pre-defined musical styles.The system described by Burton in [4] had an ART neural network trained to cluster drumset's patterns of different musical styles and used proximity to the cluster as the fitness functions.The other system, described by Pearce in [25], used as fitness function a MLP neural network trained with drumset's rhythmic patterns in the "drum & bass" style.
Three systems seemed to have no target musical genre and used a human to take the role of the fitness function by subjectively rating the musical quality of rhythmic patterns [13][24] [34].Horowitz [13] described a system from generation of rhythmic patterns for typical drumsets, while Pazos et al. [24] and Tokui and Iba [34] allowed free percussion ensembles.An interesting detail in the work of Tokui and Iba [34] is that they used a MLP neural network to learn the user preferences and filter out rhythms that the user is not likely to enjoy on each iteration, letting to the user the role of evaluating the remaining patterns.
Finally, Tzimeas and Mangina [41] designed the SENEgaL system to create polyphonic rhythmic patterns similar to some musical cultures from West Africa.The system is loaded with some rhythmic patterns taken from those cultures that the user can combine in a score to create a kind of template for the final polyphonic composition.For each small rhythmic pattern in the template, the user defines a target ratio which indicates how frequently the given pattern should appear in the generated composition.If the rhythmic patterns of an instrument have 100% as total ratio, for example, the SENEgaL system will not change the line for the given instrument in the final composition.Inspired on critical damped oscillators (from Physics), the fitness function directs the whole population for the target ratios by dynamically adapting its weights for each observed ratio if the population as a whole starts to diverge from the target values.

MULTIAGENT APPROACH
In this approach, intelligent agents are designed to act as percussionists playing in groups.Agents are autonomous to take decisions (i.e. to compose their parts), but a coordination mechanism is necessary to create coherent group performances.Rhythmic systems with the multiagent approach can be divided according to the following main purposes: evolution of rhythms =?, evolution of repertoires [9][18] [19], generation of percussive accompaniment =? and a tool for generation of polyphonic rhythms [7].
A system for evolution of rhythms is described by Pachet in [22].In his system, polyphonic rhythms emerge from repeated interactions between rhythmic agents.As the author, states: "these agents engage into a dynamic game which simulates a group of human players playing [percussive instruments together], in real time".Each agent in the system is configured with an initial rhythmic pattern and a set of transformation rules selected by the user from a database.The rules, which are periodically tested during the performance, have a pre-condition that, when satisfied, fires an action that modifies the agent's rhythmic pattern.An example of rule is: "if there is a strong beat where the agent does not play, then add some note in this beat".The goal of the research is basically to create an understanding of the effects of these rules in the generation of a polyphonic performance.
The three systems aimed at evolution of rhythmic repertoire are apparently inter-related [9][18] [19].As a common guideline, all these systems are based on the assumption that a repertoire of typical rhythmic phrases in a musical culture emerges by the repetitive listening of similar patterns.In [9], Gimenes and Miranda present the RGeme system that evolves a TGRGTVQKTG of rhythmic patterns.However, the system does not output a musical composition, but just a ranking of the most important monophonic rhythmic patterns in a set of scores provided as inputs.
In [18], Martins and Miranda advance in the previous idea of evolution of rhythmic repertoires by creating an agent that simulates the human's limitation in acquiring and storing musical information, which is now expanded to polyphonic rhythms.The paper describes the internal modeling (with neural networks) of the agent, but no music generation module is described.Then, in [19], the same authors (ignoring the proposed model) describe a system where agents interact according to different algorithms (which in multiagent terminology could be described as PGIQVKCVKQP RTQVQEQNU) to develop rhythmic repertoires.At a lower level, these interaction algorithms can also transform the individual rhythmic patterns that form the repertoires.The resulting rhythmic patterns are monophonic, but a general algorithm for combining them into polyphonic rhythmic patterns is also described.
With a different goal, Murray-Rust proposes the VirtuaLatin system for generation of percussive accompaniment [20].The system is designed as a collection of musician agents playing in a band of the Cuban-inspired genre known as salsa.However, the work focused on the development of only one intelligent agent -the VKODCNGTQ, which is the percussionist in a salsa band.Other agents only reproduce pre-recorded lines of their instruments.The timbalero agent receives as input all bars reproduced by the other agents.Then, it applies an original algorithm to generate an arrangement for salsa percussion that is suitable for the context.Based on the GTTM [15], the timbalero's algorithm has four stages of analysis (activity, harmony, rhythmic and parallelism) that creates a higher-level representation of the piece with information like: hierarchical sections, harmony and instrumentation level (sum of all note durations).From this representation, the system applies a set of rules to select the best rhythmic pattern from a pre-defined database of common salsa rhythmic patterns.To evaluate his system, Murray-Rust [20] conducted experiments to compare a salsa accompaniment generated by the system with an accompaniment recorded from a human musician for the same song.In the experiments, VirtuaLatin was able to fool the general public, but not the expert musicians.
The only system found in the multiagent approach whose primary goal was the generation of polyphonic rhythms was the Kinectic Engine, developed by Eigenfeldt [7].In the Kinectic Engine, intelligent agents play percussion instruments and interact between themselves to produce a coherent rhythmic performance in real time.The system receives only one high-level parameter from the user which is the desired overall density (in number of onsets) of the performance.
Agents in the Kinectic Engine [7] are modeled with a V[RG and a RGTUQPCNKV[.The type indicates which instrument an agent can play (grouped by similar timbers) and the level of density and variation that is expected from its individual rhythmic patterns.The personality of an agent indicates other features that are expected from its rhythmic patterns (such as: downbeat, offbeat and syncopation) or from the agent itself (such as: responsiveness to global changes, sociability and duration of social interactions).Agents may interact when they have too similar or too dissimilar rhythmic patterns.However, the interaction only occurs if allowed by sociability parameters of the agents' personalities.

OTHER APPROACHES
Two other systems used different technical approaches for the development of systems for percussive composition.One of them is described by Brown in [3].It uses a CA Automata for the evolution of monophonic rhythmic patterns.However, analogously to the multiagent system proposed by Pachet [22], the main goal of Brown's work was to study the GHHGEVU of CA rules in the evolution of rhythmic patterns instead of focusing on the generation of good-quality musical material.
On the other hand, the Ambidrum system proposed by Gifford, Toby and Brown [8] has the clear goal of generating percussive composition with good quality.The system is based on the idea that good music should possess a balance between novelty and coherence.Therefore, the core of the system is a measure of coherence, which is used to evaluate the coherence between the metric and some attributes of a rhythmic pattern for a drum kit.A set of target coherence levels provided as input are used by the system to modify the rhythmic pattern in successive iterations, until it reaches the target levels of coherence.

DISCUSSION
Analyzing the genetic approach, systems that used human evaluation [13][24][34] and the SENEgaL system [41] (which used the critical damped oscillator) reported more consistent outcome of goodquality and varied musical material than those with neural networks [25][4].However, the use of repeated human evaluation in each generation of a genetic algorithm is a slow and tiring process, which is known in the literature as the HKVPGUU DQVVNGPGEM problem2 [1].Therefore, the genetic system that more closely satisfies the requirements for our research is the SENEgaL system.However, the system suffers from long running times of 3 or 4 minutes, inadequate for our purposes.
The approach which can more naturally simulate percussionists playing in drum circles (which is the inspiration for our work) is the multiagent one; and the Kinectic Engine [7] is a close match for our requirements.However, the system has just one parameter, while we wish to offer more parameters to let the user adjust the composition in a personal way.Furthermore, our aim was to create an environment where cultural elements could be mixed in a controlled way, but the Kinectic Engine does not provide separation between elements of different musical cultures.
Finally, from the two other systems, the Ambidrum is the more relevant.However, like the Kinectic Engine it also does not considered cultural variations in the generation of the output.It is also devoted to typical drumsets and does not allow free percussion instruments as we desired.
As we described in section 2, the development of the CinBalada system involved the investigation of possible answers for some musicological questions (there presented).In the next sections we analyze some techniques found in the literature that could answer some of those questions.

AND EVALUATION
A central issue in the system we intend to build is to represent rhythm in a way that favors reasoning about it.MIDI, for example, is a common representation for the output of systems for automatic composition but gives no information of the perceptual structure of a piece of music.Therefore, it is necessary to work with more abstract representations of rhythms, from which we can extract properties that capture some characteristics of human perception of music.
In the next subsection, we provide a brief survey of the literature on abstract rhythm TGRTGUGPVCVKQP, giving emphasis on the models adopted in our system.Then, in the following subsection, we present some OGCUWTGU that can be applied either to extract properties from monophonic rhythms or to compare two given monophonic rhythms in some way.

REPRESENTATION
Let us start analyzing the traditional notation in scores for comparison purposes.Figure 1 shows an example of such notation for the Rumba rhythmic pattern.As it can be seen in the figure, there can be different notations for rhythmic patterns.The second notation, specifically, shows a series of notes and rests with the same duration, which happens to be the atomic beat (or isochronous pulse) in this context.From this representation, one can think of a box representation in which cells represent the atomic beats.This notation is called 67$5 (Time Unit Box System) [35] and it can easily be represented in binary notation by putting 1 to indicate an onset and 0 for silence or inter-onset intervals.As an example, the Rumba pattern is represented in TUBS in Figure 2. From the TUBS representation, other representations can also be derived.One of them is just a vector with the number of the cells (in the TUBS representation) where the onsets occurs and we call it the QPUGVU XGEVQT.For example, looking at the number of the cells where onsets occur in Figure 2, the Rumba pattern becomes the onsets vector .
However, intervals between onsets are probably more relevant to human perception than just the onsets positions.So, another representation, that we cal KPVGT QPUGV KPVGTXCNU XGEVQT [35], can easily be computed from the onsets vector by subtracting adjacent onset positions.Using Rumba as example again, we have the following inter-onset vector: <3,4,3,2,4>.In previous percussive composition systems, the most common representations used are variations of the TUBS (as in [3]) and of the inter-onset interval vector (as in [41] and in [19]).
Another approach, which was not found on previous percussive composition systems, consists in using geometric elements to give a visual perception minimally correlated to the auditory musical perception.One of such geometric representations consists in representing rhythms as polygons [35].This can be done by dividing a circumference in equally-spaced points according to the atomic beat (like in TUBS), then marking the positions where the onsets occur and, finally, linking the points.Rumba is shown in the RQN[IQPCN TGRTGUGPVCVKQP in Figure 3. Another geometric representation is the 6'&#5 (Time Elements Displayed As Squares) notation, first proposed in [11] to study the speech rhythm.It can be applied to musical rhythms by representing inter-onset intervals as squares placed side by side, as in the Figure 4 below.A property of the TEDAS representation is that the vertical axis displays the inter-onset intervals, while the horizontal axis keeps the precise time of each onset (analogous to the TUBS representation).For easier computational manipulation, the TEDAS can be treated as a vector in which each position holds the corresponding vertical value.This representation is called EJTQPQVQPKE XGEVQT [38].The Rumba rhythmic pattern has [3,3,3,4,4,4,4,3,3,3,2,2,4,4,4,4] as its chronotonic vector, for instance.
We would like to remind the reader that the representation mechanisms presented in this section were those that we found relevant in our research, but other representations are described in literature.As an example, a representation scheme which was not used in our CinBalada system is the FGPUKV[ URTGCF of the Kinectic Engine [7], which weights each higher-level beat of the metric according to the number of notes it contains.Thus, Rumba could be described by the vector |2,1,1,1|.A related topic, which is also omitted here, are representations of the meter, such as those proposed by Lerdahl and Jackendoff [15] and by London [16].
In the next subsection we describe how the representations schemes presented here can be used for the extraction of musical features and for making comparisons between rhythms.

EVALUATION
Compared to domains such as harmony, counterpoint and orchestration, rhythm is one of the least understood topics in music theory and musicology literature.Processes related to rhythmic development of a performance and to the combination of rhythmic patterns seem still to be in the realm of intuition.Fortunately, important studies have been carried out more recently on the domain representing valuable knowledge.Here we present some of the current proposals on how to evaluate and characterize individual rhythmic patterns and combination of them, stressing those techniques used in the CinBalada system.
The functions surveyed here can be seen as measures of some musical features or properties.For measuring UKOKNCTKV[ between two rhythmic patterns, for instance, we analyzed five different functions: Hamming distance, permutation distance, Euclidean interval vector distance, interval-difference vector distance and chronotonic distance [38].However, according to Toussaint in [38], the EJTQPQVQPKE FKUVCPEG is the best of them in the ability to reproduce the human perception of rhythmic similarity.The chronotonic distance is simply the minimum area between the TEDAS representations of two rhythmic patterns, as shown in Figure 5.It can easily be computed by subtracting corresponding positions in the chronotonic vectors of the patterns, and then adding up the absolute value of these differences.Equation (1) shows this function, where C K is the K-th position of a chronotonic vector C (and D K is the same for vector D) and P is the size of both vectors.
For measuring the U[PEQRCVKQP of a rhythmic pattern, four functions were found: Keith's measure, WNDB measure, offbeatness and rhythmic oddity [10].However, only the QHHDGCVPGUU measure was really adopted in our system.This measure consists simply in counting the number of onsets in offbeat positions.For this measure, offbeat positions are those in the cycle (in the polygonal representation) that are not touched by any inscribed regular polygon with a vertex in position zero.Offbeat positions are shown in figure 6.
In [40], Toussaint analyzed some African rhythmic patterns and concluded that the offbeatness measure is a good predictor of preference among Sub-Saharan African rhythm timelines.In other words, analyzing a set of rhythmic patterns from that region, the patterns that are most common in those cultures were exactly the patterns with highest QHHDGCVPGUU.
Another feature that can be extracted from rhythmic patterns is their GXGPPGUU, inspired by studies in the evenness of musical scales [37].Basically, this feature is related to how well-spaced are the onsets in a rhythmic pattern.An interesting use of this feature was made by Toussaint [36], who compared some families of African rhythms using this feature.He observed that this feature can indicate which families are the most widespread ones.
There are at least three measures for this feature: sum of arc-lengths for all pairs of onsets, sum of chord-lengths for all pairs of onsets, and the regression-evenness measure [37].This last function received its name because of its similarity to linear regression fitting of data points in statistics.To explain this function, Toussaint [37] uses a 5-note rhythmic pattern based on a 16-beat metric with onsets vector (0,4,8,12).This sequence is mapped onto a twodimensional grid of size 16 by 5 in Figure 7.The author says that "the x-axis represents the 16units of time at which the five notes are played and the y-axis indexes the five notes [...] The intersections of the horizontal note-lines with the diagonal line indicate the times at which the five notes should be played to obtain a perfectly even [...] pattern.The deviations between these intersections and the actual positions of the notes are shown in bold line segments" [37].The regression-evenness measure for the rhythm is just the sum of these deviations.
Other measures for other rhythmic features exist in the literature, but were not used in the design of the CinBalada system.Examples are the measures of TJ[VJOKE EQORNGZKV [ [32][35], and measures of geometrical features extracted from geometrical representations of rhythmic patterns [35] [39].Another measure for UKOKNCTKV[ between rhythmic sequences which was not considered here is also described in [17].Finally, an interesting measure of rhythmic EQJGTGPEG to a given meter (which deserves a closer look) is proposed in the Ambidrum system [8].
After presenting the main techniques found in literature for rhythm representation and evaluation, we present, in the next section, the complete design of the CinBalada system using these techniques.

CINBALADA SYSTEM DESIGN
Inspired on the scenario of percussionists from different cultures playing in drum circles, the CinBalada system was designed as a tool for experimentation with intercultural rhythmic mixtures.Similar to previous systems, such as [22] and [7], the CinBalada system emulates a group of percussionists playing together.Each agent in the system receives a set of pre-recorded small rhythmic patterns from one percussion instrument.In this way, we abstract the problem of composing individual rhythmic patterns to focus on the problem of combining these monophonic patterns together into bigger polyphonic ones.
Considering that combinations of rhythmic patterns are dependent on the musical culture, we propose a model for representation of culture-specific rules for selection of rhythmic patterns.We modularize these rules by dividing them in TJ[VJOKE TQNGU, which the user can assign to any instrument.So, when the performance starts, agents use their rhythmic roles to guide their interactions in a collective improvisation.Agents need to negotiate in order to choose rhythmic patterns that satisfy the rhythmic roles assigned to each of them.
In each of the next four subsections, we describe each part of the system and analyze how they answer the musicological questions presented in section 2. A fifth and final subsection analyzes how the system satisfies the requirements presented in section 2.

DATABASE OF RHYTHMIC PATTERNS
As explained before, the system uses pre-recorded rhythmic patterns, which are composed by a maximum of four bars (typical rhythmic patterns, however, have one or two bars).The rhythmic patterns are stored in the MIDI format, which is easy to manipulate and useful for sound generation, because it captures expressiveness from human performances.
The motivation for this approach was to abstract the problem of generation of individual rhythmic patterns and the problem of generation of expressiveness attributes in rhythms (as in [2]), both related to the first musicological question in section 2 (regarding to playing a single percussion in a humanlike way).However, we could not record the MIDI files from real performances, so many of them were manually sequenced from musical scores using a program for sound edition.
The scores were taken from popular percussive cultures, such as samba "batucadas" =?, maracatu =? and some African and Afro-American styles =?=?.To complement the performance information of the MIDI format, the database keeps a XML configuration file for each pattern with the following: • The name of the instrument played in the MIDI file.
• An optional name, for famous rhythmic patterns.
• The meter, represented simply as the number of atomic beats (the isochronous pulse).Most patterns were based on 16-beat3 metrics with some 12-beat patterns also.
• The musical cultures where the pattern is commonly found.
• An extra parameter indicates whether the rhythmic pattern is a fill pattern or not.Thus the database keeps MIDI rhythmic patterns categorized by percussion instruments, metrics and musical styles.However, as discussed in section 4, the MIDI format is not very useful for reasoning in composition systems.Therefore, the patterns are converted in runtime to higher-level representations.The next subsection describes the representation and part of the reasoning used in CinBalada.

RHYTHMIC PATTERNS
In runtime, the CinBalada system converts the MIDI file to alternative representations of the rhythmic pattern using the techniques described in 4.1.Such representations are used, during the system execution, by the measures of rhythmic features described in 4.2.Those measures constitute possible answers for the second musicological question of section 2 (regarding perceived features in rhythmic patterns).However, despite the reasonable amount of measures (or functions) listed there, none of them are directly aimed at assessing the compatibility of two rhythmic patterns, i.e., whether two monophonic rhythmic patterns sound good when played together, which is related to the third musicological question listed in section 2.
In order to cope with this lack of knowledge concerning rhythmic compatibility, we had to propose new measures relying in the opinion of experts.These measures were successively implemented and tested in the course of a three years project.Here we present the two main measures of compatibility we ended up to adopt: interplay and partial derivation.A third auxiliary measure for individual patterns is also presented: the activity measure.
The OGCUWTG QH KPVGTRNC[ between two rhythmic patterns is, indeed, a direct trial to measure compatibility between two rhythmic patterns.This measure is calculated from the TUBS representations and it is computed using two values: • The number of onsets that coincide in both patterns (matches).
• The number of onsets from either rhythmic pattern that has no coincident in the other pattern (mismatches).The interpaly measure is, then, computed as the absolute difference of these values, where the ideal situation (best interplay) is when it gives the value of zero.As an example, two patterns are pictured in Figure 8, with matches and mismatches highlighted.In that example, there are two matches and two mismatches, so the measure would give the value of zero.The idea behind this measure is that two monophonic rhythmic patterns sound good together when there is a balance between their affinity (i.e., the matches) and their relative originality (i.e., the mismatches).
Another measure we propose is the OGCUWTG QH FGTKXCVKQP of one rhythmic pattern in relation to another one taken as reference.We assume here that a pattern # is (completely) derived from pattern $ if all onsets of $ are also onsets of #, as in Figure 9.The idea is that, if more onset positions are added to a rhythmic pattern (without removing any of the original onsets), a new pattern FGTKXGF from the first is created, preserving some of its feeling.
However, a derivation measure taken directly from the definition would give just two values to indicate if the relation holds or not from two given patterns (could 0 or 1).A better measure was created to deal with intermediate cases, in which one pattern has just some parts (e.g.half bar) derived from the reference pattern.The OGCUWTG QH RCTVKCN FGTKXCVKQP that we propose is computed from the chronotonic vectors of two patterns.It is could be defined simply as the sum of the differences between positions in the reference pattern and the other pattern (supposed as derived).Thus, one pattern is considered (partially) derived from the reference pattern if the measure gives a positive value (because the graphic of the TEDAS 4 representation of the reference pattern is mostly above the TEDAS of the other rhythmic pattern); if it gives a negative value, the derivation relation is the inverse; and if it gives the value of zero, they are completely independent patterns.
The given definition for the measure of partial derivation is almost identical to the definition of the chronotonic distance, except that the real differences are used in the former while the absolute values are used in the later.Indeed, the chronotonic distance is the maximum value that the measure can assume for two given patterns, which is only reached when one pattern is derived from the other.Therefore, we used the chronotonic distance to normalize the measure of partial derivation proposed, so that the measure return values in the interval [-1;+1].A special case that must be treated apart is when the patterns are identical, thus having chronotonic distance of zero that cannot be used as divisor.In this case, the partial-derivation measure is defined to give the value of +1.
The formula for the derivation measure is given in equation ( 2), where T K and R K are positions of the chronotonic vectors of the reference pattern and of the other pattern, respectively.Both vectors are assumed to have the same length P.
( ) This measure is different from the others presented here in that the order in which the rhythmic patterns are taken produces different (symmetrical) values.Thus, the proposed measure gives the following values when applied to a pair of patterns (TR): • Value +1 indicates that pattern R is completely derived from pattern T (reference pattern).
• Values in the interval (0,+1) indicates that R is partially derived from pattern T.
• Value 0 indicates that they are independent.
• Values in the interval (-1,0) indicates that T is partially derived from pattern R.
• Value -1 indicates that pattern T is completely derived from pattern R. Finally, a more simple function that we also created for the CinBalada system is the CEVKXKV[ OGCUWTG, that measures how dense or busy a rhythmic pattern is.It is computed just by dividing the number of onsets (which is the length of the onsets vector) by the length of the pattern (in atomic beats).It is probably similar to the FGPUKV[ OGCUWTG used in the Kinectic Engine [7], with the difference that it seems to be a relative measurement there.
All evaluation functions for rhythms presented (either the ones first proposed here or the ones found in the literature) work only in individual patterns or in pairs of them.Therefore, they don't tell too much about how CP[ number of rhythmic patterns can be combined in a polyphonic performance, with multiple percussion instruments.In the next section, we propose a model of organization of such kinds of performances.

RHYTHMIC ROLES
In typical purely rhythmic groups, it is common to organize the performances by defining the expected rhythmic behavior of each player.Analyzing samba batucadas, which are a typical Brazilian percussive performance, Salazar [28] suggests an informal classification of the instruments by grouping them by similar rhythmic behavior: • Surdo: guides the whole performance (as a metronome) by using very regular patterns with few notes.
• Caixa, Ganzá, Pandeiro, Reco-Reco and Congas: they play more notes and are freer to do variations, but their patterns are still quite regular.
• Tamborim, Agogo, Cuica and Whistle: these are typical soloists instruments, from which are expected some degree of variation and originality.Therefore, instruments in a batucada performance are associated to specific behaviors, in order to create some sense of organization in the whole performance.We will give the name TJ[VJOKE TQNG to the behaviors expected from an instrument in a performance from a certain style.The batucada's rhythmic roles of the three groups of instruments just presented will be called: DCUG, EQORNGOGPVCT[ DCUG and UQNQ.
Although the rhythmic roles presented here are inspired specifically by samba batucadas, they may also have analogous in a number of other musical styles, even non-purely rhythmic ones.As an example, many latin musical genres use claves or cowbells to guide the performances, similar to what happens to the surdo in samba batucadas.Another example of rhythmic role is that of a soloist instrument, which is present in almost all genres.
We assume that a rhythmic roles assigned to an instrument may change during the performance, and the solo role is a typical example of a temporary one.Another typically temporary rhythmic role we will adopt will be the HKNN role, which plays very dense rhythmic pattern usually to indicate changes in the global performance.
For the sake of generality, we assume that each musical culture has its own typical rhythmic roles, which may be significantly different from the ones found in samba batucadas.Next, we will discuss how the concept of rhythmic role was modeled in order to be generally applicable to roles found in different musical styles.This is how we try to answer the last one musicological question presented in section 2 (regarding modeling of culture-specific rules).

/QFGNKPI 4J[VJOKE 4QNGU
In few works, a rhythmic role will be treated as a schema for specifying which rhythmic patterns are suitable in a given musical context.We believe that a generic model of rhythmic role needs the following five elements: • $CUKE UGNGEVKQP ETKVGTKQP HQT KPFKXKFWCN RCVVGTPU.It defines the features expected from rhythmic patterns of the role, independent of the context.Example: instruments of base role (as the surdo) should always play an even rhythmic pattern with low activity.
• 4GHGTGPEG TQNG.Instruments of a rhythmic role may be guided by instruments of another role.This creates a kind of vertical (hierarchical) relation between instruments.As an example: instruments of the complementary base role (such as pandeiro) are guided by the base role.
• 8GTVKECN ETKVGTKQP HQT EQORCTKUQP YKVJ VJG TGHGTGPEG TQNG.It defines how the reference role will exert influence in the choice of rhythmic patterns, during the performance.
Example: complementary base role must play patterns that are derived from the base role.
• *QTK\QPVCN ETKVGTKQP QH EQJGUKQP KPUKFG VJG TQNG.It defines how instruments of the same rhythmic role will choose their patterns so that they combine together.As an example: two base instruments should play similar patterns.
• 'XQNWVKQP ETKVGTKQP HQT EJCPIGU KP VKOG.It defines the degree of freedom to change the rhythmic pattern during the performance.It also defines how a new pattern can be chosen if a change occurs.Example: base role has no freedom to change, but soloist should choose a different rhythmic pattern each bar.Each rhythmic role in the system was implemented by four evaluation functions (to represent the four criteria over the patterns) and by an association between the role and its reference role.The evaluation functions of the roles were defined using measures for the features shown in subsection 4.2 and the new measures proposed in subsection 5.2.Only one basic selection criterion could not be reasonably implemented by those functions -the basic selection criterion for the HKNN role, which uses a special attribute stored in the rhythmic patterns' database, as we described in subsection 5.1.Table 2 shows the functions used for each criterion, for each batucada's rhythmic role.The functions were chosen for the roles after a careful analysis of scores from samba batucadas =?.In the CinBalada, we assume the "basic selection criterion" as the only one that can prohibit the choice of some rhythmic patterns.It is used as a filter to narrow the number of rhythmic patterns that can be played by the instrument.Then, the other three criteria, which we will call EQPVGZVWCN criteria, are used to evaluate a "level of suitability" of each rhythmic pattern for the context of the performance.
An additional consideration is that we "detached" the roles from the instruments in which they are commonly found to give more freedom to the user.Therefore, any rhythmic role can be assigned to any percussion instrument.Then, the rhythmic roles are used in the CinBalada system to organize the rhythmic composition produced by the agents.
We said before that each agent in the system plays pre-recorded rhythmic patterns of one specific instrument.Now we can add that each musician agent also receive the sequence of rhythmic roles that it must follow in each bar to guide the choice of the rhythmic pattern for each bar.This choice must, naturally, involve interaction with other agents (of the same role and of its reference role).The next subsection details how these interactions occur.

AGENT NEGOTIATION
In each bar, musician agents have the duration of the bar to decide the rhythmic pattern they will play in the following bar.This decision is made by means of a multiagent negotiation, designed to resolve the dependencies between the rhythmic roles of the agents and, as result, produce valid choices for their rhythmic patterns.In this subsection we detail how this negotiation is done in the system.Using multiagent terminology, three things are involved in a multiagent negotiation =?: negotiation objects, agent's internal decision-making models and a negotiation protocol.In our system, the negotiation objects are the rhythmic patterns and the agents' decision-making models consist in the contextual criteria of each agent's rhythmic role.The negotiation protocol of the CinBalada, in its turn, is defined by the state machine in Figure 11.The state machine describes how each agent interacts with the others during each round of negotiation (there is one round per bar).5VCVG is the machine's initial state.In this state, the agent finds other agents assigned to perform the same rhythmic role in that bar and agents assigned to performance its reference role in that bar.SVCVG is the state where the agent first chooses a rhythmic pattern (from the ones that satisfy the basic selection criterion of the role).This first choice is made without information about other agents' patterns, just as a starting point for the negotiation.If it's the first bar, the choice will be random.In other bars, the agent selects the rhythmic pattern that it played in the last time it performed the role now assigned.
In UVCVG , the agents simply exchange the patterns that they chose in the previous state.Then, in UVCVG , possessing all rhythmic patterns of all related agents, the agent can apply the three contextual criteria properly: • The vertical criterion is applied to all patterns received from other agents performing its reference role.
• The horizontal criterion is applied to all rhythmic patterns received from agents of the same role.
• The evolution criterion is applied to the agent's history (i.e. the last played patterns).
Still in UVCVG , the results of the three contextual criteria are combined and sent to the agents of the same role.Then, in UVCVG , for each role, the agents will identify which agent chose the most acceptable pattern.This is done by just comparing the combined result of the contextual criteria.Next, there are two options: • The agent with the best value will go to state 7, where its pattern is committed, being sent to the output.
• The remaining agents will go to state 6, to choose another rhythmic pattern that gives a better combined value for the contextual criteria (as in state 4).In order to reduce computational complexity, not all available patterns are tested, but just rhythmic patterns that fall in a certain window.
Therefore, except by the first agent to have his pattern accepted, agents repeats the cycle of states 3-4-5-6 until each of them chooses a rhythmic pattern that receives the best result (between the remaining agents).The negotiation is guaranteed to stop because, in each cycle, at least one agent is chosen to commit its pattern.
In the next subsection we describe the functionalities provided by the CinBalada system and we analyze how the system may satisfy the requirements provided in section 2.

RESULTS AND DISCUSSION
The CinBalada system was designed to allow different orchestrations (i.e., different percussion instruments playing together) and the user can freely choose which instruments he wants in the performance.Thus, the requirement KK for rhythmic polyphony is fully satisfied.
Regarding the requirement for high-level parameterization, the system provides the following parameters: • 1TEJGUVTCVKQP, which was already discussed.
• 4J[VJOKE TQNGU, which the user may assign to each instrument (or agent) in each bar.
• Optionally, the user may choose from which OWUKECN UV[NG the rhythmic patterns for each instrument should come.
• 6GORQ, defined in terms of intuitive labels such as: fast, moderate and slow.
• &WTCVKQP, defined in number of bars.
• /GVGT, characterized here just by the number of atomic beats.
We believe that by possessing a multicultural rhythmic database and by offering rhythmic roles taken from samba batucadas, the system allows the production of some intercultural material as desired.Therefore, we consider that the system satisfies the requirement KKK for high-level parameters.
After setting the parameters of the performance, the system takes 1 or 2 seconds to start producing audible output (sent to the system's MIDI output), thus satisfying the requirement X for response time.This quick response time could be reached even with the continuous negotiation process (for each bar) running underneath.
However, the requirements for diversity KX and the requirement for musical quality K are more difficult to analyze in an objective manner, so we conducted some experiments to analyze them.The experiments are described in the next section.
For the interested reader, examples of outputs produced by the system can be found in the following address: www.cin.ufpe.br/~pas/cinbalada/samples.

EXPERIMENT
Two sets of experiments were conducted to evaluate the system: one for assessing the quality of the system's output and another one for assessing the diversity of the outcomes.Both experiments were done with the same subjects, which we described in the next subsection.Then, the two following subsections describe the experiments.

SUBJECTS
Some works suggest that automatic composition systems should be evaluated by experienced musicians [23][27] for two main reasons: they can identify more subtle characteristics in musical samples and they are more inclined to prefer uncommon or novel musical samples.On the other side, music is a universal phenomenon that any person can enjoy.Hence, we believe that the general (non-expert) public should also be involved in the evaluation of such systems.Therefore, people from those two groups were involved in the experiments for evaluation of the CinBalada system.The group of musicians was composed by five people, with 17-year experience in practicing music, on average.For the general public group, on the other side, we chose five people with no practical experience in music or with an informal and recent music education.

QUALITY EXPERIMENT
A quality experiment could be designed to make an CDUQNWVG or a TGNCVKXG (comparative) evaluation of the system's outputs.In an absolute evaluation, users would just rate the samples as absolutely "good" or "bad", while in a relative evaluation they would rate them as "better" or "worst" than some other system taken as reference.
In CinBalada, the absolute evaluation was rejected, because it depends also on the individual quality of the database of monophonic rhythmic patterns (which lack expressivity as explained in subsection 5.1).Instead, we preferred to do a relative evaluation by comparing samples generated from the same database using three different methods for combining monophonic patterns: • Random.No evaluation is used for creating polyphonic patterns -they are simple randomly combined.
• Similarity-based.The rhythmic patterns are combined simply using the chronotonic distance.
The combination with minimum sum of distances (between all pairs) is chosen.
• Role-based.This is the CinBalada method for creating polyphonic rhythms.
The experiment was divided in rounds, were three samples (one for each of those algorithms) are presented to the user.To prepare the samples, six different CinBalada configurations with different orchestrations were created.As a result, six samples (with four to eight bars) were generated by the system.Twelve other samples were also generated for the same orchestrations using the other two algorithmsrandom and similarity-based.The orchestrations used are shown in Table 3.The subjects were not told about how the samples were generated.In each turn, each subject was simply requested to listen to the three samples and then mark in a form the best sample in his opinion.Each subject had freedom to listen to each sample as many times as he wished, before choosing the best sample in each turn.They could also write free comments for each round.
Table 4 shows the general results, considering the two groups of subjects.Subjects displayed clear preference for the samples produced by the role-based algorithm over samples generated by other mechanisms.Only in round 2, the role-based algorithm didn't produce the best samples.Separate statistics for the two groups of subjects are presented in Tables 5 and 6.Although CinBalada's role-based algorithm was the preferred in both groups, it had better results with the group of subjects with experience in music, with exception of round 2. Analyzing the comments written by the musicians about the sample created by the role-based algorithm round 2, they indicate that they didn't like some "empty parts" and the "strange ending".However, these are consequence of the parameters, which defined that the agogo should be mute in some bars and that the bongo should make a fill in the end.Therefore, we understand that the musicians didn't like the EQPEGRVKQP of the samples itself.If this round was ignored, the role-based algorithm would reach 76% of preference in this group.
Finally, an interesting point we would like to highlight in the three tables is how the results are in direct proportion with the amount of information used in each algorithm.The random-based algorithm uses no information and, therefore, exhibits the worst average preference (13,3% in general).The similaritybased algorithm, in its turn, uses an only musical feature and, as result, gets better preference levels (26,7% in general).The CinBalada's role-based scheme, in its turn, uses many musical features organized by the roles' concept and, as a consequence, exhibits the best preference (60% in general).
Therefore, we consider that the experiment indicated that the CinBalada system satisfies the requirement K for musical quality.

DIVERSITY EXPERIMENT
As in the previous experiment, there are two approaches to evaluate the diversity of the system's outputs.One of them would be to evaluate the CDUQNWVG diversity of the CinBalada's output; and another one would be to evaluate its TGNCVKXG diversity.Once again the relative evaluation of the system was chosen and we list here two reasons to do so.The first reason is that we believe it is difficult for humans to evaluate musical diversity in absolute way, especially if the musical material may exhibit some degree of novelty.The second reason is that, the absolute diversity of the system also depends on the database of rhythmic patterns used.Therefore, we elaborated a comparative experiment for diversity.
As a reference for this experiment, we used the random algorithm (described in the previous experiment), because it is the algorithm that can produce the greatest diversity, for any given database of monophonic rhythmic patterns.The experiment, thus, consisted in evaluating the diversity of the rolebase algorithm and diversity of the random algorithm for comparison purposes.
A single orchestration was chosen and eight samples were produced by each algorithm.Each of these two sets of samples were listened by the subjects in two different rounds.As in the previous experiment, subjects had no information about how each set was produced.In each round, subjects were free to listen to the samples how many times they wanted.Then, when he felt confidence to do so, he should rate the diversity of the set as a whole in a scale from zero (identical, no diversity) to 10 (completely diverse).In the end, after rating both sets, the subject should choose the set which exhibited the higher degree of diversity.He could also write additional comments.
Table 7 shows the combined results of the experiment, considering all subjects (musicians and non-musicians).As expected, the set of randomgenerated samples was evaluated with the highest degree of perceived diversity.A more important result, however, is that the subjects perceived a level of diversity in the CinBalada's samples that was not too much low compared to the random samples.The system's samples received a mark that was 72% of the mark received by the random samples.A more surprising result is that one subject (10%) chose the CinBalada set as the most diverse.The separate statistics for musicians and nomusicians is shown in Table 8 and Table 9, respectively.The Musicians perceived a slightly higher difference between the sets, evaluating CinBalada's samples a little lower and the random samples a little higher when compared to non-musicians marks.This is probably due to the fact that musicians can perceive more musical subtleties (as discussed in 6.1).A surprising result shown in Table 9 is that the only subject that mistakenly chose the CinBalada as the most diverse was a musician.This probably happened because subjects made some sort of confusion between FKXGTUKV[ and SWCNKV[ and were hesitant in choosing as the most diverse a set with the most unpleasant samples.A comment written by one subject reinforces this claim: "diversity of not very pleasant patterns".
To sum up, the second experiment shows that the CinBalada can generate some level diversity, not too distant from the diversity produced by the random algorithm.This is true in spite the fact that a fixed set of parameters was used to generate the CinBalada's samples for this experiment.If parameters variations were considered, the perceived diversity could be higher.Therefore, the system satisfies the requirement for diversity KX.

CONCLUSION
We presented the CinBalada system for automatic rhythmic composition, which satisfies five requirements: rhythmic polyphony, musical quality in its output, high-level parameters, diversity of output and fast response time.Experiments with musicians and non-musicians showed that it was successful in satisfying the requirements for quality and diversity, while the satisfaction of the other three requirements were more objectively analyzed on the basis of the design of the system.
In this way, we believe that the system can be a useful tool for experimentation with rhythms that musicians can use to create unusual or novel rhythmic arrangements.However, we believe that greater contributions of the present work are the concepts that guided its creation.It was inspired by interactions between percussionists from different musical cultures that happen in drum circles.To try to reproduce these intercultural encounters, we proposed a model for stylistic conventions of one culture.
We believe that cultural conventions are organized in two levels.At a lower level, a culture is characterized by the percussion instruments used and by the repertoire of rhythmic patterns typically played on each instrument in that culture.The system models this by keeping a database of pre-recorded rhythmic patterns categorized by their original cultures.
At a higher level of the cultural conventions, instruments follow some rules or adopt some behaviors in the performance which are specific of that culture.To model these behaviors and in face of the lack of musical theories to explain polyphonic rhythmic performances, we proposed the new concept of TJ[VJOKE TQNG.We went further and proposed a generic model for rhythmic roles and represented rhythmic roles from Brazilian's batucadas with our model.
The development of the batucada's rhythmic roles also led us to propose two new mathematical measures HQT TJ[VJOKE EQORCVKDKNKV[, which is also a problem not treated in previous works.The measures proposed here are the RCTVKCNFGTKXCVKQP OGCUWTG and the KPVGTRNC[ OGCUWTG.

FUTURE WORK
An additional requirement that could be considered in future researches is the requirement for PQXGNV[.We do have some indications that the system produces novel output in some sense, but no experiment was be done to evaluate that requirement.Another improvement left for future versions could be the use of expressive monophonic patterns, which would make the system's outputs more comparable to human's performances.Expressiveness could also be algorithmically generated, but this is known to be a difficult problem [2].
We think that another very interesting extension of the research could be to create an interactive system to accompany human musicians in a real-time performance.Such system could be useful both as a practicing tool and a tool for live performance.
Although the system only implemented rhythmic roles from samba batucadas, we believe that the model is generic enough to represent rhythmic roles from other cultures.Incorporation of rhythmic roles from another musical culture would involve a musicological study of the culture aimed at identifying the rhythmic roles and the criteria they use.
Finally, in a musicological perspective, the CinBalada system can be seen as an attempt to validate the concept of rhythmic roles, thus communicating Musicology with the field of automatic composition (or IA applied to Computer Music).The success of the system can be considered an indication of the existence of rhythmic roles.However, for a complete validation of the concept, further musicological investigation is necessary.Similar investigation is also necessary to validate the new measures proposed.

Figure 1 :
Figure 1: Alternative notations for the Rumba rhythm.

Figure 8 :
Figure 8: Interplay measure -matches and mismatches between two rhythmic patterns.

Figure 9 :
Figure 9: Pattern B derived from pattern A.

Figure 11 :
Figure 11: State machine of the CinBalada negotiation protocol.

Table 3 :
Quality experiment -orchestration for each round

Table 4 :
Quality experiment -percentage of subjects who chose each kind of sample in each round (musicians and non-musicians).

Table 5 :
Quality experiment -percentage of subjects who chose each kind of sample in each round (musicians only).

Table 6 :
Quality experiment -percentage of subjects who chose each kind of sample in each round (non-musicians only).