⬆️ ⬇️

A little more automatic music generation



Recently on Habré we saw several interesting approaches to the automatic writing of music. Let me introduce one more. Immediately make a reservation: I will not use any rules of harmony here. There will be no complicated mathematics either. We solve the problem in the simplest way. If you are not very interested in how this was done, you can scroll down, there are several examples, you can immediately evaluate how the result sounds.



So, we want to write something quite musical.



Where to begin?



Here you can go in several ways - based on the melody or on the chord sequence. In itself, building a beautifully sounding melody is quite a non-trivial task, so let's get along from the chords.

')

How to choose chords?


Obviously, not all kinds of chords should take part in our future composition (yes, composition, not less), because we don’t want the result to sound coarse? Therefore, we come up with a rule by which we choose them. All our chords consist of several musical sounds (notes). From the 12 semitones A, A #, B, C, C #, D, D #, E, F, F #, G, G # we choose, for example: A, B, C, D, E, F, G and we will continue to work only with those chords that can be made from the selected notes.







Let's start the most interesting?



Now we have everything we need to start writing our nettle. Imagine what would have been done in this case, for example, a beginner guitarist who had just learned to take chords and could not do anything else. He takes a guitar or another of his favorite musical instrument and begins to sort through all sorts of combinations of received chords. Sometimes, when he is lucky, he takes a pencil and writes successful combinations of chords on a piece of paper in a cage, and then tries to combine them in different ways. Sometimes he does it.



Approximately in the same way our program should be suitable for the problem. We will lose some short chord sequence to the user and ask what he thinks about this. Then we write down all the estimates obtained and try to collect something worthwhile from this data.



What and how to evaluate?



To begin with, we will have to decide how long passages we should give the user for evaluation. I guess two chords will be enough. So you should build on something from 3 to 5 chords at a time. Just because we do not have an army of people evaluating the sound that would be required for longer sequences. Chord fingering I used guitar. This tool is closest to me.







All is ready?


Suppose we spent the last few days on the training of our program and have an extensive base. How to combine all this to get something really beautiful. Nothing is easier! Suppose we want to get a good sequence of 12 chords. We write some sequence, cut it into many pieces of 3-5 chords. And we have already appreciated every (or almost every) of these pieces! Just add up all the estimates and voila, we evaluated the whole sequence. It remains only to find the sequence with the maximum rating. This can be done in a thousand different ways. I applied a genetic algorithm. Just because it works fast and there are many ready-made implementations for different programming languages.



Melodic part


Of course, the resulting chord sequence itself is not yet a complete work, but if you record it melodically, it may sound quite beautiful. For my first tests, I used a very simple recording method. We take the guitar fingering of the chord, first we record the lower and upper notes on the mill, and then the rest of them are consistently from the bottom up. In general, see for yourself:







Software implementation



Everything described above was implemented by me six months ago, on New Year's Eve. The algorithm in some places was a bit more complicated, but it is irrelevant. Later, a web version appeared in which everyone could help with filling the database. At the moment, the web version is not available due to hardware problems on the server.



Local version: link .

I advise you to run the local version not on the Gervill default synthesizer. From the sound of the synthesizer is very dependent on the evaluation of sequences. The archive contains a file chord_weigths.txt - already a trained base to which you can add your notes (copy from the trainee program window). Nothing is automatically saved.



Work examples

1 , 2 , 3 , 4 , 5 , 6

We listen and enjoy (well, or damn the author as an option).

Anyway, waiting for your feedback :)

Source: https://habr.com/ru/post/185606/



All Articles