Topic: Algorithmic composition using Pianoteq

I’ve always been in awe at J.S. Bach’s transformation of simple chorale melodies into fugues or other types of counterpoint, mostly in his vocal works, as well as the outstanding harmonizations he made of those melodies.

There is a data base of over 400 of these harmonizations in the form of similarly sequenced MIDI files freely available here: http://www.jsbchorales.net/index.shtml

I downloaded it and proceeded to write a program (in C for speed) to process these files and automatically generate four-part strict canons to the fifth with all this data, in the form of MIDI file that I render with varying pianoteq instruments. Canon form has the advantage that I don’t have to generate additional counterpoint as is necessary with a real fugue, while still keeping the spirit of what motivated me.

The program itself works by doing harmonic analysis of the harmonized chorale, extract the musical phrases using the results and then use brute force to evaluate harmonically ALL possible canons with the choral melody in the soprano. The other voices of the source harmonization are discarded. The best one is kept after the iterations are finished.

This process can be almost instantaneous when the number of case analyzed is in the thousands or hundred of thousands, but the longest case I found involved over twelve million cases, using about an hour in cpu time on a quad-core 3.7 GHz MacPro! These hard cases were very rare so I managed to process all the MIDI files in a couple of months (part-time of course) generating about a thousand  canons since I can vary to some point the shifting parameters of the four voices. This sometimes gives an arpeggiated result rather than a canon impression.

Of these, about 400 are at least « listenable » and about 120 have something I find interesting about them. The discarded ones are by no mean completely worthless, they sometimes are just bland or the source chorale doesn’t translate well into strict canon.

The evaluation process simply gives an arbitrary value to desirable features such as three or four notes chords while down-voting things like consecutive fifths and minor second intervals. This is purely heuristic, but I found it works quite well. Favoring all four note chords sometimes give rise to more modern harmonies as well.

I give here a number of examples, grouped by the instrument used, since the pieces are short, as are the sources chorales. All use stock presets unmodified.


1. To illustrate the complete process, here is a file with first the source harmonized chorale on the Blanchet harpsichord, followed by a canon rendering on the Vintage Tines R2, just to show how different the result can be from the source, this being a rather extreme example:

http://www.forum-pianoteq.com/uploads.p...o_R2_2.mp3

2. On piano, here are three examples, first a three-part invention, then two more jazzy pieces on the U4. The invention was initially four-part but I removed the tenor to clarify the voicing (as Bach did in his)

http://www.forum-pianoteq.com/uploads.p...o_U4_3.mp3

3. Of course, sometimes the contrapunctal nature of the canon is more obvious so here are two examples on the harpsichord:

http://www.forum-pianoteq.com/uploads.p...chet_2.mp3

4. In a more intimate or improvisation mood, here are three examples on the Kremsegg Streicher, the sound of which is interestingly vintage, I find.

http://www.forum-pianoteq.com/uploads.p...cher_3.mp3

5. Most of the pieces are very well tailored to the vibraphone’s sound. Here are two on the V-M:

http://www.forum-pianoteq.com/uploads.p...hone_2.mp3

6. My (current) favorite instrument, the Kremsegg Bechstein, has a nice midrange and works well for pieces where the harmony is more prominent than the counterpoint. Here are three examples:

http://www.forum-pianoteq.com/uploads.p...tein_3.mp3

I used a heuristic to humanize the generated velocities so as to follow the natural melodic tendency of the four voices inside their vocal range and have a less mechanical result. No pedalling though, this is a hard feature to add.

Since all the chorales have a german text attached, all these canons could be sung as well! Brahms, for instance, published a great vocal work consisting of all canons, see here:
https://www.youtube.com/watch?v=3HSFYQ2Nuvc

Finally, sometimes using orchestra instruments can enhance a result. Here is a rendering of the second Streicher example using the stock brass section samples of GarageBand:

http://www.forum-pianoteq.com/uploads.p...ection.mp3

I also used baroque pipe organ samples with very good results.


Sorry for the long post, I hope some of you find this work interesting. I used the regular forum instead of the music creation section because this is not really performed music, but I guess it really belongs there...

