Est. 2004 Intermediate

R4 script

R4 script is the C-like scene-scripting language embedded in R4, Gordon Williams's OpenGL music visualizer from RabidHamster, used from 2004 to write the '.r4' custom scenes, shaders, overlays and faders that react to sound, plus a separate call-style template language for the program's built-in web server

Created by Gordon Williams, trading as RabidHamster and later as Pur3 Ltd. Williams wrote R4 and its Winamp-plugin predecessors R1, R2, R2v2 and R2/Extreme; he studied computer science at Cambridge, did graphics contract work (including Nokia's N900), and afterwards created the Morphyre visualizer and the Espruino JavaScript microcontroller. The R4 Programming Tutorial that documents the language most fully was written by a user, Jussi Harkonen

Paradigm Procedural and imperative, in the style of a stripped-down C: statements terminated by semicolons, int and float variables and arrays, const declarations, if/else, for/while/do-while loops and user-defined functions that return a value through a special 'result' variable. A scene is organised around callback functions init(), reset() and render() and a header that instantiates named module objects; a second, call-expression template language (strcat(), set(), get(), while(), if(), hide(), newline()) drives the program's HTTP interface
Typing Static and weak, with only two scalar number types, int and float; the type of a numeric literal is decided by whether it contains a decimal point, so integer division and floating-point division are distinguished by writing 5 versus 5.0. There are no boolean or character types (true is 1 and false is 0), and strings are stored as int arrays and manipulated with strcpy/strcat; identifiers are case-insensitive
First Appeared 2004, as the scene-scripting engine inside R4. Public beta builds (versioned 0.02 upward in the changelog, which is itself undated) reportedly circulated in 2003; the 5th-generation R-series program, R4 grew out of Williams's Winamp visualizers R1, R2, R2v2 and R2/Extreme, the first of which he wrote as a student around 2001
Latest Version R4 1.25, the final build; the download server's Last-Modified date for the R4 1.25 installer is 12 January 2010. Active development of R4 ended when Williams released its successor, the Morphyre visualizer, through Pur3 Ltd in September 2009; the R4 site remains online but R4 is no longer sold or updated

R4 script is the small programming language built into R4, an OpenGL music visualizer written by Gordon Williams under the name RabidHamster. R4 draws animated 3D graphics that “twist and turn with the music,” and almost everything it puts on screen is defined by a scene: a .r4 text file written in a C-like language that the program compiles and runs many times a second. The language never had a life outside R4. It is the way you told a 2004-era visualizer what to draw, and it is remembered today mostly by the people who wrote scenes for it, by one entry in the “99 Bottles of Beer” collection, and, less happily, by a 2012 security advisory against the program that hosted it.

History and Origins

The R-series

R4 was the fifth in a line of visualizers Williams wrote for the Winamp media player. Pur3, the company he later formed, lists the lineage as R1, R2, R2v2, R2/Extreme and then R4, and dates the first R2 visuals to around 2001, when Williams was a student. The R2/Extreme page describes that fourth-generation plugin as already ambitious: 25 OpenGL scenes that could be combined, “scene fades” between them, an in-plugin user interface, a control console with bindable keys, and a telnet server in the professional version. R2/Extreme, by the site’s account, found its way into nightclubs and events, including Glastonbury and a Ministry of Sound New Year at the Millennium Dome (Morphyre’s later history page attributes that event to R4 instead, so the exact generation is uncertain).

R4 (2004)

R4 took that idea and made two changes that mattered for the language. First, it became a standalone program as well as a Winamp plugin, reading audio straight from the sound card. Second, and more important, it exposed a full scripting engine so that scenes were no longer hard-coded: a scene became a program. R4’s own change-log starts at “0.02 BETA : Public Release” and climbs through the 0.x betas - adding faders, overlays, an HTTP server and the scripting console - to version 1.00 and beyond. The log is undated, but the betas appear to belong to 2003. WinampHeritage dates the R4 1v20 plugin build to February 2004, and the bundled Java scene-builder “R4Construct” carries April 2004 file dates. By Pur3’s later reckoning R4 was downloaded by more than 1.4 million people and used in music venues around the world; the professional, brandable version sold for GBP 95.

After R4

Development wound down at the end of the decade. Williams, trading as Pur3 Ltd, spent about three years building a successor, the Morphyre visualizer, and released it in September 2009; R4’s pages began pointing visitors to Morphyre, and the final R4 build, 1.25, dates from around January 2010. Williams went on to create the Espruino JavaScript microcontroller. R4 itself resurfaced in 2012 when Luigi Auriemma published buffer-overflow and directory-traversal bugs in its optional web server, catalogued as CVE-2012-10058.

Design Philosophy

The language exists to serve one program, and its design shows it. The tutorial states the goal plainly: R4 script “is basically a stripped-down version of C,” so “learning R4 programming is much easier if you are familiar with C/C++ or Java.” It keeps C’s shape - braces, semicolons, if/else, for, while, do/while, functions - and throws out most of the rest. There are two number types, int and float, and nothing else scalar: no boolean type (true is 1, false is 0), no character type, and strings faked as int arrays. There are no ++ or -- operators and no /* */ comments, only //. Identifiers are case-insensitive. A function returns a value by assigning to a magic variable called result.

What the language adds instead is a vocabulary for real-time graphics. A scene is built from modules - SOLID, TEXTURE, GL, MAP, TUNNEL, MEDUSA, BUFLOAD/BUFSAVE and many more - that are declared in a header and then driven from code, and it hands the author the audio: soundA, soundB and soundC for bass, mid and treble energy, and 512-element waveLeft/waveRight and specLeft/specRight arrays for the waveform and its Fourier transform. This is a language whose “standard library” is a set of drawable objects and a stream of sound.

The Language

A scene

Every scene has the same skeleton: a header that names its modules, then three callbacks. init() runs once when the scene loads, reset() runs each time the scene becomes active, and render() runs before every frame.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
SCENE (
    "name"   = "Example Scene";
    "author" = "Jussi Harkonen";
    SOLID   background();
    TEXTURE texFish();
    MEDUSA  fish(background, texFish);
)

int numFishes;
const int MAX_NUM_FISHES = 10;

void init() {
    // one-time setup
}

void reset() {
    numFishes = 0;   // re-initialise per activation
}

void render() {
    // runs every frame
}

Module member variables are reached with a dot, and colours are packed into a 32-bit integer:

1
red.col = rgb(1, 0, 0);   // set a SOLID module to red

C, minus a lot

The everyday syntax is C with sharp edges. Numeric literals decide their own type, so division is a trap the tutorial warns about:

1
2
var2 = var1 / 5;     // integer division
var2 = var1 / 5.0;   // floating-point division

const values must be plain non-negative literals (no expressions, and floats need a visible decimal), strings live in int arrays and are handled with strcpy/strcat, and a return value comes back through result:

1
2
3
float randNum(float minVal, float maxVal) {
    result = minVal + ((maxVal - minVal) * rand());
}

Shaders

Modules are textured through terse shader strings, where each drawing option is a single letter followed by parameters. The string is usually set in init():

1
strcpy(gl.shader, "T0;B11;");   // use texture 0, additive blending

Here T0 selects a texture, B11 sets an additive blend mode, and other letters cover wireframe width, depth testing, culling, colour multipliers and OpenGL texture-coordinate generation. The tutorial presents the blend modes as a direct expression of the OpenGL blending equation, which is a fair summary of the whole language: a thin, music-aware scripting skin over OpenGL.

A second language for the web server

R4’s optional HTTP service used a different, call-expression syntax for pages it served. Kang Seonghoon’s “99 Bottles of Beer” entry is written in it - a single nested expression of strcat, set, get, while, if, hide and newline placed in an HTML file under R4’s wwwroot and rendered on request. It is worth knowing that “R4 script,” as catalogued in the 99-bottles collection, refers to this template facet, while the .r4 scene files use the C-like language above.

Current Relevance

R4 is a closed-source Windows program, and the language cannot be run anywhere else: there is no standalone interpreter, no port and no Docker image. The R4 site is still online and the 1.25 installer, the tutorial and the R4Construct source can still be downloaded, so the language can in principle still be exercised on a Windows machine with a capable graphics card, but nothing about it has changed since about 2010. Its creator moved on to Morphyre and then to Espruino, and the audience that once wrote R4 scenes has largely dispersed. The one piece of R4 that kept a mild afterlife is its web server, which lives on as a teaching example in Metasploit and a fingerprint in vulnerability scanners rather than as a place anyone runs visuals.

Why It Matters

R4 script is a clean example of a whole category of languages that rarely get written up: the embedded scripting language of a single application. It was never meant to be general-purpose, never had a package ecosystem, and never tried to outlive its host. What it did have was a clear job - make a music visualizer’s scenes programmable instead of hard-coded - and a pragmatic design to match, borrowing just enough of C to be learnable and adding exactly the graphics and audio primitives the job required. It is a reminder that for every language with a standards committee there are many like R4 script: small, purpose-built, tied to one program, and interesting precisely because of how tightly form followed function.

Sources

  • R4 website, RabidHamster: about.php, main.php, download.php, versions.php (the 0.02-BETA to 1.25 change history), tutorials.php, register.php, screenshot.php (rabidhamster.org/R4/)
  • Jussi Harkonen, R4 Programming Tutorial, version 1.0 (rabidhamster.org/R4/R4tut10.pdf; PDF metadata dated 21 February 2005)
  • R2/Extreme website, RabidHamster: about.php, index2.php, download.php, shopindex.php (rabidhamster.org/R2/)
  • “99 Bottles of Beer,” language entry “R4 script” #762 by Kang Seonghoon (Tokigun), dated 24 June 2005 (“Tested with R4 1v06 and 1v20”)
  • Pur3 Ltd, Visualisation (pur3.co.uk/Visualisation); Morphyre, About and Who Are We (morphyre.com), for the R-series history, the 1.4-million-download figure and Morphyre’s September 2009 release
  • WinampHeritage, R4_1v20.exe (winampheritage.com), dating that plugin build to 9 February 2004
  • Luigi Auriemma, advisory “R4 <= 1.25” (aluigi.org/adv/r4_1-adv.txt, 9 February 2012); CVE-2012-10058 / OSVDB 79007; Rapid7 Metasploit module rabidhamster_r4_log (Exploit-DB 18929, 25 May 2012); Tenable Nessus plugin 61460 “RabidHamster R4 Detection” (9 August 2012)

Timeline

2001
According to Pur3's later account, Gordon Williams - then a student - creates the R2 visuals. R4 is the fifth generation of his Winamp visualization plugins, following the 'Original RabidHamster's Bitchin' Plugin', R2, R2v2 and the fourth-generation R2/Extreme, all OpenGL plugins for the Winamp media player distributed from rabidhamster.org
2003
R4 is developed in the open as a numbered beta (approximate date: the site's change-log carries no dates, and 2003 is inferred from the February 2004 1v20 build that followed): the version history begins with '0.02 BETA : Public Release' and runs up through 0.19 before the 1.00 release, adding scenes, faders, overlays, a network server with 'hacky HTTP/1.0 serving' and the scripting console along the way. Unlike its predecessors, R4 is a standalone program (it can also run as a Winamp plugin) that reads sound from the sound card
2004
R4 1.x is released. WinampHeritage dates the R4 1v20 plugin build to 9 February 2004; the Java 'R4Construct' visual-scene constructor whose source ships with R4 carries file dates of April 2004. R4 goes on to be, in Pur3's words, 'a hugely successful system which has been downloaded by more than 1.4 million people and used in music venues across the world'. The professional version is sold for GBP 95
2005
The community documents the .r4 scene language: Jussi Harkonen's 'R4 Programming Tutorial' v1.0 is produced (its PDF is dated 21 February 2005), and on 24 June 2005 Kang Seonghoon (Tokigun) submits an R4 script '99 Bottles of Beer' program 'Tested with R4 1v06 and 1v20' that is written for R4's web-server template language and served from the program's built-in HTTP interface
2009
Williams, now trading as Pur3 Ltd, releases the Morphyre Music Visualizer in September 2009 after about three years' work. Morphyre is positioned as R4's successor for both home and professional use, and R4's own pages begin steering visitors to Morphyre; R4 is no longer actively developed
2010
The last R4 packages are published: the download server reports a Last-Modified date of 12 January 2010 for the R4 1.25 installer, the programming tutorial and the R4Construct archive. R4 1.25 is the final version
2012
Luigi Auriemma publishes an advisory (9 February 2012) reporting a stack buffer overflow, a heap overflow, a directory traversal and a screenshot stack overflow in R4's optional, disabled-by-default HTTP control service in versions up to and including 1.25. It becomes CVE-2012-10058 / OSVDB 79007; a Metasploit module (rabidhamster_r4_log, Exploit-DB 18929) follows on 25 May 2012, and a Nessus 'RabidHamster R4 Detection' plugin on 9 August 2012 fingerprints the 'R4 Embedded Server'

Notable Uses & Legacy

R4 custom scenes (.r4 files)

The primary use of the language was writing the scenes R4 renders. A scene file declares a header of module instances (SOLID, TEXTURE, GL, MAP, TUNNEL, MEDUSA, BUFLOAD/BUFSAVE and many more) and defines init(), reset() and render() functions that animate them in time with soundA/soundB/soundC and the waveLeft/waveRight and specLeft/specRight arrays. R4 shipped with a large library of such scenes in its 'predefine' directory (the site's screenshot gallery alone shows well over a hundred), and users wrote their own

Shaders, overlays and faders

The same language configures R4's compact shader strings (single-letter commands such as T for texture, B for blend mode and G for texture-coordinate generation, each a shorthand for an OpenGL call), OVERLAY scenes that post-process the running scene through a 'scenefrom' module, and faders that blend between a 'scenefrom' and a 'sceneto' surface and signal completion by setting a 'finished' variable

The built-in web server

R4's optional HTTP service let a scene be controlled - and pages served - from another network-connected computer, even a wireless PDA, without disturbing the visuals. Kang Seonghoon's '99 Bottles of Beer' entry is an example of the call-expression template language used there, placed in an HTML file under R4's wwwroot and rendered on request. The same service was later found to be exploitable (CVE-2012-10058)

Clubs, events and branded installations

R4 and the R2/Extreme plugin before it were used for live visuals at nightclubs and events. According to the R4 site, R2/Extreme featured at Glastonbury and at a Ministry of Sound New Year event at the Millennium Dome (Morphyre's later page credits that event to R4, at the venue by then renamed the O2), and R4's professional, brandable build was used in venues internationally; RabidHamster also produced custom visuals for clients including the BBC, Gainward and a Miami nightclub

Scene packs and tutorials

A small authoring community grew around the language, sharing scenes on the R4 forums and DeviantArt (including Rovastar's scene pack) and producing documentation such as Jussi Harkonen's step-by-step 'R4 Programming Tutorial', which walks through building a music-reactive 'Caribbean Sea' flow-field scene

Language Influence

Influenced By

Running Today

Run examples using the official Docker image:

docker pull
Last updated: