Schoenberg

From Esolang
Jump to navigation Jump to search
Schoenberg
Paradigm(s) imperative
Designed by User:Tomer
Appeared in 2025
Memory system Cell-based
Dimensions one-dimensional
Computational class Turing complete
Major implementations Original
Influenced by Piet, brainfuck
File extension(s) .mid

Schoenberg is an esoteric programming language where programs are written as MIDI files. A MIDI file is basically digital sheet music that tells a computer which notes to play when and how loudly.

The programming language interpreter, and transpilers between Schoenberg and brainfuck programs, can be found on GitHub.

Semantics

The operational semantics of a Schoenberg program directly match those of a brainfuck program. Since brainfuck is Turing complete, so is Schoenberg.

Like brainfuck, Schoenberg operates on an array of memory cells, each initialized to zero. There is a pointer, initially pointing to the first memory cell, and there are commands for moving the pointer, modifying the current cell, outputting the current cell, and looping.

Syntax

Since Schoenberg programs are MIDI files, its syntax is not text-based.

Instead, commands are controlled by pitch class distance, velocity, and overlap. Rhythm has no effect on a program's behavior unless it causes notes to overlap.

Command Description Syntax amount Brainfuck
Decrement Decrement the pointer cell by amount Play a note 1 pitch class away from the current note -
Increment Increment the pointer cell by amount Play a note 2 pitch classes away from the current note +
Move left Move the pointer left amount times Play a note 3 pitch classes away from the current note <
Move right Move the pointer right amount times Play a note 4 pitch classes away from the current note >
Output Output the pointer cell Play a note 5 pitch classes away from the current note N/A .
Input Input a byte into the pointer cell Play a note 6 pitch classes away from the current note N/A ,
Loop start Jump past the matching loop end if the pointer cell is 0 Play a note that overlaps the current note (a "loop note") N/A [
Loop end Jump back to the matching loop start if the pointer cell is not 0 Stop playing an active loop note N/A ]

Additionally:

  • Playing the same note twice in a row, corresponding to a pitch class distance of 0, is a no-op. However, playing and overlapping two different notes with the same pitch class (e.g. in different octaves) can be used to start loops without adding other commands.
  • When playing multiple notes at exactly the same time (e.g. a chord), the chronology of the notes is considered to be the ascending pitch order.

Every MIDI file is a syntactically valid Schoenberg program, although most don't do anything useful.

Examples

Some of these were written by hand while others were transpiled from brainfuck programs.

MIDI Description Audio (synthesized using TiMidity) Source
hello_world.mid Prints Hello, World! hello_world.mp3 Esolang Wiki
cell_width.mid Prints the interpreter's cell width cell_width.mp3 Esolang Wiki
echo.mid Prints the input, like echo echo.mp3 User:Tomer
wc.mid Counts input lines, words, and bytes, like wc wc.mp3 Daniel B. Cristofani
fib.mid Prints the entire Fibonacci sequence fib.mp3 Daniel B. Cristofani
bubble_sort.mid Sorts the input bytes using bubble sort bubble_sort.mp3 Daniel B. Cristofani
insertion_sort.mid Sorts the input bytes using insertion sort insertion_sort.mp3 Daniel B. Cristofani
quick_sort.mid Sorts the input bytes using quick sort quick_sort.mp3 Daniel B. Cristofani
brainfuck_interpreter.mid Runs a brainfuck program on its input, which should be separated by an exclamation point brainfuck_interpreter.mp3 Daniel B. Cristofani

All the programs can be found on GitHub.

Etymology

The programming language is named after Arnold Schoenberg (1874–1951), who is widely considered to be the father of atonal music.

Writing tonal music, the basis of Western music composition, requires limiting yourself to the pitch classes of a chosen key, but this is incredibly hard to do when writing Schoenberg programs.

For example, if you want to decrement the pointer cell, then the next note must be 1 pitch class away. This leaves you with only two options for the next note's pitch class, but it's possible neither of those pitch classes is in the chosen key.

As a result, Schoenberg programs tend to be atonal.

External resources