⬆️ ⬇️

Muzz car tuner

How to make music? Where is it ready to take in order to, for example, voice the video on YouTube (and so that the copyright infringement label does not appear there)? How to write this very music when no motive climbs into your head? Where to get ideas about the new melody, at least about its excerpts?



I worship the great impartial randomness. He will never compose melodies based on those already heard last week, will not, on the basis of his tastes, single out some styles of music and crush others, he has no emotions and mood. He just takes and makes music of all styles, all directions, all sizes (within the limits of the possibilities incorporated in the algorithm).





')

And my story will be devoted to an algorithm that works on the basis of such a random house, and a corresponding piece of software that plays freshly-written melodies directly into columns or saved to MID files.







He was called Muzz.



Initially, the idea was to create a ringtone generator for the PaintCAD 4Windows graphic editor. As planned, it was supposed to be one of the additional features that allows you to generate and play speakers / headphones with something relaxing for comfortable drawing in the editor. But as a result of several attempts to create melodies of isolated styles - the Muzz algorithm was brought into a universal form, generating completely random (within its capabilities) music of various styles.



Examples of the resulting music ( MIDI files )



Sad circus waltz

Mysterious Waltz

Some gas sector without choruses

Rock

Flute and music box

Bells

Tragic choir

And one more light rock



How to "compose" music programmatically



So, if you generate a random sequence of notes, then with some probability it will be one of the melodies already invented, or even those that will be invented in a year, two, five, ten years.



Similarly, by the way, with pictures - if you generate a picture from random pixels, then with a penny probability you will receive a picture that has not yet been drawn or a frame from a film that has not been taken off with an image of an unborn actor. But even in the simplest black and white chromaticity of a picture, one pixel is 1 bit, and you have to generate a decent number of pixels, for example, for a picture, 100x100 is 10,000 pixels or 2 ^ 10,000 image variants. From this it is clear that the probability of getting a beautiful picture is very, very small.



And in music, everything is a little simpler - each note is a number within a few octaves. For example, in MIDI, each note is a number from 0 to 127.



By generating a random sequence of notes of the same length - we get the musical garbage. To get something more beautiful - you need to think: “what is music?”.



What is it?



In the Muzz algorithm, I thought and divided the music into three parts:



Drum rhythm - we will compose pop music, rock, something with a clear rhythm. Sometimes the rhythm may not be included in the final result.



Accompaniment - each time a certain accompaniment style is played, according to the current chord. To do this, the algorithm first creates a queue of chords. The accompaniment is played by a specific instrument.



Melody - at the same time one note is active, notes can have different durations. There may also be pauses of various durations. The notes correspond to the current accompaniment chord. The instrument can be either the same as the accompaniment or another.



Algorithm input parameters



To get something away from “cacophony” and closer to the “masterpiece” - you need to set certain initial conditions. And shape the music according to them.



The following parameters (initial conditions) were chosen as specified by the user and input to the algorithm:

1) Color: sad, normal, cheerful.

2) Size: from 2/8 to 8/8. For example, 3/8 is a waltz, 6/8 (i.e., 3/4) is also a waltz, but long, and 2/8, 4/8 or 8/8 is ordinary pop, rock, etc.

3) A set of instruments: in MIDI there are 16 sets of instruments (8 each, for example, keyboard or brass). When creating music, you can take instruments for melody and accompaniment from one set (as if a violinist and a bass violinist are playing, or two pianists). But you can take from different.

4) The presence or absence of drums

5) Availability of entry

6) The number of couplets (from Minimum to Maximum value, the algorithm randomly selects between min and max)

7) The presence of choruses

8) The presence of a conclusion .



This is how they are selected and edited in the window:





Generation order



This service window with the “user-friendly” interface is not shown to anyone except those who run PaintCAD 4Windows with the -muzz option on the command line. It is assumed that the user simply starts the Muzz composer for playback and listens to music without seeing any of its interfaces (see the section Managing the Composer at the end of the article). But the generation algorithm uses just all these flags, fields, engines, and other components in their work:







In the middle of this window are three fields: "Source", "Prepared" and "Melody".



Script No. 1 is recorded in the “Source” field. It contains both chords and service commands (“switch the rhythm of the drums,” “change the instrument,” “change the pattern of the rhythm of the melody,” etc.).



Then cleared of service teams, he enters the list of "Prepared" - this turns out Script No. 2. There lies a pure chord sequence. One chord for one measure of music.



In addition, when recording blank chords in the “Prepared” field, the melody itself is generated and the notes are written in the “Melody” field using “N = size” per beat as script No. 3. If the size of the created melody is 8/8, then 8 notes will be created for one chord, if 3/8, then there will be 3 notes for one chord.



Choosing a drum beat



The generation algorithm must select the drum rhythms for the input parameters, verses, choruses, and conclusions. Were laid several rhythms under the size, a multiple of two. The algorithm simply chooses one of them, trying to make the intro and verses on the strength of the rhythm less / equal choruses. The possible styles are shown in the “Drum Style” frame (SDS command): Rock 1, Rock 2, Calm Rhythm, Energetic Rhythm .



There is also a “Exit” jackdaw with a field with the number A - this is the fifth style, which is mixed into any of the four above-mentioned ones, with an accent in the form of hitting plates at the end of the beat (A = 0) or even in the form of hitting plates and several drum beats (A = 1). The specific style of the “exit” (A = 0 or 1) is chosen randomly when generating each next melody.



And also the “patch” number - if you put 16 there, then the snare-drums will be powerful (from the power-set). Depending on the volume and aggressiveness of the accompaniment and melody instruments - sometimes the algorithm selects powerful drums.



When the melody is 8/8, the rhythm is played entirely, the other dimensions break the rhythm, starting in the next measure from the first note. At the same time, the rhythms are fairly easy to adapt “for the waltz” or for the exotic sizes 5/8 or 7/8, and everything seems to be excellent by ear.



Choosing a set of chords by color



Since If there are three colors of the melodies “Sad”, “Normal”, “Merry”, then each of them has its own set of chords, from which the algorithm chooses and adds chord sequences.



Sad:



Am, E, Dm - reference, used for both melody, and for the introductory and final chord of verses / choruses / introductions / conclusions



E7, F, G, C, A7, A # 7, B7 - regular, used together with the reference for the generation of intermediate chords in verses / choruses / introductions / conclusions



E6, Dm6 - very sad chords, rarely used, but aptly.



In addition, they are supplied with a table of links . It is made to eliminate the non-sounding chords in the song. The table of connections for sad chords recommends:

after A7 - take Dm as the next chord,

after A # 7, B7, E6 and Dm6 - take the next chord E.

The algorithm fulfills these recommendations for any color of a melody only in 50% of cases so that an “outlet” remains in the remaining 50% of cases to generate something unusual and extraordinary.



Normal:



A mixture of major and minor chords in the bite with septa.



Am, E, Dm, G, C, F are the reference ones and they are the main ones.



A7, D7, E7, C7, G7, F7, A # 7, B7 are rarely used.



Link table:

after A7 - take Dm as the next chord,

after D7 - take the next chord E,

after E7 - take the next chord Am,

after A # 7, B7 - take the next chord E.



Merry:



Majors as they are.



C, F, G - supporting

C7, F7, G7 - basic

D - rarely used



Link table:

no recommendations



Replays



To create the same couplets and choruses throughout the entire song, the Lx script command was introduced, allowing you to copy the chord number x and the corresponding melody notes to this place. For example, if there are 4 chords, then they are easy to repeat as follows:

1 Am

2 G

3 C

4 E

5 L1 (Am will rise here)

6 L2 (G will stand here)

7 L3 (here comes C)

8 L4 (Am will rise here)



When generating chords - each new chord can be taken together with a melody from another chord, and in any order, for example:

1 Am

2 G

3 C

4 E

5 L3 (here comes C)

6 Dm

7 L1 (Am will rise here)

8 L5 (here comes C, previously copied to the fifth line)



Thus, a sample of the intro, verse and chorus is formed. The second entry / verse / chorus refers to the first pattern and when generating the “script number 2” they turn from Lx into normal chords (and the melody is dragged from the first pattern by copying).



Selection of tools



For accompaniment and melody you need to choose instruments. In MIDI, in my opinion, there are quiet instruments, loud instruments and curved instruments. A table was made at the hearing, where 0 is a quiet, 1 is a loud, 2 is a curved instrument. We heard clean sounds from the GM.dls database supplied with Windows. Maybe on other bases the “crooked” sounds are not so crooked, but we are counting on the mass consumer listening to midi with this standard base.



Here is this table of tools.
Instvol: array [0..127] of Integer = (

1, 1, 1, 1, 0, 0, 0, 0,

0, 2, 1, 1, 0, 2, 1, 0,

1, 1, 1, 1, 1, 1, 1,

0, 1, 1, 0, 1, 1, 1, 2,

1, 0, 0, 1, 1, 0, 1, 1,

1, 1, 1, 1, 0, 0, 1, 2,

1, 2, 0, 0, 1, 0, 0, 2,

1, 1, 1, 0, 1, 0, 1, 1,

1, 1, 1, 1, 1, 1, 1,

0, 1, 0, 0, 2, 2, 0, 0,

1, 1, 0, 2, 1, 0, 2, 1,

0, 2, 1, 1, 0, 2, 1, 2,

1, 2, 1, 1, 2, 1, 1,

1, 1, 0, 1, 0, 1, 1, 0,

1, 1, 1, 1, 1, 1, 1,

1, 1, 1, 1, 1, 1, 1

);



The algorithm tries to choose instruments for the choruses louder than for the couplets. He also tries to avoid crooked instruments (although not 100%, to sometimes create a melody with an unusual sound).



The last two fragments of the table with 8 instruments each are percussion (Percussive) and sound effects (Sound effects, whistles, applause, screams, shooting, etc.), they are not used at all for accompaniment and melodies. But just in case the table has been added too.



Instruments are chosen separately for intro, verses, choruses with an increased probability of being the same for all these parts of our melody. The selected values ​​are set by the SAN (SetAccompNumber) and SMN (SetMelodyNumber) utility commands in script No. 1 at the beginning of each part of the melody (for example, “Am: SMN30: SAN40”).



Choosing an accompaniment style



At the moment there are 6 styles of accompaniment in Muzz, and the algorithm chooses them randomly for intro, verses and choruses with an increased probability of not changing them between intro, verses, choruses. These styles lie in the "Style of Chords (SAS)" frame.



Using these styles, you can generate a guitar song “Wait, steam engine, do not knock the wheels” (if you are lucky, an acoustic guitar will be chosen as the instrument, and the drums will be skipped) or more rigid rhythmic melodies or, on the contrary, relaxing tropical rhythms.



Ringtone generation



As mentioned above, when adding a clean chord to the script # 2 “Prepared” - in parallel with it, N notes or pauses are recorded in the script # 3 “Melody”, where N is the musical size from 2 (this is 2/8) to 8 (this 8/8).



At the bottom of the window there are a lot of checkboxes randomly set when each new tune is generated.



Notes can be selected randomly from the gamut of the current chord of the accompaniment; when the checkbox Leave 1,3,5,7 notes from the gamma is turned on, only these four notes (first, third, fifth, seventh) from the gamma can be selected, all the bars can also be started from the main first note of the chord (checkbox “Start all bars with acc.notes”).



Also for parts of the melody (intro, verses, choruses) a random arrangement of notes or an arrangement on the pattern of 8 digits of the “00100101” type is chosen. Where 1 - there must insert a note, where 0 there is a pass. Thus, sometimes the algorithm makes intro melodies, verses and choruses with a certain rhythm. The “By sample (P):” checkbox and the field next to it are responsible for this, and the “Pxxxxxxxx” service command (or simply “P” if you need to disable the melody according to the sample) is in script No. 1. The sample itself in the course of generation is created in a random way, so the rhythm can be anything.



