The MelodySequenceEngine is a SequenceEngine that uses a pattern (provided by the configured PatternEngine) to compose a melody that fits to the song's chords, using a simple composition algorithm which produces pretty acceptable melodies.
The MelodySequenceEngine randomly choses one of the provided "patternEngine" tags and uses it to render a pattern. Then one or more melodies will be rendered using this pattern.
Melodies are composed per distinct chord section, because a melody created for one chord section is most likely not compatible with a melody for a different chord section, as a single chord difference could make the melody sound terrible. For each distinct chord section the number of melodies is chosen randomly and the melodies are generated. These generated melodies are then used in a round-robin manner every time the same chord section appears throughout the song. Until version 0.3, only one melody could be generated per distinct chord section.
As a simple example, consider a harmony that uses the chord sections "A, A, B, A, A, B, ..." (therefore having two distinct chord sections A and B). If the MelodySequenceEngine has chosen to create 3 melodies for chord section A (called A1, A2 and A3) and 2 melodies for chord section B (called B1 and B2), the created melodies will be used in this order: A1, A2, B1, A3, A1, B2, A2, A3, B1, A1, A2, B2, A3, A1, B1, A2, A3, B2. Then this melody pattern is repeated.
For creating a melody, the algorithm starts at a random pitch between the minimum and maximum pitch. Then the pattern is inspected. The wildcard "#" can be used to create a pitch which is on the C/Am scale. The wildcard "+" can be used to create a note that is part of the current chord. For every pattern entry, a random pitch distance is chosen to modify the current pitch, then the pitch is corrected (if necessary) in the same direction to be either on the C/Am scale or to be part of the chord. If the selected pitch distance would leave the range between the minimum and maximum pitch, this process is repeated until a pitch is found within the range. If the pitch distance is 0, the current pitch is taken, unless the pattern has the wildcard "+" and the pitch is not part of the current chord; otherwise a new pitch distance is chosen.
Up to version 0.4, many of the details of the melody creation were hardcoded. Since version 0.4, most of the details can be configured as well as generating a random number of melodies per distinct chord section, which are used in a round-robin manner.
|melodies||-||list of ints||0/1||1,2,2,3||The list of possible numbers of melodies per distinct chord section. Defaults to 1. Available since version 0.4.|
|minPitch||-||int||0/1||-3||The minimum pitch to use. Defaults to -3. Available since version 0.4.|
|maxPitch||-||int||0/1||12||The maximum pitch to use. Defaults to 12. Available since version 0.4.|
|pitchDistances||-||list of ints||0/1||-2,-1,0,1,2||The list of possible pitch deltas to use from one pitch to the next. Defaults to "-2,-1,0,1,2". Available since version 0.4.|
|patternEngine||class||class||1||StringPatternEngine||The name of the PatternEngine implementation to use.|
|patternEngine||-||-||1-n||-||The configuration of the PatternEngine implementation.|
<sequenceEngine class="MelodySequenceEngine"> <melodies>1,2,2</melodies> <minPitch>-3</minPitch> <maxPitch>12</maxPitch> <pitchDistances>-3,-2,-2,-1,-1,-1,-1,0,1,1,1,1,1,2,2,3</pitchDistances> <patternEngine class="RandomPatternEngine"> <patternTicks>16</patternTicks> <patternString><random list="A1,A2,A1,A3,A1,A2,A1,B1"/></patternString> <noteProbability>75</noteProbability> <legatoProbability>0</legatoProbability> <minVelocity>32767</minVelocity> <maxVelocity>32767</maxVelocity> <minActiveTicks>7</minActiveTicks> <maxActiveTicks>13</maxActiveTicks> <offsets>0,0,0,0,0,0,+,+</offsets> <noteLengths>2,2,2,3,2,2,2,1,2</noteLengths> <pauseLengths>2,2,2,2,1,2</pauseLengths> <pitchVelocityCorrelation>100</pitchVelocityCorrelation> <velocityExponent>3</velocityExponent> </patternEngine> </sequenceEngine>