Re: Algorithmic composition using Pianoteq

Hello Gilles,

This is fascinating work that you undertook.  As a pianist and an organist who regularly performs Bach preludes and fugues, I appreciate the nature of these canonic variations that were able to be generated algorithmically.

At the same time, it gives one a sense of pause ... because JSB was able to make such beautiful "music" on top of the technical faculties he had at his command.

By chance, as these are midi files, are you able to generate musical notation from them?  I would like to have a hand at performing some of them (especially the one involving the three-part invention and jazzy U4 usage) from the standpoint of a live performer.

Sincerely,

Joe

Re: Algorithmic composition using Pianoteq

Hi Joe! Glad you like some of the canons I posted...I'm of course also of the opinion that Bach's work is infinitely more expressive and beautiful than these automated examples, but one of the things that intrigued me, since he reworked so much chorale melodies into fugues and cantata choruses, not to mention masterful organ pieces, if he ever missed some, not having the time to see the possibilities or maybe those possibilities were so well hidden that he didn't see them.

That's quite arrogant of me, I'm sure, but then with powerful computers at our disposal, why not try. This is why this quasi-correct invention was a surprise and conforted me in the interest of processing all these pieces.

I'll be glad to post some scores. Maybe the easiest way is to upload some scores as pdf files. I use the free notation program MusesScore and exporting to pdf is possible. I'll be back later to specify where they will be since the forum does not accept those. Thanks again for your kind words!

Re: Algorithmic composition using Pianoteq

I uploaded some scores in pdf format here: https://sites.google.com/site/ptqspecprof/temp

They are in 4 part-voice format (not 2-staff piano) though, and I can't recall right now how to transform them with MuseScore, if at all possible... They are mostly straight from the MIDI file. Beware of the tenor clef in places.

File names are: invention.pdf, jazz1.pdf, jazz2.pdf.

I added brass.pdf, the GarageBand demo, because it is to me one of the most expressive results, for some reason...

Also, I already had a score to which I added the singing text in order to show to my choirmaster:
Wir Christenleut.pdf.


While I'm at it, here is a good short example on baroque organ:
http://www.forum-pianoteq.com/uploads.p..._organ.mp3

I also uploaded organ.pdf at the same site.
(All my files have complicated generated names, that's why I rename them here with more generic ones...)


EDIT: I forgot some of the files are generated with augmentation of the melody, that makes for a more difficult to read score since I didn't correct the source time signature. I corrected those in *v2.pdf files.

Last edited by Gilles (18-01-2015 02:49)

Re: Algorithmic composition using Pianoteq

Fascinating post! As a Bach fan I enjoyed the canons very much. I really want to generate canons myself and I wonder if there is some program out there that would let me do that. Surely you could do that in Max or PureData but it sure would be great if there was some easy to use program that would let ordinary people generate canons for their own personal enjoyment without knowing a lot of programming. I will see if I can find such a thing and then I will be sure to share it in this thread.

-Joakim

Re: Algorithmic composition using Pianoteq

Thanks Joakim. Maybe you'd be interested in the work of David Cope : http://artsites.ucsc.edu/faculty/cope/

He's probably the most active researcher in the algorithmic composition domain, and his works spans more than 30 years! What he's doing is much more complicated than what I did (I don't have 30 years to spend...). He tries to capture the style of great composers. This was received very negatively by many scholars in musicology, but I still find his work quite fascinating. Worth exploring...

Re: Algorithmic composition using Pianoteq

I found how to combine with MuseScore my voice scores into 2-staves piano scores (3 for the organ demo). This involves getting rid of superfluous rests, I hope it is more readable on keyboard this way even if some rests may be absent or superfluous.

See files *_piano.pdf at the same site adress.

Re: Algorithmic composition using Pianoteq

For Joe, (or anybody else interested of course) I uploaded most of the remaining scores for the demos I posted as raw piano scores in pdf. The problem of editing away the extra rests is not easy, so I just removed them all (even the leading ones) since the context is probably enough for readability.

Their names all begin with MES* at the same location https://sites.google.com/site/ptqspecprof/temp
I kept the automatically generated names...too lazy to invent new ones