Five Dances based on TonicNet Chorales #46

Today’s work results from trying to isolate the variables that create the most interesting set of five dances based on the TonicNet Chorales. In this version the keys are F# minor, B minor, E major, A major and D major, tuned in Kellner’s Well Temperament. As before, I chose them because they have many segments where the notes are not in the root key of the chorale. There are dozens of variables in the creation of the dances from the original synthetic chorale material, but the main control points can be found by scanning the logs using grep:

egrep "mask.shape|factors|repeat_count|mask_zeros|midi_file" open_samples3-t46.log

This produces the following output, which includes the key values for important variables chosen by the algorithm from a set of ranges and probabilities:


The dances are scored for finger piano, balloon drum, and Ernie Ball Super Slinky Guitar strings on an old Gibson humbucking pickup.

Five more Preludes based on TonicNet Chorales #22

I’ve been using Pandas dataframes to analyze the synthetic chorales I’ve created. I started by generating 500 of them. Then I use lots of python code to learn more about the chorales. Each chorale produced by the TonicNet GRU model consists of a variable number of time steps, each consisting of Soprano, Alto, Tenor, & Bass voices expressed in MIDI note numbers. Some of those time steps have notes that are not in the dominant root key of the chorale. These are often leading tones, or suspensions, or diminished chords, augmented, and so forth. Bach used these chords to produce tension, that was always resolved in a cadence of some sort. The TonicNet model was trained on hundreds of real Bach chorale, which are further augmented by transpositions of the existing chorales to all twelve keys, so that 1,968 chorales were used as input to the model. What is amazing to me is that the final model is only 4.9 MB in size. The Coconet model ended up as 1.6 GB in size.

I like those interesting sections where the chorale uses notes not in the root key for many time steps. I wrote some python code that builds a list of the number of voices that are not in the root key of the chorale, one value for every time step:

zero_one_q = np.array([not_in_key(time_step, root, mode) for time_step in chorale_tr])

It basically calls another python function that looks at each time step and reports the number of voices not in the root key of the chorale. Once I have that array, I can build a list of sections that have notes not in the root key. I run every chorale through that routine so that I have information about each chorale that can be used to select for certain characteristics, such as lots of steps in a row not in the root key, or many sections of notes that are not in the root key.

Today’s results used a Pandas data frame to find chorales that met these characteristics:


I did the same for A minor. The value of these measures is that it produces a final result of five preludes that in total lasts about 15 minutes. That is in contrast with an earlier version that had many more challenging steps and went on for an hour and ten minutes. I used Kellner’s Well Temperament.

A Very Long Version of Five Preludes from TonicNet chorales for Finger Piano #21

The algorithm I use for most of my pieces is that first I find all the time_steps that contain notes not in the key of the chorale. Then I go about making those sections longer using a variety of elongation techniques. The code looks like this:

probability = ([0.2, 0.1, 0.6, 0.1, 0.15, 0.04, 0.05, 0.1, 0.1])
if type == 'any': type = rng.choice(['tile', 'repeat', 'tile_and_reverse', 'reverse_and_repeat',
'shuffle_and_tile', 'tile_and_roll', 'tile_and_repeat', 'repeat_and_tile',
'tile_reverse_odd'], p = probability)

I let the system choose which type of elongation. But over time, it’s certain to choose ’tile_and_reverse’ about 60% of the time. That is accomplished with this line of code:

clseg = np.flip(np.tile(clseg, factor), axis = 1)

This basically repeats a section of the piece, consisting of a certain number of voices performing over time_steps, then reverses the repeated sections. Retrograde.

All that is to say that the music is predetermined probabilistically, but not explicitly.

But if a certain chorale is dominated by ranges of the chorale that include notes not in the root key of the chorale, then there are a lot of repetitions. For this piece I chose five chorales that have that condition. So the extensions go on for a long time. In fact, in this prelude, each chorale lasts about 20 minutes, and there are five of them. You can do the math. I wouldn’t recommend this unless you like repetitive sounding music. Maybe skip around.

Tuned in Kellner’s Well Temperament.

Five more Preludes on TonicNet Synthetic Chorales #7

Today’s contribution uses synthetic chorales manufactured by a TonicNet model in the keys of E♭ major and C♮ minor, which use the same notes. This one is also tuned using Kellner’s Well Temperament. Scored for finger piano. I set it up so that all the five chorales would be about the same length, and I adjusted to tempos to ensure that. TonicNet doesn’t limit itself to 32 1/16th notes the way Coconet does, so I get to vary the length as a bonus.

