Music Macro Language (MML) is a music description language used for sequencing music on computers and video game systems. Music is written as strings of letters and numbers representing notes, durations and control parameters, which are then interpreted or compiled for the target system's sound hardware.

The designation is documented in print by May 1982, in a description of the OKI if-800. Microsoft source code from 1983 labels the BASIC implementation "MUSIC MACRO LANGUAGE", and NEC documentation from 1986 describes the channel strings of as "MML (Music Macro Language)".

History

Origins of the term

The designation Music Macro Language (MML) is documented in published sources by May 1982. In that month's issue of BYTE, an article on Japanese personal computers described the OKI if-800 using the term for its music-string syntax. The article states that "another sublanguage called MML (Music Macro Language) is used".

Microsoft documentation for GW-BASIC later described the syntax used by the statement as "a music macro language" embedded in a string expression. The notation is treated as a non-MIDI music code in Beyond MIDI: The Handbook of Musical Codes.

Music-string notation itself predates GW-BASIC. Contemporaneous BASIC documentation, such as the OKI BASIC manual, describes the statement for musical sequences but does not use the term "Music Macro Language".

Microsoft BASIC and NEC documentation

Microsoft's 1983 GW-BASIC source code labels the implementation "PLAY - MUSIC MACRO LANGUAGE". The implementation supplies a table of music commands to a shared macro-language driver, which the source identifies as supporting the Microsoft graphics and sound macro languages.

By 1986, NEC's PC-8801mkIIMR N88-BASIC / N88-日本語BASIC Reference Manual documented the extended statement and called its channel strings "MML (Music Macro Language)". The manual gives command tables and explanations for notes, duration, octave, tempo, rests, volume, articulation, timbre selection and FM/SSG-related parameters.

Neither the originator of the term nor any direct relationship between the OKI if-800 implementation and the Microsoft implementation is identified in these sources.

Dedicated music drivers and compilers

During the 1980s MML was also used as input to dedicated music-development systems, and not only as an argument to a BASIC statement. Tanaka describes the PC-8801 sound system SPLIT in connection with MML-based music development and compilation, and states that general distribution of SPLIT began at the summer Comic Market on 14 August 1988 and that twelve releases followed through 1991. The same source discusses FMP and PMD within the history of MML-based Japanese personal computer music systems.

Background

Early automatic music generation functions were used in arcade video games. Early examples of arcade video game music include Gun Fight (1975) and Circus (1977). The appearance of Space Invaders by Taito in Japanese amusement arcades in 1978 marked a considerable expansion of the domestic video game market.

Music in these systems was generally implemented as proprietary game software. The Intel 8253 programmable interval timer, released by Intel in 1978, provided one hardware approach to programmable tone generation; its Mode 3 square-wave generator was used for music in the kit computer MZ-40K () by Sharp Corporation, manufactured in Japan in May 1978. Another microcomputer, the Hitachi , used a 5-bit digital-to-analog converter for automated music reference signals, together with methods of generating music under BASIC software control. That machine was assembled by Hitachi and made in Japan in September 1978. The MZ-40K documentation included program sources for some software routines.

Music-string notation and MML syntax

Sharp MZ BASIC music-string notation

On the MZ-80K and related Sharp MZ systems, music-string facilities were provided through the SP-1002 monitor IOCS routine and the SP-5001 BASIC operating system, using the BASIC statements , and . The MZ-80K was an 8-bit machine with a Z80 processor, made by Sharp Corporation in Japan in 1978, and it used Intel 8253 hardware with memory-mapped I/O.

Syntax

The music string is supplied to the statement. Notes are specified within a three-octave range, and a piece is a sequence of single monophonic tones.

"+" (or, in some older code, " ̄") indicates the upper octave, and "−" (or, in some older code, "_") the lower octave. The characters C, D, E, F, G, A and B correspond to the degrees of the scale. A semitone is indicated by following the note with a "#" character. Note names are followed by a tone length, given as a number from 0 to 9; R indicates a rest and is likewise followed by a number from 0 to 9. The resulting duration is the internal value multiplied by the value. Tone length 0 corresponds to a demisemiquaver (SP-1002 internal value 1) and 9 to a whole note (SP-1002 internal value 32). Music is played by a call to the routine at address $0030 of the SP-1002 IOCS.

+ The sound length Value Length 0 1/32 1 1/16 2 dotted 1/16 3 1/8 4 dotted 1/8 5 1/4 6 dotted 1/4 7 1/2 8 dotted 1/2 9 1

The statement accepts values from 1 to 9, 1 being the slowest; corresponds approximately to T = 120.

Example

The following is a transcription of the Japanese song "tōryanse" in the -statement notation of the MZ-731 with SHARP S-BASIC 1Z-007B (upward compatible with SP-5001). Licensed #AAAP, including Creative Commons CC-BY-SA and the GNU Free Documentation License. 10 TEMPO 4 20 A$="E5R1E3R0D3R0E3R0E1R0D1R0-B4R1" 30 B$="F3R0F1R0F1R0A3R0F1R0E1R0F1R0E1R0D1R0D1R0E4R1" 40 C$="C3R0C1R0C1R0E3R0C1R0-B1R0C1R0-B1R0-A1R0-A1R0-B4R1" 50 D$="E1R0E1R0E1R0E1R0E1R0E1R0D1R0E1R0E1R0E1R0D1R0-A1R0-A1R0-B4R1" 60 E$="-A1R0-B1R0C1R0D1R0E1R0F1R0E1R0F3R1A3R1B1R0A1R0F3R0E3R0E1R0D1R0E4R1" 100 MUSIC A$+B$+B$ 110 MUSIC C$+C$+B$ 120 MUSIC C$+D$+E$

MML in BASIC PLAY implementations

MML of the kind found in statements originated in Microsoft BASIC and was widely used on 8-bit and 16-bit Japanese personal computers, where BASIC was generally supplied in ROM. The NEC PC-6001 of 1981 combined Microsoft BASIC with a programmable sound generator, and the notation was particularly widespread on NEC machines such as the PC-8801. The designation MML is documented for personal computer music strings by May 1982 in the description of the OKI if-800, and Microsoft's 1983 GW-BASIC source code labels its implementation "PLAY - MUSIC MACRO LANGUAGE", routing its command table through a shared macro-language driver. NEC documentation likewise records BASIC music-string implementations: the PC-6001mkII N60m-BASIC manual documents with up to three simultaneous parts, and the 1986 PC-8801mkIIMR reference manual calls the channel strings "MML (Music Macro Language)" while documenting extensions for programmable sound hardware.

Following the 2001 release of mck (Music Creation Kit), which compiles MML into music for the Nintendo Entertainment System, awareness and use of MML increased. The notation remains in use among Japanese electronic musicians and among musicians who write chiptunes.

Syntax

In the Microsoft and NEC implementations, a or statement takes an argument containing the music data as a string. Microsoft's 1983 source shows a command-table parser for the string, and NEC's 1986 manual documents the MML commands accepted by . The format is textual, letters and numbers describing the musical notes to be played, but implementations differ in their command sets and in the extensions they add for audio synthesis parameters or for common musical figures such as arpeggios.

Elements common to many implementations are listed below; individual dialects may omit, rename or extend them, and requirements such as letter case also vary.

– The letters to correspond to the musical pitches and cause the corresponding note to be played. Sharp notes are produced by appending a or , and flat notes by appending a . The length of a note is specified by appending a number representing its length as a fraction of a whole note; for example, represents a C eighth note, and an F♯ half note. – A pause or rest, sometimes also . IBM Personal Computer BASIC Version 1.10 uses , as do GW-BASIC-compatible speaker interfaces such as the Linux and BSD speaker devices. The length of the rest is specified in the same manner as the length of a note; for example, produces a whole rest. – Followed by a number, selects the octave in which the instrument plays. , – Step up or down by one octave. – Followed by a number, specifies the default length used by notes or rests that do not define one explicitly. For example, produces four eighth notes followed by four sixteenth notes. – Followed by a number, sets the volume of the instrument. The permitted range depends on the sound hardware. Some implementations also allow an ADSR envelope to be applied to the amplitude of each note. – Followed by a number, sets the tempo in beats per minute. On hardware with more than one sound channel it is often possible to set each channel to a different tempo.

Most implementations add further keywords and symbols for system-specific extensions.

Example The following is an MML transcription of Dance of the Cuckoos, with white space added for clarity; some MML interpreters require it to be removed before playback.

t104 l4 > c16f16 a>c8<a c16f16 a>c8<a c8 b-8>c8<b-8 g c8 a8>c8<a8 f c16f16 a>c8<a c16f16 a>c8<a c8 b-8>c8<b-8 g >c8 <f2

The following is a transcription of "tōryanse" in the N60-BASIC of the PC-6001 (NEC PC-6000 series), given for comparison with the Sharp MZ example above.Programmed by MOTOI Kenkichi, 11 November 2024. Licensed #AAAP, including Creative Commons CC-BY-SA and the GNU Free Documentation License. 10 A$="o4e2r32e4r32d4r32e4r32e8r32d8r32o3b2r16" 20 B$="o4f4r32f8r32f8r32a4r32f8r32e8r32f8r32e8r32d8r32d8r32e2r16" 30 C$="o4c4r32c8r32c8r32e4r32c8r32o3b8r32o4c8r32o3b8r32a8r32a8r32b2r16" 40 D$="o4e8r32e8r32e8r32e8r32e8r32e8r32d8r32" 50 E$="o4e8r32e8r32e8r32d8r32o3a8r32a8r32b2r16" 60 F$="o3a8r32b8r32o4c8r32d8r32e8r32f8r32e8r32" 70 G$="o4f4r32a4r32b8r32a8r32f4r32" 80 H$="e4r32e8r32d8r32e2r16" 100 PLAY "t120" 110 PLAY A$ 120 PLAY B$ 130 PLAY B$ 140 PLAY C$ 150 PLAY C$ 160 PLAY B$ 170 PLAY C$ 180 PLAY D$ 190 PLAY E$ 200 PLAY F$ 210 PLAY G$ 220 PLAY H$

SMX

Standard Musical Expression (SMX) is a music-string format used by the statement of Microsoft QBASIC, BASICA and GW-BASIC. In Beyond MIDI, MML is listed among the non-MIDI codes for sound representation and control, whereas SMX is listed among the interchange codes. Microsoft's own GW-BASIC source calls the implementation a music macro language. The version used by GW-BASIC is part of the modern BSDs, including FreeBSD, NetBSD, OpenBSD and MirOS; the language is described in speaker(4).

BASIC music-string comparison

The following examples give the same melody, "Twinkle, Twinkle, Little Star", in two BASIC music-string syntaxes: the notation of Sharp MZ BASIC and the notation of NEC N60-BASIC.

Sharp MZ BASIC (SP-5030)

Characteristics:

Tempo is set by a separate BASIC command. The melody is stored in a string variable. Further phrases are appended by BASIC string concatenation. Note lengths are expressed numerically after each pitch. Playback is performed by the BASIC statement. Output is monophonic, owing to the hardware of early systems. Sound is produced through the internal speaker, driven directly by the computer.

Example

10 TEMPO 4 20 A$="C3C3G3G3A3A3G6" 30 A$=A$+"F3F3E3E3D3D3C6" 40 A$=A$+"G3G3F3F3E3E3D6" 50 A$=A$+"G3G3F3F3E3E3D6" 60 A$=A$+"C3C3G3G3A3A3G6" 70 A$=A$+"F3F3E3E3D3D3C6" 80 MUSIC A$

The musical data is built up step by step as a BASIC string variable, extended by concatenation () before being passed to the command for playback.

NEC PC-6001 (N60-BASIC)

The PC-6001mkII N60m-BASIC manual describes as a statement for generating music and documents the use of up to three simultaneous parts.