Quartet Music GeneratorIntroductionYou can download Quartet Generator and see examples of Quartet Generator music at the bottom of the page in the Examples section. Quartet Generator 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. 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. If the quality is poor, the generation for particular step is repeated. Generator outputs music in midi format 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 processHere 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. Note limits generationHigh note limit is changed during the generation to decrease the possibility and repeating of high notes. Note limit moves up and down in a linear fashion between the special limits (note_max_max and note_max_min) with a customizable step. When high note limit comes close to a high voice, it stops until the voice moves down. Here the high note limit is black and when it stops it is shown gray. You can see more detailed information and listen to music in the Examples section below. Step length generationTo 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 lengths are allowed from the box:
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 is a state. Each step the probability vector to change to all the other states is calculated. The vector looks like this:
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. 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 are multiple of 120 (full measure). You can see more detailed information and listen to music in the Examples section below. Step mode generationMode 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 2 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 must always be between the starting constants (mode_mut_min and mode_mut_max). I usually use only 1 step for less alterations that 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 generationNotes 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:
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:
After the voices that should move are chosen, algorithm starts to move the voices:
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. The following is added to form the cost:
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:
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 are not changing, blue are retriggered. Yellow are affected by "too long note" rule. You can see more detailed information and listen to music in the Examples section below. Step velocities generationVelocities are generated for each note and are based on smooth model and increases for:
The smooth model usually has low range, which ensures that velocities do not change much randomly. See description of smooth model in a separate section below. Note analysisDuring the analysis phase the final melody is analyzed for:
Find and filter culminationsCulminations 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). 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 Temo row): Add chromatic turns and introductionsChromatic 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:
In the figure G is altered down to Gb. C is altered up to C#. 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:
Both chromatic turns and introductions are allowed only when the following conditions are met:
Create arpeggiosCreating 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 voices of the current step are retriggered for longer arpeggio experience. Generate tempoTempo 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:
Generate pausesDuring the pause generation stage algorithm counts the probability of creating a pause. The probability depends on:
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 envelopeAt 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 randomizationBefore 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. About Smooth modelingIn 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. ExamplesHere you can see several examples of the Quartet Generator in action. You can view music analysis only in Chrome. Other browsers are not supported.
Download Quartet GeneratorQuartet Generator 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 |