Each the chorales length is stated in the table below in thousands of MIDI ticks. I don’t understand MIDI, so I just puttered around until I found five that were of different numbers of MIDI ticks. That resulted in three fast and 3 slow preludes, alternating between major and minor.

# key E♭M Cm E♭M Cm E♭M
# k note 16k 12k 23k 23k 11k
# speed f s f f s
# index 231 371 222 371 234

You can see from the image below that the middle one is the most frantic. Reminds me of Glenn Gould’s 1955 Goldberg Variation 1. Speed demon, that guy,


5 Preludes on TonicNet Synthetic Chorales #3

These are based on four of the synthetic chorales that I manufactured using the TonicNet GRU deep neural network model. They are in A minor, C major, A minor, C major, and repeat the first at the end in A minor. Each uses a different arpeggiation matrix. The tempos are based on how many notes in the synthetic chorale. With more notes, the tempo is faster, with fewer notes, it’s slower. I made 500 chorales, and then selected some that were of a moderate length. I looked for those in complementary major and minor keys, settling on A minor and C major. A different selection criteria would have different results. This is referred to in the deep learning literature as “cherry picking”. But I’m sure Bach would approve.

Score Excerpt

Fantasia on some TonicNet Chorales #1

This is one that uses five synthetic chorales manufactured by the TonicNet model, all in the key of F# minor. It’s scored for solo finger piano. There’s a short pause between each chorale. The tuning is Kellner’s Well Temperament. I took the idea from Bach’s Well Tempered Clavier Prelude #1, where he moved through a set of chords one measure per chord. That’s what I do with the synthetic chorale. First I extend it to 4 times normal length, then arpeggiate it with a matrix of 24 1/16th notes, with zeros:ones ratio of 9:4. This ensures that there are more zeros than ones, so more notes are set to zero and therefore missing. This results in some interesting arpeggiations. I also extend some of the octaves up and down a bit. It’s kind of like if Philip Glass used Bach chord progressions instead of his own unique ones.

Fantasia on some chorales made by TonicNet #14

Today’s submission is based on a chorale synthesized by TonicNet, created by Omar Reacha. His paper, Improving Polyphonic Music Models with Feature-Rich Encoding from 26 Nov 2019 uses a type of deep neural network called the Gated Recurrent Unit to generate very nice Bach chorales. Here is the Paper and Code.

He used that network to create a database of 500 synthetic chorales in his next paper, JS Fake Chorales: a Synthetic Dataset of Polyphonic Music with Human Annotation from 3/31/2022. Here is that paper, code, and a web page that generates a fake chorale while you wait.

TonicNet Architecture

I used some python code to analyze the resulting 500 MIDI files to find those that met certain criteria:

  • Rather short, around 8 measures
  • Rather high pitch entropy, that is they frequently contain pitches that are not in the key of the chorale

The top scores went to chorales number 35, 268, 107, and 121, in the keys of G minor, F# major, E minor, and F# major respectively.

I put them through some of my python programs that lengthen, repeat, and transform sections based on the pitch entropy of the time steps. This enables me to linger over suspensions and harmonic transitions using different manipulations of the notes.

The piece is scored for a large string orchestra of about 256 string instruments: violins, violas, cellos, and double basses. I include samples of each instrument playing without vibrato, with vibrato, martele, and pizzicato. The piece starts out with everyone playing at the same time, then moves to sections that are only one type of sample. They come back together after several sections to all play at once.

I used a tuning developed by Herbert Anton Kellner, which in the Scala repository is referred to as kellner.scl Herbert Anton Kellner’s Bach tuning. 5 1/5 Pyth. comma and 7 pure fifths. Since I didn’t know what key would end up chosen, I wanted to pick a tuning that could handle almost any key.

There is a separation between each of the four chorales. Just a brief pause.


Look Down for Finger Piano, Strings, Balloon Drums, and Springs #65

This another version of the piece I’ve been working on for a while, based on a COCONET deep neural network generated synthetic chorale. The original chorale was Look Down from Heaven (BWV 2.6, K 7, R 262) Ach Gott, vom Himmel sieh darein (BWV 2.6, K 7, R 262), but it’s gone through the model many times, so it has changed significantly. Some remains the same, and shows itself at times.

