Q - Equational Programming Language





To whet your appetite, here are some scripts for your browsing pleasure:

  • hello.q: the infamous "hello world" example
  • basics.q: some basic examples. Start out with these to quickly get an idea how Q programs look like.
  • searchtree.q: an example showing the use of algebraic data types with inheritance
  • huffman.q: Huffman codes in Q
  • queens2.q: the 8 queens problem, shows how to implement backtracking in Q
  • streams.q: some stream (lazy list) programming examples
  • symbolic.q: simple examples for symbolic rewriting rules
  • dnf.q: disjunctive normal form of logical expressions, another tiny symbolic rewriting example
  • dijkstra.q: Dijkstra's shortest path algorithm, implemented with Q-Graph
  • dgram.q: a simple client/server example showing how to transmit datagrams over a socket
  • midi_examp.q: some basic realtime MIDI functions, written using the Q-Midi module

The Grab Bag


  • Tim Haynes has kindly contributed the icon shown in the headline above for use on Q-powered websites. He has also written a nice module to facilitate CGI scripting with Q, see cgi.q in the core package.
  • Peter Minten has written two very useful modules for the exchange of Q data: smash-q, a binary marshalling library for Q, and json-q, a Json converter. The core routines of smash are written in C, so the conversion is pretty fast, and extending smash for your own data structures should be a piece of cake. (Please note that this has not been updated for a while, so you might have to fiddle with the code to make it work with newer Q versions.)
  • Rob Hubbard has created Q syntax definitions for use with the Windows TextPad editor, and his "Q+Q" rational number and "Q[i][X]" polynomial libraries are now included in the distribution.
  • John Cowan has programmed an egg (Chicken Scheme library) which makes available the facilities of the Q language to Chicken programmers. Chicken is a compiler for the Scheme programming language. John's Q egg can be found in Chicken's standard egg repository here.

Various other stuff that you may find useful:

  • q-dcop-0.1.tar.gz: Preliminary version of a Q-DCOP module which lets you control KDE applications via the DCOP interface.
  • qinterp.h, qinterp.cpp: A thin C++ wrapper for libqint which makes it easier to embed Q in your C++ applications.
  • qtexamp.tar.gz: A little example demonstrating how you can employ Q-SWIG to wrap a Qt GUI for use in a Q script. (Note that this is now obsolete as a full Qt wrapper for Q is available.)
  • q-texmacs.tar.gz: A plugin which lets you run Q sessions in GNU TeXmacs, the free scientific text editor. To install, extract the tarball into your /usr/share/TeXmacs/plugins directory. (Please note that this has not been updated for a long time, so you might have to fiddle with the code to make it work with newer TeXmacs versions.)

Or maybe you feel exhausted after trying out all the stuff on this page? Then you might just want to relax playing a little classic arcade game. ;-)

  • qpong-1.0.tar.gz: a little example showing how to write Qt applications using the new Qt/Q module. This is now also included in the "all-in-one" RPM package.

The Computer Music and Multimedia Corner

Below you find my little collection of multimedia applications which demonstrate some of the capabilities of Q's multimedia library. Currently the collection focuses on sound and computer music applications. The latest addition is a collection of plugins, scripts and example patches showing how to interface between Q, Faust and Miller Puckette's Pd. The other programs are mostly enhanced versions of some of the sample scripts distributed with the multimedia library, which have also been equipped with shiny new Qt GUIs. (In the present versions of these programs, the GUIs have mostly been implemented in C++ using KDevelop and QtDesigner. However, we hope that we can soon provide updated versions of these programs which make use of Q's new Qt/Q module. The QMidiCC script has already been ported to Qt/Q.)

This software is distributed under the GPL. Most of these examples are now included in the RPM package available in the Binary Packages section of the Download page. You can also obtain the sources of the programs below. For the GUI programs you'll need KDE (probably a fairly recent version, 3.2 has been tested) and Qt 3.x. (Of course, you'll also need an installation of the Q core and multimedia packages, see the Download page for those.) Please also check the included README files for further information.


QAudioPlayer is an enhanced version of the audio_player script distributed with the Q-Audio package. It implements a player for digital audio files which can process any of the formats supported by libsndfile, featuring a waveform/FFT display, as well as volume and playback speed controls. This program demonstrates, in particular, on-the-fly samplerate conversion and FFT calculation using the corresponding libsamplerate and libfftw3 functions of the wave module.

Source: qaudioplayer-0.3.tar.gz


QMidiCC is a replacement for the midicc script included in the Q-Midi distribution. This program implements a kind of MidiShare patchbay and transport control. Clients can be connected manually, as with the msconnect program included in the MidiShare distribution. In addition, QMidiCC can be configured to automagically connect new clients as soon as they show up in the MidiShare client list, and takes care of starting up your MidiShare driver programs. It can also be connected to other MidiShare applications to print their MIDI output and to send them MIDI start and stop messages. QMidiCC uses the same midiccrc configuration file as midicc, so both programs can be used interchangeably.

Source: qmidicc-1.1.tar.gz


QMidiPlayer is a new version of the midi_player script included in the Q-Midi distribution, featuring a much improved event view and operations to jump to MIDI marker events in the input file. Thanks to MidiShare's excellent MIDI file support, this program is able to play almost any MIDI file you throw at it, including files with all kinds of meta and sysex data, SMPTE timestamps, missing tempo track or end track markers, etc., which make many other MIDI sequencers and players go bonkers. It can also record MIDI data received from MIDI input and other Q-Midi and MidiShare applications, and save the recorded data in a standard MIDI file. The program properly responds to MIDI start and stop messages which is nice for synchronization purposes.

Source: qmidiplayer-0.2.tar.gz


QSCSynth is a GUI frontend for the sclang and scsynth programs which allows you to play and control SuperCollider synthesizers defined in an SCLang source file. It implements a monotimbral software synth which can be played via MIDI input and other Q-Midi/MidiShare applications. Moreover, with MidiShare's msAlsaSeq driver, QSCSynth can easily be wired up with ALSA-based sequencer applications like Rosegarden, employing it as a fully programmable realtime software synthesizer. The audio stream generated by SuperCollider can be watched in an integrated waveform/FFT display, and can also be recorded in an audio file. Like QMidiPlayer, QSCSynth responds to MIDI start and stop messages which is nice for synchronization purposes. QSCSynth can also be configured to map arbitrary MIDI controller messages to corresponding OSC messages which change the control parameters of the synthesizer and effect units defined in the SCLang source file. Moreover, QSCSynth also provides its own control surface (constructed automatically from the parameter descriptions found in the binary synth definition files) which lets you control synth and effect units from the GUI as well.

QSCSynth is a replacement for the scgui script included in the Q-Synth distribution. It provides about the same basic functionality, but with a much nicer user interface and a lot of useful extensions. The included Q script demonstrates how a SuperCollider-based software synthesizer (actually a "MIDI to OSC" mapper) can be implemented with the Q-Midi and Q-Synth modules. While some of this code is SuperCollider-specific, it should not be very difficult to port these algorithms to other OSC-enabled sound synthesis engines like Csound and Pd.

Source: qscsynth-0.4.tar.gz


QFSynth is a Qt-based graphical application for running Faust-based realtime software synths, built on top of Q's faust module. It also includes a slightly modified/extended version of the synth.q script included in the Q-Faust distribution, and a bunch of examples. This program works quite similarly to QSCSynth (see above), but uses Faust as the underlying DSP engine. Faust (an acronym for Functional audio streams) is a very cool functional programming language for realtime sound processing and synthesis developed at Grame and distributed as GPL'ed software. QFSynth lets you run your Faust DSPs in a synth/effect chain to produce audio from MIDI and audio input in realtime.

You'll find that coding DSPs in an FPL is a very natural thing to do, as signals are just functions, so DSPs are really nothing but higher-order functions operating on them. As an FPL Faust makes that easy. However, IMHO the greatest thing about Faust is that, while it's a very-high-level language, it still gives you the feeling that you're programming to the "bare metal". In Faust you have all the flexibility to design the basic building blocks of your DSPs the way that you want them. The Faust compiler translates your functional DSPs to optimized C++ code which can compete with the performance of carefully hand-coded C routines. This makes Faust a great tool for teaching and learning DSP without having to resort to C.

Source: qfsynth-1.5.tar.gz


We also offer some additional software for interfacing between Q, Faust (see above) and Pure Data (Pd), Miller Puckette's real-time graphical programming environment for audio, video, and graphical processing. The Pd plugin interfaces for Q and Faust let you program all your specialized Pd control and audio objects using two modern-style functional languages which are much more fun than C/C++. Pd, Faust and Q together provide you with a nice interactive programming environment for developing advanced computer music and multimedia applications with ease.

The Pd/Q external is a Q plugin for Pd. It lets you implement Pd control objects using Q functions, and also enables you to access Q's other computer music and multimedia interfaces in Pd. This package can be found on the Download page. Moreover, a little demo showing how to write a simple Pd/Q pattern sequencer is available here: seqdemo.tar.gz.

In addition, the faust2pd package makes it easy to use Faust DSPs with Pd. This is now also included in recent Faust distributions. It contains puredata.cpp, a Faust architecture file to create Pd audio plugins from Faust sources, and faust2pd, a Q script which generates Pd patches with GUI from the dsp.xml files created by Faust when run with the -xml option. The package also contains a bunch of examples, including Yann Orlarey's Faust implementation of the Karplus-Strong synthesizer, various effect units, and a version of the Pd/Q pattern sequencer demo (see above) which uses Faust units for sound synthesis. Documentation is available in the README file included in the package; there you can also find information on how to get this software up and running.

Source: faust2pd-1.1.tar.gz

Guitar FX: For a more elaborate faust2pd example, I have put together a collection of guitar effect units written in Faust, along with corresponding Pd patches generated with faust2pd and a main patch which can be used as an "effects pedal". Currently this package contains an amp unit with integrated tone and balance controls and dB meter (useful both as preamp or final stage), expander and compressor (dynamics processing, can also be used as noise gate and limiter), fuzz (distortion), chorus, flanger, echo (delay effect) and Yann Orlarey's Faust implementation of freeverb (from the Faust distribution). You can get it here: guitarfx-0.1.tar.gz.

KCS Decoder: A more technical example is the following Kansas City Standard decoder for the 1980ish FA-3 tape recorder interface of the Casio PB-100/FX-700P series of calculators: kcs-example.tar.gz (README). For testing purposes, KCS encodings of two simple PB-100 Basic programs can be found here and here. There's also a nice end user version of this application available, the CasioComm patch which can be used to transfer Basic programs between a Casio PB-100 series calculator and the PC, see the README file for details. Get it here: casiocomm.tar.gz.


Last but not least, here's a little Q script which makes your live easier if you want to create SuperCollider ugens with Faust. This is a port of Stefan Kersten's faust2sc Ruby script included in the Faust distribution, but it runs much faster and also contains some bugfixes and improvements.

Source: faust2sc-1.0.tar.gz

© 2007 by Albert Gräf