Algorithmic piece for virtual band and saxophone

Again with Jmusic, I have created drums and bass lines and I have played a little with saxo over those lines.

 Bass melody:

For the bass line, there is no tonality defined, just probabilities of steps size and direction. So for each note:

  • there is a probability of 25% to change the direction of the melody.
  • for step size (number of semitones current and previus note), there is a 50% of probability to continue with the same step. And if we change, it can be either 1,2,3,4,5 or 7 semitones.
  • there are maximum and minimum pitch boundaries

Bass ryhthm:

It can either play, quarter notes, swinged eighth notes, and ternary notes. It’s chosen randomly until the maximum number of beats is reached.

Drums:

We have similar rhythm patterns as the ones for bass. But in this case probabilites will be different depending on the drum instrument.

Saxophone:

Once the drums and bass MIDI accompaniment was generated I  imported it to Cubase, and used basic VST instruments such as Virtual Bass Unit (vb1) and Drum Sample Unit (LM-7). And I recorded a saxophone solo trying to play somehow according with the virtual band (both drums and bass).

Result:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Although I am not very proud of the result, it’s been an interesting exercise, I can conclude a few things:

  • When music is generated randomly it’s very hard to make something beautiful, the first goal is to prevent it from being bad
  • I should try making melody lines with some tonality constraints
  • I made a short loop for the bass so I, in order to play a solo, I was able to learn and memorize part of the melody.
  • In all drums instruments there was I high probability for not playing. Silence was very important in order to sound better.
  • I should improve my saxophone skills :)

Detailed information about probabilites and the whole process in the source code

Creating random comping

The computer has composed some compings. He didn’t made it alone, I gave him some constraints:

- The chord wheel will be Am – G -F -Em.

- The pattern rhythm will be all quarter notes.

- First quarter note will be a bass note and the following will be first inversion chords.

Some decision were up to him:

- For each chord there can be played between 3 and 5 notes.

- Last note can be either quarter or eight note.

Using random functions we have generated a few compings.Some of them sound better than others. The only variable that seems to determine if sound nice or not is the duration of the last note of every chord. This duration will make next pattern play either upbeat or downbeat. If pattern is changed to upbeat and doesn’t turn back to downbeat, our brain forgets we are upbeat, and that makes it sound strange:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

On the other hand, some generated results that sound quite well. First one’s meter is 4-2-4-2

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Whereas the second one is 4-2-4-3

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

We used Jmusic library. See java source code

Ear training tool with jquery

After extending the jquery piano I developed a simple ear training tool, for which I used the awesome javascript sound api Soundmanager.

Try the ear training tool

By clicking start link, the user will listen to a note sequence which he will then try to reproduce by playing it with the piano. The first note is always C3 and the sequence grows adding one note each time.

The main improvement to be done is to allow the user to listen the notes sequence faster. Currently this can’t be done because I used soundmanager’s onfinish event to play the notes sequence. This means that each note will be played  right after the previous one is finished. I also tried to create rhythms with a javascript sleep function, but in didn’t work in IExplorer.

Playing jquery piano with computer keyboard

I wanted a jquery piano and I found this very flexible  plugin which triggers events when a key is pressed with the mouse… I thought I would like to be able to play that piano with the computer keyboard, so I extended it in order to be able to play up to two octaves.

There are some parameters to be sent to the constructor such as the number of octaves, and whether the letter of each key is visible or not. See the following example:

Works well on the last versions of Firefox, Chrome and IE9

Here’s the  example

The code on GitHub

 Igor Prochazca‘s original plugin

Pequeños experimentos de composición aleatoria con Jmusic

Jmusic es una librería de java que permite crear melodías en MIDI, especificando la duración (ritmo) y altura (melodía) de las notas. Al ser una librería para java, podemos fácilmente crear algoritmos para generar melodías, y usando la clase random, podemos añadir aleatoriedad en la generación de esas melodías.

Hemos hecho tres pequeños experimentos en los que generamos una melodía.

Combinación de frases

En el primero tenemos 4 frases predeterminadas de distinta duración y el algoritmo lo único que hace es combinarlas aleatoriamente. Éstas son las frases:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Y éste es el resultado después de ejecutar el proceso (obviamente cada vez que se ejecuta el proceso el resultado cambia, ya que estamos usando aleatoriedad para decidir que frase va en cada iteración).

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Transformación de una frase

En el segundo experimento partimos de una frase predeterminada que vamos repitiendo, y en cada iteración modificamos una nota subiéndola o bajándola un semitono. Tanto la decisión de qué nota modificar como la dirección (si la subimos o la bajamos) son aleatorias. Resultado:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Frase que crece

Finalmente, en el último experimento también partimos de una frase inicial en la que cada dos iteraciones, añadimos una nota con altura aleatoria (dentro de las 12 posibles de la escala temperada) y duracion que puede ser o negra o corchea.

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Los resultados obtenidos pueden no ser demasiado agradables musicalmente. Se podrían mejorar añadiendo restricciones para hacerlos más agradables al oído. No obstante, pueden servir como ideas bases para ser desarrolladas.

Aquí se puede consultar el código fuente java