# Creating Rhythms

## Software

Below are the C programs that accompany the book, Creating Rhythms. 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 2019 by Exstrom Laboratories LLC