Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

How Musical Path Finder works

Ivan Dragolov

June 19, 2022

This article is under development. It is unnished.


Abstract
Musical Path Finder (MPF) is a computer program that generates jazz
solos. The generated solo is based on (1) a set of examples - jazz solos
(corpus) and (2) chord progression on which the solo will sound. The solo
is saved in a midi le. The character of the generated solo is similar to the
character of the solos participating in the corpus. For MPF, the corpus is
what for the jazz musician are the solos he has listened to and studied over
the years. In one session (one program run), MPF generates many variants
of the determined (by the corpus and harmony) solo. As the musician
records several versions (takes) of his solo for a piece. The MPF user, like
the music producer, chooses the best take or the best parts from dierent
takes and combines them to his liking. MPF does not understand the
music it has generated, but the user understands it. The user and the MPF
work as a team, complementing each other. Examples of MPF-generated
solos can be seen on YouTube with the hashtag #musicalPathFinder, for
example on Janah Nilsson's #badSoloChallenge: https://www.youtube.
com/watch?v=f9743OxtGKw

1 How the program works (for musicians)


Initially, the solo to be generated contains at least one user-dened tone. MPF
builds the melody (the solo) tone by tone. The program consists of two main
components: BUILDER and ORACLE. Possible alternatives for the next tone
are oered by an ORACLE that sees the melody built so far and the chord
progression. The alternatives have dierent weights. An alternative with more
weight is more likely to be chosen by the BUILDER to continue the melody.
The weights returned by the ORACLE can be altered according to the user's
wishes. Thus, weights can mix (1) the inuence of corpus examples and (2)
the user's preferences. For example, if the user prefers wider intervals, then
the weights of the alternatives that generate wider intervals can be increased.
So, the BUILDER has avaible weighted alternatives for the next tone. The
BUILDER randomly chooses an alternative (next tone) to continue the melody.
The heavier alternative is more likely to be chosen. The other alternatives
are reserved and will be used if the chosen alternative leads to failure / dead
end. Failure occurs if (1) the selected alternative results in an invalid tone (for
example, a tone outside a predetermined pitch range) or (2) the ORACLE gives
no prediction (no alternative) or (3) all alternatives have failed. The generated
melody is ready when the BUILDER reaches a tone that is after a determined

1
end time (for example 32 bars). The BUILDER saves every successfully created
melody. Building the melody may fail if the user-specied start is a dead end.

2 How the ORACLE works (for musicians)


When the BUILDER asks the ORACLE about the possible alternatives for the
next tone, it gives to the ORACLE the melody built so far and the chord se-
quence. For the ORACLE, this is one situation (case). During his training, the
ORACLE has recorded many situations (cases) and for each of them - what
is the next tone. The situation and the next tone are recorded relatively. For
each tone of each solo that is in the corpus, the ORACLE has recorded one
situation (case) together with the next (after this situation) tone. When the
ORACLE is asked about possible alternatives, it extracts the situation from the
current state of the generated melody and compares it with each of the recorded
situations. If the current situation is close enough to any of the recorded situ-
ations, the ORACLE takes into account the next tone that is associated with
that recorded situation. The tones collected in these comparisons form the set
of possible alternatives that the ORACLE returns in response to the BUILDER.
The greater the closeness between the current situation and some of the recorded
situations, the greater the weight of the alternative (next tone) associated with
that recorded situation. There will be more detailed descriptions in the sections
"How the program works (for programmers)" and "How the ORACLE works
(for programmers)".

3 How the program works (for programmers)


The sections for programmers presuppose the knowledge of some basic musical
concepts. For example: pitch, scale, key, degree (of scale), chord, duration of
the musical note (whole, half, quarter, eighth, ...)
The data structures (lists, dictionaries, sets, ... ) are written in Python
syntax.

3.1 Representation of musical data

In Musical Path Finder, the musical data of a piece is represented as a list


of tones. The tone has (1) time - the moment when it starts, (2) pitch and
(3) layer in which it is performed. The layer is similar to the MIDI channel.
The tone does not have its own explicit duration. When performed, the dura-
tion of the tone depends (in dierent ways 1 ) on when the next tone starts.
The time is in ticks, with 24 ticks per quarter note. The pitch is represented in
semitones above (+) or below (-) the middle C.

1 legato, staccato, non-legato...

2
This example2 is represented as:
[(12, 5, 0), (24, 9, 0), (36, 5, 0), (48, 12, 0), (60, 5, 0),
(72, 17, 0), (84, 16, 0), (90, 14, 0), (96, 12, 0), (102, 14, 0),
(108, 12, 0), (114, 10, 0), (120, 9, 0), (126, 10, 0), (132, 9, 0),
(138, 7, 0), (144, 5, 0)]

If we work only with tones from one layer, the tone can include only time and
pitch. For simplicity, the examples in which no layer is used, the tones will be
presented only as a pair (time, pitch ). Then the above example will be presented
as follows:
[(12, 5), (24, 9), (36, 5), (48, 12), (60, 5),
(72, 17), (84, 16), (90, 14), (96, 12), (102, 14),
(108, 12), (114, 10), (120, 9), (126, 10), (132, 9),
(138, 7), (144, 5)]

Each tone can be considered as a point in 2D time-pitch space.

[(48, 2), (48, 7), (48, 11),


(72, 4), (72, 7), (72, 12),
(96, 2), (96, 7), (96, 11)]

Each tone is unique. Therefore, the melody can be represented as set. Inter-
nally, the melody is most often presented as a sorted list of tones in ascending
order. This is how the melodies will be written in this description of MPF.

3.2 Representation of harmony

The description of MPF chords is similar to that of pop and jazz pieces. Each
chord starts at a certain moment and lasts until the beginning of the next chord.
The chord is described by (1) the scale and (2) the degree on which the chord is
based. The chord Dm can be described as scale: C major, degree: II (second).
The same chord can be described dierently depending on the musical context
- the neighboring chords and / or the melody sounding with the chord. The
chord Dm can be described also as scale: D minor, degree: I (rst). The chords
are grouped according to their harmonic function: T (tonic), S (subdominant),
D (dominant).
harmonic function degree
T I, III, VI
S II, IV
D V (VII)
The chord description for MPF includes (1) the scale and (2) the harmonic
function (T, S or D). So, for MPF chords F and Dm may be represented as
(C major, S) or (D minor, T) depending on the musical context. The internal
2 The begin of J. S. Bach - Invention No. 8 in F major, BWV 779

3
representation of the chord is a pair with the rst item - the tonal basis (0 for C,
1 for C#, 2 for D, ...) and the second item - the type of chord (0 for major T, 1
for major S, 2 for major D, 3 for minor T, 4 for minor S, 5 for minor (harmonic)
D).
scale harmonic function type of chord
major T 0
major S 1
major D 2
minor T 3
minor S 4
minor (harmonic) D 5
For example: (2, 3) means D minor T (tonic), (7, 1) means G major S
(subdominant).
The chords of a piece are represented as a dictionary. The key is the time
when the chord begins, and the value is the chord itself.
The chords

may be represented as
chords = {
0: (0, 1),
48: (0, 2),
96: (0, 0)
}

To Be Continued...

You might also like