Skip to main content

Article

Generating music in F# part 3: Note values

Minna Kaitala

April 5, 2015


Previous posts in series:
Part 1
Part 2

After last post the program can generate melodies using Markov chains generated from seed data. Next important aspect of a catchy melody is note value. Note value means a relative duration of a note.

Just like notes note values are modelled as a type:

The actual duration of a note value in seconds is relative to tempo. A map of durations for values can be created using this function:

Beats per minute(bpm) means the amount of quarter notes in a minute. Dividing minute(60 seconds) with bpm yields length of quarter note in seconds. Other time values can be counted from that quarter note value.

I wanted some more complex seed data:

Melody is now represented as list of tuples of note and value. Both types will have their own Markov chain structure

Creation of random sequence is not dependent of the type of item in this case. Functions can be made more generic by removing type declarations referring to note-type.

Here is the main now:

Random sequences are created for both notes and time values. Then they are zipped into list of tuples and written to wav-file.

Full source on GitHub. Here is an example output: