This book is the result of a lifelong love of music and an obsession with patterns. The authors have for many years been exploring methods to find, create, describe and analyze patterns. They wrote this book to show how some of these methods can be used to generate rhythms. The methods can produce an almost endless variety of new rhythms along with popular traditional ones. For a lover of music what could be more wonderful than that?

The study of patterns at anything beyond a superficial level does require some mathematics. Fortunately the mathematics can be kept at a very elementary level. Anyone comfortable with a little algebra should have no trouble understanding and using these rhythm generation methods. Only the last chapter on stochastic rhythms requires a bit more than elementary mathematics. Any reader who faints at the sight of an equation should probably not buy the book.

The book has many example rhythms for which there are MIDI files that you can listen to here. If you're reading an ebook version, there are individual links to the MIDI files. There is a MIDI player for every major operating system. A good free one is TiMidity.

Accompanying this book are free command-line programs for doing calculations and creating rhythms. The programs are written in the C programming language, and will have to be compiled before you can use them. You do not have to know C to use the programs or understand the contents of the book. There is a C language compiler for every major operating system. A good one that is also free is gcc. There is nothing operating system specific about any of the programs, so you should have no problems compiling them on any computer.

You can get this book now at Amazon.

You can also get this book instantly as a pdf from Gumroad where you will be able to download it immediately after purchase.

**About the authors:**
Stefan Hollos
and J. Richard
Hollos are physicists by training, and enjoy anything related to
math, physics, and computing. They are the authors
of Pattern
Generation for Computational Art,
Finite
Automata and Regular Expressions: Problems and Solutions,
Probability
Problems and Solutions,
Combinatorics
Problems and Solutions,
The Coin Toss: Probabilities
and Patterns,
Bet Smart: The
Kelly System for Gambling and Investing, as well as
Simple Trading Strategies That Work
and Pairs
Trading: A Bayesian Example, and are brothers and business
partners at Exstrom Laboratories LLC in Longmont, Colorado. The
websites for their work
are Exstrom.com
and QuantWolf.com.

## Table of Contents

**What This Book is About****Introduction****What is a Rhythm?****Measured Rhythms****Unrestricted Rhythms****Restricted Rhythms****Rhythm Necklaces****Rhythms from Partitions****de Bruijn Rhythms****Christoffel Rhythms****Word Combinations for Rhythm Sets****Euclidean Rhythms****Generalized Christoffel Words****Christoffel Word Sequences****Square Root of 3****Square Root of 5****Square Root of 17****Golden Ratio****Transcendental Numbers****Natural Rhythms****Rhythms of the Planets****Rhythms of the Elements****Folding Rhythms****Stochastic Rhythms****Appendix A: Traditional Rhythms****Appendix B: Software****Further Reading****Acknowledgements****About the Authors**

## Software

Below are the C programs that accompany the book. You can download each as you need it, or all of them bundled into a zip file.

This software is free and distributed under the terms of the GNU General Public License. It is written in ANSI C and should compile with any C compiler. If you have questions or comments contact: Stefan (stefan at exstrom dot com) or Richard (richard at exstrom dot com).

**comp.c**

Generates all compositions of n.Usage: comp n

**compm.c**

Generates all compositions of n into m parts.Usage: compm n m

**compa.c**

Generates all compositions of n with parts in the set (p1 p2 ... pk).Usage: compa n p1 p2 ... pk

**compam.c**

Generates all compositions of n with m parts in the set (p1 p2 ... pk).Usage: compam n m p1 p2 ... pk

**comprnd.c**

Generates a random composition of n.Usage: comprnd n

**compmrnd.c**

Generates a random composition of n into m parts.Usage: compmrnd n m

**neck.c**

Generates all binary necklaces of length n.Usage: neck n

**neckm.c**

Generates all binary necklaces of length n with m ones.Usage: neckm n m

**necka.c**

Generates all binary necklaces of length n with parts in (p1 p2 ... pk). A part is the length of a substring 10...0 composing the necklace. For example the necklace 10100 has parts of size 2 and 3.Usage: necka n p1 p2 ... pk

**neckam.c**

Generates all binary necklaces of length n with m ones and parts in (p1 p2 ... pk). For a definition of parts see necka description.Usage: neckam n m p1 p2 ... pk

**part.c**

Generates all partitions of n.Usage: part n

**partm.c**

Generates all partitions of n into m parts.Usage: partm n m

**parta.c**

Generates all partitions of n with parts in the set (p1 p2 ... pk).Usage: parta n p1 p2 ... pk

**partam.c**

Generates all partitions of n with m parts in the set (p1 p2 ... pk).Usage: partam n p1 p2 ... pk

**permi.c**

Generates all permutations of the non-negative integers in the set (a1 a2 ... an). To generate all permutations the integers must be ordered: a1 < a2 < ... < an. Any other order will only generate permutations larger in lexicographic order.Usage: permi a1 a2 ... an

**debruijn.c**

Generates the largest de Bruijn sequence of order n.Usage: debruijn n

**b2int.c**

Reads binary strings from stdin and converts them to interval notation.Usage: b2int Example: echo "1010010001001000" | b2int -> 2 3 4 3 4

**int2b.c**

Reads intervals from stdin and converts them to binary string notation.Usage: int2b Example: echo "2 3 4 3 4" | int2b -> 1010010001001000

**chsequl.c**

Generates the upper or lower Christoffel word for p/q.Usage: chsequl t p q n t = type of word u = upper l = lower p = numerator q = denominator n = number of terms to generate, default=p+q

**cfsqrt.c**

Calculates the continued fraction for the square root of an integer.Usage: cfsqrt n n = integer

**cfcv.c**

Calculates a continued fraction convergent.Usage: cfcv a0 a1 a2 ... an ai = simple continued fraction term

**pfold.c**

Generates fold sequences.Usage: pfold n m f n = number of terms, 1,3,7,15,31,63,127,... m = number of bits f = function number 0 -> 2^m-1

**rndint.c**

Generates random numbers with specified correlation.Usage: rndint m s c n m = range of numbers, 0 to m s = starting number, 0 to m c = degree of correlation 0 = total correlation (all numbers = s) m = no correlation (each number is independent) n = how many random numbers to generate

**markovgen.c**

Generates random numbers using a Markov chain.Usage: markovgen mfile s n mfile = transition matrix file name s = starting state n = how many random numbers to generate

## Converting Binary Rhythms to MIDI

Here is a quick way to make a midi file, given rhythms in binary notation.

Let's say you want to hear the following two instrument binary rhythm set:

1111010110010000 Low Bongo 1000011110101100 High Bongo

Our procedure is to first convert the binary rhythm set to abc notation, then convert the resulting abc file to MIDI. To go from the binary rhythm set to abc notation we use our program bdrum.c which reads a binary rhythm definition file and sends the equivalent abc notation to standard output. In our example above, the input binary rhythm definition file would look like the following:

480 16 2 61 1111010110010000 60 1000011110101100

where 480 is the tempo (notes/minute), 16 is the number of notes
per rhythm, 2 is the number of rhythms, 61 is the
MIDI
percussion instrument number for low bongo, and 60 is high
bongo. So if our binary rhythm definition file is
called `b1.bdf` then we run `bdrum` as follows:

./bdrum b1.bdf 4

where the number 4 specifies that the rhythm set is repeated 4
times. The result is an abc notation file that can be converted to
MIDI with the program `abc2midi` (part of the
abcMIDI
package). The resulting MIDI file can be played by a program
like TiMidity.
You can listen to the above example here.
All this can be done in one command line as follows:

./bdrum b1.bdf 4 > b1.abc;abc2midi b1.abc -o b1.mid;timidity -in b1.mid

Note the above command line works in the bash shell. In Linux and Mac OS X it should work with no problem (bash is the default shell in most Linux distros and OS X). On windows, you can get the bash shell by installing MinGW or Cygwin.

Send comments to: Richard Hollos (richard[AT]exstrom DOT com)

Copyright 2014-2018 by Exstrom Laboratories LLC