Home           About           Downloads


This program demonstrates a simple procedural composition technique for automatically generating contrapuntal compositions. Sounds completely crazy? Try it.

When you run it, it generates a file called "test.mid", and proceeds to open it with the default midi playing program you have installed. I suggest using MAMPlayer, because of its visualisation of the midi file as it plays it.

What is it doing?

It generates several independent tracks, one note at a time. Notes inside beats 1 and 3 are always notes in the tonic chord, and notes inside beats 2 and 4 are always notes in the dominant 7th chord. Since it always works in C major, the tonic notes are C, E and G, and the dominant notes are G, B, D and F. Also the note that is chosen is either the nearest or 2nd nearest higher or lower note to the previous note that is part of the chord it is assigned to. The choice about whether the note is higher or lower, or is the nearest or 2nd nearest is a random choice. For example, if the previous note is C, and the next note falls inside the 2nd beat of the bar, then it may either choose the D or F above the C, or the B or G below the C. As for the rhythm, there are 3 rhythms, each 1 bar long. These are 4 crotchets, 8 quavers, or a hopping rhythm of 4 repeats of a dotted quaver and a semi-quaver. Every bar, it chooses randomly from these 3 rhythms.

Will it ever end?


Download source code

Assorted bits and pieces


This is a small program which generates a Dominosa problem to solve, then uses my implementation of Knuth's Algorithm X to solve it. The controls are:

Press 'r' to generate a new puzzle
Press 'p' to pause the solution search
Press 's' to single step the solution search
Press 'c' to continue the solution search


This started out as a utility to help explore the huge Eternity2 puzzle, but as usually happens with me, I became sidetracked by pretty objects. The puzzle solving aspect is a minor part of this tool - the major focus of it is in procedurally generating the designs of the tiles, and from a programming point of view getting practice using the OpenGL stencil buffer by using it to produce different designs, and learning how to render to many textures.

To edit a design, pan over to the single tile view (its near the bottom right of the board), and press the spacebar. (To pan, drag with the right mouse button.) Labels will appear underneath some of the sliders, indicating they may be changed to alter the design. This is the area in question:

If you pan to the left, you'll see this design repeated on a grid, to give you an indication of how it looks when tesselated. You can continue editing here as well of course.

If you like, you can still "play" Eternity 2, and attempt to solve the puzzle - when you click on an empty part of the board (the large greyish area), candidate pieces are revealed on the top right, which you can click to place the tile. Tiles highlighted green have already been placed, and will be moved if you click them. I was going to investigate some simple auto placement strategies, but I got bored and moved on before I did this.

Included is a file called e2dataset.txt. This is not the official Eternity 2 tile set - it is a randomly generated tile set which includes border and corner pieces.


A simple implementation of Peg Solitaire. Right click to move a peg. There is some inactive AI code in the project.


A simple render to texture experiment. Not interactive, but the texture is animated, so it may have instructive value.


A simple simulation to play with some of the dynamics of traffic and overtaking behaviours.

Some of the parameters are in the Freeway constructor if you want to play around.


Its an empty world. Its a simple 3D environment complete with scene picking and an intuitive camera behaviour which you can use to render whatever thing you're working with in a 3D space instead of the usual console window.

AudioTest - a precursor to a Reactable simulator


This application is a platform for some basic audio experiments and tests. It features:

  • A Lua REPL which permits the generation and modification of a waveform
  • Mouse modifiable waveform
  • Regeneration of waveform from Lua expression during the sliding of the sliders
  • The effects of modifications to the waveform are heard instantly, because it is being streamed as it is modified

It is my first foray into audio programming. It is a precursor for a "Reactable" simulator, similar to PsychoSynth.

Things to try

When the program starts, a sample expression appears, along with the resulting waveform, and the audio of the waveform should be heard.

Slide the first slider to alter the pitch of the waveform.

Slide the second slider, and notice the waveform and audio change according to the expression in the expression text box.

In the expression text box, enter a Lua expression that sets the variable "result". Variables you can refer to in the expression are:

  • x which is the time variable in the waveform, allowing you make "result" a function of time
  • p2, which is the setting of the second slider (The first slider controls the pitch). To see the value of p2, run print(p2) in the provided Lua REPL.

For example, the expression:

result = 0.2 * math.sin(x * ((2.0 * math.pi) / p2))

produces a sine wave whose frequency is modifiable with the second slider.

There are some more example expressions in audiooutput.cpp.


This project demonstrates the use of scripting languages in a Qt project to enable a 3D "live coding" environment. The scripting languages supported are Lua and Scheme (through s7 Scheme). For a version which uses Common Lisp (through ECL), see QtImagine and QtCSG.

The system calls the functions "update" and "render" in both languages to update and render the frame respectively. These functions can be redefined at runtime at the REPL.

When QtLuaImagine first starts, press "Enter" or click the "Execute" button to load an example Lua source file containing example definitions of update() and render(). Then, load the source file into your favourite text editor, make some changes, then load your freshly edited source file from the REPL by issuing the appropriate load command (dofile("filename.lua") for Lua, or (load "filename.scm") for Scheme) to see the effect of your change instantly. Of course, you can also enter expressions and definitions at the REPL itself. The REPL features a command history.

I hope this provides a starting point for programmers getting into live coding for the first time.