Quartet Music Generator

You can contact me by email: rualark at gmail.com

Quartet Music Generator (v2)

Download this article in Word format

Contents

Introduction

Generation process

Note limits generation

Step length generation

Step mode generation

Step notes generation

Creating diatonic movement

Step velocities generation

Music analysis

Find and filter culminations

Add chromatic alterations

Create arpeggios

Generate tempo

Generate pauses

Apply velocity and tempo envelope

Final time randomization

Creating reprises

Music conversion

About smooth modeling

Full music generation cycle

Examples

Download QGen2

Introduction

Quartet Generator v2 is the new version of Quartet Generator. This is the absolute music generation software. Absolute music (sometimes also called abstract music) is music that is not explicitly "about" anything. It is intended to be appreciated without any particular reference to the outside world. In my opinion there is a subtle difference between the music, that is not explicitly "about" anything and the music, that is not for listening at all. The goal of the project was to create the absolute music generation robot, using a lot of convenient music rules and simulating performer's habits. Robot's basic algorithms used for music generation were aimed at infinite developing melody line, always developing and dynamic, but not going anywhere in particular. Later additions of envelopes, reprises and parts resulted in more structured music, yet keeping an infinity touch.

Example of QGen2 in action is Rhaos - Western Train Suite.

Quartet Generator v2 generates music in steps, where step is at least one note changing. Generator uses voices, which limit the number of notes that can sound at the same time and also the number of notes that can change at a time. There are 6 voices in the figure.

You can download Quartet Generator v2 (QGen2) and see examples of Quartet Generator v2 music at the bottom of the page in the Examples section.

Quartet Generator produces music based on the random numbers with uniform distribution. During the generation of each step several rules are checked and the quality of resulting music is analysed (for example, good quality is no or little dissonance intervals). If the quality is poor, the generation for particular step is repeated until good quality is achieved.

Generator outputs music in midi format (which can be imported for example into Sibelius to see sheetmusic) and also shows graphical representation of the generation process, where many variables are shown for each step (see Examples section for details):

Algorithm is highly customizable. It needs more than 300 starting constants to be set to run. But you can always use default values instead.

Generation process

Here is the flow of the generation process. The "Generate one step" process is repeated for each step.

All the stages of generation are described in separate sections below.

The result of multi-part generation, including reprises, may look like this (2 parts are shown for example):

Each part is generated independently. Only the mode is usually transferred from the end of the previous part to the start of the next part to avoid unexpected alterations. Each part may have its unique set of constants or some predefined collection of constants, called Style. For example, for generation of West Train Suite, the following structure of Styles was used:

Part Style
Part 1 Melodic
Part 2 Fast
Part 3 Slow
Part 4 Fast
Part 5 Dissonating
Part 6 Slow
Part 7 Melodic

 

Note limits generation

High note and low note limit is changed during the generation to decrease the possibility of repeating very high and very low notes.

Note limits move up and down in a linear fashion between the static limits (note_max_max and note_max_min, note_min_max and note_min_min) with a customizable step. When a note limit comes close to a voice, it stops until the voice moves away. Here the note limits are black and when they stop, they become gray. You can see more detailed information and listen to music in the Examples section below.

Step length generation

To generate step length a finite-state machine is used. Each note length is represented as the length of time a note sounds (note sounding time). The following note length groups are allowed from the box:

Note length Note sounding time Minimum repeat count
60 1
30 2
15 2
45 + 15 1
15 + 45 1
20 (each note) 3 (each note)
24 (each note) 5 (each note)

Minimum repeat count shows the number of steps the length cannot be changed if it was selected. This prevents complex syncopation and rhythm shift.

Each note length group is a state. Each step the probability vector to change to all the other states is calculated. The vector looks like this (example for some particular state):

Next state Probability to change to this state
15 33%
20 30%
24 15%
30 7%
60 15%

Then random number is generated with uniform distribution between 1 and 100. Numbers from 1 to 33 mean changing to state 15, numbers from 34 to 63 mean changing to state 20 and so on. This guarantees that changing the particular state has the probability from the vector.

When algorithm approaches the end of the piece, probability array of lengths may gradually change to a different one. I usually increase probability of long lengths and decrease probability of short lengths. This leads to a more stable ending, even if chords are not tonic.

The result of the generation can be like this. In the time row you see the length passed from the begining to the start of the step. Green cells represent length, that is multiple of 120 (full measure). You can see more detailed information and listen to music in the Examples section below.

Step mode generation

In QGen2 only major/minor keys are used. They are called "modes" because algorithm does not provide any preference to any of the 7 notes of the mode. In CityGen algorithm you can see use of non-major/minor modes.

Mode generation is pretty simple. The starting mode in my models is usually C major, but you can set it anything. Each time a number of measure is passed (I use step of 4 measures), the probability to change mode is checked against random generator. If it wins, the mode is changed forward or backward the circle of fifths. How far the mode goes by the circle is determined by the mode step, which will always be between the starting constants (mode_mut_min and mode_mut_max). I usually use only 1 step (up or down) for more gradual modulation and less alterations that are added during the mode change.

The result of the mode generation with step of 2 measures, probability of 60% and maximum step of 1 looks like this:

Step notes generation

Notes generation is the most sophisticated procedure of the algorithm.

First the number of moving voices is determined (usually from 1 to 4). It depends on the following probabilities:

  1. Base probability of each number of moving voices (e.g. 63% for 1 voice, 21% for 2 voices, 6% for 3 voices, 10% for 4 voices)
  2. Probability multiplicator for the beginning of each measure (I usually use 50 times increased probability for 4 voices moves at the beginning of the measures) or other positions in measure
  3. Probability multiplicator based on the length of the step. For example, I usually increase probability for 3 and 4-voice movements in long steps and decrease in short steps.

Of course, if there are not enough voices, that can move, the number of moving voices is decreased.

After the number of moving voices is determined, we start to choose, which particular voices will move. I usually use 6 voices, which helps guarantee that there will be enough movable voices if for example algorithm will try to move 4 of them. The problem can be that the voice is smothered between other voices or is pressed to the higher or lower limit and cannot move until the surrounding voices make it more loose.

Determining which voices will move is also a complex random process and it takes the following probabilities into account:

  1. Base probability of each voice to move. The voices do not cross, which means that upper voices are always above the other. So you can increase the base probability of each of your voices to move. I usually slightly increase the probability for the voices 4 and 5 (where voice 0 is the lowest and 6 is the highest).
  2. If on the previous step the voice participated in the discord, algorithm increases the probability for this voice to move in the current step to resolve the discord.
  3. If the voice is smothered between the other voices or between the voice and the note limit, it's probability to move is lowered, usually down to zero.
  4. If the voice moved to a low note in the previous step, it is locked until some particular time is passed (the lower the note, the longer the lock). This ensures that low voices will not move fast and create artificial effect.
  5. If the voice is not moving for a long time (static voice), its probability to move is gradually increased each step, which ensures that music will not be formed only with a fraction of the voices.
  6. You can choose to increase probability for bass voicec to move after culmination. This helps maintain longer culmination experience in high frequencies.
  7. Algorithm has a method to increase or decrease the probability to move of the voices (neighbouring voices), that are close to the voices, which moved in the previous step. If you choose to increase probability, this leads to a more arpeggiated texture. If you choose to decrease probability, this leads to melody making long jumps up and down. I mainly use this method to increase probability of neighbouring voices to move, thus creating a smoother texture.
  8. There is also an algorithm, which can increase the probability of voices, which are close to the voices that moved in the previous step. This can be used to create trills and more smooth melodies.

After the voices that should move are chosen, algorithm starts to move the voices:

  1. First the window, where the voice can be moved is determined. It is usually the distance from the voice to the upper voice (or the the upper limit, if it is the highest voice) and to the lower voice (or to the lower limit, if it is the lowest voice).
  2. Then the window is cut to prevent long jumps, because the jumps will occur anyway due to voice change. I usually do not allow moves longer then a perfect fourth in a voice. You can choose maximum move length for each pitch. For bass voices (below some specific pitch - I usually use A3) I usually increase maximum move length to a major sixth. For high notes (above C5) I also sometimes increase maximum move length to a major sixth for longer jumps.
  3. Now the "gravitation" takes effect. It is a special instrument to push notes from the lower and higher limits so that they come to the limits less frequently and do not stay there for long. In QGen2 gravitation is maintained by cutting the movement window above the note (if close to upper limit) or below the note (if close to lower limit) to zero with some probability, which is higher for notes, that are closer to the limits. This cutting leads to that the note can move only in one direction from the limit.
  4. After the limits are chosen, the voice is moved to any note within the limits (notes out of diatonic scales are not allowed at this stage).
  5. There is also a possibility of voice staying on the same note. This may be allowed or disallowed by user. Usually I allow this for 4-voice movements and disallow for 1-voice movements.
  6. Then the movement interval is checked. Moves by a tritone, minor and major 7th, 9th and diminished 9th are prohibited. If they occur, the move is recalculated from step 4. Frankly speaking, they cannot occur if you choose move limit at least to perfect fourth. In the figure above I put this step in the analysis group, but really for optimization purposes it takes place here.

After the above algorithm has worked for all the voices that were chosen to move, program starts to analyse the resulting music. The result of analysis is the total cost of the step. The lower the cost, the higher the quality of music is. This is why the program then tries to optimize the cost by moving voices again and again and recalculating the cost. Each time the program sees the cost lower than any cost of the previous tries, it memorizes the move. If it was not possible to minimize the cost to zero this way, the program chooses the variant with the lowest cost, that was memorized.

The number of tries depends on the number of moving voices. For many moving voices the task is more complex and more tries are allowed.

If during this cycle it was not possible to minimize the cost (to the number lower than first cost limit) with the fixed moving voices numbers, then new voices are elected for moving (dotted line). If during after several iterations of new moving voices election it is still not possible to minimize the cost (to the number lower than second cost limit, which is usually lower that first limit), than the variant with the lowest cost is used.

The following is added to form the cost:

  1. The most important component of the cost is the number and rating of the intervals of dissonance (discords). If the discording notes are not played simultaneously (say, one key on the piano is pressed and the next step the other, dissonating), this number is multiplied by the sounding volume of the note to increase the significance of the loud discords and discords with the notes, that are becoming more and more quiet. Sounding volume is approximated linearly from the initial note hit velocity.
  2. Number of contradicting notes (when note not from the mode is in the previous step or one step before previous and in current step there is note that is chromatically close to that note or close the the note over an octave). These notes usually happen when mode changes.
  3. Number of loitering notes. This is almost the same as contradicting notes. Difference is that these notes can be found e.g. up to 6 steps before current step and loitering notes are mainly analysed for chromatic alterations evaluation (see Chromatic alterations section).
  4. Number of detected parallel, opposite and hidden fifths and octaves.
  5. Orchestral density (prohibiting all voices to move in one direction) is usually not checked when using 6 voices. At least two voices stay on their places, which ensures orchestral density. Anyway, algorithm allows it to be checked.
  6. Long thickenings with 3th and 6th are not checked, because they usually not formed with the random voice movements.

I show the types of notes interaction in the figure below:

On the figure below you can see an example of sounding (audible) note volume calculation. You see that sounding volume of F note initially equals its note hit velocity and then gradually decreases. When E and H notes are introduced, F note is barely audible and the dissonance of F with H (tritone) and E (major 7th) has low quality cost. You can also see that the slope of souding note volume decrease depends on the pitch of the note. Higher notes decay faster, while bass notes decay slower, which is also taken into account in the algorithm. On the figure you can see the most difference in the slope between the E4 and C6 notes. Frankly speaking, linear approximation of the sounding volume is not exact, but it is enough for approximation.

After the note moves are fixed, algorithm starts to decide which notes to retrigger. Retriggering means that the voice does not move, but the note of the voice is repeated in the current step. Retriggering notes usually have lower velocities than normal notes.

When deciding if to retrigger each voice or not, the algorithm takes the following into account:

  1. The voices that moved in this step are not retriggered of course, because it is impossible.
  2. Locked notes are not retriggered to prevent artificial sounding.
  3. Notes that were chosen to move, but did not move to decrease cost, have greater probability to retrigger, especially in the case, when not a single real note move was generated (real mcount=0).
  4. Higher and lower voices may have different probability to retrigger. I usually set lower probability to retrigger higher and lower voices.
  5. At the start of the measure retriggering may have different probabilities. I usually increase retriggering when 4 voices move in the beginning of the measure.
  6. I also usually set lower probability for short steps to retrigger, because when a man plays fast he usually does not play many voices at a time.