If the sample is not specified, the choice of “insert a note or pause” is made by the algorithm, taking into account the “Filling%” engine, located in the lower part of the window. Filling is also set randomly for each new melody (from 20 to 40%).



Melody tempo and transpose



So that the melodies do not sound the same at the same frequencies - the random factor influences the tempo (time of one tick, playing one note) specified in the field “Pause, ms (ST)” in milliseconds, as well as transposing the entire melody along with the accompaniment to the number of semitones indicated in the "+ halftones" field (it is selected randomly from 0 to 5, so that the sounds do not run far upwards).



Muzz window after generation



Here it is - the first script is generated, and on its basis - script â„–2 (chords) and â„–3 (melody):







Management composer



The control interface is a simple subsection of the Extra menu in the paintcade.



The horizontal menu in the paintcade is hidden by default (so that it does not interfere) - press “zero” on the keyboard to show it (or use the “menu” button in the upper left corner of the window under the brush icon).







To start the composition and playback, click on the Play menu or Ctrl + P. During playback, the selected color of the song, the current measure and the number of measures are displayed on the status bar of the main window of the paintkad:





To stop playing - press the same item (or the same shortcut). The next start of playback is a newly generated melody.



If you like the playing melody and you want to keep it as a souvenir - during playback, select “Save the played melody in MID” (or simply press Alt + P ). At the time of saving, the playback will be paused and continued only after saving (at the same place where the stop was).



If you want to specify which melodies to generate and play, their color, size and other parameters - select the “Settings” item in the menu or press “Ctrl + Shift + P” . The settings are saved after exiting the paintkad and will be loaded the next time you start the paintkad.



If listening to the melodies in the paintkad does not suit you, there is no time - you can quickly generate from 1 to 100 melodies and save them to MID files in the selected folder, and then manually click the files, listen, delete the unloved ones. This will help you point "MIDI-blaster" (or the keyboard shortcut Shift + P ):





Where to put all these MIDI songs?



From MIDI songs you can use any music editor (for example, FruityLoops with LSD plugin) to generate MP3 files, and then use them at least for voice acting on youtube, even in your own games as musical accompaniment.



You can also use them as a basis for creating your own compositions - all received MIDI files can be opened with any MIDI editor, for example, Cakewalk Sonar. Inside the MID file, each batch of “drums”, “melody”, “accompaniment” lies in a separate track. The change of instruments within a track is set by events (“events”, see the vent list), so if you like, you can cut out any fragment from the received music, take events of the instrument’s task and drag it off to your song.



I want to listen / generate melodies



1) Download the latest version of the free graphic editor PaintCAD 4Windows 1.2.2 via the link blackstrip.ru/pcw.rar (10 Megabytes). Unpack to an empty folder.



2) Run paintcad.exe



3) Press Ctrl + P to start / stop the Muzz composer until he gives you a normal melody. Or the other shortcuts mentioned above. Or press "0", and then in the menu select "Extra" - "Muzz Music Generator" and there the corresponding item.







Perspectives



Now, simple rhythms of 8 ticks per beat are used as drum rhythms. Therefore, there are ideas to launch parallel clocking of 32 ticks per clock. And use randomly generated sequences of rhythms, where there is a clear rod (for example, 1 beat every 8 ticks), and the rest is spread over randomly. Then you should get hip-hop rhythms and other unusual rhythms with floating accents.



And the chord link tables shown above are not perfect. It would be nice to have for each previous chord a set of probabilities on the formulation of the next. Then you can scan your work (manually listen to and calculate where and how many chords, collect a set of chords from them, see what begins and how each verse ends, chorus and loss, etc.) of any musical group, and derive the general formula that “After Am, they have Dm in 40% of cases, and G in 10% of cases,” and so on for all the chords in the set. This will result in a cloud of chords with probabilistic connections among themselves, peculiar to the creativity of this particular musical group.



And then, probably, it will be possible to choose “I would create a couple of songs of Aria, a couple of songs of Agatha Christie, and one from Prodigy”.

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



All Articles