I'm playing around with algorithmic composition, and I have the following problem.

I have a melody, a chord progression / scale / both that was used to generate that melody (via whatever method), and a new, completely different chord progression. How can I alter the notes in the melody to fit the new chord progression, while maintaining as much as possible whatever it is that makes that melody sound like it does?

This is what liquid notes (http://www.re-compose.com/liquid-notes-music-software.html) does when you choose new chords, and to my ear it does a pretty good job.

  • Could you give an example of how much the chord progressions change? Do they still stay in the same key, for instance? Jun 2, 2015 at 11:41
  • I'd like to put as few restrictions on the idea as possible. If chord progressions changing to different keys implies different algorithms for altering the melody, fair enough -- but what would need to change? How would the steps be different if the new chord progression is in a different key to if it's in the same key?
    – henreh
    Jun 2, 2015 at 11:44
  • When reharmonizing, you typically don't change the melody you just change the harmony around the melody.
    – Dom
    Jun 2, 2015 at 11:49
  • I know, but I'm interested in this specific problem. I'd like to change the melody to fit an arbitrary chord progression, I know it's possible (liquid notes shows that), and I think it could provide interesting musical ideas (which is why I'm interested in algorithmic composition). What you're suggesting is a related but distinct problem.
    – henreh
    Jun 2, 2015 at 11:50
  • Sounds interesting. There are a few things that can be done to adjust a melody to different underlying harmony, without changing its essential character - if I get time I'll post an answer. Just one other question that would help me, and possibly other people wanting to provide an answer: are you planning to have the chords change in "real-time"? In other words, will different chords be chosen once the melody is already playing - or is this static - in other words, you use this to create music, but not play it back. Jun 2, 2015 at 11:54

2 Answers 2


The short answer is: it depends upon what you mean by making the notes in the melody "fit the new chord progression". You could put any chords with a melody; but it might sound very dissonant some or all of the time! And this would: no longer produce an effect similar to the original relationship between melody and harmony (if you have already composed chords to fit with your melody); no longer produce an effect which displays the usual characteristics of common-practice harmony.

Here's an example:

enter image description here

The top line represents the simplest possible harmonisation for this melody, and certainly what one would consider to be the harmonisation most obviously suggested by the melody. But the use of an Ab Major chord throughout sounds good: very different but good. It gives the typical "horror-movie" effect of the "wrong" harmonisation of a such a simple children's melody. It works for a couple of reasons: the simple melody and use of only one major chord are both easily recognisable elements, even though they produce dissonance; there is still some recognisable relationship between the melody and harmony, the note C for instance is now the major third of the underlying chord, and the other notes (besides the E) all have a Lydian relationship with the underlying chord.

You could have chords below this unchanged melody that would be both more or less dissonant:

  • you could reharmonise this in a fairly traditional manner to use more chords from C Major (or maybe A Minor).
  • you could reharmonise this with chords that fit with the melody in a less traditional manner, but which are not dissonant, for instance by using chords from keys or modes that contain these five pitches, or that are in fact modes of C Major. (For example: F Lydian, D Dorian, F Major...)
  • you could have chords that are extremely dissonant against the melody, for instance a C#7 chord against this melody will produce a highly chromatic amalgam.

The longer answer is: if you want to have your melody retain a "traditional" relationship with the underlying chords (in other words retaining relationships characteristic of common-practice harmony) you will need to change elements of your melody as and when your chords stray from what would be considered a "comfortable" harmonisation.

In order to preserve the identity of your melodic material as far as possible, you should aim to:

  • keep the contour of the melodic line as similar to the original as possible.
  • keep the horizontal relationships between melodic intervals as similar to the original as possible.
  • trying to map chord tones and non-chord-tones in the original melody to chord-tones and non-chord-tones at the same points in your new melody.

Of course, this is easier said than done: and would require a bit of experimentation. It is almost certainly easier to do this on a case-by-case basis, rather than by creating an algorithm, but I like the sound of your challenge, and you may be able to produce rules that create melodic changes you are generally more happy than not, with.

Having pointed out the difficulties with these melodic adjustments, here are some approaches that might work, to produce traditional harmonic/melodic relationships:

  • if two or more consecutive chords can fit within one major or minor key or mode, adjust the accidentals of your melody to also fit within this key or mode.
  • where consecutive chords won't fit into a single key or mode, aim to adjust your melodic notes to be in a key which the underlying chord could be in.
  • while retaining the melodic contour as far as possible, by introducing slightly larger or smaller intervals you can aim to retain the chord-tones and non-chord-tones at the same places within your melody. (For instance, where there is a second in your original melody, you may choose to use a third instead, which may keep chord-tones and non-chord-tones in the same relative positions.)
  • consider transposing the whole melody up or down before making any other adjustments (in other words, start the melody on a different pitch). With a bit of experimentation you may find that such a transposition already makes more of your melody "fit" with more of your chords, before you then have to make other adjustments.