This version is scored for three quartets of instruments:

  1. First quartet:
    1. Finger Piano
    2. Ernie Ball Super Slinky Guitar
    3. High Balloon Drum
    4. Spring
  2. Second quartet:
    1. Finger Piano
    2. Medium Balloon Drum
    3. Baritone Guitar
    4. Bass Finger Piano
  3. Third quartet:
    1. Low Balloon Drum
    2. Finger Piano
    3. Very long string
    4. Bass Finger Piano

A certain times, all the instruments play together, but more of the time is spent with each quartet playing by themselves. Each instrument plays many notes, so the music gets fairly dense at times, and sparse at other times.

How The Star Spangled Banner became “Not the Star Spangled Banner”

This post is going to trace the path that our national anthem took as it went through a neural network and probabilistic algorithms in its journey to produce some music. It started out as a midi file downloaded from the internet. Here is the first few measures as played on a quartet of bassoons with staccatto envelope realized in Csound.

I then turn it from a nice 3:4 waltz into a 4:4 march by stretching out the first four 1/16th note time steps to 8 time steps.

The MIDI files are transformed into a set of time steps, each 1/16th note in length. Each time step has four voices, soprano, alto, tenor, and bass, with a MIDI note number for every voice sounding at that time. Zeros represent a silence. The transformation into time steps has some imperfections. In the time step data structure, the assumption is that if the time step contains a non-zero value, it represents a MIDI note sounding at that time. If the MIDI number changes from one step to the next, that voice is played. If it is not different from its predecessor, it holds the note for another 1/16th note. In the end we have an array of 32 time steps with 4 MIDI note numbers in each, but some are held, some are played, and others are silent.

The next step is to take that march, and chop it up into seventeen separate 32 1/16th-note segments. This is necessary because the Coconet deep neural network is expecting four measure chorale segments in 4:4 time. The result is a numpy array of dimension (17 segments, 4 voices, 32 time-steps of 1/16th note each). I then take that structure, and feed each of the seventeen segments into Coconet, masking one voice to zeros, and telling the network to recreate that voice as Bach would have done. I repeat that with another voice, and continue to repeat it until I have four separate chorales that are 100% synthesized. Here is one such 4 part chorale, the first of four.

And another, the last of the four, and so the most different from the original piece.

I create about 100 of these arrays of 16 voice chorales (four 4-voice synthetic chorales), and pick the ones that have the highest pitch entropy. That is, the ones with the most notes not in the original key of C major. It takes about 200 hours of compute time to accomplish this step, but I have a spare server in my office that I can task with this process. It took this one about a week to finish all 100.

Then I take one of those result sets, and put it through a set of algorithms that accomplish several transformations. The first is to multiply the time step voice arrays by a matrix of zeros and ones, randomly shuffled. I have control of the percentages of ones and zeros, so I can make some sections more dense than others.

Imagine a note that is held for 4 1/16th notes. After this process, it might be changed into 2 eighth notes, or a dotted eighth and a sixteenth note. Or a 1/16th note rest, followed by a 1/16th note, followed by a 1/8th note rest. This creates arpeggiations. Here is a short example of that transformation.

That’s kind of sparse, so I can easily double the density with a single line of python code:

one_chorale = np.concatenate((one_chorale, one_chorale),axis = 0) # stack them on top of each other to double the density

I could have doubled the length by using axis = 1

That’s getting more interesting. It still has a slight amount of Star Spangled Banner in it. The next step will fix that.

The second transformation is to extend sections of the piece that contain time steps with MIDI notes not in the root key of the piece, C major. I comb through the arrays checking the notes, and store the time steps not in C. Then I perform many different techniques to extend the amount of time on those time steps. For example, suppose the time steps from 16 to 24 all contain MIDI notes that are not in the key of C. I transform the steps 16 through 24 by tiling each step a certain number of times to repeat it. Or I might make each time step 5 to 10 times longer. Or I might repeat some of them backwards. Or combine different transformations. There is a lot of indeterminacy in this, but the Python Numpy mathematical library provides ways to ensure a certain amount of probabilistic control. I can ensure that each alternative chosen a certain percentage of time.

Here is a section that shows some of the repeated sections. I also select from different envelopes for the notes, with 95% of of them very short staccato, and 5% some alternative of held for as long as the note doesn’t change. The held notes really stick out compared to the preponderance of staccato notes. I also add additional woodwind and brass instruments. Listen for the repetitions that don’t repeat very accurately.

There are a lot of other variations that are part of the process.

Here’s a complete rendition: