Home           About           Downloads





Synthbench - A Reactable Simulator - Update 2





This is a bug fix release for the Synthbench_2010_12_14 version. The program should no longer hang regardless of the node network you try to create.

Whenever there is a cycle in the network, Synthbench no longer hangs - the nodes in the cycle merely stop updating.

Synthbench - A Reactable Simulator - Update 1



This program is inspired by the Reactable, and it attempts to simulate it. This is a very limited early version - the project is an excercise in audio programming.

Differences between this version (2010_12_14) and the previous version (2010_12_03):
  • Its possible to add new nodes to the table by dragging them from the palette
  • The nodes auto-connect and disconnect as you drag them. Controller nodes connect to generators and other controllers, while generators only connect to the output node. Also, a node won't auto connect with a node further away from the output node than it is, encouraging radial node layouts. I may change this rule.
  • The nodes are labelled - generators are labelled "g", controllers are labelled "c".
  • The controller nodes modify a parameter away from the base setting, which means that manipulating the sliders will have an effect even if a controller node is connected.

Controls:
  • Move a node by dragging it with the left mouse button
  • Pan the view by dragging an empty spot with the left mouse button
  • Zoom the view by dragging an empty spot up and down with the right mouse button
 Limitations and known bugs:
  • The output node doesn't do any mixing - it accepts only one input from a generator node
  • In fact, all the nodes accept only one input at the moment, which means the only thing you can make at the moment is a chain.
  • The only parameter a controller will modify is the period
  • The program might hang if you make a complex structure it can't support - only make a chain for now.
Despite these limitations, you can still achieve some interesting effects.

Coming up in the next version(s):
  • Low/high/band pass filters nodes and other effect nodes
  • Sequencer nodes
  • Controller nodes affecting more parameters
  • Improving the look - possibly switching to 3D so effects can be added
  • Make more use of the Lua console

Synthbench - A Reactable simulator


This program is inspired by the Reactable, and it attempts to simulate it. This is a very limited early version - the project is more of a proof of concept which provides an excercise in audio programming. You can still have some fun with it though. The table layout consists of a sinewave generator, with a sinewave controller controlling it. Selecting the sinewave controller (the node on the left) allows you to modify its parameters using the sliders at the top of the window.

The Lua scripting pane is a functional Lua repl that allows you to enter multi-line Lua expressions and programs, although isn't tied to anything in the simulator yet.

A better, actually useful version is coming soon.

Syntax Party 2010

I attended Syntax Party 2010 this year. I've always admired the demoscene from afar, so when I heard there was going to be an event in Melbourne, I had to go and see it. I ended up having the time of my life! The venue was filled with like-minded, friendly, enthusiastic programmers and artists all eager to show their creations, and to query in detail about the creations of others. People from all over Australia arrived to code and party all weekend, and the atmosphere was relaxed and fun. Even though I didn't have a production prepared specifically for the event, I was encouraged to enter some of the programs I had been showing people during the event. They were Mechabach and Ball Game, and they were both well received. I've made some great new friends, including an ANSI artist named Ozzy who created a logo for my new handle, "fugue":


I look forward to next year's Syntax Party event in Sydney!

Mechabach


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

Download source code

Assorted bits and pieces

DominoSolver


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

Eternity2



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.

PegSolitaire



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

RenderToTexturePlay



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

FreewaySim

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.


EmptyWorld



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

Downloads:





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.

QtLuaImagine


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.

Download

QtCSG - Constructive Solid Geometry scripted from ECL







This project is the same as the earlier project, QtImagine except this also features an implementation of "Constructive Solid Geometry" operations that can be performed on 3D models such as difference, union and intersection. The algorithm for performing these operations comes from the UnBBoolean (http://unbboolean.sourceforge.net/) Java CSG implementation.



See the files csg-test.lisp, csg-test2.lisp and csg-test3.lisp for examples on how to use these features. To run them, note that they need to be loaded in order - first csg-test.lisp, then csg-test2.lisp, then finally csg-test3.lisp, since they reference objects that were created by earlier scripts.

Similarly, see init.lisp and live-render.lisp for a live rendering example script.


QtImagine - a skeleton project for live coding using ECL

QtImagine has been updated!

In the process of releasing QtLuaImagine, I cleaned up the code for QtImagine. All lisp code is now run through a (handler-bind) block so that error messages can be captured. What this means is that error messages are displayed in the main window, so no more need to flip between the console and the main window when an error occurs. Also, grey streams have been used to redirect trace output to the main window as well.






This project demonstrates the use of ECL in a Qt project to enable a 3D "live coding" environment.

The system calls the lisp functions (update) and (render) to update and render the frame respectively. These functions can be redefined at runtime at the REPL.

When QtImagine first starts, click the "Execute" button to load an example lisp source file containing example definitions of (update) and (render) which will produce a simple animation. 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 load command (load "live-render.lisp") 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.

Scripting simulations with ECL



Download: QtEclSmallSimulations2.zip (Win32 binary)

I've been adding to the program mentioned in a previous post. The circuit simulator and origami crease pattern editor are drivable from the lisp repl, and the verlet physics based paper simulator has been implemented and is manipulated from the repl.

Also, the repl itself features command history.

Here is the list of functions currently available from the repl:

ORIGAMI CREASE EDITOR

origami-start
Initialises origami crease editor with a plain sheet of paper consisting of 1 four sided facet.

origami-end
Clears the origami crease editor.

origami-creasecoords
Takes 4 parameters (x1 y1 x2 y2) representing the 2 endpoints of a crease line.

origami-crease
Takes 2 vertex ids (nodeA nodeB) and uses them as the 2 endpoints of a crease line.

origami-creasepp
Takes 2 vertex ids (nodeA nodeB) and forms the crease from "folding" one vertex on the other. The crease line is the perpendicular bisector.

origami-creasell
Takes 4 vertex ids (l1v1 l1v2 l2v1 l2v2) to describe the endpoints of 2 lines, and forms the crease from "folding" one line onto the other.

origami-fold
Takes 3 vertex ids (nodeF nodeA nodeB) and attempts to fold nodeF around the (nodeA nodeB) line by finding its mirror on the other side. It does the same with connected vertices as necessary.

origami-makeverletpaper
Makes a verlet physics representation of the current crease pattern, so it can be manipulated in the verlet physics environment.

VERLET PHYSICS

verlet-lock
Takes 1 vertex id, and fixes that node in space.

verlet-free
Takes 1 vertex id, and frees that node if it was fixed.

verlet-freeall
Removes all position constraints

verlet-rotate
Takes 4 parameters (nodeF nodeA nodeB angle) and rotates nodeF around the axis defined by nodeA and nodeB using the angle parameter. As the system resolves this attempt to do this rotation, you'll see whether the system currently permits or rejects such a motion.

verlet-numnodes
Returns the number of nodes.

verlet-numstruts
Returns the number of struts.

verlet-show
Not implemented - will show the given node id.

verlet-hide
Not implemented - will hide the given node id.

verlet-showall
Not implemented - will show all node ids.

verlet-hideall
Not implemented - will hide all node ids.

verlet-addfstrut
Not implemented - will add a folding strut, which is the same as the crease struts, but is marked as a folding strut, because it can be removed when a given fold is completed.

verlet-addsstrut
Not implemented - will add a structural strut manually. For facets containing more than 3 edges, structural struts are necessary to keep those facets flat. For the crane model, all facets are triangular, so this isn't necessary yet.

verlet-removefstruts
Not implemented - will remove all folding struts.

verlet-removesstruts
Not implemented - will remove all structural struts.

verlet-autoaddsstruts
Not implemented - will automatically add structural struts where needed for facets containing more than 3 edges.

verlet-satisfy
Not implemented - will allow the user to manually invoke the verlet constraint resolver, rather than having it run all the time.

CIRCUIT SIMULATOR

circuit-AddNode
Takes 2 parameters (x y) and adds a new node at that location.

circuit-AddResistor
Takes 3 parameters (nodeA nodeB resistance) and creates a resistor connecting nodeA and nodeB using the resistance parameter.

circuit-AddVoltage
Takes 3 parameters (nodeA nodeB voltage) and creates a voltage source connecting nodeA and nodeB using the voltage parameter.

circuit-AddCurrent
Takes 3 parameters (nodeA nodeB voltage) and creates a current source connecting nodeA and nodeB using the current parameter.

circuit-SetTweenA
Takes 3 parameters (component x y) and adds a tween vertex on one side of the component. For circuit rendering purposes.

circuit-SetTweenB
Takes 3 parameters (component x y) and adds a tween vertex on one side of the component. For circuit rendering purposes.

circuit-DoLoops
Automatically finds the loops in the circuit. It is necessary to call this once modifications to the circuit are complete for the circuit to be simulated correctly.

circuit-Clear
Clears the current circuit.

circuit-ShowCurrent
Turns on the animated rendering of the current.

circuit-ShowComponents
Turns on rendering of the components.

circuit-ShowNodes
Turns on rendering of the nodes.

circuit-ShowLoops
Turns on rendering of the loops.

circuit-HideCurrent
Turns off the animated rendering of the current.

circuit-HideComponents
Turns off rendering of the components.

circuit-HideNodes
Turns off rendering of the nodes.

circuit-HideLoops
Turns off rendering of the loops.

circuit-Rewire
Takes 3 parameters (componentID nodeFrom nodeTo) and disconnects the component from nodeFrom and connects it to nodeTo.

circuit-DeleteComponent
Takes a componentID as a parameter and deletes it.

circuit-DeleteNode
Takes a nodeID as a parameters and deletes it if there is nothing connected to it.

LIVE RENDERING

ogl-renderon
Turn on live rendering

ogl-renderoff
Turn off live rendering

ogl-drawline
Takes 6 parameters (x1 y1 z1 x2 y2 z2) that describe a 3D line, and renders it. This can only be called from within the paper-render function. Redefine the paper-render function at will at runtime.

OLD TEST FUNCTIONS

myadd
Takes 2 parameters and adds them

myaddlist
Takes a list and adds the numbers in the list.

Screenshots:

Press "Execute" when the program starts to load the script which computes the crane crease pattern:



Having a look at the crease pattern in the pattern editor:



Verlet physics paper manipulation and live rendering: Calling verlet-rotate from the repl to rotate the 4 corner vertices at once, 0.1 degrees at a time (the rotation continues due to momentum), then calling ogl-renderon to turn on live rendering, and modifying the paper-render function live by loading live-render.lisp (the function simul-rotate has been defined for convenience to do the simultaneous rotation):


Circuit simulator: Switching to the circuit simulator and loading a circuit (block-circuit.lisp):


Loading the scripts "block-circuit2.lisp" and "block-circuit3.lisp" to modify the circuit:

Embedding a Lisp interpreter into a Qt app



Download: QtEclSmallSimulations2.zip (Win32 binary)

I've been working on a few things these past few months. This includes:
  • A crease pattern generator that can calculate the crease pattern a piece of paper will have based on the sequence of folds applied to it. Conceptualising the paper as a mesh of facets, and determining the operations that can be performed on facets such as splitting was the key to implementing this.
  • A circuit simulator that uses an iterative process to solve the circuit. Since Verlet physics is very successful at applying physical constraints (such as ensuring a point mass is fixed in space, or ensuring two point masses are always a fixed distance apart) using little more than repeatedly pushing objects according to the pressure that each constraint is applying, I thought I would try the same idea with electric circuits and the pressures of KVL and KCL.
When I managed to embed a Lisp interpreter into my app using ECL, I decided this is a suitable thing to tell other people about.
The advantages of scripting using Lisp in this way are numerous and exciting:
  • Its an excellent way to ease into the beauty of Lisp without abandoning my other work.
  • Initially, I can create Lisp bindings that manipulate the interface of the simulation such as adding components to the circuit, or applying specific folds. Doing this, I get loading/saving functionality for free, because my circuit/origami folds/other simulation configuration are defined in a lisp script. Also, I can manipulate my simulation “live” in the lisp repl while the simulation is running.
  • Gradually, I can transfer more and more of the simulation implementation to lisp. Doing so, I can enjoy a real “live coding” environment. I have fluxus to thank for the inspiration.
  • Lisp is a magnificent programming language. Having a Lisp repl in my app means I get a beautiful customisable programming language allowing me to describe a DSL without having to write a single line of parsing code.
The possibilities having a Lisp running in your app are breathtaking. In the past, the only thing that kept me from writing my own language to control my simulations was the mind numbing drudgery of writing parsers. Now, I get all the advantages of a custom language completely for free!
The “Lisp” tab is initially active. It features the Lisp REPL. The only C++ function it is hooked to is myadd – not very exciting from the user's point of view, but VERY exciting for me, since it shows that I can have lisp control the whole show!
Non lisp stuff (will be lispified later):
  • In the “Crease Pattern” tab, press “Push button” repeatedly to see the effect of applying a fold sequence.
  • In the “Circuit” tab, right click a component to select it, and drag the slider to change its parameter (voltage for voltage sources, current for current sources, resistance for resistors.). In between frames, the algorithm runs 100 passes to solve the circuit. You'll notice that the visualisation is inspired by Paul Falstad's circuit simulator – I just wanted to add more interactivity!