We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

MelodyCode

From Esolang
Jump to navigation Jump to search

MelodyCode (also known as PIANOLANG) is an esoteric programming language created in 2026 by Patricia Sánchez, Valeria Jiménez, Alba Santoyo and Marcos Hidalgo for a university project. In MelodyCode, the source code is text, and the machine code is music. It blurs the line between software engineering and musical composition by compiling text into MIDI audio, and reverse-compiling real piano audio captured via microphone into code using the Fast Fourier Transform (FFT).

Concept and Syntax

MelodyCode abandons the traditional alphabetical mapping to piano keys (e.g., A=C, B=D). Instead, it implements an ergonomic "Piano QWERTY" based on Spanish letter frequency.

The most frequently used letters (E, A, O, S, R) are placed on the central octaves (the natural resting position for a pianist's hands), while less common consonants (X, W, K) are pushed to the outer octaves.

The duration of the note dictates the character's case:

  • Staccato (short presses < 0.5s): Lowercase letters, typically used for commands.
  • Legato (sustained presses > 0.6s): Uppercase letters, typically used for variables.
  • Rests (silences): Short silences separate characters, while long silences act as spaces or execution delimiters.

Accented vowels (Á, É, Í) share the same MIDI note as their base vowels to maintain musical harmony without being hindered by orthographic rules.

Execution Modes

The reference implementation (written in Python) features a bidirectional interpreter:

  1. Text to Audio (Musical Compiler): The programmer types code into a console. The interpreter compiles the string and plays the corresponding melody in real-time using a MIDI synthesizer, while a graphical piano interface highlights the keys and creates a scrolling console.
  2. Audio to Text (Acoustic Interpreter): The system listens to an analog piano through a microphone. It uses pure mathematics (Fast Fourier Transform via NumPy) to analyze the sound waves, isolate the exact frequency in Hertz, and translate the physical performance into digital text syntax on the screen, actively filtering out background noise.

External resources