Two really important things to bear in mind:

  • it may be that your melody has quite a chromatic/dissonant character to start with: in this case you will need to assess whether you want your changed melody to retain a similarly chromatic/dissonant relationship with any chord changes, or whether you want to "smooth" out these dissonances to create more consonant relationships.
  • This is probably the most significant aspect of what you are trying to do: if your changed chords don't seem to have an easily recognisable relationship horizontally, it is likely that any changes you make to your melody, in order to make it "fit" with your underlying harmony, will result in a melody that fails to retain important horizontal relationships. (Yes, I know this is really obvious!) Put most simply: if your chords jump from key to key, your melody is likely to be similarly disjointed as it jumps from key to key.

As I see it, there is one other big choice that you should probably make: when changes are made to your melody, do you then continue your melody wholly changed in relationship to the one changed note (e.g. if a note is flattened by a semitone, do you continue with every other note "transposed" down by a semitone), or do you continue as you would have done, with just the one note changed? Again, this is likely to be dependent upon which of these will allow the most notes to "comfortably" fit with the underlying chord or chords.


Although your chord changes could be arbitrarily complex, let's stick with the melody and new chord from the example above, even though this represents a very simple case. (The original melody is harmonised with a single major chord and the new chord progression consists of a single major chord, too. So a trivial solution is to transpose the whole melody down a major third, to start on Ab.) If we take the Ab Major chord as our tonic chord (we may as well - it is the only chord!) we can adjust the pitches to be in Ab Major:

enter image description here

This works well; in particular, because the first two bars still have chord-tones in the same relative positions. The Gs in the third and fourth bars sound less good: they are not especially dissonant, but would sound better if they were adjusted to chord-tones - this suits these longer notes, as the melody comes to rest on them. Although neither of the following solutions (bars 3-4) are as effective as the original melody, they do work better for having the Ab chord-tone for the minims (personally I prefer the fourth bar):

enter image description here

The example above would sound okay with Ds instead of Dbs, too. This could be interpreted as Ab Lydian, or as being on chord IV of Eb Major.

But let's try a more difficult example. The chords below were chosen at random (not that interesting to know how, but it was fair!):

enter image description here

Okay, pretty weird chords - but that's a random choice for you! This works fairly well as an example though, because as it stands the melody certainly doesn't seem to fit well with the underlying chords.

At first glance, Bbm and Eb are fairly closely related (they could both be in the related keys/modes of Ab Major, Bb Dorian, F Natural Minor...), so we may be able to transpose our melody to fit better over these chords. Here are a couple of ways to change the melody to fit over the first two chords. Both retain (mostly) the position of chord-tones and non-chord-tones. The first retains the repetition of pitches bar-to-bar, but changes the intervals (and implies Eb7); the second retains the exact intervals, but uses a sequence for the second bar (i.e. the notes are transposed up a tone):

enter image description here

Both of these solutions have their merits, but trying these out with the next chord, I think the second will work better:

enter image description here

Here we manage to keep the exact intervallic relationships in the third and fourth bars as are in the original melody (and the repetition). In fact, the third bar has exactly the same relationship between melody and harmony as the original. Also, the fourth bar has the same relationship between melody and harmony as the second bar of the altered melody (again implying a 7th chord).

But how good does it sound? Well, to my ears, it sounds pretty bad. It might be the best solution possible, but not necessarily what I would compose if given a free choice of underlying harmony. In other words, the chord progression sounds a bit weird, like it doesn't quite work, and so it is no surprise that the altered melody sounds like this too...

A few closing comments: Here I've just given one simple example. But the possibilities are of course endless (quicker changes of chord; different chord types/extensions; more complex melodic lines). And this is the essential problem: here I've come up with just one "bespoke" solution for one melody and set of chords - this has involved a certain amount of reasoning about the melodic and harmonic materials involved. As these will inevitably be different in each case, I'm not sure whether an algorithmic solution will be possible. And if it is, it won't be easy to find!

Lastly, if you haven't already, you need to make sure you have a good understanding of common-practice harmony and how to approach harmonisation and reharmonisation of melodies (essentially what you are doing is very closely related, even though it may seem like the opposite). Also, reading up on fugal technique, particularly about how real and tonal answers are adjusted to fit different harmonies and key centres, may be of use.

  • If I were embarking on your project, I'd post several melodies online and several chord sequences of the same lengths, and then ask people to make melodic changes to fit melodies to chord sequences. You could then analyse this material to look for common approaches. Music.SE is almost certainly not the place for this, though, as the various solutions would necessarily be subjective. Jun 2, 2015 at 16:08
  • Thank you for such a fantastically detailed answer. You mention that there are a lot of choices to be made about the direction in which to take the melody based on the new chords, which it seems to me boils down to choosing a set of relationships to preserve over others. Some approaches retain contour, but therefore might not retain specific intervallic relationships, while another approach might retain intervallic relationships between successive notes but not retain the same character in relation to the underlying chord progression.
    – henreh
    Jun 4, 2015 at 13:08
  • I'm quite interested in how each method distorts the melody, so I am going to implement all your approaches and experiment with how they sound.
    – henreh
    Jun 4, 2015 at 13:08

In my other answer, here, I suggest ways in which a given melody could be adapted to "fit" a different chord sequence. This approach is likely to feel contrived and yield unsatisfactory results though, particularly where the new chord sequence has very different horizontal relationships to the original chord sequence.

So, I thought it might it might be useful to approach this process from the opposite viewpoint, in order to suggest why such an approach is likely to be ineffective, rather than looking at how such a process might be achieved.

An unaccompanied melodic line will usually imply one or more harmonic accompaniments. How closely a melody is tied to a specific implied harmony will depend upon a number of factors:

  • whether the whole melody, or large parts of it, use the notes of a single key or mode.
  • whether figurations within the melody strongly outline chord-tones.
  • whether figures within the melody strongly imply cadential figures.

Even if a melody remains within a single key or mode, it is likely to comfortably fit with a particular series of chords drawn from this key or mode and not just any chords from this key or mode. Even if new chords are selected only from the same key or mode, this is not likely to harmonise the melody well without adjustments. And these adjustments may well cause the melody to function less effectively. Put quite simply, a given melody which sounds "good" is likely to work because it also implies a coherent chord sequence, with coherent phrasing and cadential points.

It is true that a given melody can usually be reharmonised in a number of ways. However, any chord progression that effectively reharmonises a given melody will not simply be any arbitrary series of chords, but will be related to the initial harmony in some way:

  • the chords may be extensions or alterations of the original chords (e.g. C6 instead of C).
  • the chords may be commonly used substitutions, for instance: tritone substitutions; extra chords in cadential figures (ii-V-I replacing V-I, for example); chords sharing one or more notes with the original chords (for example, Em replacing C).

Melodic lines using fewer pitches are likely to be more conducive to being reharmonised easily, as they are likely to less strongly imply just one specific chord at a time. The following three note melody is a good example:

enter image description here

(Okay, these are only simple reharmonisations, which don't harmonise many of the melody notes as non-chord tones or with any extended chords...) The following example shows both: how easily one can reharmonise an even simpler melody (just one note!); how one can use extended/altered chords to provide more options by making more chord-tones available:

enter image description here

Because the melody above consists of just a single pitch, it doesn't strongly imply a particular chord progression; it could allow a whole range of different harmonisations easily. Crucially though, the chords here still have a self-contained coherence, largely provided by the descending chromatic root notes - they are not arbitrary.

Whether a given melody strongly implies a certain harmonisation or not, there are always likely to be a limited number of harmonic progressions that fit well with it. For this reason, if an arbitrary series of chords are chosen to harmonise a given melody, it is likely that significant changes will need to be made to the melody, and these may significantly affect the character of the melody. This is particularly likely to be the case where an arbitrary chord progression lacks its own coherence (provided by, for instance: common key/mode; established cadential patterns).

Even where a chosen chord progression does have its own self-contained coherence (it works as a chord sequence on its own), significant changes may need to be made to a melody in order that it fits with such a chord sequence. In some cases this may be achievable by only making a few changes to the melody, so that it strongly retains its character, but in other cases the melody may no longer work well, as it moves too far from its original phrasing, contour and harmonic function of each of its notes.

If one is not concerned with trying to stick as as closely possible to the original melody, this process would be more effective: in this case one could choose shorter elements from the original melody to be used with the new harmonic accompaniment, be these: short figurations, motives or even particular intervals. This is, after all, a well-used compositional technique, be it in a Baroque fugue, a Wagner opera, a serial composition, or any other compositional work built upon internal motivic relationships. In this case, the success of such an approach is likely to be based as much upon the effectiveness/coherence of the chosen harmonic structure (chord sequence), than on how one then uses melodic fragments with it.

  • This is an interesting perspective, and I think to an extent you may be right. One of the reasons I put in the constraint of "as closely as possible" was to try and elucidate what exactly defines the character of a melody in relation to its underlying harmonic progression, and whether it's possible to preserve that. Conversely, I'm also interested in non-close adaptations since I think in many cases it could serve as an aid in creativity by suggesting novel compositional ideas (which is one aim of my algorithmic project).
    – henreh
    Jun 4, 2015 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.