Music Macro Language
Music Macro Language (MML) is a text-based music description language that enables the sequencing and playback of music on early personal computers and video game consoles using simple alphanumeric strings to denote notes, durations, octaves, tempos, and effects.[1] Originating in Japan during the late 1970s, it was first implemented as music commands within BASIC interpreters on systems like the Sharp MZ series, allowing direct embedding of musical notation into program code for hardware-limited sound generation via components such as the Intel 8253 timer.[2] The formal naming of "Music Macro Language" emerged with Microsoft GW-BASIC in the 1980s, where thePLAY statement processed MML strings to produce tones through the PC speaker, supporting features like note specification (e.g., C for middle C), length modifiers (e.g., L4 for quarter notes), octave shifts (e.g., O3), and tempo settings (e.g., T120 for 120 beats per minute).[3] This syntax, resembling ASCII sheet music, facilitated easy composition without specialized editors and became integral to Japanese computing culture on platforms like the NEC PC-88 and MSX.[4]
Over time, MML evolved beyond BASIC, powering sound drivers in video games for consoles such as the Nintendo Entertainment System (NES) and Sega Genesis through compilers like the Music Compiler Kit (MCK), which convert MML text into binary audio data compatible with specific sound chips (e.g., the NES's 2A03).[5] Its simplicity and portability made it a staple in the chiptune scene, enabling retro-style music creation, ROM hacking (e.g., via tools like AddMusicK for Super Mario World), and modern applications in software editors like Macrotune.[6] Despite the rise of graphical trackers, MML persists among enthusiasts for its precise control and text-based workflow, particularly in Japan's doujin game development and online communities.[4]
Overview and History
Definition and Purpose
Music Macro Language (MML) is a domain-specific language designed for describing musical sequences through concise alphanumeric notations. Early concepts originated in 1978 with Sharp Corporation's MZ-80K computer, using proprietary BASIC commands for music generation, and evolved into a standardized form as an extension within Microsoft BASIC interpreters for Japanese microcomputers in the early 1980s.[7] This text-based system enables the specification of pitches, durations, volumes, and other musical parameters in a compact, readable format, allowing users to compose and play music directly via simple string inputs.[8] The primary purpose of MML is to facilitate programmatic music generation on resource-constrained hardware, providing an accessible method for creating tones, rhythms, and effects without requiring graphical user interfaces or complex software tools.[7] It was particularly suited to the limitations of early personal computers, where memory and processing power were scarce, by translating human-readable commands into synthesizer instructions for real-time playback.[4] This approach democratized music composition for hobbyists and developers, integrating seamlessly into programming environments like BASIC's PLAY statement. Key advantages of MML include its compact representation, which minimizes storage needs for musical data; ease of embedding within code for dynamic generation or modification; and inherent support for polyphony, enabling multiple simultaneous voices despite hardware constraints such as limited sound channels.[7] These features made it ideal for applications on 8-bit systems, where it allowed efficient polyphonic music in environments with only three or four voice channels.[8] The formal term "Music Macro Language" emerged around 1983 with Microsoft GW-BASIC and MSX-BASIC, developed in collaboration between Microsoft and ASCII Corporation for the MSX standard launched in 1983, which incorporated FM synthesis and aimed to unify software across manufacturers.[9] Over time, MML evolved into variants used in video games and music trackers.[7]Origins and Early Development
Music Macro Language (MML) originated in Japan as a text-based system for generating music on early personal computers, with its foundational commands first implemented in 1978 by Sharp Corporation on the MZ-80K model. This implementation was integrated into the SP-1002 MONITOR IOCS and SP-5001 BASIC operating systems, utilizing the Intel 8253 programmable interval timer for sound generation and featuring BASIC statements such as MUSIC, TEMPO, and BEEP to control pitch, duration, and rhythm through ASCII data strings.[7][10] The development of MML was influenced by earlier text-based music notation systems used in mainframe computing during the 1960s and 1970s, such as those in programs like MUSIC IV, which allowed composers to describe musical structures algorithmically, but adapted for the limitations of affordable home computing hardware lacking dedicated synthesizers. This shift addressed the need for simple, programmable music synthesis on resource-constrained 8-bit systems, enabling users to create chiptune-style audio without complex assembly code.[11] Early adoption of MML occurred primarily among Japanese microcomputers, beginning with the MSX standard launched in 1983, where it became a de facto method for sound programming via the PLAY statement in MSX BASIC, supporting polyphonic playback on the system's Programmable Sound Generator (PSG).[12] Key milestones in MML's initial spread included its integration into BASIC interpreters as early as 1978 on Sharp systems and by 1984 on platforms like the NEC PC-8801, where it facilitated music creation alongside the system's PSG hardware; early documentation appeared in Sharp MZ-80K user manuals from 1978 and subsequent guides in the early 1980s, solidifying its role in hobbyist and game development.[7] By the 1990s, MML began transitioning toward more advanced variants for emerging multimedia applications.[7]Core Syntax and Elements
Basic Note and Rhythm Notation
In Music Macro Language (MML), musical pitches are denoted using the letters A through G, typically in lowercase to distinguish them from commands, representing the notes of the diatonic scale from A to G.[13][14] These letters can be modified with sharps (+) or flats (-) for chromatic alterations, such as c+ for C-sharp or d- for D-flat.[14] Octave shifts are managed explicitly with the 'o' command followed by a digit from 1 to 8, where o4 sets the octave containing middle C (C4); subsequent notes adopt this octave until changed, and relative adjustments use '>' to ascend or '<' to descend by one octave.[13][14] For instance, the sequenceo4 c d e plays C, D, and E in the fourth octave.[13]
Rhythm and duration are specified by appending a number after the note letter, which scales the length relative to a whole note (1); common values include 4 for a quarter note or 8 for an eighth note, with the default assuming quarter-note length if unspecified.[13][14] The global default length can be set with 'l' followed by a number (e.g., l8 for eighth notes), applying to notes without explicit durations.[13] Ties extend a note's duration using '&' to connect it to the next identical pitch, such as c4 & c4 equating to a half note.[13] Dotted notes, indicated by '.', add half the note's value (e.g., c4. for a dotted quarter note), allowing for rhythmic variation without ties.[14]
Rests are notated with 'r' followed by an optional duration number, mirroring note syntax; for example, r4 inserts a quarter-note rest, and the default length follows the current 'l' setting.[13][14] A basic sequence might read o4 l4 c d r e, producing quarter notes C and D, a quarter rest, and E in the fourth octave.[13]
Tempo is established at the sequence's start with 't' followed by a value in beats per minute (typically 30 to 255), such as t120 for 120 BPM, influencing the playback speed across all channels.[14][1] Volume levels are set per channel or note using 'v' followed by an integer from 0 (silent) to 15 (maximum), for example v8 before a note to play at medium volume; this scales the amplitude in implementations supporting 4-bit volume resolution.[14][1] While classical MML variants like the MSX BASIC PLAY command use uppercase equivalents (e.g., O for octave, T for tempo), modern chiptune applications standardize on lowercase for consistency.[12][14]
Control and Modulation Commands
In Music Macro Language (MML), control commands manage the flow and structure of musical sequences, enabling composers to organize playback without redundant notation. Looping and repetition are fundamental, with square brackets enclosing a sequence followed by a repeat count, such as[CDE]4 to play the notes C, D, and E four times in succession. This construct supports nested loops up to 32 levels in implementations like PMD, allowing complex patterns while optimizing code length for resource-constrained systems. Additionally, the L command designates a global loop point, returning playback to that position upon reaching the sequence end, which facilitates indefinite repetition in channels until interrupted.[15]
Modulation commands adjust pitch and timbre dynamically, with > and < shifting the octave up or down by one, respectively, for relative changes without specifying absolute values; for instance, >C raises C to the next octave. Vibrato and envelope effects, often platform-specific, apply modulation to pitch or volume, such as using envelope shaping commands like 'E' in PMD to define parameters for SSG/PCM envelopes, or @MP in MCK for vibrato depth, speed, and delay. These commands enhance expressiveness in chiptune compositions by simulating analog-like variations on digital hardware.[15][14]
Channel and polyphony controls support multi-voice arrangements, where sequences for different tracks are separated by commas in a single string, such as CDE,EFG to assign the first melody to one channel and a harmony to another. Gate length modulates note sustain, with Q followed by a value like Q4 setting a 50% gate for staccato effects, cutting the note duration relative to its full length. End-of-sequence markers like ; terminate input strings, preventing parsing errors and allowing comments, ensuring clean termination in multi-channel notations. These features vary slightly across MML variants, such as MSX's emphasis on PSG channels versus PMD's FM support.[12][15]
Versions and Variants
Classical MML
Classical MML originated in 1978 as an integrated feature within the BASIC interpreter of the Sharp MZ-80 series computers, using the MUSIC statement to generate simple melodies through the system's speaker without dedicated audio hardware beyond the built-in sound capabilities. This early implementation marked one of the first standardized notations for algorithmic music in consumer hardware, tied closely to the era's limitations.[16] The syntax of classical MML was constrained by hardware, supporting mono output, limited note ranges (typically three octaves), and basic duration specifications. Notes were denoted by letters A-G, with # for sharps, R for rests, numbers 1-9 after notes for length (1 longest, 9 shortest), and octave shifts via '+' for higher or numbers for specific octaves. The TEMPO statement set playback speed (e.g., TEMPO 7), and strings were limited by available memory, often short to avoid overflow. Integration with BASIC allowed dynamic generation using variables, such as MUSIC M, where M holds the melody, enabling loops or variations. Errors for invalid syntax halted execution with diagnostic messages.[16] A representative example of classical MML in Sharp MZ BASIC is:This sets a moderate tempo and plays D, E, F#, G, A as default-length notes (quarter notes), demonstrating the concise notation for embedding music in programs. Such syntax laid foundational conventions for note and control symbols, influencing later variants despite its simplicity.[16]300 TEMPO 7 310 MUSIC "DE#FGA"300 TEMPO 7 310 MUSIC "DE#FGA"
Modern MML
Modern MML emerged in the early 1980s with implementations in Microsoft BASIC on Japanese personal computers, such as the NEC PC-6001 (1981) and MSX systems (1983), adapting classical forms for more advanced home computers and consoles. This version expanded flexibility for compositions, supporting multi-channel playback for polyphony via the Programmable Sound Generator (PSG) in MSX, without reliance on hardware-specific routines. The PLAY statement in MSX BASIC processes MML strings, as in PLAY "CDE" for a basic scale on the primary channel, with enhanced commands for octaves (O), lengths (L), and tempo (T). Tools like SmileBASIC and PPMCK further this by defining sequences across tracks, e.g., :0 for melody and :1 for harmony.[12][17][5] Key enhancements include control over parameters like volume envelopes and modulation. In MCK for NES chiptunes, envelopes use @v0={10 9 8 7 6 5 4 3 2} for decaying volume. Repetition via [sequence]count enables structured pieces, and length limits are lifted; SmileBASIC allows up to 1 million characters, while MCK uses #BANK-CHANGE for extensions beyond 8K.[14][17] In chiptune communities, syntax varies for 8-bit hardware, with Japanese scenes using MML for retro emulation (e.g., VRC6 for NES) and Western demoscene blending with trackers for chips like SID or 2A03. Tools like XPMCK compile for multiple targets including Game Boy and Commodore 64.[5][18][19] A representative multi-track example in SmileBASIC-style syntax:t120 :0 o4 C4 D4 E4 G4 :1 o3 G4 r4 <A4 r4 B4. Here, t120 sets tempo, :0 plays melody in octave 4, :1 provides bass in octave 3 with rests, synchronizing for harmony.[17]