Retriggering of each note is independent and in some cases all notes except the moving one can retrigger.

An example of the resulting notes sequence is shown below (mcount is number of changing notes).

  • Orange notes show changing notes,
  • Green notes are not changing,
  • Blue notes are retriggered.
  • Yellow notes have zero sounding volume (have decayed).
  • Black (or gray) notes are affected by "too long note" rule.

You can see more detailed information and listen to music in the Examples section below.

To understand this chart better, pay attention to that a single color column is built above a single note and represents its qualities (yellow, orange, green, blue or black).

Creating diatonic movement

In QGen2 diatonic movement means a sequence of notes moving diatonically along the scale (with or without occasional moves over a third):

You see diatonic movement from F to A, then movement over a third from A to C, then diatonic movement from C to E. Movements over a third are introduced to avoid tritone (F - H in example).

Diatonic movement creation algorithm is used in place of normal note generation algorithm (described in section Step notes generation). First thing to do is to decide when to switch to a diatonic movement creation algorithm and thus start diatonic movement. Every step before note generation possibility to switch to diatonic movement is analysed:

  1. Diatonic movements at the end of piece are usually not allowed.
  2. Diatonic movements of long notes are not allowed (I usually do not allow more than quarter note).
  3. Diatonic movement must not start close to previous diatonic movement (not closer than 10 steps for example). This prevents transfers between several diatonic lines. If you want them, you can decrease this limit to zero.
  4. Diatonic movements are not allowed in low voices (I usually allow starting from the second voice). Also, diatonic movements lower than some minimum pitch are not allowed (I usually use H3). This prevents short and close note moves in bass, which sounds unusual (short) and dissonating (close).
  5. To allow diatonic movement, you need to have at least some minimal space (in semitones) between any two adjacent voices. Diatonic movement will walk from one of these voices to another.
  6. Also, probability may be checked to decrease overall occurence of diatonic movements (I use 50% probability).

If general conditions are met, two separate diatonic movements are simulated between two selected voices (up and down) and resulting music quality is analysed. If resulting music quality is not too low, diatonic movement is allowed and is started. Algorithm selects the direction of diatonic movement, which resulted in better music quality. Of course, diatonic movement walks through a current mode (scale).

