====== The abc music standard 2.1 (Dec 2011) ====== //The original source of this standard can be found at [[https://abcnotation.com/wiki/abc:standard:v2.1]].// ** Chris Walshaw ** \\ [[https://abcnotation.com/contact|abcnotation.com/contact]] \\ [[https://chriswalshaw.co.uk|chriswalshaw.co.uk]] ===== 1. Introduction ===== Abc is a text-based music notation system designed to be comprehensible by both people and computers. Music notated in abc is written using characters - letter, digits and punctuation marks - on paper or in computer files. This description of abc has been created for those who wish to understand the notation, and for implementers of abc software applications. Some example tunes are included in [[#sample_abc_tunes|sample abc tunes]]. ==== 1.1 How to read this document ==== Start at the beginning and work through to the end. Alternatively, for selected highlights, take a look at [[#how to avoid reading this document|how to avoid reading this document]]. === 1.1.1 Terminology / definitions === Note that the following terms have specific meanings in the context of the abc standard. For convenience, each time one of these terms is used in the standard it is linked to the section in which it is defined: * [[#abc file definition|abc file]] * [[#abc fragment definition|abc fragment]] * [[#abc tune definition|abc tune]] * [[#abc tunebook definition|abc tunebook]] * [[#code line-break definition|code line-break]] * [[#comment definition|comment]] * [[#embedded definition|embedded]] * [[#empty line definition|empty line]] * [[#file header definition|file header]] * [[#free text definition|free text]] * [[#information field definition|information field]] * [[#inline field definition|inline field]] * [[#music code definition|music code]] * [[#score line-break definition|score line-break]] * [[#stylesheet directive definition|stylesheet directive]] * [[#text string definition|text string]] * [[#tune body definition|tune body]] * [[#tune header definition|tune header]] * [[#typeset text definition|typeset text]] Please see also [[http://www.ietf.org/rfc/rfc2119.txt]] for formal definitions of the key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL. Finally, the word // VOLATILE // is used to indicate sections which are under active discussion and/or likely to change in some future version of the standard. ==== 1.2 How to avoid reading this document ==== The abc standard contains a lot of information, much of which will not be immediately useful to the beginner. Apart from reading this section, [[#introduction|1. Introduction]], newcomers are recommended to familiarise themselves with all of [[#abc file structure|2.2 Abc file structure]], [[#information fields|3.0 Information fields]], a few subsections in [[#description of information fields|3.1 Description of information fields]] (in particular [[#xreference number|3.1.1]], [[#ttune title|3.1.2]], [[#mmeter|3.1.6]], [[#lunit note length|3.1.7]] and [[#kkey|3.1.14]]), [[#use of fields within the tune body|3.2 Use of fields within the tune body]], and as much of section [[#the tune body|4. The tune body]] as is desired (but in particular [[#pitch|4.1]], [[#note lengths|4.3]], [[#beams|4.7]], [[#repeat bar symbols|4.8]]). Newcomers are also advised to take a look at section [[#sample abc tunes|13. Sample abc tunes]] and one of the [[#abc tutorials|abc tutorials]] that is available. After that, it may depend on what you want to use abc for, but further reading suggestions would be: * [[#lyrics|5. Lyrics]] for transcribing songs * [[#typesetting|6.1 Typesetting]] for printing abc transcriptions in staff notation * [[#multiple voices|7. Multiple voices]] for working with multi-voice music ==== 1.3 Abc tutorials ==== This document is also best read in conjunction with an introduction to abc notation. Several are available - see, for example: * [[https://abcnotation.com/learn|abcnotation.com/learn]] - a number of tutorials are linked from here * http://abcplus.sourceforge.net/#ABCGuide * http://www.lesession.co.uk/abc/abc_notation.htm * http://trillian.mit.edu/~jc/music/abc/doc/ABCtutorial.html ==== 1.4 Abc extensions ==== Since the abc notation system was originally written, a large number of abc software packages (programs which: produce printed sheet music; play or create audio files, usually MIDI; search or organise tune databases; or that analyse or manipulate tunes in some way) have been developed. However, not all of them follow this standard absolutely. This document aims at solving, or at least reducing, the problem of incompatibility between applications. Nevertheless, when using abc it is good to be aware of the existence of such extensions. Extensions implemented by some major abc packages are described at the following links: * http://moinejf.free.fr/abcm2ps-features.txt - extensions implemented by [[https://abcnotation.com/software#abcm2ps|abcm2ps]] * http://abc.sourceforge.net/standard/abc2midi.txt - extensions implemented by [[https://abcnotation.com/software#abcMIDI|abc2midi]] * http://www.barfly.dial.pipex.com/bfextensions.html - extensions implemented by [[https://abcnotation.com/software#BarFly|BarFly]] * http://www.lautengesellschaft.de/cdmm/userguide/userguide.html - extensions implemented by [[https://abcnotation.com/software#abctab2ps|abctab2ps]] ==== 1.5 Further information and changes ==== Questions about this standard, or abc in general, can be addressed to the abcusers e-mail list, or the abcnotation forums: * http://groups.yahoo.com/group/abcusers/ (abcusers - subscriptions and archive of posts) * http://www.mail-archive.com/abcusers@argyll.wisemagic.com/ (abcusers - archive of old posts) * [[https://abcnotation.com/discuss|abcnotation.com/discuss]] To propose changes to the standard, please read * [[https://abcnotation.com/wiki/abc:standard:route-map|abcnotation.com/wiki/abc:standard:route-map]] - a route map of proposed changes to the standard plus instructions for proposing changes ==== 1.6 Document locations ==== This document can be found at: * [[https://abcnotation.com/wiki/abc:standard:v2.1|abcnotation.com/wiki/abc:standard:v2.1]] The latest version of the standard, plus links to older versions and other developmental work, can always be found via: * [[https://abcnotation.com/wiki/abc:standard|abcnotation.com/wiki/abc:standard]] ===== 2. Abc files, tunes and fragments ===== Tunes written in abc are normally stored in [[#abc file definition|abc files]], either on a computer's hard-drive or linked from a web-page. However, an increasing number are found on web-pages or in databases. This section describes the basic structure of [[#abc file definition|abc files]] and [[#abc tune definition|abc tunes]], as well as a definition for including fragments of abc tunes elsewhere (e.g. web-pages). ==== 2.1 Abc file identification ==== All [[#abc file definition|abc files]] should have the extension ".abc" (all lower-case) on all platforms. // Comment: // Some web-servers only allow a limited selection of file types; in this case a ".txt" extension is the best alternative. Every [[#abc file definition|abc file]] should begin with the string ''%abc''. An optional version number may follow on the same line, e.g. %abc-2.1 Version numbers of 2.1 or higher indicate that the [[#abc file definition|abc file]] is to be [[#strict_interpretation|interpreted strictly]] according to the corresponding abc standard; if the version number is missing, the file will be treated under [[#loose_interpretation|loose interpretation]]. The [[#version field|version field]] may also be used to indicate abc versions for individual tunes. // Note for developers: // Software should ignore the [[http://en.wikipedia.org/wiki/Byte_order_mark|byte order mark]] (BOM) if encountered as the first character of the file. When an [[#abc file definition|abc file]] is included in a multi-part e-mail, its MIME type must be "text/vnd.abc" (see [[http://www.iana.org/assignments/media-types/text/vnd.abc|IANA text/vnd.abc]]). ==== 2.2 Abc file structure ==== {{anchor:abc_file_definition}}An **abc file** consists of one or more [[#abc tune definition|abc tune]] transcriptions, optionally interspersed with [[#free text definition|free text]] and [[#typeset text definition|typeset text]] annotations. It may optionally start with a [[#file header definition|file header]] to set up default values for processing the file. The [[#file header definition|file header]], [[#abc tune definition|abc tunes]] and [[#free text and typeset text|text annotations]] are separated from each other by [[#empty line definition|empty lines]] (also known as blank lines). {{anchor:abc_tunebook_definition}}An [[#abc file definition|abc file]] with more than one tune in it is called an **abc tunebook**. === 2.2.1 Abc tune === {{anchor:abc_tune_definition}}An **abc tune** itself consists of a [[#tune header definition|tune header]] and a [[#tune body definition|tune body]], terminated by an [[#empty line definition|empty line]] or the end of the [[#abc file definition|file]]. It may also contain [[#comment definition|comment lines]] or [[#stylesheet directive definition|stylesheet directives]]. {{anchor:tune_header_definition}}The **tune header** is composed of several [[#information field definition|information field]] lines, which are further discussed in [[#information fields|information fields]]. The [[#tune header definition|tune header]] should start with an ''X:''(reference number) field followed by a ''T:''(title) field and finish with a ''K:''(key) field. {{anchor:tune_body_definition}}The **tune body**, which contains the [[#music code definition|music code]], follows immediately after. Certain fields may also be used inside the tune body - see [[#use of fields within the tune body|use of fields within the tune body]]. It is legal to write an [[#abc tune definition|abc tune]] without a [[#tune body definition|tune body]]. This feature can be used to document tunes without transcribing them. {{anchor:music_code_definition}}Abc **music code** lines are those lines in the [[#tune body definition|tune body]] which give notes, bar lines and other musical symbols - see [[#the tune body|the tune body]] for details. In effect, music code is the contents of any line which is not an [[#information field definition|information field]], [[#stylesheet directive definition|stylesheet directive]] or [[#comment definition|comment line]]. === 2.2.2 File header === {{anchor:file_header_definition}}The file may optionally start with a **file header** (immediately after the version field), consisting of a block of consecutive [[#information field definition|information fields]], [[#stylesheet directive definition|stylesheet directives]], or both, terminated with an [[#empty line definition|empty line]]. The [[#file header definition|file header]] is used to set default values for the tunes in the file. The [[#file header definition|file header]] may only appear at the beginning of a file, not between tunes. Settings in a tune may override the [[#file header definition|file header]] settings, but when the end of a tune is reached the defaults set by the [[#file header definition|file header]] are reinstated. Applications which extract separate tunes from a file must insert the fields of the original [[#file header definition|file header]] into the header of the extracted tune. However, since users may manually extract tunes without regard to the [[#file header definition|file header]], it is not recommended to use a [[#file header definition|file header]] in an [[#abc tunebook definition|abc tunebook]] that is to be distributed. === 2.2.3 Free text and typeset text === The terms [[#free text definition|free text]] and [[#typeset text definition|typeset text]] refer to any text not directly included within the [[#information field definition|information fields]] in a [[#tune header definition|tune header]]. Typically such text is used for annotating [[#abc tunebook definition|abc tunebooks]]; [[#free text definition|free text]] is for annotating the [[#abc file definition|abc file]] but is not included in the typeset score, whereas [[#typeset text definition|typeset text]] is intended for printing out. {{anchor:free_text_definition}}**Free text** is just that. It can be included anywhere in an [[#abc file definition|abc file]], after the [[#file header definition|file header]], but must be separated from [[#abc tune definition|abc tunes]], [[#typeset text definition|typeset text]] and the [[#file header definition|file header]] by [[#empty line definition|empty lines]]. Typically it is used for annotating the [[#abc file definition|abc file]] but in principle can be any text not containing [[#information field definition|information fields]]. // Comment: // Since raw html markup and email headers are treated as [[#free text definition|free text]] (provided they don't inadvertently contain [[#information field definition|information fields]]) this means that abc software can process a wide variety of text-based input files just by ignoring non-abc code. By default [[#free text definition|free text]] is not included in the printed score, although typesetting software may offer the option to print it out (e.g. via a command line switch or GUI checkbox). In this case, the software should treat the [[#free text definition|free text]] as a [[#text string definition|text string]], but may format it in any way it chooses. {{anchor:typeset_text_definition}}**Typeset text** is any text specified using [[#text directives|text directives]]. It may be inserted anywhere in an [[#abc file definition|abc file]] after the [[#file header definition|file header]], either separated from tunes by [[#empty line definition|empty lines]], or included in the [[#tune header definition|tune header]] or [[#tune body definition|tune body]]. [[#typeset text definition|Typeset text]] should be printed by typesetting programs although its exact position in the printed score is program-dependent. [[#typeset text definition|Typeset text]] that is included in an [[#abc tune definition|abc tune]] (i.e. within the [[#tune header definition|tune header]] or [[#tune body definition|tune body]]), must be retained by any programs, such as databasing software, that splits an [[#abc file definition|abc file]] into separate [[#abc tune definition|abc tunes]]. === 2.2.4 Empty lines and line-breaking === {{anchor:empty_line_definition}}**Empty lines** (also known as blank lines) are used to separate [[#abc tune definition|abc tunes]], [[#free text definition|free text]] and the [[#file header definition|file header]]. They also aid the readability of [[#abc file definition|abc files]]. Lines that consist entirely of white-space (space and tab characters) are also regarded as [[#empty line definition|empty lines]]. Line-breaks (also known as new lines, line feeds, carriage returns, end-of-lines, etc.) can be used within an [[#abc file definition|abc file]] to aid readability and, if required, break up long input lines - see [[#continuation of input lines|continuation of input lines]]. More specifically, line-breaks in the [[#music code definition|music code]] can be used to structure the abc transcription and, by default, generate line-breaks in the printed music. For more details see [[#typesetting_line-breaks|typesetting line-breaks]]. === 2.2.5 Comments and remarks === {{anchor:comment_definition}}A percent symbol (''%'') will cause the remainder of any input line to be ignored. It can be used to add a **comment** to the end of an abc line or as a **comment line** in its own right. (To get a percent symbol, type ''\%'' - see [[#text strings|text strings]].) {{anchor:remark_definition}}Alternatively, you can use the syntax ''[r:remark]'' to write a **remark** in the middle of a line of music. // Example: // |:DEF FED| % this is an end of line comment % this is a comment line DEF [r:and this is a remark] FED:| Abc code which contains [[#comment definition|comments]] and remarks should be processed in exactly the same way as it would be if all the [[#comment definition|comments]] and [[#remark definition|remarks]] were removed (although, if the code is preprocessed, and [[#comment definition|comments]] are actually removed, the [[#stylesheet directive definition|stylesheet directives]] should be left in place). Important clarification: lines which just contain a [[#comment definition|comment]] are processed as if the entire line were removed, even if the [[#comment definition|comment]] is preceded by white-space (i.e. the ''%'' symbol is the not first character). In other words, removing the [[#comment definition|comment]] effectively removes the entire line and so no [[#empty line definition|empty line]] is introduced. === 2.2.6 Continuation of input lines === It is sometimes necessary to tell abc software that an input line is continued on the next physical line(s) in the [[#abc file definition|abc file]], so that the two (or more) lines are treated as one. In abc 2.0 there was a universal continuation character (see [[#outdated continuations|outdated continuations]]) for this purpose, but it was decided that this was both unnecessary and confusing. In abc 2.1, there are ways of continuing each of the 4 different input line types: [[#music code definition|music code]], [[#information field definition|information fields]], [[#comment definition|comments]] and [[#stylesheet directive definition|stylesheet directives]]. In abc [[#music code definition|music code]], by default, line-breaks in the code generate line-breaks in the typeset score and these can be suppressed by using a backslash (or by telling abc typesetting software to ignore line-breaks using ''I:linebreak $'' or ''I:linebreak '') - see [[#typesetting line-breaks|typesetting line-breaks]] for full details. // Comment for programmers: // The backslash effectively acts as a continuation character for [[#music code definition|music code]] lines, although, for those used to encountering it in other computer language contexts, its use is very abc-specific. In particular it can continue [[#music code definition|music code]] lines through [[#information field definition|information fields]], [[#comment definition|comments]] and [[#stylesheet directive definition|stylesheet directives]]. The 3 other input line types can be continued as follows: * [[#information field definition|information fields]] can be continued using ''+:'' at the start of the following line - see [[#field continuation|field continuation]]; * [[#comment definition|comments]] can easily be continued by adding a ''%'' symbol at the start of the following line - since they are ignored by abc software it doesn't matter how many lines they are split into; * most [[#stylesheet directive definition|stylesheet directives]] are too short to require a continuation syntax, but if one is required then use the ''I:'' form (see ''[[#iinstruction|I:instruction]]''), in place of ''%%'' and continue the line as a field - see [[#field continuation|field continuation]]. // Comment for developers: // Unlike other languages, and because of the way in which both [[#information field definition|information fields]] and [[#music code definition|music code]] can be continued through [[#comment definition|comments]], [[#stylesheet directive definition|stylesheet directives]] and (in the case of [[#music code definition|music code]]) [[#information field definition|information fields]], it is generally not possible to parse [[#abc file definition|abc files]] by pre-processing continuations into single lines. Note that, with the exception of abc [[#music code definition|music code]], continuations are unlikely to be needed often. Indeed in most cases it should be possible, although not necessarily desirable, to write very long input lines, since most abc editing software will display them as wrapped within the text editor window. // Recommendation: // Despite there being no limit on line length in [[#abc file definition|abc files]], it is recommended that users avoid writing abc code with very long lines. In particular, judiciously applied line-breaks can aid the (human) readability of abc code. More importantly, users who send [[#abc tune definition|abc tunes]] with long lines should be aware that email software sometimes introduces additional line-breaks into lines with more than 72 characters and these may even cause errors when the resulting tune is processed. ==== 2.3 Embedded abc and abc fragments ==== {{anchor:embedded_definition}}Traditionally abc has been used in dedicated [[#abc file definition|abc files]]. More recently, however, the possibility has arisen to include [[#abc tune definition|abc tunes]], and even fragments, within other document types. An abc element included within another document type is referred to as **embedded** in that document. Often, although not always, some form of markup is used to indicate where the [[#embedded definition|embedded]] abc code starts and finishes. // Example: // Within an html document a tune could be included as follows:
  X:1
  T:Title
  K:C
  DEF FED:|
  
// Important note: // The abc standard makes no stipulation about //how// the abc code is included in the document. For example, in html it could be via a ''%%
%%'', ''%%
%%'', '''', ''