Each step when continuing diatonic movement the following is checked:

  1. Diatonic movements must not be longer than x notes in a row (I usually use 4 notes).
  2. Diatonic movement may anytime be randomly aborted with a probability (I often do not use this probability, but it may help to avoid constant
  3. To avoid masked tritones, note may move up to 2 tones (minor or major third). This is done by increasing the movement interval of current note. The resulting note must also be in scale.

Example of resulting diatonic movement (from real algorithm run):

Step velocities generation

Velocities (midi velocities, or volume in other words) are generated for each note and are based on smooth model and increases for:

  1. Note length (usually the shorter the note, the higher the velocity)
  2. Note jump (usually the longer the note jump within the voice, the higher the velocity)
  3. Note pitch (usually the higher the note, the higher the velocity)

The smooth model usually has low range, which ensures that velocities do not change much without cause.

See description of smooth model in a separate section below.

Music analysis

During the analysis phase the final melody is analyzed for:

  1. Music quality (see Step mode generation section)
  2. Locked and smothered notes are detected. Left volume is calculated.
  3. Chords are detected. Chords are used for pause generation. Also chords help to understand voice moves.
  4. Melody character is analysed (tonic, dominant, subdominant). Currently melody character is not used in the algorithm. It also helps to understand voice moves.

For chord detection only sounding notes are analysed. Array of currently sounding notes is compared to a database of chord types, each transposed to all of the 12 possible keys. Currently the following chord types are supported:

  • =C (means only one note is sounding or several notes with octaves between them)
  • C:G (means only two notes, C and G or any other interval, e.g. C:F, C:A...)
  • C, C7, Cmaj7,
  • Cm, Cm7,
  • Co7 (diminished 7), C%7 (half-diminished), Co (diminished),
  • Caug (augmented), Caug7,
  • C7b9, Cmb9, Cm7b9 (diminished 9th)
  • Cad9 (added 9), Cad13 (added 13), Cmad9 (added 9), Cmad13 (added 13)
  • C9, C13, Cm9, Cm13,
  • Csus4, Csus2, C7sus4, C7sus2, Cmaj7sus4, Cmaj7sus2,
  • C57 (C + G + Bb notes), C37 (C + E + Bb notes), Cm37 (C + Eb + Bb notes),
  • Cmmaj7 (minor chord with major 7th)
  • C+9, C7+9, Cmaj7+9 (augmented 9th)

If exact chord cannot be determined (because there is no exact match, e.g. in case of A + G + H triad), the closest match is found. The closest matching takes the number of notes repeated and does not pay much attention to the notes, that are not in current mode, which are usually chromatic alterations. In this case closest matching chord is written in parentheses.

If bass note is different from the chord tonic, it is printed after slash (e.g. Am/E). The color of the chord shows amount of tension that it creates.

Melody character is analysed by counting number of notes, which belong to the character group of current mode (I, III, V notes for tonic; II, V, VII notes for dominant; I, IV, VI for subdominant) and dividing by total number of sounding notes. Then resulting variables are averaged using moving average algorithm (I usually use averaging radius of 5 steps).

Melody character is shown using a 3-color chart, where for each step 3 colored blocks are shown:

  • The more saturated the green block is, the more tonic character melody has.
  • The more saturated the blue block is, the more subdominant character melody has.
  • The more saturated the red block is, the more dominant character melody has.

You can see in the figure that when mode changes from C to G, tonic character in C (C, E, G) becomes subdominant in G (C, E, G).

Find and filter culminations

Culminations are detected when there are no notes higher in range of n steps (n is customizable, I use 26 steps) and note makes a jump at least x semitones (x is customizable, usually 2, but may be 1 to use chromatic turn effect).

Culminations receive rating based on their height. After the analysis all the culminations are sorted by their height and those which are lowest are thrown away. Filtering is based on percentage, which is customizable. For example, if you say to throw away 40% culminations, then if 5 culminations are detected during the whole piece, 2 of them will be thrown away and will not cause tempo changes.

Culminations, that are already stressed by the pause, are also thrown away.

Culminations, that suffer filtering process, receive tempo decrease before culmination and return of tempo to its previous value after culmination (tempo decreased due to culmination is shown yellow in the Tempo row):

Add chromatic alterations

Chromatic turns are introduced by moving the note down chromatically to decrease the pitch change when both notes before and after the changing note are lower. When both notes are higher, note is moved up chromatically. For this to be allowed, several requirements must be met:

  1. Jumps before and after note must be in allowed diapasone (I usually use 2 semitones strict)

In the figure G is altered down to Gb (turn). C is altered up to C# (introduction). D is altered to C# (shift).

Chromatic introductions are created by moving the note down to the next note when the previous note is higher and next note is lower then the current note. When previous note is lower and next note is higher then the current note, current note is moved up. For this to be allowed, several requirements must be met:

  1. Jump after note must be in allowed diapasone (I usually use 2 semitones strict)

As opposed to other alterations, chromatic shifts are created not from the three notes, but from two notes - by moving the second note one semitone to the previous note in the voice. Two initial notes must have an interval of one whole tone between them. The result is three notes going in chromatic semitone fashion.

Chromatic alterations (turns, introductions and shifts) are allowed only when the following conditions are met:

  1. There must be enough room for alteration between the altered voice and the voice in direction of alteration (I usually use 2 semitones minimum)
  2. There must be low loiter raiting. This means that there must be little notes before current step (I usually check up to 6 steps before), which contradict with the altered note.
  3. Chromatic alterations are usually allowed only when one voice is moved to prevent dissonating intervals.
  4. Chromatic alterations are not allowed if length of any note in a customizable window around the changing notes is longer then some customizable length. I usually check one note before and one after to be shorter than 21.
  5. After chromatic alteration all retriggered notes in the current step, that form dissonating intervals, may be deleted (this is customizable).
  6. Notes in the beginning and at the end of the piece cannot be altered (I usually set 25 starting and 25 ending notes). This prevents alterations when mode is not set up yet (in the beginning) and when the resolving strictness is required (in the end).

Create arpeggios

Creating arpeggio is really distribution of the chord notes on the time scale. Arpeggios are created for the chords, that have at least L length (L is customizable, I use 100).

During the arpegio generation the time between arpegiated notes is chosen randomly between minimum and maximum values. Also a slowing down with random tempo can be added (a), if the length of the pause allows.

First the random time offset increase a is calculated, which falls within the available pause time.

All the notes of the current step (which do not dissonate and are not locked) are retriggered for longer arpeggio experience.

To extend the arpeggio experience, a note one octave above the highest note in the initial arpeggio may be added. This is done with some probability (I use 100%) only if the followig conditions are met:

  1. The added super-high note must be lower than the maximum note limit.
  2. The arpeggio step must be long enough so that the added note will not sound like unwanted some noise.

Generate tempo

Tempo generation has an algorithm similar to note velocities generation.

In the figure the colors are similar to the colors in the tempo histogram of the algorithm output. On the histogram you see how much tempo each algorithm subtracts:

The following is used to generate tempo:

  1. Smooth model is used with limited range to ensure that tempo does not stay constant but is not totally random.
  2. Near the long notes and chords (multivoice moves) the tempo is decreased. This is done to prepare the listener to the long notes and chords coming.
  3. When after the longer note goes a shorter note, the tempo is decreased for several steps to gradually decrease and prepare fast note passages.
  4. Culminations result in most powerful tempo decrease and you can hear it in the examples.
  5. First step of reprise gets a little tempo decrease for smoother transition from standard generated music to reprise.

Generate pauses

During the pause generation stage algorithm counts the probability of creating a pause. The probability depends on:

  1. Intervals of dissonance and contradicting notes usually prohibit pauses to avoid stressing the step and to resolve faster.
  2. More long steps have greater probability of having a pause.
  3. Basic standard chords and intervals have greater probability of having a pause over complex chords like diminished, augmented, 7th, maj7 and other.
  4. Chords have more probability of having a pause then single voice melodies.
  5. Parallel, opposite and hidden fifths and octaves may decrease the possibility of having a pause.

The chart shows the probability of the pause with the intensity of the yellow color. If the probability is less than 100% there is always possibility that there will be no pause. Pause is added to step length.

Pauses are added recursively, each time checking the probability, until the maximum value is reached.

Apply velocity and tempo envelope

At the beginning of the piece tempo and note velocities gradually increase to their normal values.

At the end of the piece tempo and note velocities gradually decrease.

Tempo envelope for short melody of 30 notes is shown below:

Final time randomization

Before convertion to midi the start of each note is randomized by 1/15 of the eighth note length for less machine-gun sound.

This randomization is not included in MIDI files generated for music software to allow more exact recognition of notes.

Creating reprises

QGen2 creates reprises for more structured and repetetive music experience. Reprise in QGen2 is repeating notes from previous steps.

First thing to do is to decide if we should start reprise. This decision is done every step before starting to generate anything (see Generation process section):

  1. Do not start reprise at start and at the end of piece. In the beginning of the piece you actually have nothing to "reprise" and at the end algorithm creates music with new characteristics.
  2. Do not start reprise inside len group. Usually reprises are started with new measure. If not, current time is checked to prevent starting reprise off-beat.
  3. Check probability. This decreases number of reprises and leaves more chances for longer reprises..
  4. Prohibit reprise incapsulation. Reprise incapsulation is the situation when a reprise repeats the notes of the previous reprise, thus incapsulation one reprise into the other. You can prohibit this or allow. Allowing incapsulation increases the number of repeats in music and sounds usually more artificial.
  5. Do not reprise constant length passages. If the selected template for reprise consists of notes of the same length (e.g. all quavers), the reprise is prohibited, because it will decrease length dynamics, which usually sounds more artificial.
  6. You can also disable reprising of very long or very short notes, but I usually do not activate these options.

If algorithm decides that it can start reprise, several starting parameters are chosen:

  1. Reprise length is chosen depending on the amount of available free music (by free I mean not-reprised music if incapsulation is prohibited) and probabilities for each reprise length in measures.
  2. Repeat count is the number of repeats of the template (also called repeating sentence). I usually allow 1-2 repeats.
  3. Choose if mode is copied from template. You can make simple reprise, when mode is directly copied from the template. In this case notes, that are copied from the template, do not need conversion. You also have a powerful option of converted reprise, when copied notes are converted to new mode. You choose one of these options by setting if mode is directly copied from the template, or can be changed as usual.
  4. Choose if note volume is copied with notes or new volume can be generated. I usually allow to generate new volume in 100% of cases, because this leads to more realistic sounding, like when playing the same notes performer plays them a little bit differently.

When reprise properties are determined, the reprise starts. Now for each step the following actions are taken:

  1. Find the step in template, which will be the parent of current step. This is done by simply subtracting the reprise size (in steps) from the current step number.
  2. Copy length from the parent step in template. This is done always, until reprise is totally aborted.
  3. Copy mode. Mode is copied only if reprise has this property.
  4. Copy notes. Notes are not copied for finishing X% steps (I usually use 30%) of each repeating sentence to create a new resolution and new preparation to repeating sentence each time. If current step mode differs from template mode, copied notes are converted to new mode. If algorithm cannot preserve enough music quality during this conversion, notes are thrown away and generated from scratch as if it was a usual step (see Step notes generation section). For description of conversion algorithm see Music conversion section.
  5. Copy notes volume. This is carried out only if notes are copied and only if reprise has this property. Also, in the first step of each repeating sentence, if notes are copied, volume is always copied from the first step of the template to avoid dramatic volume increase in case of long voice jumps.
  6. Abort reprise randomly. This option can be enabled with some particular probability per step for experimental sounding. I usually do not use this option.
  7. Abort reprise at the end of last repeating sentence (I usually use position at 40% of steps). As note length seizes copying with this abort, this option allows for some new resolution, but may also lead to unexpected junction of different melodies and textures.

I would say that using reprises makes music both more repetitive and more experimental. If you want more uniform experience, use reprises with caution or do not use them.

When copying notes from template to a reprise, only moving notes are copied to avoid unwanted multivoice move in the beginning of each reprise. Sometimes this leads to crossing voices, when voice that was below, becomes above another voice. In these cases voices exchange ntoes to avoid crossing: lower voice always takes lower note and higher voice always take higher note. To avoid unwanted dissonances, notes that are retriggered due to crossing resolution have decreased volume (I usually use 50%).

In the example below you can see that when repeating a template crossed voices are flipped (each voice has its own color): E note becomes highest voice and D note becomes middle voice. Also you can see that only moving voices are repeated (only middle voice is moving in template). In this case D note is retriggered in the second measure two times (in different voices) and each time it has decreased volume.

Remember, that tempo is generated later and usually is slightly different for each repeated sentence, as you can see in example below.

Example of reprise is shown in the figure:

"Reprise" row shows pink background color for steps that are being used as templates for repeating. Darker pink background with numbers shows steps, where step length is copied from previous template (pink) steps. The number shows how many steps are left before the end of current reprise sentence. If number is bold, it means, that note moves are copied from template steps. If not bold, notes are not copied.

In the example you can see that reprise starts at step 78 by repeating note moves of step 65. Then in step 79 note moves of step 66 are repeated and so on up to step 88. In step 88 only step len is repeated from step 75 (this is noted by non-bold font of reprise number). This happens to allow new notes at the end of reprised music sentence. Then in step 91note moves of step 65 are repeated again.

In this example mode is constant (Eb major). You can see small tempo decreases (light green) at the beginning of each reprise.

Here is how the resulting sheet music of the example look like:

Template steps 65-77 are marked here with measure numbers 90-93. Notes that were repeated from the template steps are marked green. You can see that measure 97 has the same note lengths as measure 93. This is because note lengths were repeated, but new notes were generated for that lengths. Measures 100 and 101 also have different note moves from measures 92-93 and 96-97. Pay attention, that in our case note lengths in measures 100-101 match note lengths in measures 96-97, but this happened by accident. Note lengths in measures 100-101 were generated from scratch, but it happened that they matched measures 96-97. In other cases they can be different.

Music conversion

Music conversion is used when notes are reprised, but the mode has changed and notes need to fall into the new mode. Usual transposition is not used, because it would lead to the movement of notes over long intervals and would create junction problems in places where mode changes. Instead, special conversion technique is used, which allows each note move not further than one semitone.

Conversion algorithm run as follows for each step:

  1. First all notes, that do not belong to the new mode are detected. For each of detected notes two variants of moving one semitone up and one semitone down are checked. If there is no possibility to move up or down a semitone (because note is close to limits or other voice), only the variant of moving in opposite direction is analysed.
  2. Matrix of all possible variants of voice movements is built. For example, if voice 2 can move up and down and voice 4 can move up and down, 4 variants are analysed (2 up 4 up, 2 up 4 down, 2 down 4 up, 2 down 4 down).
  3. For each variant notes are moved and resulting music quality is analysed exactly like in usual music generation algorithm (see Step notes generation section).
  4. Best variant with best music quality is chosen.

Here you can see an example of music conversion from F major mode to Bb major mode (from real algorithm run):

In the figure above, copied notes are green. Notes, that were copied, but converted to new mode, are red. You can see, that 54 measure has not only new notes, but also new note lengths, because the reprise is totally aborted in the end.

About Smooth modeling

In Quarter Generator smooth modeling is used for velocity and tempo modeling. I can tell you that much more profound use of smooth modeling can be found in my City Generator, where smooth models are also used for note pitches and note lengths.

Smooth model works in a step-by-step manner, modeling the second derivative of the target value, then using it to model the first derivative and then modeling the target value.

Here is an example of smooth modeling a value. Important properties of the model is that it produces cycling value without jumps, with changing period and amplitude peaks.

Full music generation cycle

If you want to generate music with Quartet Generator v2, you will need to:

  1. Install Apache, PHP and QGen2 sources
  2. Set coefficients you want in the CQSettings.php and CQSet.php (you can skip this step)
  3. Run QGen2 by opening the index.php in browser. After the music is generated, QGen2 will automatically export midi into file temp.mid and show you the graphical representation of music
  4. Load temp.mid into the DAW of your choice (e.g. Cubase). Do not forget to load not only notes, but also tempo from temp.mid
  5. Load instrument of your choice into the DAW. Currently QGen2 is optimized for piano instruments. You can use powerful piano sample libraries or you can start with simple instruments (e.g. Truepianos VST).
  6. Master and export audio from your DAW (e.g. into MP3).

QGen2 outputs the following files that you may need:

  1. temp.html file with graphical output of the algorithm
  2. temp.mid - main MIDI output file for sound purposes
  3. temp-sib.mid - MIDI output file for importing into Sibelius. This file is not intended to be played. It is optimized for better graphical output. Main difference from the normal MIDI file here is that notes are very short and do not overlap.
  4. Other files (*.log and *.txt) - these files are for debug purposes. You usually do not need them.
  5. When you choose to save your project, all output files are copied into the project folder. Also all php files are copied into this folder, so that you always can find out, which parameters resulted in this particular music.

When generating MIDI files for Sibelius display and printing, QGen2 uses the following notation:

  1. P means pause or fermate. It means that this note should be played longer than its written length
  2. Rx means that algorithm starts reprise and is planning to repeat x last measures.
  3. Chords are displayed (see Chords section), but be aware that really sounding notes are used to calculate chord.

Examples

Here you can see several examples of the Quartet Generator in action. You can view music analysis only in Chrome. Other browsers are not supported.

  1. Short example #1: Listen. See music analysis. Sheet music. File for Sibelius.
  2. Longer pieces can be listened on the Rhaos project page (Train pieces).

Download QGen2

Quartet Generator v2 is a PHP project. To run it you need an HTTP server (Apache) with PHP installed.

You should understand that generation is very CPU intensive. For an example, generation of 100 step music (about 40 seconds of sounding) takes algorithm about 3-7 seconds to run, during which the CPU is used 100%.

Download Quartet Generator source code (180 Kb)

If you want only to change settings, do not modify any files except CQSettings.php and CQSet.php

Thanks

I would like to thank people who helped me designing and developing this algorithm:

  • Alexander Lavrov
  • Sergey Arkhipenko
  • Andrey Koritkin
  • Pavel Jurkin